Commit graph

716 commits

Author SHA1 Message Date
Josh Rickmar fcccae3d1a Manage wallet db namespaces from wallet package.
This changes the wallet.Open function signature to remove the database
namespace parameters.  This is done so that the wallet package itself
is responsible for the location and opening of these namespaces from
the database, rather than requiring the caller to open these ahead of
time.

A new wallet.Create function has also been added.  This function
initializes a new wallet in an empty database, using the same
namespaces as wallet.Open will eventually use.  This relieves the
caller from needing to manage wallet database namespaces explicitly.

Fixes #397.
2016-03-21 11:25:28 -04:00
John C. Vernaleo b1500ba02b Print version string at startup.
This makes btcwallet match btcd's behavior.

Initially pointed out in:
decred/dcrwallet#125
2016-03-21 09:27:30 -04:00
Josh Rickmar 5d6392b65d Fix race in TestThrottle test.
Closes #355.
2016-03-16 11:55:27 -04:00
Josh Rickmar 71649abefe improve language 2016-03-11 17:01:04 -05:00
Josh Rickmar 6e6cb307fa Log wallet locks and unlocks.
Fixes #392.
2016-03-11 16:22:43 -05:00
Josh Rickmar 6cf22b7944 Remove legacy JSON-RPC notifications.
These notifications were added to support real time updates for
btcgui.  As the btcgui project is no longer being developed, there are
no more consumers of this API, and it makes sense to remove them given
their various issues (the largest being that notifiations are sent
unsubscribed to clients that may never be interrested in them).

A new notification server has already been added to the wallet package
to handle notifications in a RPC-server agnostic way.  This server is
the means by which the wallet notifies changes for gRPC clients.  If
per-client registered notifications are to be re-added for the
JSON-RPC server, they should be integrated with the new notification
server rather than using this legacy code.
2016-03-11 14:14:33 -05:00
Josh Rickmar 9fe02c43ca Disallow naming accounts the empty string.
This change only prevents creating new accounts with the empty name or
renaming an existing account to one.  Any accounts in the DB that are
already named the empty string are left untouched (and should be
renamed to something meaningful by the user).

Fixes #369.
2016-03-11 10:45:09 -05:00
Josh Rickmar cee0411a2e Default to mainnet.
Note that this is a breaking change since it removes the mainnet
config option, replacing it with a testnet option.  Old configuration
files that set mainnet=1 will cause the wallet to error during startup
since extraneous flags are treated as errors.

Because configuration files will have to be updated for the change
regardless, the old deprecated (and unused) options `disallowfree` and
`keypoolsize` have also been removed.

Closes #383.
2016-03-11 09:08:38 -05:00
Josh Rickmar 2b79aad79c Stop wallet and close wallet DB on interrupt.
This corrects and simplifies the shutdown logic for interrupts, the
walletrpc.WalletLoaderService/CloseWallet RPC, and the legacy stop RPC
by both stopping all wallet processes and closing the wallet database.
It appears that this behavior broke as part of the wallet package
refactor, causing occasional nil pointer panics and memory faults when
closing the wallet database with active transactions.

Fixes #282.

Fixes #283.
2016-03-10 23:10:18 -05:00
Josh Rickmar 24fc8bb6c5 Read synchronized relay fee once when checking outputs. 2016-03-09 15:03:42 -05:00
Josh Rickmar d09c2a84c1 Protect the relay fee field with a mutex.
This prevents races when setting a new relay fee through the legacy
RPC server (settxfee).

Fixes #379.
2016-03-09 14:54:09 -05:00
Janus Troelsen 397beadfd5 Fix spelling in legacy test and docs using aspell 2016-03-09 20:39:03 +01:00
Josh Rickmar f084802fec Refactor wallet transaction creation code.
This began as a change to improve the fee calculation code and evolved
into a much larger refactor which improves the readability and
modularity of all of the transaction creation code.

Transaction fee calculations have been switched from full increments
of the relay fee to a proportion based on the transaction size.  This
means that for a relay fee of 1e3 satoshis/kB, a 500 byte transaction
is only required to pay a 5e2 satoshi fee and a 1500 byte transaction
only need pay a 1.5e3 fee.  The previous code would end up estimating
these fees to be 1e3 and 2e3 respectively.

Because the previous code would add more fee than needed in almost
every case, the transaction size estimations were optimistic
(best/smallest case) and signing was done in a loop where the fee was
incremented by the relay fee again each time the actual size of the
signed transaction rendered the fee too low.  This has switched to
using worst case transaction size estimates rather than best case, and
signing is only performed once.

Transaction input signature creation has switched from using
txscript.SignatureScript to txscript.SignTxOutput.  The new API is
able to redeem outputs other than just P2PKH, so the previous
restrictions about P2SH outputs being unspendable (except through the
signrawtransaction RPC) no longer hold.

Several new public packages have been added:

wallet/txauthor - transaction authoring and signing
wallet/txfees - fee estimations and change output inclusion
wallet/txrules - simple consensus and mempool policy rule checks

Along with some internal packages:

wallet/internal/txsizes - transaction size estimation
internal/helpers - context free convenience functions

The txsizes package is internal as the estimations it provides are
specific for the algorithms used by these new packages.
2016-03-08 17:42:27 -05:00
John C. Vernaleo 82e743754f Rename some rpc commands to something more generic.
StartBtcdRpc becomes StartConsensusRpc.

This is useful for forks such as decred or if someone were to write
another compatible server.

Bump up the api version as this is a change.
2016-03-03 14:22:14 -05:00
Josh Rickmar 5140086f6e Use LICENSE file and short license headers. 2016-02-28 22:22:34 -05:00
Josh Rickmar 620a3c649e Add VersionService to gRPC server to query server versions.
Fixes #375.
2016-02-24 00:22:37 -05:00
Josh Rickmar f03556b2f9 Document changes to the NextAddress RPC. 2016-02-23 19:39:53 -05:00
Josh Rickmar 8455454ed5 Add Kind enum to NextAddress request.
Fixes #371.
2016-02-23 18:03:39 -05:00
Josh Rickmar b286d697c9 Regenerate gRPC files from descriptor. 2016-02-23 17:16:34 -05:00
Josh Rickmar 0a9645326d Follow specification for FundTransaction RPC.
The specification states that even when the target output amount
cannot be reached, all available outputs should still be included in
the response and it is up to the caller to check that the target can
be satisified or not.  Follow this behavior by not erroring when the
target was not met.
2016-02-23 12:55:13 -05:00
Josh Rickmar d2e93f9427 Make walletpassphrase with timeout=0 never lock the wallet.
This broke when the Unlock API changed to replace the timeout in
seconds with a time.Time channel.
2016-02-15 11:35:28 -05:00
Josh Rickmar 4171638553 Fix several typos in documentation and comments. 2016-02-12 11:58:38 -05:00
Josh Rickmar da145968c4 Create results for each wallet.TransactionSummary output.
The gRPC server requires this as it must include the properties of
every transaction output, not just those that are controlled by the
wallet.
2016-02-12 11:44:36 -05:00
Josh Rickmar 2806a153df Use btcsuite vendored crypto repo. 2016-02-11 11:20:03 -05:00
John C. Vernaleo 2808c4fe40 If wallet already exists show path.
This was initially pointed out by davec in
decred/dcrwallet#18
2016-02-11 10:51:25 -05:00
Josh Rickmar 567752ea9b Add option for one time TLS keys.
This option prevents the RPC server TLS key from ever being written to
disk.  This is performed by generating a new certificate pair each
startup and writing (possibly overwriting) the certificate but not the
key.

Closes #359.
2016-02-11 00:15:30 -05:00
Josh Rickmar 97963b47ce Update README for gRPC changes.
While here, remove mention of btcgui and add a disclaimer that total
compatibility with the JSON-RPC server cannot be achieved.
2016-02-09 10:42:43 -05:00
Josh Rickmar 102cd553c5 Set account name for gettransaction results.
This only sets the name for any kind of "receiving" category
(receive/immature/generate).

Fixes #360.
2016-02-09 09:41:39 -05:00
Olaoluwa Osuntokun 32ca19322a Allow spending from the waddrmgr.ImportedAddrAccount via wallet.SpendPairs.
Previously, when creating a change address during the process of
creating a new transaction an error case would be hit in the waddrmgr
triggered by attempting to derive a new internal address from under a
waddrmgr.ImportedAddrAccount. To remedy this error, we now use the
default account for change when spending outputs from an imported
key. This approach allows funds under the control of imported
private keys to be protected under the wallet's seed as soon as
they've been partially spent.
2016-02-06 13:15:50 -08:00
Josh Rickmar b480a0a09d Set account field in listtransactions result.
This field is only set for non-"send" categories since the wallet does
not track a "from account" like Core's wallet does.

Fixes #353.
2016-02-06 14:59:32 -05:00
Josh Rickmar cc97e063b8 Do not error for empty tx comments.
This prevents the server from returning an error when empty strings
are passed as parameters for transaction comments for the
sendfrom/sendmany/sendtoaddress RPCs.  Non-empty strings will still
cause errors since transaction comments are not saved.

Fixes #356.
2016-02-02 09:56:02 -05:00
Josh Rickmar fda2e14b99 Change datadir short option to -b.
Fixes #339.
2016-02-01 17:39:04 -05:00
John C. Vernaleo aec660c749 Return WWW-Authenticate header
On invalide credentials return WWW-Authenticate the same way btcd does.

Pointed out by @davec in decred/dcrwallet#14
2016-02-01 09:10:22 -05:00
Josh Rickmar 515cbc69ce Always lock waddrmgr for every timeout or explicit request.
Use waddrmgr.IsError to avoid logging errors when trying to lock an
already locked wallet.

Fixes #349.
2016-01-31 22:38:59 -05:00
Olaoluwa Osuntokun 4c839ae3d3 Generate a seed when creating a new wallet if none was provided.
Previously, if a nil seed was passed into loader.CreateNewWallet, a
random seed was never generated. This would cause an error within the
waddrmgr due to the seed being of invalid (0) length.
2016-01-31 13:37:57 -08:00
Josh Rickmar bb1102b414 Fix fee calculation for gettransaction. 2016-01-29 12:58:05 -05:00
Josh Rickmar 497ffc11f0 Modernize the RPC server.
This is a rather monolithic commit that moves the old RPC server to
its own package (rpc/legacyrpc), introduces a new RPC server using
gRPC (rpc/rpcserver), and provides the ability to defer wallet loading
until request at a later time by an RPC (--noinitialload).

The legacy RPC server remains the default for now while the new gRPC
server is not enabled by default.  Enabling the new server requires
setting a listen address (--experimenalrpclisten).  This experimental
flag is used to effectively feature gate the server until it is ready
to use as a default.  Both RPC servers can be run at the same time,
but require binding to different listen addresses.

In theory, with the legacy RPC server now living in its own package it
should become much easier to unit test the handlers.  This will be
useful for any future changes to the package, as compatibility with
Core's wallet is still desired.

Type safety has also been improved in the legacy RPC server.  Multiple
handler types are now used for methods that do and do not require the
RPC client as a dependency.  This can statically help prevent nil
pointer dereferences, and was very useful for catching bugs during
refactoring.

To synchronize the wallet loading process between the main package
(the default) and through the gRPC WalletLoader service (with the
--noinitialload option), as well as increasing the loose coupling of
packages, a new wallet.Loader type has been added.  All creating and
loading of existing wallets is done through a single Loader instance,
and callbacks can be attached to the instance to run after the wallet
has been opened.  This is how the legacy RPC server is associated with
a loaded wallet, even after the wallet is loaded by a gRPC method in a
completely unrelated package.

Documentation for the new RPC server has been added to the
rpc/documentation directory.  The documentation includes a
specification for the new RPC API, addresses how to make changes to
the server implementation, and provides short example clients in
several different languages.

Some of the new RPC methods are not implementated exactly as described
by the specification.  These are considered bugs with the
implementation, not the spec.  Known bugs are commented as such.
2016-01-29 11:18:26 -05:00
Josh Rickmar 6af96bfdb7 Correctly handle RPC listen addresses with IPv6 zones.
Fixes #341.
2016-01-14 13:33:08 -05:00
Mawuli Adzoe c4abe025d0 Fix minor typos. 2015-12-30 15:24:31 -07:00
Josh Rickmar b701fadd7b Update travis config for recent Go versions. 2015-12-08 11:40:20 -05:00
Josh Rickmar 647e7fdd22 Update README.
Removed links to outdated btcsuite MSIs, replacing these with links to
Github releases.

Combined installation and updating instructions since they are
identical.

Added Windows to the list of operating systems that the "Build from
source" instructions work with.

Added PowerShell examples for copying the sample btcd and btcwallet
configs for both MSI and source installs.
2015-11-25 12:27:34 -05:00
Josh Rickmar b0566e09c8 Separate out default ports and utility funcs.
This change moves the chain and network parameter definitions, along
with the default client and server ports, to a package for reuse by
other utilities (most notably, tools in the cmd dir).  Along with it,
functions commonly used for config parsing and validation are moved to
an internal package since they will also be useful for distributed
tools.
2015-11-25 01:02:50 -05:00
Josh Rickmar 5482feecf4 Prepare for release 0.7.0. 2015-11-23 10:44:37 -05:00
Josh Rickmar 8999c13f4d Add 0.7.0 deps to deps.txt. 2015-11-23 10:44:36 -05:00
Rune T. Aune 52b8e1903f Add the chain subsystem logger to btcrpcclient.
Logging from btcrpcclient is currently not possible to set, and defaults
to nothing. Letting it inherit chain's logger can greatly simplify
debugging of connectivity issues.

Also remove a now redundant log message upon connecting to btcd.
2015-11-19 17:15:20 -06:00
Dave Collins 6ba74e6730 Update for hdkeychain NewMaster API change. 2015-11-10 12:05:16 -06:00
Josh Rickmar 4f6edce6dc Fix signmessage RPC to match Core.
AFAICT this function has never worked correctly due to the hash being
signed not matching the hash created by Core.  Core wallet writes
serialized strings to a double-sha256 hashing stream, while we were
using string concatination.  This produced different messages since
the message before hashing did not include compact integers (called
varints in btcsuite code) preceding each string with the string
length.

Tested by creating signed messages from btcwallet and verifying them
with Bitcoin-Qt, as well as creating signatures from Bitcoin-Qt and
verifying them with btcwallet.

Fixes #323.
2015-10-16 14:13:59 -04:00
John C. Vernaleo cef002139f Fix wallet compile after SigCache addition to NewEngine. 2015-10-12 13:09:40 -04:00
Josh Rickmar 31d152608b Temporarly increase session RPC timeout. 2015-09-23 12:24:24 -04:00
Josh Rickmar 33d053c6a7 Detect silent network drops.
This change introduces additional network activity with the btcd
process to ensure that the network connection is not silently dropped.
Previously, if the connection was lost (e.g. wallet runs on a laptop
and connects to remote btcd, and the laptop is suspended/resumed) the
lost connection would not be detectable since all normal RPC activity
(excluding requests from btcwallet to btcd made by the user) is in the
direction of btcd to wallet in the form of websocket notifications.
2015-09-22 14:54:40 -04:00