coinable 0.0.0 → 0.0.1
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 +4 -4
- data/README.md +23 -8
- data/coinable.gemspec +3 -0
- data/lib/coinable.rb +78 -12
- data/lib/coinable/error.rb +3 -0
- data/lib/coinable/version.rb +1 -1
- metadata +31 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dfbd6dd8ce2d56ee215ac2ca73ad1f15c3fdf75c
|
4
|
+
data.tar.gz: c80e9cae199b1eaa27a64ec2c06fc7f1351e0d74
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 578a65b0585b32bbc86c142c34676672e00553549e3bf468176041de64bf6d0c4b4dc393c7fd44ee8738b65850c4accb50a15bc1b62ff8fdcb86253cd3c64586
|
7
|
+
data.tar.gz: e662fcf1a8009e59f193e5ff4e308ca91e093b9b33486142708bdfde6b4ecda16ba0aa4771b92e9b642dd8d5fe46520a3bc340dc5cb66cf6de102caabf1c190a
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# Coinable
|
2
2
|
|
3
|
-
|
3
|
+
Communicate with Bitcoin, Litecoin, Emercoin and other Altcoin JSON RPC the Ruby way.
|
4
4
|
|
5
|
-
|
5
|
+
Coinable implements original Bitcoin API methods (not all of them yet). So if your altcoin based on them you are free to use Coinable.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -22,20 +22,35 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
25
|
+
```ruby
|
26
|
+
class Bitcoin
|
27
|
+
extend Coinable
|
28
|
+
end
|
29
|
+
|
30
|
+
Bitcoin.configure do |config|
|
31
|
+
config.host = '123.45.678.91' # default: 'localhost'
|
32
|
+
config.port = 1337 # default: 8543
|
33
|
+
config.user = 'admin' # default: 'rpcuser'
|
34
|
+
config.password = 'swordfish' # default: 'rpcpassword'
|
35
|
+
end
|
36
|
+
|
37
|
+
Bitcoin.new_address #=> '14gnToPKhRKhRKXZHV4mJyu8N5EFAoFU6G'
|
26
38
|
|
27
|
-
|
39
|
+
class Litecoin
|
40
|
+
extend Coinable
|
41
|
+
end
|
28
42
|
|
29
|
-
|
43
|
+
Litecoin.configure do |config|
|
44
|
+
# set host, port, user and password
|
45
|
+
end
|
30
46
|
|
31
|
-
|
47
|
+
Litecoin.new_address #=> 'LcaNTWEF9FMUnwKkvtzfRtxwsqs979LLom'
|
48
|
+
```
|
32
49
|
|
33
50
|
## Contributing
|
34
51
|
|
35
52
|
Bug reports and pull requests are welcome on GitHub at https://github.com/dmxhZGp1c2hh/coinable.
|
36
53
|
|
37
|
-
|
38
54
|
## License
|
39
55
|
|
40
56
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
-
|
data/coinable.gemspec
CHANGED
@@ -18,7 +18,10 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
+
spec.add_runtime_dependency 'httparty', '~> 0.13.7'
|
22
|
+
|
21
23
|
spec.add_development_dependency 'bundler', '~> 1.11'
|
22
24
|
spec.add_development_dependency 'rake', '~> 10.0'
|
23
25
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
26
|
+
spec.add_development_dependency 'faker', '~> 1.6'
|
24
27
|
end
|
data/lib/coinable.rb
CHANGED
@@ -1,6 +1,14 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'httparty'
|
1
3
|
require 'coinable/version'
|
4
|
+
require 'coinable/error'
|
2
5
|
|
3
6
|
module Coinable
|
7
|
+
HEADERS = {
|
8
|
+
'Content-Type' => 'application/json',
|
9
|
+
'Accept' => 'application/json'
|
10
|
+
}.freeze
|
11
|
+
|
4
12
|
attr_writer :host, :port, :user, :password
|
5
13
|
|
6
14
|
def host
|
@@ -154,8 +162,14 @@ module Coinable
|
|
154
162
|
end
|
155
163
|
|
156
164
|
# getnewaddress
|
157
|
-
def new_address
|
158
|
-
|
165
|
+
def new_address(account = nil)
|
166
|
+
payload = {
|
167
|
+
method: 'getnewaddress'
|
168
|
+
}
|
169
|
+
|
170
|
+
payload[:params] = [account] unless account.nil?
|
171
|
+
|
172
|
+
request(payload)
|
159
173
|
end
|
160
174
|
|
161
175
|
# getpeerinfo
|
@@ -189,8 +203,13 @@ module Coinable
|
|
189
203
|
end
|
190
204
|
|
191
205
|
# gettransaction
|
192
|
-
def transaction
|
193
|
-
|
206
|
+
def transaction(txid)
|
207
|
+
payload = {
|
208
|
+
method: 'gettransaction',
|
209
|
+
params: [txid]
|
210
|
+
}
|
211
|
+
|
212
|
+
request(payload)
|
194
213
|
end
|
195
214
|
|
196
215
|
# gettxout
|
@@ -224,8 +243,14 @@ module Coinable
|
|
224
243
|
end
|
225
244
|
|
226
245
|
# listaccounts
|
227
|
-
def list_accounts
|
228
|
-
|
246
|
+
def list_accounts(minconf = nil)
|
247
|
+
payload = {
|
248
|
+
method: 'listaccounts'
|
249
|
+
}
|
250
|
+
|
251
|
+
payload[:params] = [minconf] unless minconf.nil?
|
252
|
+
|
253
|
+
request(payload)
|
229
254
|
end
|
230
255
|
|
231
256
|
# listaddressgroupings
|
@@ -249,8 +274,18 @@ module Coinable
|
|
249
274
|
end
|
250
275
|
|
251
276
|
# listtransactions
|
252
|
-
def list_transactions
|
253
|
-
|
277
|
+
def list_transactions(account = nil, count = nil, from = nil)
|
278
|
+
payload = {
|
279
|
+
method: 'listtransactions'
|
280
|
+
}
|
281
|
+
|
282
|
+
unless account.nil?
|
283
|
+
payload[:params] = [account]
|
284
|
+
payload[:params] << count unless count.nil?
|
285
|
+
payload[:params] << from unless from.nil?
|
286
|
+
end
|
287
|
+
|
288
|
+
request(payload)
|
254
289
|
end
|
255
290
|
|
256
291
|
# listunspent
|
@@ -289,8 +324,16 @@ module Coinable
|
|
289
324
|
end
|
290
325
|
|
291
326
|
# sendtoaddress
|
292
|
-
def send_to_address
|
293
|
-
|
327
|
+
def send_to_address(address, amount, comment = nil, comment_to = nil)
|
328
|
+
payload = {
|
329
|
+
method: 'sendtoaddress',
|
330
|
+
params: [address, amount]
|
331
|
+
}
|
332
|
+
|
333
|
+
payload[:params] << comment unless comment.nil?
|
334
|
+
payload[:params] << comment_to unless comment_to.nil?
|
335
|
+
|
336
|
+
request(payload)
|
294
337
|
end
|
295
338
|
|
296
339
|
# setaccount
|
@@ -329,8 +372,13 @@ module Coinable
|
|
329
372
|
end
|
330
373
|
|
331
374
|
# validateaddress
|
332
|
-
def validate_address
|
333
|
-
|
375
|
+
def validate_address(address)
|
376
|
+
payload = {
|
377
|
+
method: 'validateaddress',
|
378
|
+
params: [address]
|
379
|
+
}
|
380
|
+
|
381
|
+
request(payload)
|
334
382
|
end
|
335
383
|
|
336
384
|
# verifymessage
|
@@ -352,4 +400,22 @@ module Coinable
|
|
352
400
|
def wallet_passphrase_change
|
353
401
|
raise NotImplementedError
|
354
402
|
end
|
403
|
+
|
404
|
+
def valid_address?(address)
|
405
|
+
validate_address(address)['isvalid']
|
406
|
+
end
|
407
|
+
|
408
|
+
private
|
409
|
+
|
410
|
+
def request(payload)
|
411
|
+
response = HTTParty.post(url, body: payload.to_json, headers: HEADERS)
|
412
|
+
|
413
|
+
raise Error, response.message unless response.code == 200
|
414
|
+
|
415
|
+
JSON.parse(response.body)['result']
|
416
|
+
end
|
417
|
+
|
418
|
+
def url
|
419
|
+
"http://#{user}:#{password}@#{host}:#{port}"
|
420
|
+
end
|
355
421
|
end
|
data/lib/coinable/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: coinable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vlad D
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.13.7
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.13.7
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,6 +66,20 @@ dependencies:
|
|
52
66
|
- - "~>"
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: faker
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.6'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.6'
|
55
83
|
description:
|
56
84
|
email: dmxhZGp1c2hh@yandex.ru
|
57
85
|
executables: []
|
@@ -70,6 +98,7 @@ files:
|
|
70
98
|
- bin/setup
|
71
99
|
- coinable.gemspec
|
72
100
|
- lib/coinable.rb
|
101
|
+
- lib/coinable/error.rb
|
73
102
|
- lib/coinable/version.rb
|
74
103
|
homepage: https://github.com/dmxhZGp1c2hh/coinable
|
75
104
|
licenses:
|