public async Task <Result <BigInteger> > GetNonceAsync( Atomex.Ethereum ethereum, string address, CancellationToken cancellationToken = default) { var transactionCountResult = await((IEthereumBlockchainApi)ethereum.BlockchainApi) .GetTransactionCountAsync(address, cancellationToken) .ConfigureAwait(false); if (transactionCountResult.HasError) { return(transactionCountResult); } var nonce = transactionCountResult.Value; lock (_syncRoot) { if (_nonces.TryGetValue(address, out var offlineNonce)) { if (offlineNonce.Value >= nonce && DateTime.UtcNow - offlineNonce.LastUpdatedTimeUtc <= ExpirationTimeOut) { return(offlineNonce.Value++); } _nonces[address] = new NonceEntry { Value = nonce + 1, LastUpdatedTimeUtc = DateTime.UtcNow }; return(nonce); } _nonces.Add(address, new NonceEntry { Value = nonce + 1, LastUpdatedTimeUtc = DateTime.UtcNow }); return(nonce); } }
public static ICurrencySwap Create( Currency currency, IAccount account, ISwapClient swapClient) { return(currency switch { BitcoinBasedCurrency _ => (ICurrencySwap) new BitcoinBasedSwap( account: account.GetCurrencyAccount <BitcoinBasedAccount>(currency.Name), swapClient: swapClient, currencies: account.Currencies), ERC20 _ => (ICurrencySwap) new ERC20Swap( account: account.GetCurrencyAccount <ERC20Account>(currency.Name), ethereumAccount: account.GetCurrencyAccount <EthereumAccount>("ETH"), swapClient: swapClient, currencies: account.Currencies), Atomex.Ethereum _ => (ICurrencySwap) new EthereumSwap( account: account.GetCurrencyAccount <EthereumAccount>(currency.Name), swapClient: swapClient, currencies: account.Currencies), NYX _ => (ICurrencySwap) new NYXSwap( account: account.GetCurrencyAccount <NYXAccount>(currency.Name), tezosAccount: account.GetCurrencyAccount <TezosAccount>("XTZ"), swapClient: swapClient, currencies: account.Currencies), FA2 _ => (ICurrencySwap) new FA2Swap( account: account.GetCurrencyAccount <FA2Account>(currency.Name), tezosAccount: account.GetCurrencyAccount <TezosAccount>("XTZ"), swapClient: swapClient, currencies: account.Currencies), FA12 _ => (ICurrencySwap) new FA12Swap( account: account.GetCurrencyAccount <FA12Account>(currency.Name), tezosAccount: account.GetCurrencyAccount <TezosAccount>("XTZ"), swapClient: swapClient, currencies: account.Currencies), Atomex.Tezos _ => (ICurrencySwap) new TezosSwap( account: account.GetCurrencyAccount <TezosAccount>(currency.Name), swapClient: swapClient, currencies: account.Currencies), _ => throw new NotSupportedException($"Not supported currency {currency.Name}"), });
public CompositeEthereumBlockchainApi(Atomex.Ethereum currency, Chain chain) { _web3 = new Web3BlockchainApi(currency, chain); _etherScanApi = new EtherScanApi(currency); }
public EtherScanApi(Atomex.Ethereum currency) { Currency = currency; BaseUrl = currency.BlockchainApiBaseUri; }