Commit graph

127 commits

Author SHA1 Message Date
David Hill
2b9f5b8932 in getrawmempool verbose mode, initialize depends to an empty array.
this matches bitcoind.

from jrick
ok davec
2014-01-29 22:22:07 -05:00
David Hill
b532860477 sync with btcjson changes to getrawtransaction.
ok oga@
2014-01-29 21:21:58 -05:00
Owain G. Ainsworth
82fca37eae implement the getinfo rpc command.
This contains some wallet inforamtion, but bitcoind if wallet is
disabled returns just the non wallet information. we do the same.
2014-01-29 18:31:33 +00:00
Owain G. Ainsworth
8d930ceed1 convert getdifficulty to getBlockHeaderBySha to save some cycles. 2014-01-29 18:31:33 +00:00
Dave Collins
72afc787e6 Move getinfo RPC method to askwallet list.
The getinfo RPC method requires access to information only available in
the wallet.  Therefore, it has been moved to the list of methods which
return an error information the caller to send the request to the wallet
instead.
2014-01-27 13:52:59 -06:00
Dave Collins
b9a641ab79 Move getnewaddress RPC method to askwallet list.
The getnewaddress RPC method deals with wallet-related functionality and
therefore has been moved to the list of methods which return an error
information the caller to send the request to the wallet instead.
2014-01-27 10:58:24 -06:00
Dave Collins
0bf4e0e097 Move getblocktemplate/getwork to askwallet list.
Both of these RPC methods require access to information ony available in
the wallet.  Therefore they have been moved to the list of methods which
return an error information the caller to send the request to the wallet
instead.
2014-01-25 22:58:38 -06:00
Dave Collins
dcef4128b8 Add support for getaddednodeinfo RPC command.
This commit adds full support for the getaddednodeinfo RPC command
including DNS lookups which abide by proxy/onion/tor rules when the DNS
flag is specified.  Note that it returns an array of strings when the DNS
flag is not set which is different than the current version of bitcoind
which is bugged and scheduled to be fixed per issue 3581 on the bitcoind
issue tracker.
2014-01-25 22:50:32 -06:00
Dave Collins
5859deea7e Improve RPC authentication failure responses.
This commit improves how the legacy RPC server responds to authentication
failures so things like web browsers can react better.  The following
changes have been made:

First, authentication failures were only printing the 401 error response
in the body instead of setting the http status code.  This means the
response had a 200 OK header with a body of 401 Unauthorized.  Therefore
the client would think everything was ok, but see the response as
malformed JSON.

Second, the spec for 401 Unauthorized responses state they must include a
WWW-Authenticate header to instruct the client how to authenticate.
Without this, browsers won't prompt the user for credentials.
2014-01-23 11:27:48 -06:00
Dave Collins
0d40bf901d Implement alternative auth for websockets.
The previous websocket code required HTTP auth headers to be sent in order
to use the websocket.  While this makes sense for most applications, some
use cases such as javascript-based websockets from browsers do no have the
ability to send headers.

This commit modifies the authentication logic to allow an alternative
authentication mechanism when HTTP auth headers can't be sent.  In
particular, it introduces a new JSON-RPC command named authenticate which
accepts the username and passphrase for the RPC server.  The command is
only required if the connetion has not already been authenticated via HTTP
auth headers and it must be the first command to be received.  Sending any
other command will immediately disconnect the websocket.

ok from @owainga and @jrick.

This closes #77.
2014-01-22 17:40:14 -06:00
Owain G. Ainsworth
9cb5190ac2 add support for the ping rpc command.
And the pingtime and pingwait fields of getpeerinfo.
2014-01-22 16:21:08 +00:00
Owain G. Ainsworth
1487a352da add basic support for the help rpc command. 2014-01-22 16:20:38 +00:00
Dave Collins
8c7d44c8dc Add authentication deadline to RPC server cnxns.
Previously it was possible to open a connection to the RPC server, never
authenticate, and idle forever.

This is work toward #68.
2014-01-18 00:08:39 -06:00
Dave Collins
0fbd962f8a Use our own websocket.Server instance.
The websocket.Server used the by websocket.Handler type automatically adds
a handshake function which prevents connections when the Origin header is
not set.  Not all clients send this information and we already require
authentication headers as the auth mechanism anyways.
2014-01-17 16:30:29 -06:00
Dave Collins
f089853d4d Move RPC websocket init code to rpcwebsocket.go. 2014-01-17 15:44:36 -06:00
Josh Rickmar
20e56d6eda Ask for block(dis)connected updates.
This removes the last notification that was being sent unsolicited.
Since it is no longer needed, the code to duplicate notifications to
all clients has been removed.
2014-01-17 16:38:16 -05:00
David Hill
871481ce1b Implement submitblock.
Closes #61.
2014-01-15 15:07:43 -06:00
Josh Rickmar
bd98836a2b Fix several bugs in the RPC server shutdown.
The RPC server was performing some of the shutdown logic in the wrong
order, that is, logging the the server has shut down, waiting for all
server goroutines to finish, and then closing a channel to notify
server goroutines to stop.  These three items have been reversed to
fix a hang where goroutines currently being waited on had not shut
down because they did not receive the notification.

While here, the server waitgroup was incremented for a goroutine that
was running without it, another select statement was added to stop a
duplicate close (which never occured last commit when I added the
select statements), and the "stopping rescan" logging was moved to
debug to make the ^C shutdown logging nicer.
2014-01-14 22:53:07 -05:00
Josh Rickmar
6abad1d8ac Change websocket handlers to return results.
This is the first step to fixing #66.
2014-01-14 13:15:22 -05:00
Josh Rickmar
035f8f82b7 Switch to btcutil for certificate generation. 2014-01-10 15:41:57 -05:00
David Hill
3a59e4d064 Set the Connection header to close 2014-01-10 10:57:05 -05:00
Josh Rickmar
cd3084afcd Rework the btcwallet connection.
This changes the protocol between btcd and btcwallet to follow
JSON-RPC specifications sending notifications as requests with an
empty ID.

The notification request context handling has been greatly cleaned up
now that IDs no longer need to be saved when sending notifications.
2014-01-09 14:03:00 -05:00
Dave Collins
462bc5a031 Update for recent btcscript API changes.
This commit changes all code which deals with extracting addresses from
scripts to use the btcscript API ExtractPkScriptAddrs which in turn makes
use of the new btcutil.Address interface.

This provides much cleaner code for dealing with arbitrary script
destinations which is extensible without having to churn the APIs if new
destination types are added.
2014-01-08 11:22:29 -06:00
Dave Collins
8a73f9b245 Correct p2sh field of decodescript RPC result.
The p2sh field in the result should be the encoded address which includes
the network (human-readable address) instead of just the raw hash.
2014-01-04 12:44:14 -06:00
Dave Collins
92eee5cb96 Populate p2sh field in decodescript RPC result. 2014-01-04 11:55:09 -06:00
Dave Collins
47a78ea5c2 Add support for decodescript RPC command. 2014-01-03 23:29:24 -06:00
Dave Collins
b6b2fd15b3 Add support for createrawtransaction RPC command. 2014-01-03 12:43:13 -06:00
Josh Rickmar
405eca4a44 Remove usage of deprecated address encode/decode API. 2014-01-03 13:22:28 -05:00
Francis Lam
082ad7caf2 Updated createVoutList to support scripthash/multisig outputs
Used updates in btcscript/btcutil to support decoding scripthash and
multisig outputs for display in getrawtransactions/decoderawtransaction
2014-01-02 13:48:50 -06:00
Dave Collins
30802fdd52 Rename RPC handlers map to rpcHandlers.
The name handlers for a package level is a bit too generic and could
easily cause a name collision.  Even though the compiler would catch it,
use something a bit more descriptive.
2013-12-31 15:53:19 -06:00
Dave Collins
835cee229a Move RPC handler maps near the top of file.
Since the command to handler mappings are the most often modified and
referenced code in rpcserver.go and rpcwebsocket.go, move them near the
top of their respective files.
2013-12-31 14:48:50 -06:00
Dave Collins
9b166b3876 Remove wallet notifications chan from std commands.
This commit cleans up the standard RPC command hanlding a bit by removing
the websocket specific notification channel from the handlers.  This was
previously required because the sendrawtransaction, when called from a
websocket enabled connection, needs to add a notification for when the
transaction is mined.

This commit modifies that to instead implement a websocket extended
version of sendrawtransaction which invokes the standard handler and adds
the notification.  In addition, the main send was modified to first look
if the command has a websocket specific handler first, and then falls back
to standard commands, rather than the previous approach of first checking
for a standard command and falling through to websocket commands.  This
essentially allows websockets connections to extend commands with the same
name with additional functionality such as what was done in this commit.
2013-12-31 14:42:15 -06:00
Dave Collins
5ad6d543d6 Move RPC websocket code to its own file.
The rpcserver.go file is starting to get a bit unwieldy.  This commit
moves the separable websocket specific bits into a separate file named
rpcwebsocket.go.
2013-12-31 13:19:07 -06:00
Dave Collins
f2a2744bec Correct error handling from the previous commit. 2013-12-30 20:27:36 -06:00
Francis Lam
28d08f8b16 Small changes to createVinList/createVoutList
Added error checking for script disassembley

Changed vout to handle errors in processing the way bitcoind does: the
type displayed is "nonstandard" when the calculated type is nonstandard
or nulltype and also when there is an error getting the address.

Still doesn't properly support multisig addresses, but now it should
return "nonstandard" since since address lookup fails for those cases.
2013-12-30 20:06:13 -05:00
Dave Collins
eb624acfd4 Add support for decoderawtransaction RPC command.
Since the decoderawtransaction result makes use of the same vin and vout
lists, this commit also factors the logic for those out into separate
functions.
2013-12-30 18:33:13 -06:00
Dave Collins
d17a97b485 Correct verifychain RPC call return.
The return value should be a boolean for compatibility.
2013-12-30 10:59:14 -06:00
Josh Rickmar
bd29b12d31 Notify wallets when mempool txs pay to a wallet address. 2013-12-30 09:33:36 -05:00
Dave Collins
674ef590bb No need to cast something is already a uint32. 2013-12-27 13:20:13 -06:00
Dave Collins
f0cc672d23 Update for btcjson sequence number type change. 2013-12-27 12:38:51 -06:00
Dave Collins
ca0e38e58b Update for recent btcjson getrawtransaction change.
The ScriptSig field of the Vin type for TxRawResult is now a pointer in
btcjson so it can be properly omitted.  This commit updates the code to
create the new ScriptSig object as needed.
2013-12-27 12:24:03 -06:00
Dave Collins
e0fab228a4 Correct getrawtransaction RPC handling and cleanup.
The getrawtransaction RPC call should return a hex-encoded string of the
transaction when verbose is false instead of a TxRawResult object with the
Hex field set to be compatible with the Sathoshi client.  This commit,
along with a recent commit to btcjson corrects this.

Also, while here, do a bit of cleanup, finish a TODO to check for an
invalid hash, and optimize the handling of non-verbose slightly.
2013-12-26 23:30:57 -06:00
Dave Collins
af3609d861 Factor out common message to hex in RPC server. 2013-12-26 22:53:44 -06:00
Dave Collins
8477ef569a Update btcctl getblock for recent changes.
This commit allows btcctl to accept the optional verbosity parameters on
getblock.
2013-12-26 11:19:32 -06:00
Dave Collins
67b5c2fb7e Correct getblock RPC handling and optimize.
The getblock RPC call should return a hex-encoded string of the block when
verbose is false instead of a BlockResult object with a Hex field set to
be compatible with the Sathoshi client.  This commit, along with a recent
commit to btcjson corrects this.

Also, while here, move code which only applies to verbose mode after the
call which handles the non-verbose logic.  This saves a few cycles since
the non-verbose logic doesn't need the extra information.
2013-12-26 11:13:31 -06:00
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