Commit graph

17 commits

Author SHA1 Message Date
Josh Rickmar
399f91bba2 Error if writing a wallet fails during privkey import. 2013-12-16 09:12:25 -05:00
Josh Rickmar
75d3a77106 Fix build for new btcws notifications. 2013-12-13 11:00:31 -05:00
Josh Rickmar
d4e756bc23 Add getaddressbalance websocket extension request. 2013-12-10 16:15:25 -05:00
Josh Rickmar
c97e0d5fc6 Detect reorgs after btcd disconnect/reconnect.
This change saves (at most) the last 20 block hashes to disk.  Upon
btcd connect, in the handshake, btcwallet checks whether btcd's best
chain still contains these blocks, starting from the most recently
added block and continuing until the earliest saved.  If any blocks
are missing, Tx history and UTXOs from any blocks no longer in the
chain are removed, and a rescan is started from after the best block
still in the main chain.

If all previous block hashes are exhausted (either due to a large
reorg, or because not enough blocks have been seen), a full rescan is
triggered (full meaning from the earliest block that matters to this
wallet) since the last synced up to point is no longer available.

The previous 20 seen block hashes are saved to the wallet file, which
required bumping the file version.  Older wallets written with lesser
versions will use the previous reading function, making this change
backwards compatible.
2013-12-09 15:19:20 -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
378af40329 Remove some fmt.Printf debugging. 2013-12-03 12:45:27 -05:00
Josh Rickmar
c54af23849 Perform signature verifiction when generating addresses.
This change adds an additional check when creating a new wallet or
extending the keypool.  All public and private keypairs are parsed
from their serialized forms, and an ecdsa signature is created and
verified using the keypairs.  If the verifiction fails at any point,
the wallet creation or keypool extension is aborted to prevent any
errors where an address is returned to a user, but any funds send to
that address are unspendable due to a mismatched keypair.
2013-12-03 12:37:18 -05:00
Josh Rickmar
af1438eecd Add frontend support for displaying txs.
This change adds a new websocket extension command,
listalltransaction, which works just like listtransactions except it
does not take the count or from optional args, and will return an
array of all transaction details.  Notifications for newly-added
transactions are now sent to frontends as well, using the newtx
notification.

No support for updating tx details or removing failed txs is
implemented yet, and will be when cleanly failing a tx send is
implemented later.
2013-12-02 17:34:36 -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
413f23ea18 Add support for listtransactions RPC request.
This change adds support for the listtransactions RPC command.  To
properly reply to this command, additonal information about received
transactions was added, and is now saved in an account's tx.bin file.
Additionally, when sending a transaction, a *tx.SendTx is now saved to
the Tx store, and is included in listtransactions replies under the
"send" category.

WARNING: All account's tx.bin and utxo.bin files should be removed
before running with this change, or else the files may not be read
correctly.  Removing tx.bin is not an issue as it was not being used
before, and was being saved with incorrect data.  Removing utxo.bin is
not an issue as it will just trigger a rescan on next start.  File
format versions are now included in both files, so automatic updates
from previous file formats will be possible with future changes.

Fixes #12.
2013-11-26 16:22:15 -05:00
Josh Rickmar
57802d8daf Rename some Account variables. 2013-11-21 11:23:50 -05:00
Josh Rickmar
417aa63534 Add a missing mutex lock/unlock.
Spotted by dhill.
2013-11-21 10:27:58 -05:00
Josh Rickmar
1ff67707e4 Fix issues found by golint. 2013-11-19 20:46:16 -05:00
Josh Rickmar
00fe439670 Add private key import and export support.
This adds the necessary bits for handling importing addresses for the
wallet file format, as well as implementing the importprivkey and
dumpprivkey RPC requests.

Initial code by dhill.
2013-11-19 20:18:11 -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