Socket
Socket
Sign inDemoInstall

github.com/hlandauf/btcjson

Package Overview
Dependencies
0
Alerts
File Explorer

Install Socket

Detect and block malicious and high-risk dependencies

Install

    github.com/hlandauf/btcjson

Package btcjson implements the bitcoin JSON-RPC API. A complete description of the JSON-RPC protocol as used by bitcoin can be found on the official wiki at https://en.bitcoin.it/wiki/API_reference_%28JSON-RPC%29 with a list of all the supported calls at https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_Calls_list. This package provides data structures and code for marshalling and unmarshalling json for communicating with a running instance of btcd or bitcoind/bitcoin-qt. It also provides code for sending those messages. It does not provide any code for the client to actually deal with the messages. Although it is meant primarily for btcd, it is possible to use this code elsewhere for interacting with a bitcoin client programatically. All messages to bitcoin are of the form: The params field can vary in what it contains depending on the different method (or command) being sent. Replies will vary in form for the different commands. The basic form is: The result field can be as simple as an int, or a complex structure containing many nested fields. For cases where we have already worked out the possible types of reply, result is unmarshalled into a structure that matches the command. For others, an interface is returned. An interface is not as convenient as one needs to do a type assertion first before using the value, but it means we can handle arbitrary replies. The error field is null when there is no error. When there is an error it will return a numeric error code as well as a message describing the error. id is simply the id of the requester. All RPC calls must be authenticated with a username and password. The specifics on how to configure the RPC server varies depending on the specific bitcoin implementation. For bitcoind, this is accomplished by setting rpcuser and rpcpassword in the file ~/.bitcoin/bitcoin.conf. For btcd, this is accomplished by setting rpcuser and rpcpass in the file ~/.btcd/btcd.conf. The default local address of bitcoind is 127.0.0.1:8332 and the default local address of btcd is 127.0.0.1:8334 The general pattern to use this package consists of generating a message (see the full list on the official bitcoin wiki), sending the message, and handling the result after asserting its type. For commands where the reply structure is known, such as getinfo, one can directly access the fields in the Reply structure by type asserting the reply to the appropriate concrete type. For other commands where this package does not yet provide a concrete implementation for the reply, such as getrawmempool, the reply uses a generic interface so one can access individual items as follows:


Version published

Readme

Source

btcjson

[Build Status] (https://travis-ci.org/conformal/btcjson)

Package btcjson implements the bitcoin JSON-RPC API. There is a test suite which is aiming to reach 100% code coverage. See test_coverage.txt for the current coverage (using gocov). On a UNIX-like OS, the script cov_report.sh can be used to generate the report. Package btcjson is licensed under the liberal ISC license.

This package is one of the core packages from btcd, an alternative full-node implementation of bitcoin which is under active development by Conformal. Although it was primarily written for btcd, this package has intentionally been designed so it can be used as a standalone package for any projects needing to communicate with a bitcoin client using the json rpc interface. BlockSafari is one such program that uses btcjson to communicate with btcd (or bitcoind to help test btcd).

JSON RPC

Bitcoin provides an extensive API call list to control bitcoind or bitcoin-qt through json-rpc. These can be used to get information from the client or to cause the client to perform some action.

The general form of the commands are:

	{"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

	msg, err := btcjson.CreateMessage("getinfo")
	reply, err := btcjson.RpcCommand(user, password, server, msg)

Documentation

Full go doc style documentation for the project can be viewed online without installing this package by using the GoDoc site here.

You can also view the documentation locally once the package is installed with the godoc tool by running godoc -http=":6060" and pointing your browser to http://localhost:6060/pkg/github.com/conformal/btcjson

Installation

$ go get github.com/conformal/btcjson

TODO

  • Increase test coverage to 100%.

GPG Verification Key

All official release tags are signed by Conformal so users can ensure the code has not been tampered with and is coming from Conformal. To verify the signature perform the following:

  • Download the public key from the Conformal website at https://opensource.conformal.com/GIT-GPG-KEY-conformal.txt

  • Import the public key into your GPG keyring:

    gpg --import GIT-GPG-KEY-conformal.txt
    
  • Verify the release tag with the following command where TAG_NAME is a placeholder for the specific tag:

    git tag -v TAG_NAME
    

License

Package btcjson is licensed under the liberal ISC License.

FAQs

Last updated on 21 Jul 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc