Пример #1
0
        public override async Task <Money> GetAddressBalanceAsync(Address address, ulong startHeight = 0)
        {
            PathInfo balanceCache = DefaultCachePath.SubPath("balances");
            FileInfo cache        = FileInfo.Create(balanceCache, String.Format("{0}.{1}", GetHashedAddress(address), "bal"));

            Money balance = await base.GetAddressBalanceAsync(address, startHeight);

            using (var writer = new StreamWriter(FileStream.Create(cache, FileMode.Create))) {
                await writer.WriteLineAsync(balance.Cents.ToString());
            }
            return(balance);
        }
Пример #2
0
        public override async Task <Money> GetCachedBalanceAsync(Address address, ulong startHeight = 0)
        {
            PathInfo balanceCache = DefaultCachePath.SubPath("balances");
            FileInfo cache        = FileInfo.Create(balanceCache, String.Format("{0}.{1}", GetHashedAddress(address), "bal"));


            if (cache.Exists)
            {
                using (var stream = FileStream.Create(cache, FileMode.Open)) {
                    using (var reader = new StreamReader(stream)) {
                        return(new Money(Int64.Parse(await reader.ReadLineAsync()), "BTC"));
                    }
                }
            }

            return(await base.GetCachedBalanceAsync(address, startHeight));
        }
Пример #3
0
        public override async Task <Transaction> GetTransactionAsync(Transaction.Info info)
        {
            PathInfo txCache = DefaultCachePath.SubPath("transactions");
            FileInfo cache   = FileInfo.Create(txCache, String.Format("{0}.{1}", info.Hash, "tx"));

            Transaction tx;

            if (cache.Exists)
            {
                tx = new Transaction();
                tx.ReadPayload(new BinaryReader(FileStream.Create(cache, FileMode.Open)));
                tx.Height = info.Height;
            }
            else
            {
                tx = await base.GetTransactionAsync(info);

                tx.WritePayload(new BinaryWriter(FileStream.Create(cache, FileMode.Create)));
            }
            return(tx);
        }