Commit graph

169 commits

Author SHA1 Message Date
Dave Collins
7db8ff3f9a Update btcec import paths to new location. 2015-01-16 18:08:45 -06:00
Dave Collins
283aa28be5 Update btcwire import paths to new location. 2015-01-16 16:03:04 -06:00
Dave Collins
d71bc3193f Update btcrpcclient import paths to new location. 2015-01-15 21:28:09 -06:00
Dave Collins
174005d586 Update websocket import paths to new location. 2015-01-15 17:52:53 -06:00
Dave Collins
ea0d0ec280 Update for recent btcjson changes. 2015-01-15 17:52:12 -06:00
Dave Collins
afeb509c45 Update btcutil import paths to new location. 2015-01-15 10:48:58 -06:00
John C. Vernaleo
a702473c57 Check for nil to prevent panic.
ok jrick@
2015-01-14 09:57:28 -05:00
John C. Vernaleo
88e28a26a8 Compile again after btcjson changes. 2015-01-13 11:26:25 -05:00
Javed Khan
469a6f86eb Allow disabling RPC server TLS for localhost only.
This commit introduces a new flag, --noservertls, which can be used to disable
TLS for the RPC server.  However, the flag can only be used when the RPC
server is bound to localhost interfaces.  This is intended to prevent the
situation where someone decides they want to expose the RPC server to the
web for remote management/access, but forgot they have TLS disabled.
2015-01-09 15:07:06 +05:30
Josh Rickmar
df3779f780 Require TLS 1.2 minimum.
This prevents a downgrade attack to the vulnerable SSLv3.  While here,
go ahead and require at least TLS 1.2 since TLS 1.0 and 1.1 have their
own set of issues and it's only a matter of time before those would
need to be completely avoided as well.
2014-12-15 13:18:28 -06:00
Javed Khan
9225863706 Updated VerifyMessage to not use the keystore 2014-11-07 10:28:25 +05:30
Dave Collins
ccb2b1e16d Update for recent btcjson API change.
This commit updates the Tx field of the ListReceivedByAddressResult to
TxIDS to mirror the recent change btcjson.
2014-10-26 13:29:13 -05:00
Josh Rickmar
4c7243157f Make move and setaccount unsupported methods.
We no longer need to lie about supporting these in the future as they
will be impossible to implement correctly with the upcomming HD
wallet.
2014-10-14 13:11:11 -05:00
Javed Khan
3f99ed233f implemented ListReceivedByAccount 2014-10-13 10:08:37 -05:00
Javed Khan
9ab659cda3 Added tx ids to ListReceivedByAddress result 2014-10-13 18:50:06 +05:30
Jimmy Song
8d928ce2e1 Update for recent btcec API changes.
This change is introduced so that btcwallet will continue to compile after
issue 6 in btcec is merged.
2014-10-12 21:23:12 -05:00
Jonathan Gillham
a9cf4a2bf5 Removed hashType byte cast. 2014-10-11 21:00:27 +01:00
Jonathan Gillham
e6bdb4465d Changed TxIn.PreviousOutpoint to TxIn.PreviousOutPoint. 2014-10-01 17:27:55 +01:00
Josh Rickmar
2c52062894 Implement getreceivedbyaddress RPC.
Unlike Bitcoin Core wallet, this implementation does not ignore
coinbase transactions.
2014-09-11 10:09:02 -05:00
Josh Rickmar
5615e3530a Check websocket RPC auth for every method.
Previously, the createencryptedwallet and stop requests did not check
that the client had successfully authenticated to the server.  This
change moves the check outside of the select statement for these
special cased handlers (previously run from the default case) so an
auth check will occur even if a request method does not match either
of these two.
2014-08-19 08:03:06 -05:00
Josh Rickmar
97c9d986d4 Log an unexpected error that was encountered.
The stack trace did not make it evidant which request had caused this
issue, so add extra logging for the request that caused it.  Sanitize
this request if it may contain any secrets.

Additionally, in this situation, begin shutting down the wallet rather
than simply dropping the response.  This will help to catch the issue
since it's easier to notice all requests failing, rather than just one
that was dropped.  If shutdown takes an unreasonably long time, panic.
2014-08-14 14:23:47 -05:00
Josh Rickmar
7b90b48bc6 Fix shutdown deadlock for ws notification queue.
While here, correct the comment on rpcServer.notificationQueue.

Closes #122.
2014-08-13 09:05:08 -05:00
Josh Rickmar
42a494f762 Serialize transaction creation.
Fixes #120.
2014-08-11 21:43:59 -05:00
Javed Khan
8759d12617 allow client to disconnect when handlers are done
added a waitgroup on websocketClient to keep track of handler
goroutines specific to the client
2014-08-08 18:33:38 +05:30
David Hill
9b14cd99f1 Enable ScriptStrictMultiSig when creating or signing txs.
ok @jrick
2014-08-01 14:58:17 -04:00
Josh Rickmar
e7263e48dc Drain chain server connected notifications.
Fixes a possible hang on shutdown.
2014-08-01 11:05:26 -05:00
Josh Rickmar
5e18693d2a Register for ntfns when the RPCS creates wallets.
Previously, registerations for wallet notifications (new txs, changed
account balances) were only passed up to websocket clients if the
wallet was loaded off disk (SetWallet was called with a non-nil
wallet), and not for the case when the RPC server would create the
wallet (if it wasn't created yet, and the user manually created it
with createencryptedwallet).  This change fixes that by registering
for these notifications when this code path is taken.
2014-07-31 08:27:30 -05:00
Josh Rickmar
248ea9c08f Send btcdconnected notifications without a wallet.
The notified chain server connection state was being passed through
the wallet and then notified to the RPC server, which prevented this
notification from ever firing if a wallet didn't exist yet.  Instead,
make the RPC server register for these notifications directly from the
chain server RPC client.

I'm not happy with this notification and how it's handled in the code,
but to not break existing clients this change is being made.  Fixing
the notifiation mess and modifying existing clients to use a new
notification API will need to be done sometime later.
2014-07-30 09:47:50 -05:00
Josh Rickmar
400153d7c0 Drain notification registeration channel.
This prevents a hang when attempting to set the wallet (and register
for wallet notifications) when the process is interrupted and the rpc
server begins shutting down.
2014-07-29 08:36:28 -05:00
Josh Rickmar
549d0920f1 Fix build. 2014-07-28 09:51:49 -05:00
Josh Rickmar
c908a44665 Fix typos from my last commit. 2014-07-28 09:38:44 -05:00
Josh Rickmar
8771664af7 Send btcdconnected ntfns to connected clients.
If a websocket client was already connected and the wallet and/or
chain server is loaded into the rpc server (enabling the handlers
specific to those components), the btcdconnected notifications were
not being sent, and this could break clients that expected the
notification.  I'm not happy with this change, but since this is how
notifications are currently done (unsolicited), and to not break
compatibility yet, I'm adding these back in for now.

Eventually, this notification will require explicit registration
before it is received by a client.  See issue #84.

Closes #115.
2014-07-28 09:33:00 -05:00
Josh Rickmar
cd1aebb68e Remove 'getaddressbalance' extension RPC.
Addresses do no have balances.  In situations where a payment is
required and just a single address was provided, it is better to track
the unspent outputs themselves, rather than watching some artificial
measure of payment.
2014-07-26 10:27:10 -05:00
Josh Rickmar
49b15625b9 Fix sending next queued websocket notification. 2014-07-26 10:15:38 -05:00
Josh Rickmar
b9fd527d33 Remove account support, fix races on btcd connect.
This commit is the result of several big changes being made to the
wallet.  In particular, the "handshake" (initial sync to the chain
server) was quite racy and required proper synchronization.  To make
fixing this race easier, several other changes were made to the
internal wallet data structures and much of the RPC server ended up
being rewritten.

First, all account support has been removed.  The previous Account
struct has been replaced with a Wallet structure, which includes a
keystore for saving keys, and a txstore for storing relevant
transactions.  This decision has been made since it is the opinion of
myself and other developers that bitcoind accounts are fundamentally
broken (as accounts implemented by bitcoind support both arbitrary
address groupings as well as moving balances between accounts -- these
are fundamentally incompatible features), and since a BIP0032 keystore
is soon planned to be implemented (at which point, "accounts" can
return as HD extended keys).  With the keystore handling the grouping
of related keys, there is no reason have many different Account
structs, and the AccountManager has been removed as well.  All RPC
handlers that take an account option will only work with "" (the
default account) or "*" if the RPC allows specifying all accounts.

Second, much of the RPC server has been cleaned up.  The global
variables for the RPC server and chain server client have been moved
to part of the rpcServer struct, and the handlers for each RPC method
that are looked up change depending on which components have been set.
Passthrough requests are also no longer handled specially, but when
the chain server is set, a handler to perform the passthrough will be
returned if the method is not otherwise a wallet RPC.  The
notification system for websocket clients has also been rewritten so
wallet components can send notifications through channels, rather than
requiring direct access to the RPC server itself, or worse still,
sending directly to a websocket client's send channel.  In the future,
this will enable proper registration of notifications, rather than
unsolicited broadcasts to every connected websocket client (see
issue #84).

Finally, and the main reason why much of this cleanup was necessary,
the races during intial sync with the chain server have been fixed.
Previously, when the 'Handshake' was run, a rescan would occur which
would perform modifications to Account data structures as
notifications were received.  Synchronization was provided with a
single binary semaphore which serialized all access to wallet and
account data.  However, the Handshake itself was not able to run with
this lock (or else notifications would block), and many data races
would occur as both notifications were being handled.  If GOMAXPROCS
was ever increased beyond 1, btcwallet would always immediately crash
due to invalid addresses caused by the data races on startup.  To fix
this, the single lock for all wallet access has been replaced with
mutexes for both the keystore and txstore.  Handling of btcd
notifications and client requests may now occur simultaneously.
GOMAXPROCS has also been set to the number of logical CPUs at the
beginning of main, since with the data races fixed, there's no reason
to prevent the extra parallelism gained by increasing it.

Closes #78.

Closes #101.

Closes #110.
2014-07-25 13:26:14 -05:00
Josh Rickmar
7ca16dfe70 Synchronize notifications and client gr shutdown.
The responses chan for a websocket client was being closed by one of
the websocket goroutines, but it was not the only sender to this
channel.  There was also the notification handler, run by the server
to handle notifications to all websocket clients.  It was possible to
hit cases where sends to this channel would still occur (the select
statement doesn't guarantee that the picked channel operation won't
panic, even if there's another that won't).  To fix this, wait on the
client being removed from the notification group, or if the server is
already shutting down, wait on the notification handler completely
closing, to ensure that no more sends to the channel will occur,
before closing the channel.

Fixes #110.
2014-07-14 09:24:41 -05:00
Josh Rickmar
b42ab5b743 Handle *btcjson.Error errors from RPC handlers.
The btcrpcclient package returns RPC errors as *btcjson.Error, but
wallet was only handling btcjson.Error (no pointer) as special.
Handle both.
2014-07-08 15:41:59 -05:00
Josh Rickmar
3dba4ba87d Rename wallet package to keystore.
This package is used solely for the storage of private and public
keys, and the addresses they represent.  Since "wallet" is an
overloaded term and a working wallet requires transaction history as
well, rename this package and its data structures to more clearly
reflect what it is for.
2014-07-08 14:04:31 -05:00
Josh Rickmar
2d9fb71afd Move fee increment to Account structure.
When a BIP0032 wallet is implemented and multiple address chains can
be supported by a single keystore, the Account structure will
represent a single wallet (and be renamed to reflect that change),
rather than keeping the collection of Account structs as currently
managed by the AccountManager.  In preperation for this, and to remove
a global variable, move the fee increment for created transactions to
this structure.  When setting the fee, look it up from the default
account.
2014-07-08 11:33:19 -05:00
Josh Rickmar
0abe6e32bf Updates for untyped btcutil consts. 2014-07-08 11:22:09 -05:00
Javed Khan
9036d36e68 Fix hang during shutdown when client is connected.
Closes #108.
2014-07-08 09:03:03 -05:00
Josh Rickmar
061a220354 Move last seen block to RPC client structure.
Pass the RPC client to the notification handlers.  Update the last
seen block for blockconnected notifications in the client structure
directly, protecting access with a mutex.
2014-07-07 16:57:00 -05:00
Josh Rickmar
770384be12 Write imported multisig addresses to disk.
When the addmultisigaddress RPC was called, the wallet with the
imported address was not being written to disk, and if no more writes
were scheduled, the address could be lost.  This change immediately
writes the updated keystore to disk before the RPC returns.

Closes #98.
2014-07-07 11:23:53 -05:00
Josh Rickmar
5a3be85bf4 Mark imported script addresses for their account.
Spotted by @tuxcanfly.
2014-07-07 10:38:14 -05:00
Tomás Senart
9f4bfeb056 Throttle RPC and WS concurrent active clients
This change set implements tunable concurrent active clients throttling.
2014-07-03 13:12:37 -05:00
Josh Rickmar
f8f7eed4ae Pass even byte length strings to hex.DecodeString.
ok @davecgh
2014-07-01 21:05:02 -05:00
Josh Rickmar
e64d948093 Synchronize locking/unlocking of all keystores.
This change fixes the asynchronous deferred locking that used to be
performed after some timeout after a call to walletpassphrase by
managing the locked state of each account in a new account manager
goroutine.  The timeouts for new unlock requests replace any running
timeouts for older requests, rather than allowing previous timeouts to
expire before the most recent one.

Fixes #105.
2014-07-01 10:09:50 -05:00
Dave Collins
478a7ec867 Update for recent btcjson changes.
This commit updates the types to match the recent changes to the btcjson
result types.
2014-06-29 17:48:07 -05:00
Josh Rickmar
2a006cc83a Clean up interface pointer ID handling. 2014-06-27 16:05:01 -05:00
Josh Rickmar
6909e0dc68 Remove stray fmt.Printf. 2014-06-27 16:03:08 -05:00
Josh Rickmar
c0e77b3e2d Add additional server shutdown checking. 2014-06-25 11:40:40 -05:00
Josh Rickmar
cb6969843b Remove gettxout and gettxoutsetinfo handlers.
These RPCs should be implemented by btcd (see conformal/btcd#141 and
conformal/btcd#142), so remove them from the RPC handlers map.
2014-06-24 16:59:15 -05:00
Josh Rickmar
5155ea1b28 Wait for account manager shutdown during server shutdown. 2014-06-24 16:11:06 -05:00
Josh Rickmar
b145868a4b Implement clean ^C shutdown and add the stop RPC.
Closes #69.
2014-06-24 16:00:27 -05:00
Josh Rickmar
85af882c13 Implement lockunspent and listlockunspent.
Closes #50.

Closes #55.
2014-06-23 16:59:57 -05:00
Josh Rickmar
cf92f1e5df Remove getwork and getblocktemplate handlers.
These are being implemented by btcd, so there's no reason to have
handlers here as well.
2014-06-20 16:08:16 -05:00
Josh Rickmar
632148ed55 Fix various issues found by profiling.
This commit is the result of inspecting the results of both cpu and
memory profiling, to improve areas where wallet can be more efficient
on transaction inserts.

One problem that's very evident by profiling is how much waiting there
is for file (txstore, wallet) writes.  This commit does not attempt to
fix this yet, but focuses on the easier-to-fix memory allocation
issues which can slow down the rest of wallet due to excessive garbage
collection scanning.

While here, fix a race where a closure run as a goroutine was closing
over a range iterator.
2014-06-18 17:08:02 -05:00
Josh Rickmar
6a72a0ad4d Pass txstore.Credit/Debits directly, not pointers.
The Credit and Debits structures are simple wrappers around an
embedded *txstore.TxRecord, as well as an output index in the case of
Credit.  This means that a Credit is at most two words, while a Debits
struct is just one.  To avoid the unnecessary garbage of creating
Credit and Debits structures on the heap (where the underlying
TxRecord likely already is), simply pass around everywhere as
non-pointer types, and modify the receivers for all Credit and Debits
methods to non-pointer receivers since none of them ever modify the
value.
2014-06-18 00:16:08 -05:00
Josh Rickmar
83e27ae7db Remove unused goroutine. 2014-06-17 08:38:34 -05:00
Josh Rickmar
0f808dc00f Remove unnecessary uint32 type conversions. 2014-06-16 16:25:04 -05:00
Josh Rickmar
f418fe3772 Remove tx send/recv write order synchronization.
This was only necessary for a very old version of the transaction
store.  The current implementation stores both sent (debit) and
received (credit) records for individual transactions.
2014-06-16 15:47:05 -05:00
Josh Rickmar
afee3e2ca7 No need to check map before removing a key. 2014-06-16 15:32:20 -05:00
Josh Rickmar
3ff16d7539 Modify websocket endpoint from 'frontend' to 'ws'. 2014-06-12 12:54:58 -05:00
Josh Rickmar
ec92578194 Switch to gorilla websocket and btcrpcclient.
Closes #96.
2014-06-12 11:39:26 -05:00
Nicola 'tekNico' Larosa
7ec4e96c6b Implement listreceivedbyaddress.
Closes #53.
2014-06-10 22:19:50 -05:00
Josh Rickmar
99c986e21f Consistantly create empty bytes.Buffers. 2014-06-04 22:23:32 -05:00
Josh Rickmar
d863c75be7 Fix and simplify RPC server error handling.
This change rewrites much of the error handling for the RPC server
components to match a more idiomatic Go error handling style as well as
fix several issues regarding error equality checks.

Closes #94.
2014-06-03 19:55:48 -05:00
Josh Rickmar
6597d789b7 Avoid slice out-of-bounds indexing panic.
The gettransaction handler was attempting to lookup the "sent-to"
address of an outgoing transaction from the transaction store (as a
wallet credit).  This is the incorrect address when sending to an
address controlled by another wallet, and panics when there are no
credits (for example, sending to another wallet without any change
address).  Instead, use the first non-change output address is used as
the address of the "send" result.

This fixes the panic reported when debugging issue #91.

While here, fix the category strings used for wallet credits to
support immature and generate (the categories for coinbase outputs).
2014-06-02 11:56:38 -05:00
Josh Rickmar
733677433d Use btcjson.ErrWallet for createencryptedwallet.
If an unexpected error is encounted when creating the encrypted
wallet, rather than using btcjson.ErrInternal, wrap the error message
using btcjson.ErrWallet.Code.
2014-05-30 09:31:42 -05:00
Josh Rickmar
242cb22719 Check every error.
This change is the result of using the errcheck tool
(https://github.com/kisielk/errcheck) to find all unchecked errors,
both unassigned and those assigned to the blank identifier.

Every returned error is now handled in some manner.  These include:

  - Logging errors that would otherwise be missed
  - Returning errors to the caller for further processing
  - Checking error values to determine what to do next
  - Panicking for truely exceptional "impossible" errors

On the subject of panics, they are a sharp tool and should be used
sparingly.  That being said, I have added them to check errors that
were previously explicitly ignored, because they were expected to
always return without failure.  This could be due to fake error paths
(i.e. writing to a bytes.Buffer panics for OOM and should never return
an error) or previous logic asserts that an error case is impossible.
Rather than leaving these unhandled and letting code fail later,
either with incorrect results or a nil pointer dereference, it now
produces a stack trace at the error emit site, which I find far more
useful when debugging.

While here, a bunch of dead code was removed, including code to move
pre-0.1.1 uxto and transaction history account files to the new
directory (as they would be unreadable anyways) and a big chunk of
commented out rpcclient code.
2014-05-28 00:10:35 -05:00
Josh Rickmar
4495a523d8 Updates for btcutil and btcscript's btcnet conversion. 2014-05-27 17:49:36 -05:00
Owain G. Ainsworth
2c4ea4e4bc hashtype is not flag based despite having a flag embedded.
So (SigHashAll & SigHashSingle)!= 0, which is not the intention here. fix up
that check to only match SigHashSingle.

Found by drahn, debugged together, fix by me.
2014-05-27 23:46:21 +01:00
Josh Rickmar
c3224f4fbc Begin update to use btcnet.Params.
This is an intial pass at converting the btcwallet and deps codebases
to pass a network by their parameters, rather than by a magic number
to identify the network.  The parameters in params.go have been
updated to embed a *btcnet.Params, and all previous uses of cfg.Net()
have been replaced with activeNet.{Params,Net} (where activeNet is
the global var for the active network).

Although dependancy packages have not yet been updated from using
btcwire.BitcoinNet to btcnet.Params, the parameters are now accessible
at all callsites, and individual packages can be updated to use btcnet
without requiring updates in each external btc* package at once.

While here, the exported API for btcwallet internal library packages
(txstore and wallet) have been updated to pass full network parameters
rather than the btcwire definition of a network.
2014-05-22 21:24:08 -05:00
Josh Rickmar
987dc8f1c4 Updates for btcutil WIF API changes. 2014-05-21 17:50:47 -05:00
Geert-Johan Riemer
3fb569e73d btcec is changed, this fixes btcwallet to work with the new changes. 2014-05-20 10:48:09 -05:00
Josh Rickmar
c4a0b70835 go fmt. 2014-05-16 12:48:50 -05:00
Josh Rickmar
f36a83b3cc Rename tx package to txstore.
Prodded by @davecgh, and I had this change in the back of my head for
a while now anyways.
2014-05-08 14:51:33 -05:00
Owain G. Ainsworth
2762d58a83 Add support for the signrawtransaction command. 2014-05-07 16:08:50 +01:00
Owain G. Ainsworth
49adb8312f Add acctmgr.Address to look up any known address.
Use where possible to shorten things.
2014-05-07 16:08:47 +01:00
Josh Rickmar
e39fa32487 Fix listtransactions category for coinbase outputs.
The category for a received coinbase output should be "generate" for a
mature coinbase (one that has reached btcchain.CoinbaseMaturity
confirmations), or "immature" if the required number of confirmations
has not been reached yet.  New Confirmed and Confirmations methods
have been added to the transaction store's TxRecord type to check if
the required number of confirmations have been met for coinbase
outputs.

While here, update the main package to use the new TxRecord methods,
rather than duplicating the confirmation checking code in two places.
2014-05-06 22:48:12 -05:00
Josh Rickmar
e9bdf2a094 Another day, another tx store implementation.
The last transaction store was a great example of how not to write
scalable software.  For a variety of reasons, it was very slow at
processing transaction inserts.  Among them:

1) Every single transaction record being saved in a linked list
   (container/list), and inserting into this list would be an O(n)
   operation so that records could be ordered by receive date.

2) Every single transaction in the above mentioned list was iterated
   over in order to find double spends which must be removed.  It is
   silly to do this check for mined transactions, which already have
   been checked for this by btcd.  Worse yet, if double spends were
   found, the list would be iterated a second (or third, or fourth)
   time for each removed transaction.

3) All spend tracking for signed-by-wallet transactions was found on
   each transaction insert, even if the now spent previous transaction
   outputs were known by the caller.

This list could keep going on, but you get the idea.  It was bad.

To resolve these issues a new transaction store had to be implemented.
The new implementation:

1) Tracks mined and unmined transactions in different data structures.
   Mined transactions are cheap to track because the required double
   spend checks have already been performed by the chain server, and
   double spend checks are only required to be performed on
   newly-inserted mined transactions which may conflict with previous
   unmined transactions.

2) Saves mined transactions grouped by block first, and then by their
   transaction index.  Lookup keys for mined transactions are simply
   the block height (in the best chain, that's all we save) and index
   of the transaction in the block.  This makes looking up any
   arbitrary transaction almost an O(1) operation (almost, because
   block height and block indexes are mapped to their slice indexes
   with a Go map).

3) Saves records in each transaction for whether the outputs are
   wallet credits (spendable by wallet) and for whether inputs debit
   from previous credits.  Both structures point back to the source
   or spender (credits point to the transaction that spends them, or
   nil for unspent credits, and debits include keys to lookup the
   transaction credits they spent.  While complicated to keep track
   of, this greatly simplifies the spent tracking for transactions
   across rollbacks and transaction removals.

4) Implements double spend checking as an almost O(1) operation.  A
   Go map is used to map each previous outpoint for all unconfirmed
   transactions to the unconfirmed tx record itself.  Checking for
   double spends on confirmed transaction inserts only involves
   looking up each previous outpoint of the inserted tx in this map.
   If a double spend is found, removal is simplified by only
   removing the transaction and its spend chain from store maps,
   rather than iterating a linked list several times over to remove
   each dead transaction in the spend chain.

5) Allows the caller to specify the previous credits which are spent
   by a debiting transaction.  When a transaction is created by
   wallet, the previous outputs are already known, and by passing
   their record types to the AddDebits method, lookups for each
   previously unspent credit are omitted.

6) Bookkeeps all blocks with transactions with unspent credits, and
   bookkeeps the transaction indexes of all transactions with unspent
   outputs for a single block.  For the case where the caller adding a
   debit record does not know what credits a transaction debits from,
   these bookkeeping structures allow the store to only consider known
   unspent transactions, rather than searching through both spent and
   unspents.

7) Saves amount deltas for the entire balance as a result of each
   block, due to transactions within that block.  This improves the
   performance of calculating the full balance by not needing to
   iterate over every transaction, and then every credit, to determine
   if a credit is spent or unspent.  When transactions are moved from
   unconfirmed to a block structure, the amount deltas are incremented
   by the amount of all transaction credits (both spent and unspent)
   and debited by the total amount the transaction spends from
   previous wallet credits.  For the common case of calculating a
   balance with just one confirmation, the only involves iterating
   over each block structure and adding the (possibly negative)
   amount delta.  Coinbase rewards are saved similarly, but with a
   different amount variable so they can be seperatly included or
   excluded.

Due to all of the changes in how the store internally works, the
serialization format has changed.  To simplify the serialization
logic, support for reading the last store file version has been
removed.  Past this change, a rescan (run automatically) will be
required to rebuild the transaction history.
2014-05-05 16:12:05 -05:00
David Hill
6b24abfdad Code cleanup.
- Additional error checking
- Use the stack for small data sizes to avoid garbage collection
- Use io.ReadFull vs Read to detect underflows
2014-04-16 17:22:39 -04:00
David Hill
d9432fe8ad Have listsinceblock return a btcjson result type.
ok @jrick
2014-04-11 20:33:15 -04:00
Josh Rickmar
00403c7839 Use []Type{} instead of make([]Type, 0). 2014-04-11 13:58:04 -05:00
David Hill
f08da980f0 Cleanup TxInfo 2014-04-11 14:51:41 -04:00
David Hill
880c1cbaeb Make gettransaction return a btcjson GetTransactionResult type 2014-04-11 14:10:27 -04:00
Dave Collins
677ec10ee7 Convert all tx results to use new concrete type.
This commit modifies all code paths which work with transaction result
objects to use the concrete ListTransactionsResult provided by the btcjson
package.  This provides nicer marshalling and unmarshalling as well as
access to properly typed fields.
2014-04-10 21:15:35 -05:00
Owain G. Ainsworth
674e9f2427 Rework wallet apis somewhat.
- Instead of returning a special constructed type whenever queries for an
address.  Return the internal object with an immutable external
interface.

- Make the private key gettable from PubKeyAddress to prevent having to look up
multiple times to get information from the same structure

- Enforce addresses always have public keys.
2014-04-09 22:40:28 +01:00
David Hill
936d922579 Return a btcjson result type for createmultisig.
ok @jrick
2014-04-09 13:57:28 -04:00
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