コード例 #1
0
ファイル: Wallet.cs プロジェクト: neurocis/electrolyte.net
        public async static Task <Wallet> LoadAsync(FileInfo fileInfo)
        {
            using (var stream = FileStream.Create(fileInfo, FileMode.Open)) {
                using (var reader = new StreamReader(stream)) {
                    var wallet = new Wallet(fileInfo);
                    await wallet.ReadAsync(reader);

                    return(wallet);
                }
            }
        }
コード例 #2
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);
        }
コード例 #3
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));
        }
コード例 #4
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);
        }
コード例 #5
0
ファイル: Wallet.cs プロジェクト: neurocis/electrolyte.net
        public async Task SaveAsync(FileInfo file)
        {
            await saveLock.WaitAsync();

            try {
                if (IsLocked)
                {
                    throw new LockedException();
                }

                if (file != null)
                {
                    FileInfo backup = file.WithExtension("bak");
                    FileInfo temp   = file.WithExtension("new");

                    temp.Delete();
                    backup.Delete();
                    file.MoveTo(backup);

                    if (!IsLocked)
                    {
                        await EncryptAsync(EncryptionKey);
                    }

                    // TODO: Set proper file permissions
                    using (var stream = FileStream.Create(file, FileMode.CreateNew)) {
                        using (var writer = new StreamWriter(stream)) {
                            await WriteAsync(writer);
                        }
                    }
                }
            }
            finally {
                saveLock.Release();
            }
        }