sendSyncTx method

Future<BlockchainResponse> sendSyncTx(
  1. List<String> params
)

Implementation

Future<BlockchainResponse> sendSyncTx(List<String> params) async {
  final res = await networkClient.postHTTP('', {
    "jsonrpc": "2.0",
    "id": "dontcare",
    "method": "broadcast_tx_commit",
    "params": params
  });
  if (res.data['error'] != null) {
    return BlockchainResponse(
      data: res.data['error'],
      status: BlockchainResponses.error,
    );
  }

  String? transactionHash = res.data['result']['transaction']['hash'];
  String response = res.data['result']['status']['SuccessValue'] != null
      ? NearFormatter.decodeResultOfTransactionResponse(
          res.data['result']['status']['SuccessValue'].toString())
      : "no data in response";
  final String? functionCallError = res.data?['result']?['status']?['Failure']
      ?['ActionError']?['kind']?['FunctionCallError']?['ExecutionError'];
  final String? executionError = res.data?['result']?['status']?['Failure']
      ?['ActionError']?['kind']?['FunctionCallError']?['MethodResolveError'];

  if (res.isSuccess && functionCallError == null && executionError == null) {
    return BlockchainResponse(
      data: {
        "txHash": transactionHash,
        "success": response,
      },
      status: BlockchainResponses.success,
    );
  } else {
    return BlockchainResponse(
      data: {
        "txHash": transactionHash,
        "error": functionCallError ?? executionError,
      },
      status: BlockchainResponses.error,
    );
  }
}