Commit graph

830 commits

Author SHA1 Message Date
Dave Collins
e3769bcec6 Add the new ErrInvalidKeyType to the stringer map.
Also add it to the stringer test.
2014-10-31 10:20:58 -05:00
Dave Collins
732ffe4ed1 Address a couple of nits with recent En(De)crypt.
This commit adds comments about the specific crypto key types, moves the
selectCryptoKey function before the Encrypt/Decrypt functions that call it
to be more consistent with the rest of the code base, and slightly
modifies the verbiage of the comment.
2014-10-31 10:09:44 -05:00
Lars Hesel Christensen
7f7f6f33cb Expose functions needed from the voting pool package 2014-10-31 11:28:26 +01:00
Javed Khan
50da5a9f8c Update unspentOutputs to remove spent unconfirmed outputs 2014-10-29 11:06:21 -05:00
Dave Collins
fb7e87b1ef Move new addrmgr Options type and default to top.
Default values near the top of the file is preferrable so they are more
easily spotted.
2014-10-29 02:27:38 -05:00
Lars Hesel Christensen
402fcf0dd0 Make scrypt parameters overridable/optional 2014-10-28 23:46:28 -05:00
Guilherme Salgado
ec8a5bc10c Refactor txToPairs into smaller functions
Also adds tests for those functions, and improve fee estimation.
2014-10-28 15:12:15 -02:00
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
Javed Khan
2ea0ef66ea revert cafile error handling, continue with nil
This reverts commit 2a5e8587f6.
2014-10-15 23:15:35 +05:30
Josh Rickmar
fb1530a78f Remove plan9 rename function.
This function was misleading because it was actually *not* atomic
(meaning it should have never been used at all where atomicity was
required).  This will break builds on Plan 9 but I consider this fine
to do since the soon-to-be-integrated waddrmgr package relies on bolt
as a database and also does not compile for Plan 9.
2014-10-14 13:46:49 -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
2a5e8587f6 Handle chain server connection errors, if any 2014-10-14 22:28:47 +05:30
Dave Collins
966b6b0ec7 Unexport the cryptoKey type.
The crypto key type unsed in the manager is not needed outside of the
package.  Also, rather than having the newCryptoKey func return the
specific cryptoKey type, make it return the EncryptorDecryptor interface.
This will allow it to be overridden with another type that implements the
interface from the tests.
2014-10-13 16:19:12 -05:00
Guilherme Salgado
85f4856230 Allow injection of crypto keys into the manager.
Useful to test error conditions.

Also provide a new function that wraps snacl.GenerateCryptoKey(),
defined as a variable so that it can be replaced in tests.
2014-10-13 16:19:11 -05:00
Dave Collins
d0938d817f Provide new wallet address manager package.
This commit implements a new secure, scalable, hierarchical deterministic
wallet address manager package.

The following is an overview of features:

- BIP0032 hierarchical deterministic keys
- BIP0043/BIP0044 multi-account hierarchy
- Strong focus on security:
  - Fully encrypted database including public information such as
    addresses as well as private information such as private keys and
    scripts needed to redeem pay-to-script-hash transactions
  - Hardened against memory scraping through the use of actively clearing
    private material from memory when locked
  - Different crypto keys used for public, private, and script data
  - Ability for different passphrases for public and private data
  - Scrypt-based key derivation
  - NaCl-based secretbox cryptography (XSalsa20 and Poly1305)
  - Multi-tier scalable key design to allow instant password changes
    regardless of the number of addresses stored
- Import WIF keys
- Import pay-to-script-hash scripts for things such as multi-signature
  transactions
- Ability to export a watching-only version which does not contain any
  private key material
- Programmatically detectable errors, including encapsulation of errors
  from packages it relies on
- Address synchronization capabilities

This commit only provides the implementation package.  It does not
include integration into to the existing wallet code base or conversion of
existing addresses.  That functionality will be provided by future
commits.
2014-10-13 16:19:09 -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
Guilherme Salgado
4a2c4a38c9 Fix a couple comments 2014-09-23 07:36:49 -03: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
Dave Collins
7faa16c238 Configure TravisCI to pull pkgs needed for tests. 2014-08-30 00:14:00 -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
757244a8da Fix logging for improper redeemingtx notifications. 2014-08-14 15:27:14 -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
Josh Rickmar
8bc6eee32c Begin with root key index when reading keystores.
Instead of using the zero value, explicitly set the last chain index
to -1, which represents the root key.  If no additional keys are read
from the io.Reader, this could result in panics when looking up keys
at index 0, when no additional keys have been created yet.

Fixes #119.
2014-08-06 08:48:17 -05:00
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
Guilherme Salgado
ef6aa91b6a Refactor Wallet.txToPairs into smaller functions
Also add a unit test for one of them.
2014-07-31 16:52:52 -03:00
Guilherme Salgado
868625d8c3 Remove a unused channel from chain.NewClient 2014-07-31 14:33:46 -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
dd856160aa Save logs to network specific directories.
Fixes #114.
2014-07-30 12:17:19 -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
2b5eefae56 Use btcd-specific RPC user/pass for chain RPC. 2014-07-28 09:52:16 -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
Michalis Kargakis
a4dab8a713 Update travis
Tested on lint.travis-ci.org
2014-07-22 14:09:04 +03: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
35b929aa6b go fmt 2014-07-08 14:09:58 -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