Пример #1
0
        public async Task <IReadOnlyDictionary <BlockchainAsset, decimal> > GetBalancesAsync(string address, DateTime at)
        {
            var indexResp = await(_baseUrl.AppendPathSegment("slr/address.dws") + $"?{address}.htm")
                            .GetStringAsync();

            var id = ChainIdDeserializer.GetChainid(indexResp);

            var txsResp = await _baseUrl.AppendPathSegment("explorer/address.summary.dws").SetQueryParams
                          (
                new
            {
                coin = "slr",
                id
            }
                          )
                          .GetStringAsync();

            if (txsResp.Contains("busy"))
            {
                throw new ArgumentException("Request failed due rate limiter");
            }

            var history = ChainIdDeserializer.DeserializeTransactionsResp(txsResp);
            var result  = 0m;

            foreach (var entry in history.Where(p => p.date <= at))
            {
                result += entry.amount;
            }

            return(new Dictionary <BlockchainAsset, decimal>
            {
                { _baseAsset, result }
            });
        }
        public async Task CanDeserializerTransactionsResp()
        {
            var respExample = await File.ReadAllTextAsync("SolarCoinTransactionsResp.json");

            var tx = ChainIdDeserializer.DeserializeTransactionsResp(respExample).Last();

            Assert.Equal("b63cf086b16e5d1570848e32bd65cc7747537cf4f3a32ac74b72d24c28adc54e", tx.id);

            Assert.Equal(DateTime.Parse("2019-07-14 16:58:16"), tx.date);
            Assert.Equal(-549.60515999m, tx.amount);
        }
        public async Task CanGetChainIdFromHtml()
        {
            var respExample = await File.ReadAllTextAsync("SolarCoinIndex.html");

            Assert.Equal(140227, ChainIdDeserializer.GetChainid(respExample));
        }