coinrpc 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/Gemfile +2 -0
- data/LICENSE +21 -0
- data/README.md +39 -0
- data/Rakefile +1 -0
- data/coinrpc.gemspec +26 -0
- data/lib/coinrpc.rb +67 -0
- data/lib/coinrpc/version.rb +3 -0
- metadata +160 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 82fb42b5172af64422df198f14195dfe74fe4d621542d0384156fac0efc1a24e
|
4
|
+
data.tar.gz: b42d1a1686c07c6331246a48c2864da530085951d0742eac9bb121347920a60a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 22353b587dff698678c72d288b1d8e6e6e37d3b0dbba8871d2f36596717a06d63cf6a97f25e176059a94bbb2a3d621efcdeadffc1473b4d7ec5948230b651ca3
|
7
|
+
data.tar.gz: 7a97a419aff86ceec716f3a4f51f262a50d470db894775a03a1a6e3b7cfb1452f232f1f9f7fd60e95eaef977c260f481a005450ca757f2a5b618248c9560729a
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2020 Atif Nazir
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# CoinRPC
|
2
|
+
|
3
|
+
A simple client for Bitcoin Core style RPC. Supports batch requests.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'coinrpc'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install coinrpc
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```
|
22
|
+
require 'coinrpc'
|
23
|
+
client = CoinRPC::Client.new("http://username:password@hostname:port")
|
24
|
+
puts client.getblockchaininfo
|
25
|
+
```
|
26
|
+
|
27
|
+
Responses will contain coin values as BigDecimals:
|
28
|
+
|
29
|
+
```
|
30
|
+
puts client.getrawtransaction(txid)['vout'].first['value'].to_s("F")
|
31
|
+
```
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
1. Fork it ( https://github.com/doersf/coinrpc/fork )
|
36
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/coinrpc.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'coinrpc/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "coinrpc"
|
7
|
+
spec.version = CoinRPC::VERSION
|
8
|
+
spec.authors = ["Atif Nazir"]
|
9
|
+
spec.email = ["a@block.io"]
|
10
|
+
spec.summary = %q{A fast RPC client for Bitcoin Core style software.}
|
11
|
+
spec.description = %q{This Ruby Gem is a fast RPC client for Bitcoin Core style software, including Dogecoin, Litecoin, and other similar software that implements Bitcoin Core RPC interfaces.}
|
12
|
+
spec.homepage = "https://github.com/doersf/coinrpc"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.required_ruby_version = ">= 2.4", "< 3.0"
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.6", ">= 1.6", "< 3.0"
|
23
|
+
spec.add_development_dependency "rake", '~> 13.0', ">= 13.0", "< 14.0"
|
24
|
+
spec.add_runtime_dependency "oj", "~> 3.10.6", ">= 3.10", "< 4.0"
|
25
|
+
spec.add_runtime_dependency "http", "~> 4.4.1", ">= 4.4.1", "< 5.0"
|
26
|
+
end
|
data/lib/coinrpc.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'http'
|
2
|
+
require 'oj'
|
3
|
+
require 'coinrpc/version'
|
4
|
+
|
5
|
+
module CoinRPC
|
6
|
+
class Client
|
7
|
+
def initialize(url)
|
8
|
+
|
9
|
+
urinfo = URI.parse(url)
|
10
|
+
|
11
|
+
@client = HTTP.persistent("http://#{urinfo.host}:#{urinfo.port}").timeout(60).basic_auth({:user => urinfo.user, :pass => urinfo.password})
|
12
|
+
@id = rand(1000000)
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
def method_missing(method, *args)
|
17
|
+
|
18
|
+
@id += 1
|
19
|
+
|
20
|
+
fixed_method = method.to_s.gsub(/\_/,"").freeze
|
21
|
+
|
22
|
+
post_data = nil
|
23
|
+
|
24
|
+
if args.first.is_a?(Array) and args.first.size > 0 then
|
25
|
+
# batch request
|
26
|
+
|
27
|
+
post_data = []
|
28
|
+
|
29
|
+
args.each do |arg|
|
30
|
+
@id += 1
|
31
|
+
post_data << ({:jsonrpc => "2.0", :method => fixed_method, :params => arg, :id => @id})
|
32
|
+
end
|
33
|
+
|
34
|
+
else
|
35
|
+
|
36
|
+
post_data = ({
|
37
|
+
:method => fixed_method,
|
38
|
+
:params => args,
|
39
|
+
:jsonrpc => "1.1",
|
40
|
+
:id => @id
|
41
|
+
})
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
return api_call(post_data)
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
def api_call(params)
|
51
|
+
|
52
|
+
response = @client.post("/", :body => Oj.dump(params, mode: :compat)).to_s
|
53
|
+
|
54
|
+
result = Oj.strict_load(response, :bigdecimal_load => :bigdecimal)
|
55
|
+
|
56
|
+
raise result['error']['message'] if !result.is_a?(Array) and result['error']
|
57
|
+
|
58
|
+
return result['result'] if result.is_a?(Hash)
|
59
|
+
|
60
|
+
# batch call
|
61
|
+
return result.map{|r| r['result'] || r['error']}
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
metadata
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: coinrpc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Atif Nazir
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-05-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
- - "~>"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '1.6'
|
23
|
+
- - "<"
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: '3.0'
|
26
|
+
type: :development
|
27
|
+
prerelease: false
|
28
|
+
version_requirements: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '1.6'
|
33
|
+
- - "~>"
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '1.6'
|
36
|
+
- - "<"
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '3.0'
|
39
|
+
- !ruby/object:Gem::Dependency
|
40
|
+
name: rake
|
41
|
+
requirement: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '13.0'
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '13.0'
|
49
|
+
- - "<"
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '14.0'
|
52
|
+
type: :development
|
53
|
+
prerelease: false
|
54
|
+
version_requirements: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '13.0'
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '13.0'
|
62
|
+
- - "<"
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '14.0'
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: oj
|
67
|
+
requirement: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '3.10'
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 3.10.6
|
75
|
+
- - "<"
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '4.0'
|
78
|
+
type: :runtime
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '3.10'
|
85
|
+
- - "~>"
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: 3.10.6
|
88
|
+
- - "<"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '4.0'
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: http
|
93
|
+
requirement: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: 4.4.1
|
98
|
+
- - "~>"
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: 4.4.1
|
101
|
+
- - "<"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '5.0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 4.4.1
|
111
|
+
- - "~>"
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: 4.4.1
|
114
|
+
- - "<"
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '5.0'
|
117
|
+
description: This Ruby Gem is a fast RPC client for Bitcoin Core style software, including
|
118
|
+
Dogecoin, Litecoin, and other similar software that implements Bitcoin Core RPC
|
119
|
+
interfaces.
|
120
|
+
email:
|
121
|
+
- a@block.io
|
122
|
+
executables: []
|
123
|
+
extensions: []
|
124
|
+
extra_rdoc_files: []
|
125
|
+
files:
|
126
|
+
- ".gitignore"
|
127
|
+
- Gemfile
|
128
|
+
- LICENSE
|
129
|
+
- README.md
|
130
|
+
- Rakefile
|
131
|
+
- coinrpc.gemspec
|
132
|
+
- lib/coinrpc.rb
|
133
|
+
- lib/coinrpc/version.rb
|
134
|
+
homepage: https://github.com/doersf/coinrpc
|
135
|
+
licenses:
|
136
|
+
- MIT
|
137
|
+
metadata: {}
|
138
|
+
post_install_message:
|
139
|
+
rdoc_options: []
|
140
|
+
require_paths:
|
141
|
+
- lib
|
142
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '2.4'
|
147
|
+
- - "<"
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '3.0'
|
150
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
151
|
+
requirements:
|
152
|
+
- - ">="
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: '0'
|
155
|
+
requirements: []
|
156
|
+
rubygems_version: 3.0.3
|
157
|
+
signing_key:
|
158
|
+
specification_version: 4
|
159
|
+
summary: A fast RPC client for Bitcoin Core style software.
|
160
|
+
test_files: []
|