Project

silkroad

0.01
No commit activity in last 3 years
No release in over 3 years
A fast, thread-safe, simple, lightweight, batchable, sober interface to the bitcoind JSON-RPC api.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0
 Project Readme

Silkroad

A fast, thread-safe, simple, lightweight, batchable interface to the bitcoind JSON-RPC api. Uses HTTPClient for high performance.

Installation

Add this line to your application's Gemfile:

gem 'silkroad'

And then execute:

$ bundle

Or install it yourself as:

$ gem install silkroad

Usage

Initialize the client:

silkroad = Silkroad::Client.new

You can set a custom uri:

silkroad = Silkroad::Client.new 'https://rpcuser:rpcpass@yourbitcoinddaemon.com:31337'

Now you can make RPC API calls (see the API calls list). Pass params as per the spec, and the result will be returned as a primitive type (string, number, boolean, and nil) or structured type (hash, array), depending on the call:

silkroad.rpc 'getbalance', 'derp@example.com' # => 31337

Errors throw the Silkroad::Client::Error exception. Catch it if you want to do something custom:

begin
  silkroad.rpc 'failcmd', 'fail'
rescue Silkroad::Client::Error => e
  puts "Error: #{e.inspect}"
end

Batching

If you use batching, it will throw all your requests into a JSON array, send them at once, and return all of them when they are done, per the JSON-RPC spec. Batch is much lower level, and does not raise exceptions on errors. You will need to look for the response[index]['error'] in the return and handle it.

response = @silkroad.batch do
  rpc 'getbalance', 'tyler@example.com'
  rpc 'notworking', 'derp'
end

# response is:
[
  {result: 31337, error: nil, id: nil},
  {result: nil, error: {code: -32601, message: 'Method not found'}, id: nil}
]

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Winners Don't Use Drugs - William S. Sessions, Director, FBI