ContractFunctionWithValues.fromJson constructor

ContractFunctionWithValues.fromJson(
  1. Map json
)

Implementation

factory ContractFunctionWithValues.fromJson(Map json) {
  if (json
      case {
        "name": String name,
        "parameters": List<dynamic> parameters,
      }) {
    return ExternalContractFunctionWithValues(
      name: name,
      parameters: [
        for (final param in parameters)
          FunctionParamWithValue.fromJson(param),
      ],
    );
  }
  if (json case {"name": String name, "data": String data}) {
    final dataBytes = data.hexToBytes;
    return switch (name) {
      "Unknown" => UnknownContractFunction(data: dataBytes),
      "NotDecodable" => NotDecodableContractFunction(data: dataBytes),
      _ => throw Exception("Invalid json"),
    };
  }

  throw Exception("Invalid json");
}