Commit graph

960 commits

Author SHA1 Message Date
Josh Rickmar
b4373dc070 Open all account files at startup.
This change checks for all wallet files in the account directory, and
then attempts to open each of the available accounts for those
wallets.  Before, only the default account would ever be opened.
2014-01-23 17:12:55 -05:00
Josh Rickmar
830829a79f Add dirty wallets to disc sync schedule.
There were several places where various account files (wallet, tx, or
utxo stores) were being marked as dirty, and then not being either
immediately synced to disk or marked as a dirty account so they would
be scheduled to be synced to disk.  This change adds Account functions
to mark as dirty and add the account to the map of scheduled accounts
so they won't be missed by the disk syncer goroutine.
2014-01-23 12:38:39 -05:00
Josh Rickmar
bd89f076cd Implement exporting a watching-only wallet.
This change allows for the use of watching-only wallets.  Unlike
normal, "hot" wallets, watching-only wallets do not contain any
private keys, and can be used in situations where you want to keep one
wallet online to create new receiving addresses and watch for received
transactions, while keeping the hot wallet offline (possibly on an
air-gapped computer).

Two (websocket) extension RPC calls have been added:

First, exportwatchingwallet, which will export the current hot wallet
to a watching-only wallet, saving either to disk or returning the
base64-encoded wallet files to the caller.

Second, recoveraddresses, which is used to recover the next n
addresses from the address chain.  This is used to "sync" a watching
wallet with the hot wallet, or vice versa.
2014-01-23 11:01:04 -05:00
Josh Rickmar
8b65e651cd Mark new wallet addresses as belonging to account.
This adds some missing bookkeeping which broke rescans for the root
addresses of newly created wallets (not wallets read from disk) by
marking all active addresses (which would be just the root address) as
belonging to the account with a some particular name.

While here, return an error to the caller rather than just logging the
error if the newly-created wallet cannot be immediatelly written to
disk.
2014-01-23 09:51:31 -05:00
Owain G. Ainsworth
ce2decb275 make TxStore use generic interface
Means we can replace a bunch of type assertions with generic code.
2014-01-23 00:00:10 +00:00
Owain G. Ainsworth
f1577a1718 add keypoolrefill command.
Since we handle this automatically it is just a noop.

Closes #48
2014-01-22 21:58:01 +00:00
Josh Rickmar
e8c8823bfe Fix a bookkeeping error on watching wallet exports.
The exported watching wallet would include all imported addresses'
chain indexes added to the chain index map.  Imported addresses are
special as they do not belong to the address chain, and this would
cause issues when serializing the wallet.
2014-01-21 17:05:54 -05:00
Josh Rickmar
04b51ee426 Add func to get next n active addresses.
This adds a new function, ExtendActiveAddresses, to extend the number
of active addresses, generated by the address chain, by any arbitrary
positive number.  This will be used for recovering wallet addresses
from a wallet backup, as well as getting the next as many addresses as
required to keep a watching wallet in sync with an original wallet
with the private keys, or sync an original wallet with new addresses
generated by the watching wallet.
2014-01-21 11:23:09 -05:00
Josh Rickmar
effd810e54 Add function+tests for exporting a watching wallet.
This change introduces a new function to export a wallet in memory to
a watching wallet.  Watching wallets allow to watch for balance
changes and transactions to wallet addresses while only storing the
public parts of a wallet (no private keys).  New addresses created by
the watching wallet will use pubkey address chaining and will allow to
receive funds to an indefinite number of new addresses, and create the
private keys for said addresses from the non-watching wallet later.

The actual exporting of a watching wallet to a file (triggered by an
RPC request) is not yet implemented.

While here, fix an issue found by new test code for the chained
address code which incorrectly set the starting index of addresses in
the chain needing private keys to be created.
2014-01-20 16:02:44 -05:00
Josh Rickmar
8952fc5acf Remove unnecessary string copy.
Strings are immutable, so instead of copying as a new variable (like
how was needed when receiving byte slices), just pass the marshaled
JSON string to the notification processing code.
2014-01-17 18:05:34 -05:00
Josh Rickmar
11ea5e31b4 Receive btcd messages as websocket.TextFrame. 2014-01-17 18:03:56 -05:00
Josh Rickmar
f87aab49df Explicitly request block notifications. 2014-01-17 16:45:40 -05:00
Josh Rickmar
a309196ea2 Create missing directories before writing certpair. 2014-01-17 12:17:51 -05:00
Josh Rickmar
80b16790bc Remove unused (and commented-out) function. 2014-01-17 10:33:29 -05:00
Josh Rickmar
54355f16e7 Return meaningful errors for locked wallets.
This change adds a check for a valid (32-byte length) secret before
attempting to encrypt or decrypt any addresses.  If the check fails, a
meaningful error (ErrWalletLocked) is returned to the caller, rather
than an error out of the aes package.
2014-01-17 10:29:44 -05:00
Josh Rickmar
97e1442e8d Remove exported Version func from wallet package.
This function was not implemented (returning zero values) and all
versioning is handled internally by the wallet's ReadFrom and WriteTo
functions.  If the read wallet does not match the latest file version,
it is read in the old format, but always written back with the new
format.
2014-01-17 09:43:23 -05:00
Josh Rickmar
82f2067ac4 Remove unnecessary mutex around wallet secret.
The wallet package was using a sync.Mutex around the saved decryption
key (kept in memory for an unlocked wallet).  As the wallet package is
designed to use no internal locking, and correct synchronization is
provided by the importers of the package, this mutex has been removed.
2014-01-17 09:35:52 -05:00
Josh Rickmar
311d6176a8 Generate new addresses from pubkeys if keypool is depleted.
This change uses the ChainedPubKey function to create addresses from
the previous address's public key and the wallet chaincode, without
the need for the private key, if the keypool has been depleted and the
wallet is locked.  This is done since the next chained private key is
unsolvable without a locked wallet.

If a wallet contains any of these chained addresses with missing
private keys, the private keys are created during the next wallet
unlock, using ChainedPrivKey.
2014-01-16 19:37:34 -05:00
Josh Rickmar
be4c549682 Tests build again. 2014-01-16 12:04:47 -05:00
Josh Rickmar
ea54b638f3 Add ChainedPubKey function and tests.
This change adds a function to generate the next public key of the
address chain from the previous public key and chaincode, without
needing the previous address's private key.  This will be used to
allow generating new addresses with an unlocked wallet, where the
private keys are created on the next unlock.

Tests have been added to verify that the chained private and private
keys match each other (using both chaining functions) as well as an
expected value in the test case. ECDSA signature creation and
verifiction is also performed using the generated keypairs to verify
the next keypair is valid.
2014-01-16 11:50:08 -05:00
Josh Rickmar
3dc9b175d0 Use correct hash algorithm for chained addresses.
btcwallet originally correctly copied the behavior of armory when
chaining new private keys off the previous private key, but this
regressed in commit e8265eca41 with a
switch from double sha256 to a single sha256.

This change reverts the behavior (using the clearly-named function
btcwire.DoubleSha256) to match armory's and old btcwallet's address
chaining algorithm.

If you have flipped the switch to use btcwallet on mainnet, any newly
generated addresses created for the keypool after Jan 6, 2014 (the
date the regression was committed) should be backed up with
dumpprivkey (using btcctl) and a new wallet backup should be made of
your current wallet file (~/.btcwallet/mainnet/wallet.bin on unix) to
avoid the possibility of losing any real money.
2014-01-15 18:25:19 -05:00
Josh Rickmar
21afda2506 Fix tests for new NewWallet func signature. 2014-01-15 18:23:02 -05:00
Josh Rickmar
f0c649b7ac Make maximum keypool size a config option. 2014-01-15 17:29:01 -05:00
Josh Rickmar
87b6335cc2 Fix a couple typos in the README. 2014-01-15 15:32:18 -05:00
Josh Rickmar
4c97bd3c5c Add dummy handlers for getblocktemplate and getwork. 2014-01-15 14:53:09 -05:00
Josh Rickmar
80606d7344 Mark new wallet tx/utxo stores as dirty.
This change makes the disk syncer write all three files (wallet, tx,
and utxo) instead of just the wallet, which will result in warnings at
startup if the tx/utxo files cannot be found.

Fixes #30.
2014-01-15 14:25:37 -05:00
Josh Rickmar
7866fd8931 Do not import privkeys resulting in duplicate addresses.
Fixes #35.
2014-01-15 14:07:08 -05:00
Josh Rickmar
30aff3a468 Explicitly call wallet function for Wallet var.
This change makes it more explicit that the function being called is
for an account's embedded *wallet.Wallet and not an account function.
2014-01-15 12:33:32 -05:00
Josh Rickmar
55882173a2 Spawn goroutine to rescan on imported privkeys.
Fixes #34.
2014-01-15 12:27:02 -05:00
Josh Rickmar
74f671b09a Fix typo. 2014-01-15 11:42:00 -05:00
Josh Rickmar
f82ca754ca Prepare for release 0.2.1. 2014-01-15 11:35:16 -05:00
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
cec819a887 Release account reader lock before rescaning. 2014-01-15 09:50:14 -05:00
David Hill
d2d278a9ee fix typo 2014-01-15 08:51:20 -05:00
Josh Rickmar
3b9d84b1e2 Release reader lock before syncing to disk.
When disk syncing a wallet file, if the wallet is flagged dirty, the
disk syncer must grab the wallet writer lock to set dirty=false.  The
disk syncing code was being called in the end of
(*Account).RescanActiveAddresses with the reader lock held (unlocked
using a defer), which prevented the writer lock from being aquired.

This change removes the defered unlock to release the reader lock
before syncing to disk.
2014-01-14 20:24:12 -05:00
Josh Rickmar
d811f38309 Prepare for release 0.2.0. 2014-01-14 19:25:31 -05:00
Josh Rickmar
8f4add7032 Update sample configuration with all options. 2014-01-14 19:20:08 -05:00
Josh Rickmar
86cf8e7005 Write RPC cert and key to correct files. 2014-01-14 11:13:27 -05:00
Josh Rickmar
ba92c234b3 Add another TODO to the README. 2014-01-11 03:07:24 -05:00
Josh Rickmar
76f3657ad3 Update README with recent changes and additional details. 2014-01-11 03:02:37 -05:00
Josh Rickmar
ecc959677c Do not print help usage twice with -h. 2014-01-10 17:18:42 -05:00
Josh Rickmar
467d976f0a Switch to btcutil for certificate generation. 2014-01-10 15:51:54 -05:00
Josh Rickmar
eca8914254 Write dirty tx and utxo files when rescans finish. 2014-01-10 14:53:47 -05:00
Josh Rickmar
ebcaa95b35 Use smarter btcd cert path logic.
If ~/.btcwallet/btcd.cert does not exist and the CA file has not been
explicitly set using the config file or command line flags, it's
possible that the cert can be found in ~/.btcd.  If connecting to a
localhost btcd and the previous statements are true, the default CA
file config option is updated for the certificate in them btcd
homedir.

If ~/.btcwallet/btcd.cert does exist and the CA file has not been set,
it is used without checking for a cert in the btcd homedir.
2014-01-10 11:39:03 -05:00
Josh Rickmar
3e2f67fda7 Short circuit handshake if default account does not exist. 2014-01-09 19:25:51 -05:00
Josh Rickmar
a6e0f3bc2a Update copyright years on remaining files. 2014-01-09 14:13:26 -05:00
Josh Rickmar
15ffc674a9 Rework the btcd RPC connection.
This change greatly cleans up the RPC connection between btcwallet and
btcd.  Proper (JSON-RPC spec-following) notifications are now expected
rather than Responses with a non-empty IDs.

A new RPCConn interface type has also been introduced with a
BtcdRPCConn concrete type for btcd RPC connections.  Non-btcd-specific
code handles the RPCConn, while the btcd details have been abstracted
away to a handful of functions.  This will make it easier to write
tests by creating a new fake RPC connection with hardcoded expected
replies.
2014-01-09 14:07:17 -05:00
Josh Rickmar
42055d5b7c Fix sample listen address in config. 2014-01-09 10:51:33 -05:00
Josh Rickmar
15c85b5c75 Fix same issue as before, but for getaccountaddress. 2014-01-06 16:39:32 -05:00