sendTransferNativeCoin method

Future<BlockchainResponse> sendTransferNativeCoin({
  1. required TransferRequest transferRequest,
})

Implementation

Future<BlockchainResponse> sendTransferNativeCoin({
  required TransferRequest transferRequest,
}) async {
  final wallet = walletsStream.valueOrNull
      ?.firstWhereOrNull((element) => element.id == transferRequest.walletId);
  if (wallet == null) {
    throw Exception('Does not exist wallet with this name');
  }

  final privateKey = wallet.blockchainsData?[transferRequest.blockchainType]
      ?.firstWhereOrNull((element) =>
          element.derivationPath == transferRequest.currentDerivationPath)
      ?.privateKey;

  final publicKey = wallet.blockchainsData?[transferRequest.blockchainType]
      ?.firstWhereOrNull((element) =>
          element.derivationPath == transferRequest.currentDerivationPath)
      ?.publicKey;
  if (publicKey == null) {
    throw Exception('Public key is null');
  }
  if (privateKey == null) {
    throw Exception('Private key is null');
  }

  transferRequest.privateKey = privateKey;
  transferRequest.publicKey = publicKey;
  return blockchainService.sendTransferNativeCoin(
      transferRequest: transferRequest);
}