private async Task <string> SendTransactionAsync(string from, string to, string data, BigInteger value, BigInteger?gasPrice, BigInteger?gasValue) { from = from == Constants.AddressForRoundRobinTransactionSending ? await _transactionRouter.GetNextSenderAddressAsync() : from; var semaphore = _semaphores.GetOrAdd(from, f => new SemaphoreSlim(1, 1)); try { await semaphore.WaitAsync(); (gasPrice, gasValue) = await GetGasPriceAndValueAsync(gasPrice, gasValue); var nonce = await _nonceCalculator.GetNonceAsync(from, true); var transaction = new Nethereum.Signer.Transaction(to, value, nonce.Value, gasPrice.Value, gasValue.Value, data); var signRequest = new EthereumTransactionSignRequest { FromProperty = new AddressUtil().ConvertToChecksumAddress(from), Transaction = transaction.GetRLPEncoded().ToHex() }; var signResponse = await _signingApi.ApiEthereumSignPostAsync(signRequest); var txHash = await _sendRawTransaction.SendRequestAsync(signResponse.SignedTransaction.EnsureHexPrefix()); return(txHash); } finally { semaphore.Release(); } }
public async Task <string> SignRawTransactionAsync(string fromAddress, string rawTransactionHex) { var requestBody = new EthereumTransactionSignRequest() { FromProperty = _addressUtil.ConvertToChecksumAddress(fromAddress), Transaction = rawTransactionHex }; var response = await _signatureApi.ApiEthereumSignPostAsync(requestBody); return(response?.SignedTransaction.EnsureHexPrefix()); }
/// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='signRequest'> /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <TransactionSignResponse> ApiEthereumSignPostAsync(this ILykkeSigningAPI operations, EthereumTransactionSignRequest signRequest = default(EthereumTransactionSignRequest), CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.ApiEthereumSignPostWithHttpMessagesAsync(signRequest, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='signRequest'> /// </param> public static TransactionSignResponse ApiEthereumSignPost(this ILykkeSigningAPI operations, EthereumTransactionSignRequest signRequest = default(EthereumTransactionSignRequest)) { return(operations.ApiEthereumSignPostAsync(signRequest).GetAwaiter().GetResult()); }