Commit graph

82 commits

Author SHA1 Message Date
Dave Collins
dc200d002e Correct getrawmempool verbose fee field.
The fee field of the getrawmempool RPC JSON response should be in Bitcoins
instead of Satoshi.  This commit corrects that issue.

Also, add a couple of comments and fix a comment typo while here.
2013-12-25 12:33:12 -06:00
Owain G. Ainsworth
d72255bce3 gofmt 2013-12-17 14:02:35 +00:00
Owain G. Ainsworth
8aaad1e97b Add support for verbose in getrawmempool.
Closes #55.
2013-12-16 18:14:50 +00:00
Josh Rickmar
e4fa45ff08 Better logging for rescans. 2013-12-16 09:09:28 -05:00
Owain G. Ainsworth
f93203b91e Initial basic support for selection of external ip address.
This implements only the bare bones of external ip address selection
using very similar algorithms and selection methods to bitcoind. Every
address we bind to, and if we bind to the wildcard, every listening
address is recorded, and one for the appropriate address type of the
peer is selected.

Support for fetching addresses via upnp, external services, or via the
command line are not yet implemented.

Closes #35
2013-12-10 19:39:47 +00:00
Dave Collins
7654eb1eb5 Cast SatoshiPerBitcoin const for createTxRawResult. 2013-12-08 20:21:23 -06:00
Francis Lam
22b61f634a Updated createTxRawResult to use btcutil.SatoshiPerBitcoin 2013-12-08 18:47:39 -05:00
Francis Lam
dd10de9e8b Fix handleGetBlock/handleGetRawTransaction to return btcjson.Error
Wrap *.BtcEncode errors into btcjson.Error when failing to encode wire
bytes to buffer
2013-12-08 18:43:47 -05:00
Francis Lam
762fc2c11c Fixed up GetRawTransaction and updated GetBlock to handle verbose
Updated handleGetRawTransaction to populate all the fields required to
match bitcoind.  It still doesn't handle MULTISIG addresses correctly.

Changed handleGetBlock to implement new optional verbose (default true)
flag and also added a verboseTx flag to return TxRawDefault instead of
Txid.  When verbose=false, GetBlock returns hex-encoded wire bytes for
the block.
2013-12-08 14:57:14 -05:00
Josh Rickmar
305be0c29f Correctly set vout for getrawtransaction.
The vout field (as part of the getrawtransaction JSON reply) should be
set to the input's previous outpoint's index, not the current input
index.

Found by flam and reported on IRC. Thanks!
2013-12-06 17:34:18 -05:00
Josh Rickmar
bbb10dc387 Make authentication check time-constant. 2013-12-05 13:21:51 -05:00
Josh Rickmar
f22164b261 Search each txout for payment to a wallet address.
This switches a break to a continue if a txout does not include a
pay-to-pubkey-hash script type.  btcwallet only supports
pay-to-pubkey-hash at the moment, and this fixes an issue where a tx
may have an different type of output, as well as pay-to-pubkey-hash,
which may be ignored by the wallet notification code.

Found by dhill.
2013-12-02 10:35:25 -05:00
Josh Rickmar
aea23ddff3 Send nil when rescan is finished.
I previously fixed the duplicate send (before seeing GH issue #54),
but forgot that btcwallet expects a nil reply when rescan has
finished.  This adds the final reply back, but replies with nil.

Fixes #54.
2013-12-02 10:24:22 -05:00
Josh Rickmar
41ecc9f835 Do not duplicate sending final rescan tx. 2013-12-02 10:11:00 -05:00
Josh Rickmar
d1570c5d87 Include more data in tx-to-wallet-address notifications.
This updates the replies for rescan and tx notifications with
additional information that is needed for wallet to properly support
the listtransactions command.

While here, drastically improve rescan performance by not looking up
every sha in rescan's block range.
2013-11-26 15:07:01 -05:00
Josh Rickmar
7e21226ca6 Update for new btcws.TxMinedNtfn information. 2013-11-25 12:54:23 -05:00
Dave Collins
daa5310e2f Add support for debuglevel RPC command.
Also include the supported subsystems in the error message if an invalid
subsystem is specified.

Closes #15.
2013-11-22 10:47:29 -06:00
John C. Vernaleo
e930dc55f0 Change a variable name to match btcjson. 2013-11-22 08:50:15 -05:00
Dave Collins
eb8688df79 Convert btcd to use new btclog package.
Also, make every subsystem within btcd use its own logger instance so each
subsystem can have its own level specified independent of the others.

This is work towards #48.
2013-11-21 17:41:21 -06:00
Marco Peereboom
694fccefa8 typo 2013-11-20 15:55:36 -06:00
John C. Vernaleo
3f37e881dc Remove workaround for certs on go1.1.2.
btcd now requires go1.2.  A note to that effect is in README.md.
2013-11-20 15:34:37 -05:00
Josh Rickmar
5d13288174 Check auth header for websocket connections. 2013-11-19 18:28:08 -05:00
Dave Collins
9edf7d44fa Ensure generated cert contains 127.0.0.1. 2013-11-19 16:35:00 -06:00
David Hill
deb19c2fa3 Bring MarshalECPrivateKey local so < go1.2 works.
Closes #45.
2013-11-19 15:53:31 -06:00
Dave Collins
c3fab78e2c Use consistent case in TLS logging. 2013-11-19 11:42:56 -06:00
Dave Collins
5cd4c8265c Add subsystem to RPC cert generation log messages. 2013-11-19 11:41:31 -06:00
David Hill
6fcc1c9d1b Add localhost to DNSNames in generated certificate. 2013-11-19 12:02:40 -05:00
Owain G. Ainsworth
75e577c82e RPC TLS Support.
All rpc sockets now listen using TLS by default, and this can not be
turned off. The keys (defauling to the datadirectory) may be provided by
--rpccert and --rpckey. If the keys do not exist we will generate a new
self-signed keypair with some sane defaults (hostname and all current
interface addresses).

Additionally add tls capability to btcctl so that it can still be used.
The certificate to use for verify can be provided on the commandline or
verification can be turned off (this leaves you susceptible to MITM
attacks)

Initial code from dhill (rpc tls support) and jrick (key generation),
cleanup, debugging and polishing from me.
2013-11-19 14:50:31 +00:00
Owain G. Ainsworth
5da5dfe1c4 Add --rpclisten that behaves frighteningly similar to --listen.
Except it works for the rpcserver instead of the main server.

Closes #34
2013-11-19 14:48:58 +00:00
David Hill
7b7d4e8555 fix typo - now addresses show up in getrawtransaction 2013-11-15 16:12:08 -05:00
Owain G. Ainsworth
6116a6cb02 Support --listen.
This allows the provision of address/port pairs to be listened on instead
of just providing the port. e.g.:
btcd --listen 1.2.3.4:4321 --listen 127.0.0.01 --listen [::1]:5432

When --proxy and --connect are used, we disable listening *unless* any --listen
arguments have been provided, when we will listen on those addresses as
requested.

Initial code by davec, integration by myself.

Closes #33

allow listens to fail, but warn. error if all failed

fmt
2013-11-14 01:15:47 +00:00
Owain G. Ainsworth
31a97d5c09 look up tx in mempool first for getrawtransaction
Closes #26
2013-11-12 22:57:27 +00:00
Owain G. Ainsworth
bb276b53aa Add support for the verifychain command.
So far we only do level 0 and level 1 checks (precense and basic
sanity). The checks done at higher levels in bitcoind are closely
coupled with their database layout.

arguably Closes #13
2013-11-12 22:57:26 +00:00
Josh Rickmar
31f27cffd5 Safely remove elements from list.Lists. 2013-11-12 16:24:32 -05:00
Josh Rickmar
77e1af792b Fix mutex handling for removing minedtx requests.
Previously, RemoveMinedTxRequest was being run from a caller which
held a reader lock for the websocket request contexts.  When
RemoveMinedTxRequest tried to grab a writer lock, it would block.
This change creates a new function, removeMinedTxRequest, that does
not grab any locks, and the caller (NotifyBlockConnected) grabs a
writer lock instead of a reader lock.
2013-11-11 14:23:11 -05:00
Josh Rickmar
8b5413a4ac Always release ws context reader lock.
Previously, on a blockconnected notification, the websocket context
reader lock was not always being given up properly.  This change
defers the unlock so it will always happen.

This fixes an issue where wallet will stop responding (due to not
being able to complete its handshake) on reconnect.
2013-11-11 12:54:49 -05:00
Josh Rickmar
41838b83b0 Use btcws package for wallet notifications. 2013-11-08 12:44:00 -05:00
Owain G. Ainsworth
d81a2c9067 Check for 0 shas before dereferencing list 2013-11-07 22:26:43 +00:00
Josh Rickmar
ced24946a4 Rework JSON handlers to take a btcjson.Cmd.
This change reworks where the command parsing occurs to be done before
handlers are checked.  Before, the websocket extension handler called
the standard handler with the same message, and if it was unhandled,
would unmarshal it a second time for checking extension handlers.
2013-11-07 13:53:41 -05:00
Josh Rickmar
d403863e2b Don't marshal a function for getbestblockhash replies. 2013-11-07 13:53:22 -05:00
Josh Rickmar
b97a2145d8 Try to match bitcoind sendrawtransaction RPC errors. 2013-11-07 10:34:55 -05:00
Owain G. Ainsworth
d8c5222474 Rework the way we send notifications over the websocket
Redo the datastructures we search so that we only do one lookup per txin and
txout instead of doing a loop per wallet connection.

Don't send spent data on tx notifications, this can be worked out in wallet and
it is expensiveish to calculate. However we DO check upon getting a notification
request if the output is already spent, and in which case we send an immediate
notification to force a rescan.

MinedTxNotfications are handled separately to the connected block messages
largely to enable this to scale rather better.

Tested by jrick (who found one bug i had introduced, thanks!)

Additionally (accidentally squashed in):

Add handlers for all known commands.

We have handlers for all wallet-requiring commands that will return a suitable
error.

Unimplemented commands temporarily return an error stating so.
2013-11-06 18:47:06 +00:00
Josh Rickmar
8c2b9ae06e Begin using btcws.
This change adds support for the unmarshaling custom commands sent by
btcwallet and supported in the btcws package.
2013-11-06 11:20:36 -05:00
Josh Rickmar
1f087adf15 Separate ws command handlers into separate funcs. 2013-11-04 14:15:05 -05:00
Josh Rickmar
53e1c2d6bd Stringify the address hash for txRequests map.
This change allows map lookups using address hashes (which are
returned as []byte) instead of either copying the hash into an array,
or doing a bytes.Equal().

A stupid range over a map until the right key is found was also just
changed to a single map lookup.
2013-11-04 14:11:39 -05:00
Josh Rickmar
2511fee152 Complete rescan extension.
This adds to the initial rescan implementation, but switches it to
rescan based on a group of addresses, rather than just one.  Due to
how expensive database lookups are during a rescan, wallets should
take advantage of this to rescan once for all needed addresses for all
accounts.
2013-11-01 09:35:52 -04:00
Dave Collins
a4794798d4 Make use of new btcwire SerializeSize API.
This commit changes the various cases that were serializing transactions
into a buffer and taking the length to use the new faster SerializeSize
API.  It also completes a TODO since the serialized size of a transaction
output is now available.
2013-10-31 00:28:37 -05:00
Dave Collins
470ef8c58e Use correct calls to tx.Sha() in RPC server. 2013-10-30 18:40:55 -05:00
Dave Collins
b866e9f14c Improve RPC server log of rejected transactions.
Rather than showing all errors from ProcessTransaction as an error, check
if the error is a TxRuleError meaning the transaction was rejected as
opposed to something actually going wrong and log it accordingly.
2013-10-30 14:11:45 -05:00
Dave Collins
e76fada2d2 Optimize NotifyNewTxListener.
Looking up transactions from the database is an expensive operation.
This commit modifies the NotifyNewTxListener code to simply iterate the
transactions in the block instead of looking them up from the db.

Currently the wallet code needs a spent flag which ultimately shouldn't be
required.  For now, the spent data is simply created on the fly which is
still significantly faster than doing database transaction lookups.

Closes #24.
2013-10-30 10:54:03 -05:00