Exemple #1
0
 public override void MoveTo(AbstractFileInfo destination)
 {
     if (Exists)
     {
         System.IO.File.Move(Path, destination.Path);
     }
 }
Exemple #2
0
        protected Wallet(FileInfo file = null, PrivateKeyCollection keys = null, AddressCollection publicAddresses = null, AddressCollection watchAddresses = null)
        {
            PrivateKeys     = keys ?? new PrivateKeyCollection();
            WatchAddresses  = watchAddresses ?? new AddressCollection();
            PublicAddresses = publicAddresses ?? new AddressCollection();

            File = file;
        }
Exemple #3
0
        public static async Task <Wallet> CreateAsync(byte[] passphrase, FileInfo file = null, PrivateKeyCollection keys = null, AddressCollection publicAddresses = null, AddressCollection watchAddresses = null)
        {
            var wallet = new Wallet(file, keys, publicAddresses, watchAddresses);
            await wallet.LockAsync(passphrase);

            await wallet.UnlockAsync(passphrase);

            return(wallet);
        }
Exemple #4
0
        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);
                }
            }
        }
        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);
        }
        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));
        }
        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);
        }
        protected override void Initialize(Electrolyte.Portable.IO.FileInfo info, FileMode mode)
        {
            File = info;
            Mode = mode;

            switch (mode)
            {
            case FileMode.Append:
            case FileMode.Create:
            case FileMode.CreateNew:
            case FileMode.OpenOrCreate:
            case FileMode.Truncate:
                if (!info.Location.Exists)
                {
                    info.Location.Create();
                }
                break;
            }

            InternalFileStream = new InternalFileStream(info.Path, ToInternalFileMode(mode));
        }
Exemple #9
0
        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();
            }
        }
Exemple #10
0
		protected Wallet(FileInfo file = null, PrivateKeyCollection keys = null, AddressCollection publicAddresses = null, AddressCollection watchAddresses = null) {
			PrivateKeys = keys ?? new PrivateKeyCollection();
			WatchAddresses = watchAddresses ?? new AddressCollection();
			PublicAddresses = publicAddresses ?? new AddressCollection();

			File = file;
		}
Exemple #11
0
		public abstract void CopyTo(FileInfo destination);
Exemple #12
0
		public abstract void MoveTo(FileInfo destination);
Exemple #13
0
 public static async Task <Wallet> CreateAsync(string passphrase, FileInfo file = null, PrivateKeyCollection keys = null, AddressCollection publicAddresses = null, AddressCollection watchAddresses = null)
 {
     return(await CreateAsync(Encoding.UTF8.GetBytes(passphrase), file, keys, publicAddresses, watchAddresses));
 }
Exemple #14
0
		public static async Task<Wallet> CreateAsync(string passphrase, FileInfo file = null, PrivateKeyCollection keys = null, AddressCollection publicAddresses = null, AddressCollection watchAddresses = null) {
			return await CreateAsync(Encoding.UTF8.GetBytes(passphrase), file, keys, publicAddresses, watchAddresses);
		}
Exemple #15
0
		public override void MoveTo(AbstractFileInfo destination) {
			if(Exists)
				System.IO.File.Move(Path, destination.Path);
		}
Exemple #16
0
		public static async Task<Wallet> CreateAsync(byte[] passphrase, FileInfo file = null, PrivateKeyCollection keys = null, AddressCollection publicAddresses = null, AddressCollection watchAddresses = null) {
			var wallet = new Wallet(file, keys, publicAddresses, watchAddresses);
			await wallet.LockAsync(passphrase);
			await wallet.UnlockAsync(passphrase);

			return wallet;
		}
Exemple #17
0
		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();
			}
		}
Exemple #18
0
		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;
				}
			}
		}