public async Task <HexBigInteger> GetNextNonceAsync() { if (Client == null) { throw new NullReferenceException("Client not configured"); } var ethGetTransactionCount = new EthGetTransactionCount(Client); await _semaphoreSlim.WaitAsync().ConfigureAwait(false); try { var nonce = await ethGetTransactionCount.SendRequestAsync(_account, BlockParameter.CreatePending()) .ConfigureAwait(false); if (nonce.Value <= CurrentNonce) { CurrentNonce = CurrentNonce + 1; nonce = new HexBigInteger(CurrentNonce); } else { CurrentNonce = nonce.Value; } return(nonce); } finally { _semaphoreSlim.Release(); } }
public async Task <HexBigInteger> GetNonceAsync(TransactionInput transaction) { if (Client == null) { throw new NullReferenceException("Client not configured"); } if (transaction == null) { throw new ArgumentNullException(nameof(transaction)); } var ethGetTransactionCount = new EthGetTransactionCount(Client); var nonce = transaction.Nonce; if (nonce == null) { //we are doing a check all the time on current nonce, we could just cache an increment but we might get out of sync. nonce = await ethGetTransactionCount.SendRequestAsync(_account).ConfigureAwait(false); if (nonce.Value <= _nonceCount) { _nonceCount = _nonceCount + 1; nonce = new HexBigInteger(_nonceCount); } else { _nonceCount = nonce.Value; } } return(nonce); }
public async Task <HexBigInteger> GetNonceAsync(string fromAddress, bool checkTxPool) { if (checkTxPool) { var txPool = await _client.SendRequestAsync <JObject>(new RpcRequest($"{Guid.NewGuid()}", "txpool_inspect")); var maxNonce = txPool["pending"] .Cast <JProperty>() .FirstOrDefault(x => x.Name.Equals(fromAddress, StringComparison.OrdinalIgnoreCase))? .FirstOrDefault()? .Cast <JProperty>() .Select(x => long.Parse(x.Name)) .Max(); if (maxNonce.HasValue) { return(new HexBigInteger(new BigInteger(maxNonce.Value + 1))); } } return(await _getTransactionCount.SendRequestAsync(fromAddress, BlockParameter.CreatePending())); }
public override async Task <HexBigInteger> ExecuteAsync(IClient client) { var ethGetTransactionCount = new EthGetTransactionCount(client); return(await ethGetTransactionCount.SendRequestAsync(Settings.GetDefaultAccount())); }
public async Task <object> ExecuteTestAsync(IClient client) { var ethGetTransactionCount = new EthGetTransactionCount(client); return(await ethGetTransactionCount.SendRequestAsync("0x12890d2cce102216644c59dae5baed380d84830c")); }
public async Task<dynamic> ExecuteTestAsync(RpcClient client) { var ethGetTransactionCount = new EthGetTransactionCount(client); return await ethGetTransactionCount.SendRequestAsync( "0x12890d2cce102216644c59dae5baed380d84830c"); }