getTransaction method

Future<BcnTransactionResponse> getTransaction(
  1. String hash,
  2. String address
)

Implementation

Future<BcnTransactionResponse> getTransaction(
    String hash, String address) async {
  BcnTransactionRequest bcnTransactionRequest;
  BcnTransactionResponse bcnTransactionResponse;

  Map<String, dynamic> mapParams;

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

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

    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) {
        bcnTransactionResponse =
            bcnTransactionResponseFromJson(response.text);
        if (bcnTransactionResponse != null &&
            bcnTransactionResponse.result != null &&
            bcnTransactionResponse.result.from != address) {
          bcnTransactionResponse = null;
        }
      }
    } else {
      bcnTransactionRequest = BcnTransactionRequest.fromJson(mapParams);
      String body = json.encode(bcnTransactionRequest.toJson());
      http.Response responseHttp = await http.post(Uri.parse(this.apiUrl),
          body: body, headers: requestHeaders);
      if (responseHttp.statusCode == 200) {
        bcnTransactionResponse =
            bcnTransactionResponseFromJson(responseHttp.body);
        if (bcnTransactionResponse != null &&
            bcnTransactionResponse.result != null &&
            bcnTransactionResponse.result.from != address) {
          bcnTransactionResponse = null;
        }
      }
    }
  } catch (e) {
    logger.e(e.toString());
  }

  _completer.complete(bcnTransactionResponse);
  return _completer.future;
}