Commit graph

225 commits

Author SHA1 Message Date
Dave Collins
cb7c24141a Reimagine btcjson package with version 2.
This commit implements a reimagining of the way the btcjson package
functions based upon how the project has evolved and lessons learned while
using it since it was first written.  It therefore contains significant
changes to the API.  For now, it has been implemented in a v2 subdirectory
to prevent breaking existing callers, but the ultimate goal is to update
all callers to use the new version and then to replace the old API with
the new one.

This also removes the need for the btcws completely since those commands
have been rolled in.

The following is an overview of the changes and some reasoning behind why
they were made:

- The infrastructure has been completely changed to be reflection based instead
  of requiring thousands and thousands of lines of manual, and therefore error
  prone, marshal/unmarshal code
  - This makes it much easier to add new commands without making marshalling
    mistakes since it is simply a struct definition and a call to register that
    new struct (plus a trivial New<foo>Cmd function and tests, of course)
  - It also makes it much easier to gain a lot of information from simply
    looking at the struct definition which was previously not possible
    such as the order of the parameters, which parameters are required
    versus optional, and what the default values for optional parameters
    are
- Each command now has usage flags associated with them that can be
  queried which are intended to allow classification of the commands such
  as for chain server and wallet server and websocket-only
- The help infrastructure has been completely redone to provide automatic
  generation with caller provided description map and result types. This
  is in contrast to the previous method of providing the help directly
  which meant it would end up in the binary of anything that imported the
  package
- Many of the structs have been renamed to use the terminology from the
  JSON-RPC
  specification:
  - RawCmd/Message is now only a single struct named Request to reflect the fact
    it is a JSON-RPC request
  - Error is now called RPCError to reflect the fact it is specifically an RPC
    error as opposed to many of the other errors that are possible
    - All RPC error codes except the standard JSON-RPC 2.0 errors have been
      converted from full structs to only codes since an audit of the codebase
      has shown that the messages are overridden the vast majority of the time
      with specifics (as they should be) and removing them also avoids the
      temptation to return non-specific, and therefore not as helpful, error
      messages
  - There is now an Error which provides a type assertable error with
    error codes so callers can better ascertain failure reasons
    programatically
- The ID is no longer a part of the command and is instead specified at the time
  the command is marshalled into a JSON-RPC request.  This aligns better with
  the way JSON-RPC functions since it is the caller who manages the ID that is
  sent with any given _request_, not the package
- All <Foo>Cmd structs now treat non-pointers as required fields and pointers as
  optional fields
- All New<Foo>Cmd functions now accept the exact number of parameters, with
  pointers to the appropriate type for optional parameters
  - This is preferrable to the old vararg syntax since it means the code will
    fail to compile if the optional arguments are changed now which helps
    prevent errors creep in over time from missed modifications to optional args
- All of the connection related code has been completely eliminated since this
  package is not intended to used a client, rather it is intended to provide
  the infrastructure needed to marshal/unmarshal Bitcoin-specific JSON-RPC
  requests and replies from static types
  - The btcrpcclient package provides a robust client with connection management
    and higher-level types that in turn uses the primitives provided by this
    package
  - Even if the caller does not wish to use btcrpcclient for some reason, they
    should still be responsible for connection management since they might want
    to use any number of connection features which the package would not
    necessarily support
- Synced a few of the commands that have added new optional fields that
  have since been added to Bitcoin Core
- Includes all of the commands and notifications that were previously in
  btcws
- Now provides 100% test coverage with parallel tests
- The code is completely golint and go vet clean

This has the side effect of addressing nearly everything in, and therefore
closes #26.

Also fixes #18 and closes #19.
2015-02-19 00:41:07 -06:00
Olaoluwa Osuntokun
fca277e194 Extend getpeerinfo result with current block height.
* This adds support for displaying the progress of dynamically
   updating the current height of connected peers.
2015-02-14 14:17:56 -08:00
Javed Khan
78e2c8401b Added new cmds importaddress, importpubkey 2015-02-07 11:09:13 +05:30
Josh Rickmar
316d92d613 Update Go versions for Travis.
Also use Travis' container-based build infrastructure.
2015-02-06 10:02:09 -05:00
Olaoluwa Osuntokun
1b57f5bf87 Change searchrawtransaction to be compatible with bitcoind
* Pluralise `searchrawtransaction` -> `searchrawtransactions`
 * Change the `verbose` parameter from a bool to an int.
2015-02-05 15:31:39 -08:00
Olaoluwa Osuntokun
dc4989461a Add new logging subsystem ADXR to debuglevel help 2015-01-26 18:50:06 -08:00
Dave Collins
578d1debc5 Update btcjson import paths to new location. 2015-01-16 23:49:20 -06:00
Olaoluwa Osuntokun
b94598da55 Remove omitempty fromTxRawResult confirmations
* Previously both searchrawtransaction and getrawtransaction would omit
the 'Confirmations' field by default if the transaction was found in
the mempool.
* By removing `omitempty`, a mempool transaction will now have
'Confirmations:0'
2015-01-16 09:12:21 -08:00
Javed Khan
62eb2f2198 Accept nil string for account name 2015-01-12 23:27:37 +05:30
Olaoluwa Osuntokun
b9c8ec92d6 Add searchrawtransaction 2015-01-07 20:05:56 -08:00
Olaoluwa Osuntokun
effe99b4b5 Correct typo: Unmashal -> Unmarshal 2015-01-07 20:05:56 -08:00
Dave Collins
39d758c2c3 Fix TravisCI build for Go release version. 2015-01-06 21:09:16 -06:00
Dave Collins
7214218925 Be more specific in TravisCI go vet version test. 2014-12-11 12:21:13 -06:00
Dave Collins
d041b80301 Correct recent TravisCI go vet fetch script. 2014-12-11 11:53:19 -06:00
Dave Collins
43b4cad8b6 Update TracisCI for Go 1.4 release.
Our policy is to only ensure the code compiles for the latest Go release
minus one version.  Since Go 1.4 has now been released, this commit
updates TravisCI to remove Go 1.2 from the build matrix and add Go 1.3.

Also, go vet changed locations in between Go 1.3 and Go 1.4, so a check
has been added to download the appropriate version based on which version
of Go is running the integration tests.

Finally, the previous removed Go tip entry in the build matrix has been
reintroduced since it will now work again.
2014-12-11 11:33:23 -06:00
John C. Vernaleo
e0d536640d Add invalidateblock and reconsiderblock. 2014-12-02 13:51:35 -05:00
John C. Vernaleo
503670f7a5 For now, do not have travis build tip.
The location of go vet moved but the new version only works with tip
while the old one works with release.  So for now, not building tip.
2014-12-02 13:10:21 -05:00
Javed Khan
d87778df6d update ValidateAddressResult for IsWatchOnly 2014-10-29 13:02:48 +05:30
Dave Collins
e316258f6d Update ListReceivedByAddressResult txids field.
The name of the field in the returned JSON is txids, not tx.
2014-10-26 13:22:39 -05:00
Dave Collins
dd4763c726 Don't modify nil getnetworkinfo result.
Since the result might not be set when the response does not contain one,
such as in the case when the command is not implemented by the server,
don't attempt to modify it until ensuring it exists.
2014-10-23 10:18:56 -05:00
Dave Collins
a5b1a31e07 Use the net package function for credentials.
This change ensures any usernames or passwords which contain symbols that
would confuse the URL parser are properly escaped.
2014-09-20 19:05:38 -05:00
Javed Khan
1caddd4a37 handle http errors
ok @jrick, @jcvernaleo
2014-09-16 12:45:47 -04:00
Josh Rickmar
26802c7ecc Fix JSONGetMethod to prevent panics on bad input.
ok @jcvernaleo
2014-09-16 10:13:07 -05:00
John C. Vernaleo
3e465b2012 Remove extra go vet 2014-09-16 08:14:49 -04:00
John C. Vernaleo
036daa5817 Bring .travis.yml in line with others.
Add tip too.
2014-09-16 08:02:03 -04:00
John C. Vernaleo
4bc2c7f04f Slight siplification in .travis.yml 2014-09-08 08:41:26 -04:00
John C. Vernaleo
8f4643df14 Add go vet and golint to travis-ci config.
For golint, min_confidence is set to 0.9 since things aren't totally
golint clean yet.
2014-09-08 08:29:06 -04:00
John C. Vernaleo
c630b6ca1f Minor golint cleanups. 2014-09-05 13:45:01 -04:00
Javed Khan
d6a4b89601 updated ListReceivedByAddressResult for Tx ids
also added InvolvesWatchonly while here
2014-09-04 20:56:06 +05:30
David Hill
3d76571621 Update getnetworkinfo structure.
This matches the changes in Bitcoin Core.
Tested with btcctl.

OK @jcvernaleo
2014-08-29 09:29:44 -04:00
John C. Vernaleo
766d571317 Replace common error with defined value. 2014-07-24 10:06:25 -04:00
John C. Vernaleo
6aea36c550 Various changes to make golint happier. 2014-07-15 10:09:35 -04:00
Olaoluwa Osuntokun
033b00dd1c Properly set reply.Result to output of unmarshalled GetTxOutResult JSON.
Fix panic caused by nil pointer dereference.

Create new error type for invalid tx vout (gettxout).
2014-07-15 09:46:25 -04:00
Dave Collins
8005d2e455 Update TODO list in README.
This package has supported https for quite some time.
2014-07-07 22:40:32 -05:00
David Hill
2e0a243383 Support gettxout 2014-07-04 10:46:21 -04:00
Dave Collins
6aa6bec7fc goimports -w . 2014-07-02 19:41:28 -05:00
Dave Collins
2d32ed6ba7 Add MaxTime field support from BIP0023 mutations. 2014-06-30 10:38:15 -05:00
Dave Collins
e2e688e3d6 Make a compatibility pass.
This commit modifies some of the types of the values to better match the
reference client JSON-RPC API.
2014-06-29 16:35:53 -05:00
Dave Collins
ed76ff2172 Add BIP0023 block proposal fields.
This commit adds the optional block proposal fields defined by BIP0023 to
the GetBlockTemplateResult and TemplateRequest types.

ok @jcvernaleo
2014-06-27 13:03:00 -05:00
Dave Collins
b5db9fb485 Add BIP0023 basic pool extension fields.
This commit adds the optional basic pool extension fields defined by
BIP0023 to the GetBlockTemplateResult GetBlockTemplateCmd types.

ok @jcvernaleo
2014-06-27 13:02:46 -05:00
Dave Collins
b6c474de2a Add support for BIP0022 GetBlockTemplateResult.
This commit adds a new result type for the getblocktemplate RPC which
provides the fields as defined by BIP0022.  The extension fields defined
by BIP0023 are not included yet.

ok @jcvernaleo
2014-06-27 13:02:28 -05:00
Dave Collins
5290cb1186 Allow more BIP0022 fields in GetBlockTemplateCmd.
BIP0022 defines optional fields in a getblocktemplate request for long
polling and template tweaking.

In addition, for template tweaking, there are two fields, sigoplimit and
sizelimit, which are atypical in that they are allowed to be either
booleans or numeric.  This requires the fields to be represented as
interfaces which means any code making use of the struct will need to use
type assertions or a type switch.

This commit updates GetBlockTemplateCmd accordingly.

ok @jcvernaleo
2014-06-27 13:02:11 -05:00
Dave Collins
dc84f95fe9 Name field WorkID to make golint happy. 2014-06-27 00:30:37 -05:00
Josh Rickmar
00874b6ec2 Unmarshal correct lockunspent outpoints parameter. 2014-06-23 16:51:21 -05:00
Dave Collins
370899e1fc Change RawTxInput.Vout to uint32 as well.
This was missed by the previous commit.
2014-06-16 15:49:40 -05:00
Dave Collins
b585d4e3a0 Make params which reference txout indices uint32.
This reasons for this change follow:

- All instances of the same key should be consistent amongst the commands
  and returns
- Output indices can't be negative, so rather than adding more code to
  check for a negative after unmarshal, just allow the unmarshal to weed
  out negatives

ok @jcvernaleo
2014-06-16 14:44:04 -05:00
Dave Collins
1997d73c65 Alphabetize result type declarations. 2014-06-13 17:06:41 -05:00
John C. Vernaleo
3d7749fcea Change PingTime and PingWait to float64.
This is to match bitcoin-core.  Caught by Skelsey.

Closes #24
2014-06-12 15:36:57 -04:00
Dave Collins
ac5cc1d64e Use default genproclimit of -1 on setgenerate RPC.
The correct default for the genproclimit on the setgenerate RPC is -1.

ok @jcvernaleo.
2014-06-12 14:23:38 -05:00
Josh Rickmar
93f5aab0db Update test coverage report. 2014-06-11 12:02:35 -05:00