public async Task <IActionResult> SubmitSignedTransaction([FromBody] PrivateWalletEthSignedTransaction ethTransactionSigned) { if (!ModelState.IsValid) { throw new ClientSideException(ExceptionType.WrongParams, JsonConvert.SerializeObject(ModelState.Errors())); } string serialized = JsonConvert.SerializeObject(ethTransactionSigned); await _log.WriteInfoAsync("PrivateWalletController", "SubmitSignedTransaction", serialized , "StartSubmitSignedTransaction", DateTime.UtcNow); string transactionHash; if (!await _transactionValidationService.IsTransactionErc20Transfer(ethTransactionSigned.SignedTransactionHex)) { transactionHash = await _privateWalletService.SubmitSignedTransaction(ethTransactionSigned.FromAddress, ethTransactionSigned.SignedTransactionHex); } else { transactionHash = await _erc20Service.SubmitSignedTransaction(ethTransactionSigned.FromAddress, ethTransactionSigned.SignedTransactionHex); } await _log.WriteInfoAsync("PrivateWalletController", "SubmitSignedTransaction", $"{serialized}-TransactionHash:{transactionHash}", "EndSubmitSignedTransaction", DateTime.UtcNow); return(Ok(new HashResponse() { HashHex = transactionHash })); }
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"); } } }
/// Example for debugging purpose: signedTransaction - 0xa9059cbb000000000000000000000000aa4981d084120aef4bbaeecb9abdbc7d180c7edb000000000000000000000000000000000000000000000000000000000000000a public async Task ValidateInputForSignedAsync(string fromAddress, string signedTransaction) { await _transactionValidationService.ValidateInputForSignedAsync(fromAddress, signedTransaction); Nethereum.Signer.Transaction transaction = new Nethereum.Signer.Transaction(signedTransaction.HexToByteArray()); string erc20Address = transaction.ReceiveAddress.ToHex().EnsureHexPrefix(); string erc20InvocationData = transaction.Data.ToHex().EnsureHexPrefix(); if (!await _transactionValidationService.IsTransactionErc20Transfer(signedTransaction)) { throw new ClientSideException(ExceptionType.WrongParams, "Transaction is not a erc20 transfer"); } string parametrsString = erc20InvocationData.Replace(Constants.Erc20TransferSignature, ""); var amount = parametrsString.Substring(64, 64); HexBigInteger tokenAmount = new HexBigInteger(amount); await ValidateTokenAddressBalanceAsync(fromAddress, erc20Address, tokenAmount); }