public async Task <ICoinTransaction> ProcessTransaction(CoinTransactionMessage transaction) { var receipt = await _transactionService.GetTransactionReceipt(transaction.TransactionHash); if (receipt == null) { return(null); } ICoinTransaction coinDbTransaction = await _coinTransactionRepository.GetTransaction(transaction.TransactionHash) ?? new CoinTransaction() { ConfirmationLevel = 0, TransactionHash = transaction.TransactionHash }; bool error = coinDbTransaction?.Error == true || !await _transactionService.IsTransactionExecuted(transaction.TransactionHash); var confimations = await _contractService.GetCurrentBlock() - receipt.BlockNumber; var coinTransaction = new CoinTransaction { TransactionHash = transaction.TransactionHash, Error = error, ConfirmationLevel = GetTransactionConfirmationLevel(confimations) }; await _coinTransactionRepository.InsertOrReplaceAsync(coinTransaction); return(coinTransaction); }
public async Task ThrowOnExistingHashAsync(string trHash) { bool transactionInPool = await _ethereumTransactionService.IsTransactionInPool(trHash); TransactionReceipt reciept = await _ethereumTransactionService.GetTransactionReceipt(trHash); if (transactionInPool || reciept != null) { throw new ClientSideException(ExceptionType.TransactionExists, $"Transaction with hash {trHash} already exists"); } }
public async Task TestTransferTokens() { var colorCoin = await _coinRepository.GetCoinByAddress(_tokenAdapterAddress); var toAddress = _settings.EthereumMainAccount; await CashinTokens(_externalTokenAddress, _clientTokenTransferAddress, new BigInteger(100), _tokenAdapterAddress, _clientA); var transferUser = await _transferContractService.GetTransferAddressUser(colorCoin.AdapterAddress, _clientTokenTransferAddress); var currentBalance = await _transferContractService.GetBalanceOnAdapter(colorCoin.AdapterAddress, _clientA); Assert.AreEqual(transferUser, _clientA.ToLower()); var guid = Guid.NewGuid(); EthUtils.GuidToBigInteger(guid); var externalSign = await _exchangeService.GetSign(guid, _tokenAdapterAddress, _clientA, toAddress, currentBalance); var transferHash = await _exchangeService.Transfer(guid, _tokenAdapterAddress, _clientA, toAddress, currentBalance, externalSign); while (await _transactionService.GetTransactionReceipt(transferHash) == null) { await Task.Delay(100); } var currentBalanceOnAdapter = await _transferContractService.GetBalanceOnAdapter(colorCoin.AdapterAddress, _clientA); var newBalance = await _transferContractService.GetBalanceOnAdapter(colorCoin.AdapterAddress, toAddress); Assert.IsTrue(await _transactionService.IsTransactionExecuted(transferHash, Constants.GasForCoinTransaction)); Assert.IsTrue(currentBalanceOnAdapter == 0); Assert.IsTrue(currentBalance <= newBalance); }