Commit graph

99 commits

Author SHA1 Message Date
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 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
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 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 3778ddd024 Update for btcws API change. 2014-01-24 11:17:19 -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
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 4c97bd3c5c Add dummy handlers for getblocktemplate and getwork. 2014-01-15 14:53:09 -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 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 15c85b5c75 Fix same issue as before, but for getaccountaddress. 2014-01-06 16:39:32 -05:00
Josh Rickmar bdf2198215 Reply to getnewaddress with the encoded address. 2014-01-06 16:33:07 -05:00
Josh Rickmar e8265eca41 Switch to new btcutil Address encoding/decoding API. 2014-01-06 12:24:29 -05:00
Josh Rickmar ac79a59c90 Implement the getaccountaddress RPC command. 2013-12-31 14:39:27 -05:00
Josh Rickmar fa699ef4a5 Add getaccount RPC command. 2013-12-30 16:31:33 -05:00
Josh Rickmar 920ff10155 Add getunconfirmedbalance websocket RPC extension. 2013-12-30 15:11:41 -05:00
Josh Rickmar 8be51e37cf Add handlers to unimplemented RPC requests.
Fixes #29.
2013-12-30 12:44:51 -05:00
Josh Rickmar 5bf8f89e4b Add listaddresstransactions extension.
Fixes #27.
2013-12-30 11:10:06 -05:00
Josh Rickmar 614ed93a1d Support mempool transaction notifications. 2013-12-20 12:48:47 -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 48a685e85e Calculate the minimum tx fee when creating transactions. 2013-12-04 12:13:40 -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 2dd3fd0a21 Fix build. 2013-11-27 16:07:00 -05:00
Josh Rickmar 0056958dfa More verbose tx handling. 2013-11-27 14:50:43 -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 38ed238a7f Refill keypool if empty and wallet is unlocked. 2013-11-22 11:34:40 -05:00
Josh Rickmar 57802d8daf Rename some Account variables. 2013-11-21 11:23:50 -05:00
Josh Rickmar 649112b764 Reply with errors if the expected account does not exist.
This fixes the cases for the walletlock and walletpassphase requests
to return an appropiate error to the frontend when the default account
does not exist.
2013-11-21 11:06:46 -05:00
Josh Rickmar 47b5e17917 Return from dumpwallet handler after replying with an error. 2013-11-21 10:40:09 -05:00
Josh Rickmar 908b419443 Fix a typo. 2013-11-21 10:34:51 -05:00
Josh Rickmar 7e0a24950a Disable dumpwallet RPC handler that snuck in.
We do not support this yet, and need to match bitcoin'd behavior
before the function is added back to the RPC handler map.
2013-11-19 20:44:37 -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 28087af90b Add handling for standard bitcoind-style RPC.
With the exception of the createencryptedwallet extension (which is
required to make a wallet), all websocket-specific handlers are now
only available from a websocket connection, and standard RPC requests
are handled with a normal HTTP request and reply.

As an added bonus, listening on IPv6 now works.
2013-11-18 15:51:50 -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 b7aec7f7a1 Type assert GetNewAddressCmd correctly. 2013-11-12 12:40:20 -05:00
Josh Rickmar be26855266 Clean up replying to frontend commands.
This change moves the handlers to a map (instead of falling through a
switch statement), and updates each handler to use a btcjson.Cmd
instead of passing parameters in a btcjson.Message manually.

Plenty of comments were also added, which should also make the code
much more understandable.
2013-11-12 12:01:32 -05:00
Josh Rickmar cdd9bea5db Log sent tx ids to debug.
While here, add createdTx to unmined pool for 'sendfrom' commands as
well, instead of just 'sendmany'.
2013-11-07 15:29:17 -05:00
Josh Rickmar 85219a70d3 Update for new btcd notifications.
This removes the enforced check for the spent field for tx-to-me
notifications, as this is no longer sent, and should be calculated by
wallet (not done yet).  Additionally, the full CreatedTx information
is saved with the unmined tx map, so when a tx is mined, information
about which inputs and ouputs it creates that are relevant to the
wallet can be used.
2013-11-06 14:05:14 -05:00
Josh Rickmar f809638c72 Write dirty wallet to disk if a change address is added. 2013-11-06 12:52:01 -05:00
Josh Rickmar e65206f752 Begin using btcws.
This change begins using the btcws package for marshaling custom
commands used for websocket connections to btcd.
2013-11-06 11:23:30 -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