getTxReceipt method

Future<BcnTxReceiptResponse> getTxReceipt(
  1. String txHash
)

Implementation

Future<BcnTxReceiptResponse> getTxReceipt(String txHash) async {
  BcnTxReceiptRequest bcnTxReceiptRequest;
  BcnTxReceiptResponse bcnTxReceiptResponse;

  Map<String, dynamic> mapParams;

  Completer<BcnTxReceiptResponse> _completer =
      new Completer<BcnTxReceiptResponse>();

  if (this.nodeType == PUBLIC_NODE) {
    mapParams = {
      'method': BcnTxReceiptRequest.METHOD_NAME,
      'params': [txHash],
      'id': 101,
    };
  } else {
    mapParams = {
      'method': BcnTxReceiptRequest.METHOD_NAME,
      'params': [txHash],
      'id': 101,
      'key': keyApp
    };
  }

  try {
    if (this.nodeType == NORMAL_VPS_NODE) {
      SSHClientStatus sshClientStatus;
      sshClientStatus = await VpsUtil().connectVps(this.apiUrl, keyApp);
      if (sshClientStatus.sshClientStatus) {
        sshClient = sshClientStatus.sshClient;
      }
      var response = await ssh.HttpClientImpl(
          clientFactory: () =>
              ssh.SSHTunneledBaseClient(sshClientStatus.sshClient)).request(
          this.apiUrl,
          method: 'POST',
          data: jsonEncode(mapParams),
          headers: requestHeaders);
      if (response.status == 200) {
        bcnTxReceiptResponse = bcnTxReceiptResponseFromJson(response.text);
      }
    } else {
      bcnTxReceiptRequest = BcnTxReceiptRequest.fromJson(mapParams);
      body = json.encode(bcnTxReceiptRequest.toJson());
      responseHttp = await http.post(Uri.parse(this.apiUrl),
          body: body, headers: requestHeaders);
      if (responseHttp.statusCode == 200) {
        bcnTxReceiptResponse =
            bcnTxReceiptResponseFromJson(responseHttp.body);
      }
    }
  } catch (e) {
    logger.e(e.toString());
  }

  _completer.complete(bcnTxReceiptResponse);

  return _completer.future;
}