ParsedSmartContractRequest.fromJson constructor

ParsedSmartContractRequest.fromJson(
  1. Map<String, dynamic> json,
  2. AbiFunctionFragment? fragment
)

Implementation

factory ParsedSmartContractRequest.fromJson(
    Map<String, dynamic> json, AbiFunctionFragment? fragment) {
  if (json["Error"] != null) {
    return ParsedSmartContractRequest._error(json);
  }
  final result = Map<String, dynamic>.from(json["result"]);
  if (!result.containsKey("result") || result["result"] != true) {
    return ParsedSmartContractRequest._error(json);
  }
  final List<Map<String, dynamic>> contractRevertErrors =
      List<Map<String, dynamic>>.from(json["transaction"]["ret"]);
  for (final i in contractRevertErrors) {
    if (i.isNotEmpty) {
      return ParsedSmartContractRequest._error(json);
    }
  }
  List<dynamic>? decodeResult;
  if (json.containsKey("constant_result") && fragment != null) {
    final outputs = List.from(json["constant_result"]);
    if (outputs.isEmpty) {
      decodeResult = [];
    } else {
      decodeResult =
          fragment.decodeOutput(BytesUtils.fromHexString(outputs.first));
    }
  }

  return ParsedSmartContractRequest._(
      respose: json,
      transactionRaw:
          TransactionRaw.fromJson(json["transaction"]["raw_data"]),
      energyUsed: json["energy_used"],
      outputResult: decodeResult);
}