ContractFunction.fromJson constructor

ContractFunction.fromJson(
  1. Map json
)

Implementation

factory ContractFunction.fromJson(Map json) {
  if (json
      case {
        "name": String name,
        "parameters": List<dynamic> parameters,
      }) {
    return ExternalContractFunction(
      name: name,
      parameters: [
        for (final param in parameters) FunctionParam.fromJson(param),
      ],
    );
  }
  if (json case {"name": String name, "data": String data}) {
    final dataBytes = data.hexToBytes;
    final timestamp = json["timeStamp"] as int?;
    return switch (name) {
      "Unknown" =>
        UnknownContractFunction(data: dataBytes, timeStamp: timestamp),
      "NotDecodable" =>
        NotDecodableContractFunction(data: dataBytes, timeStamp: timestamp),
      _ => throw Exception("Invalid json"),
    };
  }

  throw Exception("Invalid json");
}