bitcoin_rpc 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/README.md +58 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/bitcoin_rpc.gemspec +29 -0
- data/lib/bitcoin_rpc/version.rb +3 -0
- data/lib/bitcoin_rpc.rb +31 -0
- metadata +128 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5f25a39c212479c4a6d54c720422e0de5918749d
|
4
|
+
data.tar.gz: a18956d14b2ea94d42775f56685f7d8e144e43f8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 47a87130bd45c27bac21757447b1a2511e7963552d1a3bd1bcc20b8aed8be650176c6480c427374b2d901550da5f3d96bca0d85eff409720efe38336d44c920c
|
7
|
+
data.tar.gz: 95848ba79849f5696161922e46f3a055339f00463ea039615fce6ae606309992bb19da8a3ffae6115527fd6bacabe4fdb791b0e0f17da424502407a9798f9f6e
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# BitcoinRpc
|
2
|
+
|
3
|
+
Tiny JSON-RPC client for Bitcoin-Core, forwards calls via method_missing.
|
4
|
+
Uses OJ and BigDecimal to accurately deserialize amounts.
|
5
|
+
Heavily based on some throwaway snippets found around the web.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'bitcoin_rpc'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install bitcoin_rpc
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
>>> client = BitcoinRpc::Client.new('http://user:pass@bitcoin-rpc-host:18332')
|
26
|
+
=> #<BitcoinRpc::Client:0x007fae4a94c780 @uri=#<URI::HTTP http://user:pass@bitcoin-rpc-host:18332>>
|
27
|
+
>>> client.getinfo
|
28
|
+
=> {
|
29
|
+
"version" => 100000,
|
30
|
+
"protocolversion" => 70002,
|
31
|
+
"walletversion" => 60000,
|
32
|
+
"balance" => 1.27007770,
|
33
|
+
"blocks" => 315281,
|
34
|
+
"timeoffset" => 0,
|
35
|
+
"connections" => 9,
|
36
|
+
"proxy" => "",
|
37
|
+
"difficulty" => 1.00000000,
|
38
|
+
"testnet" => true,
|
39
|
+
"keypoololdest" => 1418924649,
|
40
|
+
"keypoolsize" => 101,
|
41
|
+
"paytxfee" => 0.00000000,
|
42
|
+
"relayfee" => 0.00001000,
|
43
|
+
"errors" => ""
|
44
|
+
}
|
45
|
+
|
46
|
+
## Development
|
47
|
+
|
48
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
49
|
+
|
50
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
51
|
+
|
52
|
+
## Contributing
|
53
|
+
|
54
|
+
1. Fork it ( https://github.com/[my-github-username]/bitcoin_rpc/fork )
|
55
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
56
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
57
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
58
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "bitcoin_rpc"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/bitcoin_rpc.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'bitcoin_rpc/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "bitcoin_rpc"
|
8
|
+
spec.version = BitcoinRpc::VERSION
|
9
|
+
spec.authors = ["Nubis", "Eromirou"]
|
10
|
+
spec.email = ["nb@bitex.la", "tr@bitex.la"]
|
11
|
+
|
12
|
+
spec.summary = "Tiny JSON-RPC client for Bitcoin-Core"
|
13
|
+
spec.description = %{
|
14
|
+
Tiny JSON-RPC client for Bitcoin-Core, forwards calls via method_missing.
|
15
|
+
Uses OJ and BigDecimal to accurately deserialize amounts.
|
16
|
+
Heavily based on some throwaway snippets found around the web.
|
17
|
+
}
|
18
|
+
spec.homepage = "https://github.com/bitex-la/bitcoin-rpc"
|
19
|
+
|
20
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
spec.bindir = "exe"
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
spec.add_dependency "oj", "~> 2.0"
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.9"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
spec.add_development_dependency "rspec", "~> 2"
|
28
|
+
spec.add_development_dependency "webmock", "~> 1.21"
|
29
|
+
end
|
data/lib/bitcoin_rpc.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require "net/http"
|
2
|
+
require "uri"
|
3
|
+
require 'oj'
|
4
|
+
require "bitcoin_rpc/version"
|
5
|
+
|
6
|
+
module BitcoinRpc
|
7
|
+
class Client
|
8
|
+
def initialize(service_url)
|
9
|
+
@uri = URI.parse(service_url)
|
10
|
+
end
|
11
|
+
|
12
|
+
def method_missing(name, *args)
|
13
|
+
post_body = Oj.dump({method: name, params: args, id: 'jsonrpc'}, mode: :compat)
|
14
|
+
raw_response = http_post_request(post_body)
|
15
|
+
resp = Oj.load( raw_response, symbol_keys: true, bigdecimal_load: true)
|
16
|
+
raise JsonRpcError, resp[:error] if resp[:error]
|
17
|
+
resp[:result]
|
18
|
+
end
|
19
|
+
|
20
|
+
def http_post_request(post_body)
|
21
|
+
http = Net::HTTP.new(@uri.host, @uri.port)
|
22
|
+
request = Net::HTTP::Post.new(@uri.request_uri)
|
23
|
+
request.basic_auth @uri.user, @uri.password
|
24
|
+
request.content_type = 'application/json'
|
25
|
+
request.body = post_body
|
26
|
+
http.request(request).body
|
27
|
+
end
|
28
|
+
|
29
|
+
class JsonRpcError < RuntimeError; end
|
30
|
+
end
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bitcoin_rpc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nubis
|
8
|
+
- Eromirou
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-09-15 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: oj
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '2.0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '2.0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: bundler
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '1.9'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '1.9'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rake
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '10.0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '10.0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rspec
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '2'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '2'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: webmock
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '1.21'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '1.21'
|
84
|
+
description: "\n Tiny JSON-RPC client for Bitcoin-Core, forwards calls via method_missing.\n
|
85
|
+
\ Uses OJ and BigDecimal to accurately deserialize amounts.\n Heavily based
|
86
|
+
on some throwaway snippets found around the web.\n "
|
87
|
+
email:
|
88
|
+
- nb@bitex.la
|
89
|
+
- tr@bitex.la
|
90
|
+
executables: []
|
91
|
+
extensions: []
|
92
|
+
extra_rdoc_files: []
|
93
|
+
files:
|
94
|
+
- ".gitignore"
|
95
|
+
- ".rspec"
|
96
|
+
- ".travis.yml"
|
97
|
+
- Gemfile
|
98
|
+
- README.md
|
99
|
+
- Rakefile
|
100
|
+
- bin/console
|
101
|
+
- bin/setup
|
102
|
+
- bitcoin_rpc.gemspec
|
103
|
+
- lib/bitcoin_rpc.rb
|
104
|
+
- lib/bitcoin_rpc/version.rb
|
105
|
+
homepage: https://github.com/bitex-la/bitcoin-rpc
|
106
|
+
licenses: []
|
107
|
+
metadata: {}
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options: []
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 2.4.5
|
125
|
+
signing_key:
|
126
|
+
specification_version: 4
|
127
|
+
summary: Tiny JSON-RPC client for Bitcoin-Core
|
128
|
+
test_files: []
|