abiEncode method

  1. @override
EncoderResult abiEncode(
  1. AbiParameter params,
  2. List input
)
override

Encodes a tuple of dynamic values to ABI-encoded bytes.

Implementation

@override
EncoderResult abiEncode(AbiParameter params, List<dynamic> input) {
  bool isDynamic = false;
  List<EncoderResult> encoded = [];
  if (input.length != params.components.length) {
    throw const SolidityAbiException("Invalid argument length detected.");
  }
  for (int i = 0; i < params.components.length; i++) {
    final paramComponent = params.components[i];
    EncoderResult result = paramComponent.abiEncode(input[i]);
    if (result.isDynamic) {
      isDynamic = true;
    }
    encoded.add(result);
  }
  if (isDynamic) {
    return EncoderResult(
        isDynamic: true,
        encoded: _ABIUtils.encodeDynamicParams(encoded),
        name: params.name);
  }
  final re = encoded.map((e) => e.encoded).toList();
  return EncoderResult(
      isDynamic: false, encoded: [for (var i in re) ...i], name: params.name);
}