Commit graph

30 commits

Author SHA1 Message Date
Josh Rickmar b1a71d5f83 Delay JSON unmarshaling until needed.
This change takes advantage of the RawMessage type in the
encoding/json package to defer unmarshaling of all JSON-RPC values
until absolutely necessary.

This is particularly important for request passthrough when btcwallet
must ask btcd to handle a chain request for a wallet client.  In the
previous code, during the marshal and unmarshal dance to set the
original client's request id in the btcd response, large JSON numbers
were being mangled to use (scientific) E notation even when they could
be represented as a integer without any loss of precision.
2014-04-09 12:50:16 -05:00
Josh Rickmar a1b731f69e Remove old, commented-out code.
Found by @davecgh.
2014-04-08 22:09:22 -05:00
Josh Rickmar 902bbd1111 Report correct change address after composing txs. 2014-04-08 17:49:02 -05:00
David Hill 08c23d858d fix up validateaddress to use a btcjson.ValidateAddressResult.
Also fix setting the account and hex fields.

ok @jrick
2014-04-07 14:21:20 -04:00
Owain G. Ainsworth 35bd7ef6d9 rework the account manager somewhat.
- Move the MarkAddresForAccount and LookupAccountByAddress functionality
into account maanger.

- Move the wallet opeing logic into account manager (the only place that calls
it) and unexport.

- Move accountHandler to using a single channel for commands. Many of
the commands have ordering restraints (add account, list all accounts,
remove account, access account, mark account for address) which are very
much undefined with the multi-channel model.

- Rework all callers of LookupAccountByAddress to get the account structure
directly.
2014-04-03 17:52:16 +01:00
Owain G. Ainsworth 391b269d06 Implement addmultisigaddress and createmultisig. 2014-04-03 17:52:15 +01:00
Josh Rickmar 189df5c535 Mark partially synced addresses.
This change adds a notification handler for the new rescanprogress
notification and takes advantage of the recent rescan manager and
partial syncing support to mark addresses as partially synced.  If the
network connection to btcd is lost or wallet is restarted during a
rescan, a new rescan will start at the earliest block height for any
wallet address, taking partial syncs into consideration.
2014-03-28 11:28:59 -05:00
Josh Rickmar aa0980bfa7 Simplify logic in WalletRequestProcessor. 2014-03-27 22:18:23 -05:00
Jimmy Song e22d221ea8 Issue #65: Give the correct error when wallet is locked
When sending coins to an address with a wallet that's both
locked and has insufficient funds, the correct ErrWalletLocked
error will be returned.
2014-03-25 16:38:31 -05:00
Owain G. Ainsworth 6dea3789cb update for btcutil.DecodeAddress api change. 2014-03-19 01:47:12 +00:00
Josh Rickmar d179af8ecf Use min of now and blocktime for tx recv time. 2014-03-18 15:31:16 -05:00
Josh Rickmar e7cf48aa26 Warn when inconsistant TxStore is detected. 2014-03-17 20:42:47 -05:00
Josh Rickmar 089fa9de18 Rescan and track sync status of imported addresses.
The private key import codepath (called when handling the
importprivkey RPC method) was not triggering rescans for the imported
address.  This change begins a new rescan for each import and adds
additional logic to the wallet file to keep track of unsynced imported
addresses.  After a rescan on an imported address completes, the
address is marked as in sync with the rest of wallet and future
handshake rescans will start from the last seen block, rather than the
import height of the unsynced address.

While here, improve the logging for not just import rescans, but
rescanning on btcd connect (part of the handshake) as well.

Fixes #74.
2014-03-17 13:46:42 -05:00
Owain G. Ainsworth 2ef11ae7f5 Add support for pay-to-script-hash addresses to wallet. 2014-03-17 14:09:02 +00:00
Owain G. Ainsworth df31e30839 Make AddressInfo an interface.
Shortly we will add new types of address, so make AddressInfo an
interface, with concrete types providing address-specific information.
Adapt existing code to this new status quo.
2014-03-13 19:14:27 +00:00
Josh Rickmar 2e76bcd159 Handle out-of-order notifications from btcd.
Notifications ariving from btcd were being reordered (each handled by
its own goroutine, rather then being always sent in the order they
originated).  This was breaking the new transaction store by inserting
transaction records in an 'impossible' manner, that is, inserting txs
without block info after the store already held records of the same tx
with block info, without first performing a rollback.

This is handled by the transaction store insert methods by checking
for identical transactions (double spends with the same tx sha), but
where the block heights mismatch and the new record does not have a
block set.  The error is returned all the way up to the goroutine
running each rpc request/notification handler, and if hit, the btcd
connection is closed and all accounts are reopened from disk.  This is
not optimal, but it allows us to use the connect logic to correctly
catch us up to the best chain with the last good state of all accounts
while only rescanning a few blocks.

Fixes #72.
2014-02-28 15:43:50 -05:00
Josh Rickmar 76c6379a54 Update for btcutil.Address API change. 2014-02-26 15:22:48 -05:00
Josh Rickmar fc2e313a39 Introduce new transaction store.
This change replaces the old transaction store file format and
implementation.  The most important change is how the full backing
transactions for any received or sent transaction are now saved,
rather than simply saving parsed-out details of the tx (tx shas, block
height/hash, pkScripts, etc.).

To support the change, notifications for received transaction outputs
and txs spending watched outpoints have been updated to use the new
redeemingtx and recvtx notifications as these contain the full tx,
which is deserializead and inserted into the store.

The old transaction store serialization code is completely removed, as
updating to the new format automatically cannot be done.  Old wallets
first running past this change will error reading the file and start a
full rescan to rebuild the data.  Unlike previous rescan code,
transactions spending outpoint managed by wallet are also included.
This results in recovering not just received history, but history for
sent transactions as well.
2014-02-24 14:35:30 -05:00
Josh Rickmar e837ca5b64 Cleanly remove disconnected clients.
Also fixes a bug where responses for a single client would be sent to
every connected client.
2014-02-18 12:39:53 -05:00
Owain G. Ainsworth 3a6ae93a4b Implement validateaddress rpc command.
Closes #60
2014-02-14 14:35:59 +00:00
Owain G. Ainsworth ed264697e7 Implement the listunspent command
closes #54
2014-02-14 14:35:58 +00:00
Owain G. Ainsworth 70eb389029 fmt. 2014-02-13 18:42:22 +00:00
Owain G. Ainsworth 5f52df997c Add support for signmessage and verifymessage
Closes #58
Closes #61
2014-02-12 15:41:47 +00:00
Josh Rickmar 114bb581f7 Fix hang related to account file writes.
The disk syncer now maintains its own countdown timer, creating a new
timer only when necessary (when there is no timer running, and
something is scheduled to be written).  When the timer expires, the
select loop begins selecting on a grab of the account manager's binary
semaphore, and if read, performs the sync and nils the select channel
to prevent a future grab until a new timer has expired.

Tested with a race-enabled build on Windows.  No lockups or races
related to the disk syncing experienced with constant client requests
and incoming btcd notifications, and scheduled writes run as expected
once the countdown timer expires, locking out all server request and
notifiation handling.
2014-02-05 12:47:33 -05:00
Owain G. Ainsworth e685d0279f Implement SendToAddress.
Closes #56
2014-02-05 00:04:18 +00:00
Owain G. Ainsworth b978c7e059 Impelment the gettransaction rpc command.
Closes #44.
2014-02-04 16:29:33 +00: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 b90e7aae82 Implement getrawchangeaddress.
Closes #41.
2014-02-03 10:52:02 -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
Renamed from cmdmgr.go (Browse further)