coinrpc 1.0.2 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8b17071c447912159783c43735408c9c2e83c248152fd4c7f522283481cae100
4
- data.tar.gz: 70246a85de88e14dc13066ba581d6d8757a6467288406a405aff643fb95fd791
3
+ metadata.gz: f80efb4ad16cc2494f8c143fa84607c207317cfe0594f086d59fa068a4807072
4
+ data.tar.gz: d9c5104d11491b5495eda5aa23eb275d576ccd5d7e934c79d22309abc81727b5
5
5
  SHA512:
6
- metadata.gz: 2befbaac00aaf9209cc7b4a9d4cbfa28f930b740a3567465dc983d5c87f1103b99fe032721b278a5e1d63f73e1dfd242ca8777d4a7db7043afb1d06c5b3033b8
7
- data.tar.gz: 6a97cc8a629b538da472b89eaef38e476d03bba1aadbee569f6c02d475333ca9576e9194f7b43c57b35a9a6efa5e47406226f24d9b9f6ee53df0441e94777e9c
6
+ metadata.gz: 9dc237a79a5084bb2457faefdf885d49f5c50c5543ffa9f9c65ac0b66d7fa8454559433caae0f92d08c82dbf7124809b8810a815194ac21cd56125f5e35e4fa8
7
+ data.tar.gz: 35f065275ae97da765aee7054ec77836928356d8d2efbd17fdd046f6337d71c6fb6c8ae997258c1fd7c7d60e167c2f5bf52fc1faece9cce387e8d9ba59c1e3ce
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 'coinrpc'
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 'coinrpc'
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)['vout'].first['value'].to_s("F")
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 'Add some feature'`)
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('../lib', __FILE__)
1
+ lib = File.expand_path("../lib", __FILE__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require 'coinrpc/version'
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.4", "< 3.1"
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 "http", ">= 4.4", "< 5.1"
26
+ spec.add_runtime_dependency "http", ">= 4.4", "< 5.2"
27
27
  end
@@ -1,3 +1,3 @@
1
1
  module CoinRPC
2
- VERSION = "1.0.2"
2
+ VERSION = "2.0.1"
3
3
  end
data/lib/coinrpc.rb CHANGED
@@ -1,13 +1,17 @@
1
- require 'http'
2
- require 'oj'
3
- require 'json'
4
- require 'coinrpc/version'
1
+ require "http"
2
+ require "oj"
3
+ require "json"
4
+ require "coinrpc/version"
5
5
 
6
6
  # let OJ mimic JSON
7
7
  Oj.mimic_JSON
8
8
 
9
9
  module CoinRPC
10
10
  class Client
11
+
12
+ JSONRPC_V1_1 = "1.1".freeze
13
+ JSONRPC_V2_0 = "2.0".freeze
14
+
11
15
  def initialize(url)
12
16
 
13
17
  urinfo = URI.parse(url)
@@ -19,34 +23,17 @@ module CoinRPC
19
23
 
20
24
  def method_missing(method, *args)
21
25
 
22
- @id += 1
23
-
24
26
  fixed_method = method.to_s.gsub(/\_/,"").freeze
25
-
26
27
  post_data = nil
27
28
 
28
- if args.first.is_a?(Array) and args.first.size > 0 then
29
+ if args[0].is_a?(Array) and args[0].size > 0 then
29
30
  # 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
-
31
+ post_data = args.map{|arg| {:jsonrpc => JSONRPC_V2_0, :method => fixed_method, :params => arg, :id => (@id += 1)} }
38
32
  else
39
-
40
- post_data = ({
41
- :method => fixed_method,
42
- :params => args,
43
- :jsonrpc => "1.1",
44
- :id => @id
45
- })
46
-
33
+ post_data = {:method => fixed_method, :params => args, :jsonrpc => JSONRPC_V1_1, :id => (@id += 1)}
47
34
  end
48
35
 
49
- return api_call(post_data)
36
+ api_call(post_data)
50
37
 
51
38
  end
52
39
 
@@ -55,15 +42,17 @@ module CoinRPC
55
42
 
56
43
  response = @client.post("/", :body => Oj.dump(params, mode: :compat)).to_s
57
44
 
58
- # this won't work without Oj.mimic_JSON
45
+ # this won"t work without Oj.mimic_JSON
59
46
  result = Oj.strict_load(response, :decimal_class => BigDecimal)
60
47
 
61
- raise result['error']['message'] if !result.is_a?(Array) and result['error']
62
-
63
- return result['result'] if result.is_a?(Hash)
48
+ raise result["error"]["message"] if result.is_a?(Hash) and !result["error"].nil?
64
49
 
65
- # batch call
66
- return result.map{|r| r['result'] || r['error']}
50
+ if result.is_a?(Hash) then
51
+ result["result"]
52
+ else
53
+ # batch call
54
+ result.map{|r| r["result"] || r["error"]}
55
+ end
67
56
 
68
57
  end
69
58
 
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: 1.0.2
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Atif Nazir
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-18 00:00:00.000000000 Z
11
+ date: 2022-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -105,7 +105,7 @@ dependencies:
105
105
  version: '4.4'
106
106
  - - "<"
107
107
  - !ruby/object:Gem::Version
108
- version: '5.1'
108
+ version: '5.2'
109
109
  type: :runtime
110
110
  prerelease: false
111
111
  version_requirements: !ruby/object:Gem::Requirement
@@ -115,7 +115,7 @@ dependencies:
115
115
  version: '4.4'
116
116
  - - "<"
117
117
  - !ruby/object:Gem::Version
118
- version: '5.1'
118
+ version: '5.2'
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,17 +145,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
145
145
  requirements:
146
146
  - - ">="
147
147
  - !ruby/object:Gem::Version
148
- version: '2.4'
148
+ version: '2.6'
149
149
  - - "<"
150
150
  - !ruby/object:Gem::Version
151
- version: '3.1'
151
+ version: '3.2'
152
152
  required_rubygems_version: !ruby/object:Gem::Requirement
153
153
  requirements:
154
154
  - - ">="
155
155
  - !ruby/object:Gem::Version
156
156
  version: '0'
157
157
  requirements: []
158
- rubygems_version: 3.2.15
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.