Commit graph

752 commits

Author SHA1 Message Date
Dave Collins
e92f94dcd1 Update for recent chainhash-related API changes. (#450)
This updates all code to make use of the new chainhash package since the
old wire.ShaHash type and related functions have been removed in favor
of the abstracted package.

Also, while here, rename all variables that included sha in their name
to include hash instead.

Finally, update glide.lock to use the required version of btcd, btcutil,
and btcrpcclient.
2016-08-08 14:49:09 -05:00
Josh Rickmar
959ef467da Set GO15VENDOREXPERIMENT=1 earlier in travis script. 2016-06-16 17:15:46 -04:00
Alex Yocom-Piatt
127246fb22 Fix logic for CreateTemp needing either appdata or datadir 2016-06-16 16:03:28 -05:00
Josh Rickmar
f3df6c8bc9 Handle flags explicitly set to defaults.
This prevents treating a flag that was explicitly set to the default
as unchanged, since the explicit set is recorded in the new
*cfgutil.ExplicitString flag type.
2016-05-25 09:37:23 -04:00
Josh Rickmar
39fd9bd0f3 Switch from forked to upstream bolt package. 2016-05-06 14:42:00 -04:00
Josh Rickmar
7704a6d5c3 Switch from forked to upstream flags package.
In https://github.com/btcsuite/btcwallet/pull/419#issuecomment-212482492
I mentioned that btcwallet should wait until btcd also switches back
to upstream package paths so that duplicate packages are not included
in and bloat the btcwallet binary.  Even while btcd has not yet
switched to the upstream flags package, this change can still be made
now since it is only used by btcd's main package, which is not
included in btcwallet.
2016-05-06 12:41:42 -04:00
Josh Rickmar
00deaece98 Don't use go install $(glide novendor) in examples.
This will build all (non-vendored) packages recursively, even if they
are not used in any of the binaries (e.g. votingpool).  Additionally,
since a subshell is no longer used, the example commands can be run in
a Windows command prompt.  I don't encourage the use cmd.exe over
alternatives such as PowerShell, but there's no reason this command
could not be run there.
2016-05-06 10:10:13 -04:00
Josh Rickmar
250818957e Update to latest Go in Travis config. 2016-05-06 10:02:43 -04:00
Josh Rickmar
877947d6af Enable vendor experiment for Go 1.5 on Travis-CI.
Previously, the GO15VENDOREXPERIMENT environment variable was unset,
leaving travis to only use the vendored packages during builds for Go
1.6 which enabled the experiment by default.  Export the variable so
it also correctly tests under Go 1.5.
2016-05-06 09:55:41 -04:00
Josh Rickmar
268c466d69 Fix description for recommended install instructions.
The description had previously said that non-vendored packages were
not installed to $GOPATH/bin, but this is incorrect.  Remove this part
of the description so it includes all packages.
2016-05-05 17:41:59 -04:00
David Hill
c292c68cba btcwallet: handle signal SIGTERM
When an OS reboots or shuts down, it sends all processes SIGTERM before
sending SIGKILL.  This allows btcwallet to do a proper shutdown which
most importantly closes the databases.
2016-05-05 16:50:03 -04:00
Josh Rickmar
ce3bd39238 Unexport private methods from legacyrpc package.
This unexports every RPC handler function, as well as the
Server.PostClientRPC method which was only called by this package.

Fixes #435.
2016-05-05 11:28:18 -04:00
Josh Rickmar
4d51f8358f Use -b for deprecated --datadir short option.
When 29f31725ee deprecated the datadir
option, replacing it with --appdata/-A, the short --datadir option was
unintentinally changed from -b to -D.  It was previously changed to -b
in fda2e14b99 for consistency with
btcd's --datadir short option.

This change reverts the unintentional switch back to -D.
2016-05-04 17:45:52 -04:00
Josh Rickmar
146e92edc1 Fix credit slice indexing for transaction notifications.
Previously, this would always check a transaction output index against
the 0th credit's index.
2016-05-04 15:13:28 -04:00
Josh Rickmar
fb06a6bd04 Cleanup TransactionDetails RPC messages.
Remove the addresses field from TransactionDetails.Output.  It is
assumed that the caller is able to deserialize the transaction and
encode the output scripts to addresses, so this is unnecessary server
overhead and conflicts with the current API philosophy of not
duplicating data already included in another field.

Since there is no additional data included for outputs not controlled
by the wallet, remove the `mine` specifier from the Output message and
replace it with an output index.  Only include messages for controlled
outputs, rather than creating messages for both controlled and
uncontrolled outputs.  Rename the repeated field from `outputs` to
`credits` to be consistent with the `debits` field.

Bump major API version as this is a breaking change.

Closes #408.
2016-04-28 11:53:03 -04:00
Josh Rickmar
5e3613775d Make default config relative to appdata directory.
This modifies the default configuration file to be relative to the
application data directory (configuratble with --appdata).  If there
is no configuration file in this directory, then no additional
configuration options are applied (it does not fallback to
~/.btcwallet/btcwallet.conf).

Fixes #421.
2016-04-28 11:21:44 -04:00
Josh Rickmar
178717341e Expand several more config options.
This adds home directory and OS environment variable expansion for the
following configuration options: configfile, appdatadir, rpccert,
rpckey.
2016-04-28 11:16:17 -04:00
Josh Rickmar
f91303f507 Lookup actual home directory when expanding ~.
This fixes home directory expansion on Windows and OS X.  Previously
on these platforms, a leading ~ would expand to %LOCALAPPDATA% on
Windows or ~/Library/Application Support/ on OS X.

While here, add support for ~otheruser expansion to expand to
otheruser's home directory.
2016-04-28 11:16:17 -04:00
Josh Rickmar
42593c7dfd Remove code intended for Go 1.4 and older.
This change only removes optimizations for older Go releases that we
no longer support in the internal/zero package.  This package should
still continue to build on older releases.
2016-04-28 09:50:20 -04:00
Josh Rickmar
b97d824975 Document need for GO15VENDOREXPERIMENT=1.
Fixes #425.
2016-04-28 09:38:40 -04:00
Josh Rickmar
1e8c735294 Fix example node.js client after breaking API change.
Fixes #426.
2016-04-28 09:36:58 -04:00
Josh Rickmar
2009ee0230 Set gRPC cipher suites sooner in node.js example.
While here, also rename OpenSSL to BoringSSL since gRPC Core has
switched to that.

Fixes #429.
2016-04-27 16:36:05 -04:00
Josh Rickmar
91093362f2 Convert project to glide.
Fixes #399.
2016-04-26 13:28:20 -04:00
Josh Rickmar
a549b6908a Avoid calling getrawtransaction from signrawtransaction.
Replace all calls to getrawtransaction with gettxout.

As btcd no longer enables the transaction index by default,
getrawtransaction can no longer be depended on.  gettxout is safe to
use since it queries the utxo set.  This also means that it will
continue to work even when pruning is enabled.

This should be further improved in the future to not look up previous
output scripts over btcd rpc when they are already saved by the
wallet.

Fixes #410.
2016-04-22 12:00:48 -04:00
Josh Rickmar
c82b8bae20 Ignore config in current directory by default.
Fixes #415.
2016-04-20 11:08:14 -04:00
Josh Rickmar
7b2e1ac282 Do not include zero value change outputs.
Due to the way dust is calculated, if the transaction relay fee is
zero, then a zero output amount is not considered dust.  As the
transaction authoring code used this dust check to determine whether a
change output can be included or not, it could create unnecessary
change outputs which return no value back to the wallet.  Prevent this
by including an explicit check for zero values.
2016-04-20 10:46:12 -04:00
Josh Rickmar
f827743934 Modify goclean.sh to run go vet recursively.
Fix remaining issues discovered by vet.
2016-04-19 17:02:51 -04:00
Josh Rickmar
86420c4890 Regenerate walletrpc package. (#418)
Fixes build when using newer versions of the grpc packages.
2016-04-19 09:12:17 -04:00
Josh Rickmar
29f31725ee Rename datadir/-b options to appdata/-A.
This removes an inconsistency with the datadir option from btcd, which
only set the directory containing the blockchain data and indexes.
2016-04-15 20:30:05 -04:00
Josh Rickmar
3d7b8c6f40 Resurrect rpchelp_test.go
This file was accidentally removed when the gRPC server was introduced
and the legacy JSON-RPC server was moved to the legacyrpc package.
2016-04-13 10:44:43 -04:00
Josh Rickmar
4ee9ce59fb Add sweepaccount tool.
This tool creates on-chain transactions, one per used address in a
source account, to sweep all output value to new addresses in a
different destination account.
2016-04-11 14:23:40 -04:00
John C. Vernaleo
94d813b2d4 Update TravisCI configs. (#409)
The vet tool moved to the Go tree as of go1.5 so it does not
need to be installed seperately.  With the x/tools repo now gone,
remove the install step for vet since it fails.
2016-04-07 15:01:54 -04:00
George Melika
eefc610904 Check for missing txs before dereferencing details 2016-04-06 16:24:46 -04:00
Josh Rickmar
d2c851431b Rollback namespace transactions when bucket is not found.
This fixes a deadlock where failed transactions due to the namespaces'
bucket being missing would cause deadlocks due to bolt's mmap rwmutex
still being read or write locked (and no way to unlock it, since the
underlying bolt tx was not returned on failure).
2016-04-05 11:50:18 -04:00
Josh Rickmar
e12d23716f Sort unmined transactions in their dependency order.
This changes the wtxmgr.Store.UnminedTxs method to sort transactions,
using the Kahn topological sort algorithm, before returning
transactions to the caller.  This is possible because transactions
form a sort of directed acyclic graph (DAG) where transactions
reference other transactions to spend their outputs (multiple
referenced outputs from a single transaction spent by the same
transaction count as a single graph edge).

This prevents the possibility of orphan rejection errors when sending
unmined transactions to a full node at startup.  As these transactions
are sent using the sendrawtransaction RPC, which does not permit
orphans, this topological sort is required.

Fixes #156.
2016-04-05 11:11:15 -04:00
John C. Vernaleo
c2ed8ffc2b Add goclean.sh script from btcd.
This commit corrects various things found by the static checkers
(comments, unkeyed fields, return after some if/else).

Add generated files and legacy files to the whitelist to be ignored.

Catch .travis.yml up with btcd so goclean can be run.
2016-03-31 11:43:54 -04:00
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