Esempio n. 1
0
        public async Task <EthereumTransactionCollection> GetEthereumTransactionCollectionAsync(string address)
        {
            var result = new EthereumTransactionCollection();

            //https://api.ethplorer.io/getAddressTransactions/0xb297cacf0f91c86dd9d2fb47c6d12783121ab780?apiKey=freekey
            string uri = $"{EthereumServiceProviders.Ethplorer.GetAddressTransactionsEndpointURL}/{address}?apiKey={APIKey}";

            _logger.LogDebug($"{nameof(GetEthereumTransactionCollectionAsync)}");
            _logger.LogDebug(uri);

            try
            {
                var listTransactionJSON = await ExternalWebAPIRequestor.GetAsync <List <TransactionJSON> >(uri);

                foreach (var transactionJSON in listTransactionJSON)
                {
                    result.Transactions.Add(new EthereumTransaction
                    {
                        FromAddress = transactionJSON.from,
                        ToAddress   = transactionJSON.to,
                        Amount      = transactionJSON.value,
                        Hash        = transactionJSON.hash,
                        TimeStamp   = transactionJSON.timestamp
                    });
                }
            }
            catch (WebException ex) when((ex.Response as HttpWebResponse)?.StatusCode == HttpStatusCode.NotAcceptable)
            {
                throw new InvalidWalletAddressException(address, CurrencySymbol.ETH);
            }

            return(result);
        }
        public async Task <EthereumTransactionCollection> GetEthereumTransactionCollectionAsync(string address)
        {
            var result = new EthereumTransactionCollection();

            //https://fakechain.vioren.com/api/eth/getAddressTransactions/0xb297cacf0f91c86dd9d2fb47c6d12783121ab780
            string uri = $"{EthereumServiceProviders.FakeChain.GetAddressTransactionsEndpointURL}/{address}";

            var transactionCollectionJSON = await ExternalWebAPIRequestor.GetAsync <TransactionCollectionJSON>(uri);

            foreach (var transactionJSON in transactionCollectionJSON.transactions)
            {
                result.Transactions.Add(new EthereumTransaction
                {
                    FromAddress = transactionJSON.fromAddress,
                    ToAddress   = transactionJSON.toAddress,
                    Amount      = transactionJSON.amount,
                    Hash        = transactionJSON.hash,
                    TimeStamp   = transactionJSON.timeStamp
                });
            }

            return(result);
        }