coinrpc 1.0.3 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -4
- data/coinrpc.gemspec +4 -4
- data/lib/coinrpc/version.rb +1 -1
- data/lib/coinrpc.rb +41 -36
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3493555e3ce9e403bbd0d884396b0c6ccf803f7757e8a6bbab45408df54dfc6
|
4
|
+
data.tar.gz: 35e3547a5fe14792629730f271c0e6148bae8be395f82b76ff5a49994629d299
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8849abd81ed97fadc7ce19778cef998b64536af4142cbf0e249d4eea777e386f565a5dc26ccb766cd78d670a627f8dc2b946880f8f24f122a474157b8d11b363
|
7
|
+
data.tar.gz: db827e4d80c96fc4dddcc79e1fea46c2f69aab1aa6afbad68222616c5c91ac21651d39a60853cb85024f22a8c0fbeae56d56c18f9a362b38f653862e06be3b7d
|
data/README.md
CHANGED
@@ -6,7 +6,7 @@ A simple client for Bitcoin Core style RPC. Supports batch requests.
|
|
6
6
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
|
-
gem
|
9
|
+
gem "coinrpc"
|
10
10
|
|
11
11
|
And then execute:
|
12
12
|
|
@@ -19,7 +19,7 @@ Or install it yourself as:
|
|
19
19
|
## Usage
|
20
20
|
|
21
21
|
```
|
22
|
-
require
|
22
|
+
require "coinrpc"
|
23
23
|
client = CoinRPC::Client.new("http://username:password@hostname:port")
|
24
24
|
puts client.getblockchaininfo
|
25
25
|
```
|
@@ -27,13 +27,13 @@ Or install it yourself as:
|
|
27
27
|
Responses will contain coin values as BigDecimals:
|
28
28
|
|
29
29
|
```
|
30
|
-
puts client.getrawtransaction(txid)[
|
30
|
+
puts client.getrawtransaction(txid)["vout"].first["value"].to_s("F")
|
31
31
|
```
|
32
32
|
|
33
33
|
## Contributing
|
34
34
|
|
35
35
|
1. Fork it ( https://github.com/doersf/coinrpc/fork )
|
36
36
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
-
3. Commit your changes (`git commit -am
|
37
|
+
3. Commit your changes (`git commit -am "Add some feature"`)
|
38
38
|
4. Push to the branch (`git push origin my-new-feature`)
|
39
39
|
5. Create a new Pull Request
|
data/coinrpc.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
lib = File.expand_path(
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
-
require
|
3
|
+
require "coinrpc/version"
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "coinrpc"
|
@@ -17,11 +17,11 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
|
-
spec.required_ruby_version = ">= 2.
|
20
|
+
spec.required_ruby_version = ">= 2.6", "< 3.2"
|
21
21
|
|
22
22
|
spec.add_development_dependency "bundler", ">= 1.6", "< 3.0"
|
23
23
|
spec.add_development_dependency "rake", ">= 13.0", "< 14.0"
|
24
24
|
spec.add_runtime_dependency "json", "~> 2.0", ">= 2.3.1", "< 3.0"
|
25
25
|
spec.add_runtime_dependency "oj", ">= 3.10", "< 4.0"
|
26
|
-
spec.add_runtime_dependency "
|
26
|
+
spec.add_runtime_dependency "typhoeus", ">= 1.0", "< 2.0"
|
27
27
|
end
|
data/lib/coinrpc/version.rb
CHANGED
data/lib/coinrpc.rb
CHANGED
@@ -1,69 +1,74 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require "uri"
|
2
|
+
require "typhoeus"
|
3
|
+
require "oj"
|
4
|
+
require "json"
|
5
|
+
require "securerandom"
|
6
|
+
require "coinrpc/version"
|
5
7
|
|
6
8
|
# let OJ mimic JSON
|
7
9
|
Oj.mimic_JSON
|
8
10
|
|
9
11
|
module CoinRPC
|
12
|
+
|
13
|
+
class TimeoutError < Exception; end
|
14
|
+
class UnsuccessfulError < Exception; end
|
15
|
+
class NoResponseError < Exception; end
|
16
|
+
|
10
17
|
class Client
|
18
|
+
|
19
|
+
JSONRPC_V1_1 = "1.1".freeze
|
20
|
+
JSONRPC_V2_0 = "2.0".freeze
|
21
|
+
TIMEOUT = 60.freeze
|
22
|
+
|
11
23
|
def initialize(url)
|
12
24
|
|
13
25
|
urinfo = URI.parse(url)
|
14
26
|
|
15
|
-
@
|
16
|
-
@
|
17
|
-
|
27
|
+
@options = {:timeout => TIMEOUT, :userpwd => "#{urinfo.user}:#{urinfo.password}", :headers => {"User-Agent" => "CoinRPC/#{CoinRPC::VERSION}"}}.freeze
|
28
|
+
@url = "http://#{urinfo.host}:#{urinfo.port}/".freeze
|
29
|
+
|
18
30
|
end
|
19
|
-
|
31
|
+
|
32
|
+
def random_id
|
33
|
+
SecureRandom.hex(4).to_i(16)
|
34
|
+
end
|
35
|
+
|
20
36
|
def method_missing(method, *args)
|
21
37
|
|
22
|
-
@id += 1
|
23
|
-
|
24
38
|
fixed_method = method.to_s.gsub(/\_/,"").freeze
|
25
|
-
|
26
39
|
post_data = nil
|
27
40
|
|
28
|
-
if args.
|
41
|
+
if args[0].is_a?(Array) and args[0].size > 0 then
|
29
42
|
# batch request
|
30
|
-
|
31
|
-
post_data = []
|
32
|
-
|
33
|
-
args.each do |arg|
|
34
|
-
@id += 1
|
35
|
-
post_data << ({:jsonrpc => "2.0", :method => fixed_method, :params => arg, :id => @id})
|
36
|
-
end
|
37
|
-
|
43
|
+
post_data = args.map{|arg| {:jsonrpc => JSONRPC_V2_0, :method => fixed_method, :params => arg, :id => random_id} }
|
38
44
|
else
|
39
|
-
|
40
|
-
post_data = ({
|
41
|
-
:method => fixed_method,
|
42
|
-
:params => args,
|
43
|
-
:jsonrpc => "1.1",
|
44
|
-
:id => @id
|
45
|
-
})
|
46
|
-
|
45
|
+
post_data = {:method => fixed_method, :params => args, :jsonrpc => JSONRPC_V1_1, :id => random_id}
|
47
46
|
end
|
48
47
|
|
49
|
-
|
48
|
+
api_call(post_data)
|
50
49
|
|
51
50
|
end
|
52
51
|
|
53
52
|
private
|
54
53
|
def api_call(params)
|
55
54
|
|
56
|
-
response =
|
55
|
+
response = Typhoeus::Request.post(@url, :body => Oj.dump(params, :mode => :compat), **@options)
|
56
|
+
|
57
|
+
raise CoinRPC::TimeoutError if response.timed_out?
|
58
|
+
raise CoinRPC::NoResponseError if response.code.eql?(0)
|
59
|
+
raise CoinRPC::UnsuccessfulError unless response.success?
|
57
60
|
|
58
61
|
# this won't work without Oj.mimic_JSON
|
59
|
-
result = Oj.strict_load(response, :decimal_class => BigDecimal)
|
62
|
+
result = Oj.strict_load(response.body, :decimal_class => BigDecimal)
|
60
63
|
|
61
|
-
raise result[
|
62
|
-
|
63
|
-
return result['result'] if result.is_a?(Hash)
|
64
|
+
raise result["error"]["message"] if result.is_a?(Hash) and !result["error"].nil?
|
64
65
|
|
65
|
-
|
66
|
-
|
66
|
+
if result.is_a?(Hash) then
|
67
|
+
result["result"]
|
68
|
+
else
|
69
|
+
# batch call
|
70
|
+
result.map{|r| r["result"] || r["error"]}
|
71
|
+
end
|
67
72
|
|
68
73
|
end
|
69
74
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: coinrpc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Atif Nazir
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-09-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -97,25 +97,25 @@ dependencies:
|
|
97
97
|
- !ruby/object:Gem::Version
|
98
98
|
version: '4.0'
|
99
99
|
- !ruby/object:Gem::Dependency
|
100
|
-
name:
|
100
|
+
name: typhoeus
|
101
101
|
requirement: !ruby/object:Gem::Requirement
|
102
102
|
requirements:
|
103
103
|
- - ">="
|
104
104
|
- !ruby/object:Gem::Version
|
105
|
-
version: '
|
105
|
+
version: '1.0'
|
106
106
|
- - "<"
|
107
107
|
- !ruby/object:Gem::Version
|
108
|
-
version: '
|
108
|
+
version: '2.0'
|
109
109
|
type: :runtime
|
110
110
|
prerelease: false
|
111
111
|
version_requirements: !ruby/object:Gem::Requirement
|
112
112
|
requirements:
|
113
113
|
- - ">="
|
114
114
|
- !ruby/object:Gem::Version
|
115
|
-
version: '
|
115
|
+
version: '1.0'
|
116
116
|
- - "<"
|
117
117
|
- !ruby/object:Gem::Version
|
118
|
-
version: '
|
118
|
+
version: '2.0'
|
119
119
|
description: This Ruby Gem is a fast RPC client for Bitcoin Core style software, including
|
120
120
|
Dogecoin, Litecoin, and other similar software that implements Bitcoin Core RPC
|
121
121
|
interfaces.
|
@@ -145,7 +145,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
145
145
|
requirements:
|
146
146
|
- - ">="
|
147
147
|
- !ruby/object:Gem::Version
|
148
|
-
version: '2.
|
148
|
+
version: '2.6'
|
149
149
|
- - "<"
|
150
150
|
- !ruby/object:Gem::Version
|
151
151
|
version: '3.2'
|
@@ -155,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
155
155
|
- !ruby/object:Gem::Version
|
156
156
|
version: '0'
|
157
157
|
requirements: []
|
158
|
-
rubygems_version: 3.3.
|
158
|
+
rubygems_version: 3.3.7
|
159
159
|
signing_key:
|
160
160
|
specification_version: 4
|
161
161
|
summary: A fast RPC client for Bitcoin Core style software.
|