decodeRaw static method

ContractFunctionWithValues decodeRaw({
  1. required Uint8List data,
  2. required Map<String, String> functionMap,
})

Try to decode the raw data using the abiList and return the decoded function If the function is not found, return null

Implementation

static ContractFunctionWithValues decodeRaw({
  required Uint8List data,
  required Map<String, String> functionMap,
}) {
  if (data.length < 4) return UnknownContractFunction(data: data);

  final hex_signature = "0x${data.sublist(0, 4).toHex}";

  final text_signarure = functionMap[hex_signature];

  if (text_signarure == null) return UnknownContractFunction(data: data);

  final function =
      ContractFunction.fromTextSignature(textSignature: text_signarure);

  if (function == null) return UnknownContractFunction(data: data);

  return ContractFunction.decode(
    data: data,
    function: function,
  );
}