decode method

  1. @override
DecoderResult<List> decode(
  1. AbiParameter params,
  2. List<int> bytes
)
override

Decodes an ABI-encoded array of arbitrary types.

Implementation

@override
DecoderResult<List<dynamic>> decode(AbiParameter params, List<int> bytes) {
  final extract = _ABIUtils.toArrayType(params);
  int consumed = 0;
  int size = extract.item2;
  List<int> remainingBytes = List<int>.from(bytes);
  List<dynamic> result = [];
  if (size.isNegative) {
    final length = const NumbersCoder().decode(AbiParameter.uint32, bytes);
    size = length.result.toInt();
    consumed = length.consumed;
    remainingBytes = bytes.sublist(length.consumed);
  }
  if (extract.item1.isDynamic) {
    for (int i = 0; i < size; i += 1) {
      final decodeOffset = const NumbersCoder().decode(AbiParameter.uint32,
          remainingBytes.sublist(i * ABIConst.uintBytesLength));
      consumed += decodeOffset.consumed;
      final decodeChild = _ABIUtils.decodeParamFromAbiParameter(
          extract.item1, remainingBytes.sublist(decodeOffset.result.toInt()));
      consumed += decodeChild.consumed;
      result.add(decodeChild.result);
    }
    return DecoderResult(result: result, consumed: consumed);
  }
  for (int i = 0; i < size; i++) {
    final decodeChild = _ABIUtils.decodeParamFromAbiParameter(
        extract.item1, bytes.sublist(consumed));
    consumed += decodeChild.consumed;
    result.add(decodeChild.result);
  }
  return DecoderResult(result: result, consumed: consumed);
}