abiEncode method
Encodes a array of arbitrary types to ABI-encoded bytes.
Implementation
@override
EncoderResult abiEncode(AbiParameter params, List<dynamic> input) {
final param = _ABIUtils.toArrayType(params);
final encodedParams = input.map((e) => param.item1.abiEncode(e)).toList();
final dynamicItems =
encodedParams.isNotEmpty && encodedParams.first.isDynamic;
bool isDynamic = param.item2 == -1;
if (!isDynamic && input.length != param.item2) {
throw const SolidityAbiException("Invalid argument length detected.");
}
if (isDynamic || dynamicItems) {
final encode = _ABIUtils.encodeDynamicParams(encodedParams);
if (isDynamic) {
final length = const NumbersCoder()
.abiEncode(AbiParameter.uint256, BigInt.from(encodedParams.length))
.encoded;
return EncoderResult(
isDynamic: true,
encoded: encodedParams.isEmpty ? length : [...length, ...encode],
name: params.name);
}
return EncoderResult(isDynamic: true, encoded: encode, name: params.name);
}
final resultBytes = encodedParams.map((e) => e.encoded);
return EncoderResult(
isDynamic: false,
encoded: [for (final i in resultBytes) ...i],
name: params.name);
}