Commit graph

1240 commits

Author SHA1 Message Date
Josh Rickmar
5edd01e8a5 Unmark addresses as requiring private keys next unlock.
The flag marking chained addresses as needing private keys be
generated on the next wallet unlock was not being correctly unset
after creating and encrypting the private key.  After
serializing/deserializing the wallet, on next unlock, recreating
missing private keys would begin too early in the chain and fail due
to trying to encrypt an already encrypted address.

This change correctly unsets the flag and bumps the version so a
special case can be created for ignoring duplicate encryption attempts
when reading an old wallet file.  Tests have also been added to the
chained pubkey test to test for this error case.
2014-02-04 10:37:28 -05:00
Josh Rickmar
8dac5080ac Change AccountManager to not wait for disk flushes.
Should fix hang found by dhill.
2014-02-03 18:15:36 -05:00
Josh Rickmar
03ffa0ccd8 Do not serialize/deserialize armory unique ID.
Closes #70.
2014-02-03 15:11:17 -05:00
Josh Rickmar
a0e94501cf Add 'stop' to the RPC handlers map.
Sending a stop request to wallet should stop the wallet, not pass the
unhandled request to btcd.  Instead, catch it with the Unimplemented
handler.
2014-02-03 15:01:25 -05:00
Josh Rickmar
d7a4e5e816 Implement getreceivedbyaccount.
Closes #42.
2014-02-03 14:53:27 -05:00
Josh Rickmar
72d7dda583 Remove unused function. 2014-02-03 13:01:17 -05:00
Josh Rickmar
45e0a3fcb9 Move websocket endpoint to /ws. 2014-02-03 11:50:11 -05:00
Josh Rickmar
b90e7aae82 Implement getrawchangeaddress.
Closes #41.
2014-02-03 10:52:02 -05:00
Josh Rickmar
b3bb0481b0 Add wallet func to return a change address.
Previous to this commit, all change addresses were indistinguishable
from manually requested addresses.  This adds a new function to return
the new address, setting a new change flag to true, and return the
change status with the AddressInfo.

This is needed as part of resolving #41 (getrawchangeaddress).
2014-02-03 10:21:47 -05:00
Josh Rickmar
6a08c7de07 Redo account locking and RPC request processing.
This change removes the three separate mutexes which used to lock an
account's wallet, tx store, and utxo store.  Accounts no longer
contain any locking mechanism and rely on go's other synchronization
constructs (goroutines and channels) for correct access.

All accounts are now managed as a collection through the new
AccountManager, rather than the old AccountStore.  AccountManager runs
as its own goroutine to provide access to accounts.

RPC requests are now queued for handling, being denied if the queue
buffer is exhausted.  Notifications are also queued (instead of being
sent from their own goroutine after being received, in which order is
undefined), however, notifications are never dropped and will
potentially grow a queue of infinite size if unhandled.
2014-02-01 13:18:34 -05:00
Josh Rickmar
20e8201125 Remove some printf debugging that slipped in. 2014-01-29 17:57:14 -05:00
Josh Rickmar
430db140ee Synchronize all account file writes.
Fixes several hangs cased by incorrect locking, by removing the
locking.  Instead, a single goroutine manages all file writes.

The old account 'dirty' boolean flags have been removed.  Instead,
anytime an account structure is modified, the portion that was
modified (wallet, tx store, or utxo store) must be scheduled to be
written.
2014-01-29 17:50:58 -05:00
Owain G. Ainsworth
0b371b09e8 Implement getinfo command
Closes #63
2014-01-29 17:14:48 +00:00
Josh Rickmar
d0b942d414 Smarter locking for recording mined txs. 2014-01-28 16:52:47 -05:00
Josh Rickmar
3ab33bafd7 Fix typo. 2014-01-28 16:21:53 -05:00
Josh Rickmar
47906dc46c Don't use extra goroutine to rollback account data. 2014-01-28 16:11:59 -05:00
Josh Rickmar
c1c40975ab Mutex fixes for writing an exported wallet. 2014-01-28 15:03:07 -05:00
Josh Rickmar
f4c5cc1b7e Additional mutex fixes. 2014-01-28 14:43:55 -05:00
Josh Rickmar
dd3d7467c3 Fixes for writeDirtyToDisk.
This commit fixes two issues in the writeDirtyToDisk function:

First, closing the temporary files is now done using a defer, so they
are always closed.

Second, the various account mutexs are no longer unlocked using a
defer, preventing more than one from being held at once and causing a
deadlock caused by incorrect locking order.
2014-01-28 14:09:19 -05:00
Josh Rickmar
0d903a5a29 Invert allowfree option.
Boolean options cannot be unset from a default true value on the
command line, so invert the allowfree option, renaming it
disallowfree, so attaching fees may always be forced by specifying
disallowfree = true in the configuration file, or --disallowfree on
the command line.
2014-01-28 12:55:42 -05:00
Owain G. Ainsworth
df51a478f4 fix merge conflict, remove duplicate map entry 2014-01-27 23:29:49 +00:00
Owain G. Ainsworth
34b683b4aa Implement listsinceblock command
Closes #52
2014-01-27 23:17:32 +00:00
Josh Rickmar
845d54da55 Add allowfree configuration option.
It may be desirable to never allow free transactions, even if the
calculated priority is high enough that a fee would not be required,
so this change adds a global configuration option to remove this check
and always attach a fee.
2014-01-27 16:58:49 -05:00
Josh Rickmar
57df957687 Set sendfrom txid from sendrawtransaction result.
Fixes #64 and a bunch of broken notification handlers after sending a
transaction using sendfrom.
2014-01-27 16:26:58 -05:00
Josh Rickmar
b09e4f5200 Lock/unlock all account wallets.
Now that it has been decided that all account wallets will share the
same passphrase, the walletlock and walletpassphrase RPC handlers now
go through the accountstore to lock or unlock all account wallets,
rather than only changing the default account.
2014-01-27 15:48:12 -05:00
Josh Rickmar
e2bf9a03da Add getinfo to unhandled RPC handler map. 2014-01-27 15:05:31 -05:00
Josh Rickmar
6ad3f8786e Implement walletpassphrasechange RPC call.
Closes #62.
2014-01-27 14:14:54 -05:00
Josh Rickmar
3f6133e44b Add func to return passphrase of an unlocked wallet.
This function will be used to create new encrypted wallets with the
same passhprase as existing account wallets.
2014-01-24 12:31:08 -05:00
Josh Rickmar
3778ddd024 Update for btcws API change. 2014-01-24 11:17:19 -05:00
Josh Rickmar
13d310f8d4 Fix tests for previous TxStore change. 2014-01-24 09:03:25 -05:00
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