Commit graph

18 commits

Author SHA1 Message Date
Josh Rickmar
6f022e23cc Remove unused variable. 2014-01-15 11:13:47 -05:00
Josh Rickmar
7dd7cffbe9 Stop using unix time for temp files. 2014-01-15 11:04:43 -05:00
Josh Rickmar
a6e0f3bc2a Update copyright years on remaining files. 2014-01-09 14:13:26 -05:00
Josh Rickmar
b6601b1b6b Remove some TODOs that have been finished. 2013-12-06 09:19:00 -05:00
Josh Rickmar
e7826dae00 Add atomic rename functions for Windows and Plan 9.
This code is based off leveldb (https://github.com/syndtr/goleveldb),
and the leveldb copyright notice (a 2-clause BSD license) has been
included where used.
2013-12-05 14:06:51 -05:00
Josh Rickmar
ae4bf50f7a Move some funcs for better file organization. 2013-12-04 20:55:56 -05:00
Josh Rickmar
ce23523ed7 Introduce new account file structure.
This changes the locations that account files (wallet.bin, utxo.bin,
and tx.bin) are searched for when opening or disk syncing accounts.
Previously, files were saved in the following layout:

  ~/.btcwallet/
    - btcwallet/
      - wallet.bin
      - tx.bin
      - utxo.bin
    - btcwallet-AccountA/
      - wallet.bin
      - tx.bin
      - utxo.bin

This format had two issues.  First, each account would require its own
directory, causing a scalability issue on unix (and perhaps other)
platforms.  Second, there was no distinction between testnet and
mainnet wallets, and if mainnet support was enabled, btcwallet would
attempt to open accounts with testnet wallets.

Instead, the following file structure is now used:

  ~/.btcwallet/
    - testnet/
      - wallet.bin
      - tx.bin
      - utxo.bin
      - AccountA-wallet.bin
      - AccountA-tx.bin
      - AccountA-utxo.bin

This solves both of the previously-mentioned issues by requiring only
two subdirectories (one each for the testnet and mainnet bitcoin
networks), and by separating the locations to open and save testnet
and mainnet account files.

At startup, a check for the old account file structure is performed.
If found, files are moved to the new locations, and the old account
directories are removed.  Account files are moved to the testnet
directory, as only testnet support is currently enabled.

The version has been bumped to 0.1.1 to reflect this change.

Fixes #16.
2013-12-04 20:25:13 -05:00
Josh Rickmar
3c528f81ec New Account and AccountStore API.
This change better organizes account handling by creating a new
AccountStore type and accountstore global variable, with receiver
funcs for all operations that require all accounts.  More Account
funcs are also added to clean up account handling in the RPC code.

Intial work on this done by dhill.
2013-12-02 14:56:06 -05:00
Josh Rickmar
828544cb2f Fix some races found by -race. 2013-11-21 14:41:05 -05:00
Josh Rickmar
5ad35a4460 Create necessary directories when syncing accounts.
Fixes #15.
2013-11-21 09:24:16 -05:00
Josh Rickmar
ef49eca365 more wallet -> account renames 2013-11-15 11:44:24 -05:00
David Hill
9c827a824f Rename BtcWallet to Account and put it in its own file. 2013-11-14 12:15:16 -05:00
Josh Rickmar
503f591e88 Process tx notifications before new blocks.
This change modifies the order in which transaction to watched
addresses are processed and when frontend notifications occur.  Due to
btcd notifying all transactions before sending the blockconnected
notification, the UTXO and transaction stores can be modified without
sending any frontend notifications, and then a single frontend
notification is sent when the blockconnected notification arrives.

The order in which each file is synced to disk was also changed to
write out the UTXO and transaction stores before writing the wallet.
This is to prevent a race where wallet closes after writing the dirty
wallet, but before the dirty UTXO store is written.  In this
situation, newly added UTXOs will be missed and not found again on the
next wallet open during the rescan.  Writing the wallet (which holds
the synced-to-block information) last prevents this.

An issue where the unconfirmed change UTXO created from a new
transaction never being properly notified to frontends is fixed now as
well.
2013-11-12 14:53:38 -05:00
Josh Rickmar
18fb993d0b Implement address rescanning.
When a wallet is opened, a rescan request will be sent to btcd with
all active addresses from the wallet, to rescan from the last synced
block (now saved to the wallet file) and the current best block.

As multi-account support is further explored, rescan requests should
be batched together to send a single request for all addresses from
all wallets.

This change introduces several changes to the wallet, tx, and utxo
files.  Wallet files are still compatible, however, a rescan will try
to start at the genesis block since no correct "last synced to" or
"created at block X" was saved.  The tx and utxo files, however, are
not compatible and should be deleted (or an error will occur on read).
If any errors occur opening the utxo file, a rescan will start
beginning at the creation block saved in the wallet.
2013-11-01 10:06:38 -04:00
Josh Rickmar
4b7f858bee Close() temp files before renaming them.
Fixes syncing dirty wallet files on Windows.
2013-10-23 18:40:02 -04:00
Josh Rickmar
b5b684127c Remove debugging that slipped in. 2013-10-15 17:06:35 -04:00
Josh Rickmar
2782b7815e Sync wallet files to disk as needed, instead of waiting for a timer.
While fixing this code, the dirty flag was also cleared so that
unneeded syncs wouldn't be needed later.  The dirty flag set and sync
was also added for the 'getnewaddress' handler, as it was previously
missing.
2013-10-15 17:00:42 -04:00
Josh Rickmar
284191ec4b Sync wallet, utxo, and tx files to disk.
This runs a syncer once every minute to write any dirty wallet data
structures out to disk.  As currently implemented, dirty wallets will
be lost if not written before btcwallet closes or crashes.
Deterministic wallet help migitate this issue (as private keys can be
created again as long as a previous wallet file was written) but this
can still be a nuisance as a longer rescan will be required to catch
up to chain.
2013-10-15 15:53:49 -04:00