Skip to content

Commit

Permalink
btcjson: Replace btcjson with version 2.
Browse files Browse the repository at this point in the history
This commit removes the old and deprecated btcjsonv1 package, moves the
new version 2 package into its place, and updates all imports accordingly.
  • Loading branch information
davecgh committed May 1, 2015
1 parent 1e98e23 commit d8a4423
Show file tree
Hide file tree
Showing 63 changed files with 189 additions and 16,424 deletions.
65 changes: 24 additions & 41 deletions btcjson/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ btcjson

Package btcjson implements concrete types for marshalling to and from the
bitcoin JSON-RPC API. A comprehensive suite of tests is provided to ensure
proper functionality. Package btcjson is licensed under the copyfree ISC
license.
proper functionality.

Although this package was primarily written for btcd, it has intentionally been
designed so it can be used as a standalone package for any projects needing to
marshal to and from bitcoin JSON-RPC requests and responses.
Although this package was primarily written for the btcsuite, it has
intentionally been designed so it can be used as a standalone package for any
projects needing to marshal to and from bitcoin JSON-RPC requests and responses.

Note that although it's possible to use this package directly to implement an
RPC client, it is not recommended since it is only intended as an infrastructure
Expand All @@ -23,42 +22,6 @@ management, websocket support, automatic notification re-registration on
reconnect, and conversion from the raw underlying RPC types (strings, floats,
ints, etc) to higher-level types with many nice and useful properties.

## JSON RPC

Bitcoin provides an extensive API call list to control the chain and wallet
servers through JSON-RPC. These can be used to get information from the server
or to cause the server to perform some action.

The general form of the commands are:

```JSON
{"jsonrpc": "1.0", "id":"test", "method": "getinfo", "params": []}
```

btcjson provides code to easily create these commands from go (as some of the
commands can be fairly complex), to send the commands to a running bitcoin RPC
server, and to handle the replies (putting them in useful Go data structures).

## Sample Use

```Go
// Create a new command.
cmd, err := btcjson.NewGetBlockCountCmd()
if err != nil {
// Handle error
}

// Marshal the command to a JSON-RPC formatted byte slice.
marshalled, err := btcjson.MarshalCmd(id, cmd)
if err != nil {
// Handle error
}

// At this point marshalled contains the raw bytes that are ready to send
// to the RPC server to issue the command.
fmt.Printf("%s\n", marshalled)
```

## Documentation

[![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg)]
Expand All @@ -78,6 +41,26 @@ http://localhost:6060/pkg/github.com/btcsuite/btcd/btcjson
$ go get github.com/btcsuite/btcd/btcjson
```

## Examples

* [Marshal Command]
(http://godoc.org/github.com/btcsuite/btcd/btcjson#example-MarshalCmd)
Demonstrates how to create and marshal a command into a JSON-RPC request.

* [Unmarshal Command]
(http://godoc.org/github.com/btcsuite/btcd/btcjson#example-UnmarshalCmd)
Demonstrates how to unmarshal a JSON-RPC request and then unmarshal the
concrete request into a concrete command.

* [Marshal Response]
(http://godoc.org/github.com/btcsuite/btcd/btcjson#example-MarshalResponse)
Demonstrates how to marshal a JSON-RPC response.

* [Unmarshal Response]
(http://godoc.org/github.com/btcsuite/btcd/btcjson#example-package--UnmarshalResponse)
Demonstrates how to unmarshal a JSON-RPC response and then unmarshal the
result field in the response to a concrete type.

## GPG Verification Key

All official release tags are signed by Conformal so users can ensure the code
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"reflect"
"testing"

"github.com/btcsuite/btcd/btcjson/v2/btcjson"
"github.com/btcsuite/btcd/btcjson"
)

// TestBtcdExtCmds tests all of the btcd extended commands marshal and unmarshal
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"reflect"
"testing"

"github.com/btcsuite/btcd/btcjson/v2/btcjson"
"github.com/btcsuite/btcd/btcjson"
)

// TestBtcWalletExtCmds tests all of the btcwallet extended commands marshal and
Expand Down
88 changes: 0 additions & 88 deletions btcjson/btcws/README.md

This file was deleted.

Loading

0 comments on commit d8a4423

Please sign in to comment.