public async Task PrivateWalletServiceTest_TestBroadcastingMultiple() { string fromAddress = "0x46Ea3e8d85A06cBBd8c6a491a09409f5B59BEa28"; EthTransaction transaction = new EthTransaction() { FromAddress = fromAddress, GasAmount = 21000, GasPrice = 50000000000, ToAddress = "0xaA4981d084120AEf4BbaEeCB9abdBc7D180C7EdB", Value = 5000000000 }; for (int i = 0; i < 2; i++) { string trRaw = await _privateWallet.GetTransactionForSigning(transaction); string signedRawTr = SignRawTransaction(trRaw, _privateKey); string transactionHash; if (!await _transactionValidationService.IsTransactionErc20Transfer(signedRawTr)) { transactionHash = await _privateWallet.SubmitSignedTransaction(fromAddress, signedRawTr); } else { throw new Exception("Can;t reach it"); } } }
public async Task <IActionResult> GetTransaction([FromBody] PrivateWalletEthTransaction ethTransaction) { if (!ModelState.IsValid) { throw new ClientSideException(ExceptionType.WrongParams, JsonConvert.SerializeObject(ModelState.Errors())); } string serialized = JsonConvert.SerializeObject(ethTransaction); await _log.WriteInfoAsync("PrivateWalletController", "GetTransaction", serialized, "Get transaction for signing", DateTime.UtcNow); var transaction = new EthTransaction() { FromAddress = ethTransaction.FromAddress, GasAmount = BigInteger.Parse(ethTransaction.GasAmount), GasPrice = BigInteger.Parse(ethTransaction.GasPrice), ToAddress = ethTransaction.ToAddress, Value = BigInteger.Parse(ethTransaction.Value) }; await _privateWalletService.ValidateInputAsync(transaction); string transactionHex = await _privateWalletService.GetTransactionForSigning(transaction); await _log.WriteInfoAsync("PrivateWalletController", "GetTransaction", $"{serialized} + TransactionHex:{transactionHex}", "Recieved transaction for signing", DateTime.UtcNow); return(Ok(new EthTransactionRaw() { FromAddress = ethTransaction.FromAddress, TransactionHex = transactionHex })); }
public async Task <string> GetTransactionForSigning(EthTransaction ethTransaction, bool useTxPool = false) { string from = ethTransaction.FromAddress; var gas = new Nethereum.Hex.HexTypes.HexBigInteger(ethTransaction.GasAmount); var gasPrice = new Nethereum.Hex.HexTypes.HexBigInteger(ethTransaction.GasPrice); var nonce = await _nonceCalculator.GetNonceAsync(from, useTxPool); var to = ethTransaction.ToAddress; var value = new Nethereum.Hex.HexTypes.HexBigInteger(ethTransaction.Value); var tr = new Nethereum.Signer.Transaction(to, value, nonce, gasPrice, gas); var hex = tr.GetRLPEncoded().ToHex(); return(hex); }
public async Task PrivateWalletServiceTest_TestTransactionEstimation() { string fromAddress = "0x46Ea3e8d85A06cBBd8c6a491a09409f5B59BEa28"; EthTransaction transaction = new EthTransaction() { FromAddress = fromAddress, GasAmount = 21000, GasPrice = 50000000000, ToAddress = "0xaA4981d084120AEf4BbaEeCB9abdBc7D180C7EdB",//"0xaA4981d084120AEf4BbaEeCB9abdBc7D180C7EdB", Value = 5000000000 }; string trRaw = await _privateWallet.GetTransactionForSigning(transaction); string signedRawTr = SignRawTransaction(trRaw, _privateKey); OperationEstimationResult result = await _privateWallet.EstimateTransactionExecutionCost(fromAddress, signedRawTr); }
/// <summary> /// /// </summary> /// <param name="transaction"></param> /// <returns></returns> /// <exception cref="ClientSideException">Throws client side exception</exception> public async Task ValidateInputAsync(EthTransaction transaction) { await _transactionValidationService.ValidateAddressBalanceAsync(transaction.FromAddress, transaction.Value, transaction.GasAmount, transaction.GasPrice); }