cryptobank 0.1.0 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e4fe9ccdd2658016176c4792badfffefff8034e2
4
- data.tar.gz: 98948d1e6ba86e63f4e914b82b6186ff9a9aedcb
3
+ metadata.gz: 40f417190c2c9c8e45f58144545fc9e3bc1fb829
4
+ data.tar.gz: 7360a0f8a7e9007766ad7e990d863b404eefdda2
5
5
  SHA512:
6
- metadata.gz: 1abb2b7335db3416df90c26ae7679ec519417a5273b783ee226d7dbc1972d528ee4923856b7aab3189003eab6e3636c95f41a4ae70519bfdcd460c06623ad670
7
- data.tar.gz: 39d396125dfa28cb98fd1fc355098db85d75a1bc2b7501add1de0ba6d56ace3f155620b35d2ab1cb166a4165e1c0efaf852c40aae416e45390c518850d7a98af
6
+ metadata.gz: a183d99f1b3540e94c8222be5091f86c2dd8c0d70286bb0c01082455df87ed1cddf7e351b725431731f4093538496929bf3f7a3933b1eda6e9d89be9c9dcd8a6
7
+ data.tar.gz: 73daced9c4dd511b12e31165221363799f3b72bd29703403d2f77442e467ac8d0bf8bac43f31af2d861cfa940bba58b55a1317d8c4fda7ece4b9cc9a11efb162
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
3
+ git_source(:github) {|repo_name| "https://github.com/Grace/Cryptobank" }
4
4
 
5
5
  # Specify your gem's dependencies in cryptobank.gemspec
6
6
  gemspec
@@ -1,16 +1,16 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cryptobank (0.1.0)
5
- httparty
4
+ cryptobank (0.1.1)
5
+ httparty (~> 0.15.6)
6
+ json (~> 2.1.0)
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
9
10
  specs:
10
- httparty (0.13.7)
11
- json (~> 1.8)
11
+ httparty (0.15.6)
12
12
  multi_xml (>= 0.5.2)
13
- json (1.8.6)
13
+ json (2.1.0)
14
14
  minitest (5.10.3)
15
15
  multi_xml (0.6.0)
16
16
  rake (10.5.0)
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Cryptobank provides Ruby wrappers for the Bitcoin API JSON-RPC.
4
4
 
5
- This gem is still in development. Please feel free to contribute and make a pull request. As the gem is called 'cryptobank', it will evole into a more general toolbox for working with crypocurrencies.
5
+ This gem is still in development. Please feel free to contribute and make a pull request. As the gem is called 'cryptobank', it will evolve into a more general toolbox for working with crypocurrencies.
6
6
 
7
7
 
8
8
  ## Installation
@@ -31,8 +31,8 @@ end
31
31
  Bitcoind.configure do |config|
32
32
  config.host = '127.0.0.1' # default: 'localhost'
33
33
  config.port = 8332 # default: 8543
34
- config.user = 'admin' # default: 'rpcuser'
35
- config.password = 'swordfish' # default: 'rpcpassword'
34
+ config.user = 'lion' # default: 'rpcuser'
35
+ config.password = 'tiger' # default: 'rpcpassword'
36
36
  end
37
37
 
38
38
  Bitcoind.new_address #=> '14gnToPKhRKhRKXZHV4mJyu8N5EFAoFU6G'
@@ -52,7 +52,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
52
52
 
53
53
  ## Contributing
54
54
 
55
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/Cryptobank. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
55
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Grace/Cryptobank. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
56
56
 
57
57
  ## License
58
58
 
@@ -64,4 +64,4 @@ Everyone interacting in the Cryptobank project’s codebases, issue trackers, ch
64
64
 
65
65
  ## Credit
66
66
 
67
- Credit goes to the gem 'Coinable' for inspiring this gem.
67
+ Credit goes to the gem 'coinable' for inspiring this gem.
@@ -28,8 +28,8 @@ Gem::Specification.new do |spec|
28
28
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
29
  spec.require_paths = ['lib']
30
30
 
31
- spec.add_runtime_dependency 'httparty'
32
-
31
+ spec.add_runtime_dependency 'json', '~> 2.1.0'
32
+ spec.add_runtime_dependency 'httparty', '~> 0.15.6'
33
33
  spec.add_development_dependency 'bundler', '~> 1.16'
34
34
  spec.add_development_dependency 'rake', '~> 10.0'
35
35
  spec.add_development_dependency 'minitest', '~> 5.0'
@@ -5,467 +5,496 @@ require 'cryptobank/error'
5
5
 
6
6
  module Cryptobank # Implements Bitcoin API JSON-RPC to communicate with bitcoind
7
7
 
8
- HEADERS = {
9
- 'Content-Type' => 'application/json',
10
- 'Accept' => 'application/json'
11
- }.freeze
12
-
13
- attr_writer :host, :port, :user, :password
14
-
15
- def host
16
- @host || 'localhost'
17
- end
18
-
19
- def port
20
- @port || 8332
21
- end
22
-
23
- def user
24
- @user || 'rpcuser'
25
- end
26
-
27
- def password
28
- @password || 'rpcpassword'
29
- end
30
-
31
- def configure
32
- yield self
33
- end
34
-
35
- # addmultisigaddress
36
- def add_multisig_address(minimum_number_of_sigs, key_or_addresses, account = '')
37
- payload = {
38
- method: 'addmultisigaddress'
39
- }
40
- payload[:params] = [minimum_number_of_sigs.to_int, key_or_addresses.to_string, account.to_string]
41
- request(payload)
42
- end
43
-
44
- # addnode
45
- def add_node
46
- raise NotImplementedError
47
- end
48
-
49
- # backupwallet
50
- def backup_wallet
51
- raise NotImplementedError
52
- end
53
-
54
- # createmultisig
55
- def create_multisig
56
- raise NotImplementedError
57
- end
58
-
59
- # createrawtransaction
60
- def create_raw_transaction
61
- raise NotImplementedError
62
- end
63
-
64
- # decoderawtransaction
65
- def decode_raw_transaction
66
- raise NotImplementedError
67
- end
68
-
69
- # dumpprivkey
70
- def dump_priv_key
71
- raise NotImplementedError
72
- end
73
-
74
- # encryptwallet
75
- def encrypt_wallet
76
- raise NotImplementedError
77
- end
78
-
79
- # getaccount
80
- # A P2PKH or P2SH Bitcoin address belonging either to a specific account or the default account (“”)
81
- # returns a base58 string
82
- def account(bitcoin_address)
83
- payload = {
84
- method: 'getaccount'
85
- }
86
- payload[:params] = [bitcoin_address.to_string]
87
- request(payload)
88
- end
89
-
90
- # getaddednodeinfo
91
- def added_node_info
92
- raise NotImplementedError
93
- end
94
-
95
- # getbalance
96
- # There are additional parameters on the RPC docs to be implemented https://bitcoin.org/en/developer-reference#getbalance
97
- def balance(account = nil)
98
- payload = {
99
- method: 'getbalance'
100
- }
101
- payload[:params] = [account] unless account.nil?
102
- request(payload)
103
- end
104
-
105
- # getbestblockhash
106
- def best_block_hash
107
- raise NotImplementedError
108
- end
109
-
110
- # getblock
111
- def block(verbosity = nil)
112
- payload = {
113
- method: 'getblock'
114
- }
115
- payload[:params] = [template_request] unless verbosity.nil?
116
- request(payload)
117
- end
118
-
119
- # getblockhash
120
- def block_hash
121
- payload = {
122
- method: 'getblockhash'
123
- }
124
- request(payload)
125
- end
126
-
127
- # getblockcount
128
- def block_count
129
- payload = {
130
- method: 'getblockcount'
131
- }
132
- request(payload)
133
- end
134
-
135
- # getblocktemplate
136
- def block_template(template_request = nil)
137
- payload = {
138
- method: 'getblocktemplate'
139
- }
140
- payload[:params] = [template_request] unless template_request.nil?
141
- request(payload)
142
- end
143
-
144
- # getconnectioncount
145
- def connection_count
146
- payload = {
147
- method: 'getconnectioncount'
148
- }
149
- request(payload)
150
- end
151
-
152
- # getdifficulty
153
- def difficulty
154
- payload = {
155
- method: 'getdifficulty'
156
- }
157
- request(payload)
158
- end
159
-
160
- # getgenerate
161
- def generate
162
- payload = {
163
- method: 'getgenerate'
164
- }
165
- request(payload)
166
- end
167
-
168
- def get_account_addresses(account)
169
- payload = {
170
- method: 'getaddressesbyaccount'
171
- }
172
- payload[:params] = [account]
173
- request(payload)
174
- end
175
-
176
- # gethashespersec
177
- def hashes_per_sec
178
- raise NotImplementedError
179
- end
180
-
181
- # getinfo
182
- def info
183
- payload = {
184
- method: 'getwalletinfo'
185
- }
186
- request(payload)
187
- end
188
-
189
- # getmempoolinfo
190
- def memory_pool_info
191
- payload = {
192
- method: 'getmempoolinfo'
193
- }
194
- request(payload)
195
- end
196
- end
197
-
198
- # getmininginfo
199
- def mining_info
200
- payload = {
201
- method: 'getmininginfo'
202
- }
203
- request(payload)
204
- end
205
-
206
- # getnewaddress
207
- def new_address(account = nil)
208
- payload = {
209
- method: 'getnewaddress'
210
- }
211
- payload[:params] = [account] unless account.nil?
212
- request(payload)
213
- end
214
-
215
- # getpeerinfo
216
- def peer_info
217
- payload = {
218
- method: 'getpeerinfo'
219
- }
220
- request(payload)
221
- end
222
-
223
- # getrawchangeaddress
224
- def raw_change_address
225
- payload = {
226
- method: 'getrawchangeaddress'
227
- }
228
- request(payload)
229
- end
230
-
231
- # getrawmempool
232
- def raw_mem_pool(verbose_format = false)
233
- payload = {
234
- method: 'getrawmempool'
235
- }
236
- payload[:params] = [1] if verbose_format?
237
- request(payload)
238
- end
239
-
240
- # getrawtransaction
241
- # The TXID of the transaction to get, encoded as hex in RPC byte order
242
- def raw_transaction(txid)
243
- payload = {
244
- method: 'getrawtransaction'
245
- }
246
- payload[:params] = [txid]
247
- request(payload)
248
- end
249
-
250
- # getreceivedbyaddress
251
- '''The getreceivedbyaddress RPC returns the total amount received by the specified address in transactions with the specified number of confirmations. It does not count coinbase transactions.'''
252
- def received_by_address(address)
253
- payload = {
254
- method: 'getreceivedbyaddress'
255
- }
256
- payload[:params] = [address]
257
- request(payload)
258
- end
259
-
260
- # gettransaction
261
- def transaction(txid)
262
- payload = {
263
- method: 'gettransaction',
264
- params: [txid]
265
- }
266
-
267
- request(payload)
268
- end
269
-
270
- # gettxout
271
- def tx_out
272
- raise NotImplementedError
273
- end
274
-
275
- # gettxoutsetinfo
276
- def tx_out_set_info
277
- raise NotImplementedError
278
- end
279
-
280
- # getwork
281
- def work
282
- raise NotImplementedError
283
- end
284
-
285
- # help
286
- def help
287
- raise NotImplementedError
288
- end
289
-
290
- # importprivkey
291
- def import_priv_key
292
- raise NotImplementedError
293
- end
294
-
295
- # keypoolrefill
296
- def keypool_refill
297
- raise NotImplementedError
298
- end
299
-
300
- # listaccounts
301
- def list_accounts(minconf = nil)
302
- payload = {
303
- method: 'listaccounts'
304
- }
305
-
306
- payload[:params] = [minconf] unless minconf.nil?
307
-
308
- request(payload)
309
- end
310
-
311
- # listaddressgroupings
312
- def list_address_groupings
313
- raise NotImplementedError
314
- end
315
-
316
- # listreceivedbyaccount
317
- def list_received_by_account
318
- raise NotImplementedError
319
- end
320
-
321
- # listreceivedbyaddress
322
- def list_received_by_address
323
- raise NotImplementedError
324
- end
325
-
326
- # listsinceblock
327
- def list_since_block
328
- raise NotImplementedError
329
- end
330
-
331
- # listtransactions
332
- def list_transactions(account = nil, count = nil, from = nil)
333
- payload = {
334
- method: 'listtransactions'
335
- }
336
- unless account.nil?
337
- payload[:params] = [account]
338
- payload[:params] << count unless count.nil?
339
- payload[:params] << from unless from.nil?
340
- end
341
- request(payload)
342
- end
343
-
344
- # listunspent
345
- def list_unspent
346
- raise NotImplementedError
347
- end
348
-
349
- # listlockunspent
350
- def list_lock_unspent
351
- raise NotImplementedError
352
- end
353
-
354
- # lockunspent
355
- def lock_unspent
356
- raise NotImplementedError
357
- end
358
-
359
- # move
360
- def move
361
- raise NotImplementedError
362
- end
363
-
364
- # sendfrom
365
- def send_from
366
- raise NotImplementedError
367
- end
368
-
369
- # sendmany
370
- def send_many
371
- raise NotImplementedError
372
- end
373
-
374
- # sendrawtransaction
375
- def send_raw_transaction
376
- raise NotImplementedError
377
- end
378
-
379
- # sendtoaddress
380
- def send_to_address(address, amount, comment = nil, comment_to = nil)
381
- payload = {
382
- method: 'sendtoaddress',
383
- params: [address, amount]
384
- }
385
- payload[:params] << comment unless comment.nil?
386
- payload[:params] << comment_to unless comment_to.nil?
387
- request(payload)
388
- end
389
-
390
- # setaccount
391
- def account=(_)
392
- raise NotImplementedError
393
- end
394
-
395
- # setgenerate
396
- def generate=(_)
397
- raise NotImplementedError
398
- end
399
-
400
- # settxfee
401
- def tx_fee=(_)
402
- raise NotImplementedError
403
- end
404
-
405
- # signmessage
406
- def sign_message
407
- raise NotImplementedError
408
- end
409
-
410
- # signrawtransaction
411
- def sign_raw_transaction
412
- raise NotImplementedError
413
- end
414
-
415
- # stop
416
- def stop
417
- raise NotImplementedError
418
- end
419
-
420
- # submitblock
421
- def submit_block
422
- raise NotImplementedError
423
- end
424
-
425
- # validateaddress
426
- def validate_address(address)
427
- payload = {
428
- method: 'validateaddress',
429
- params: [address]
430
- }
431
-
432
- request(payload)
433
- end
434
-
435
- # verifymessage
436
- def verify_message
437
- raise NotImplementedError
438
- end
439
-
440
- # walletlock
441
- def wallet_lock
442
- raise NotImplementedError
443
- end
444
-
445
- # walletpassphrase
446
- def wallet_passphrase
447
- raise NotImplementedError
448
- end
449
-
450
- # walletpassphrasechange
451
- def wallet_passphrase_change
452
- raise NotImplementedError
453
- end
454
-
455
- def valid_address?(address)
456
- validate_address(address)['isvalid']
457
- end
458
-
459
- private
460
-
461
- def request(payload)
462
- response = HTTParty.post(url, body: payload.to_json, headers: HEADERS)
463
- raise Error, response.message unless response.code == 200
464
- JSON.parse(response.body)['result']
465
- end
466
-
467
- def url
468
- "http://#{user}:#{password}@#{host}:#{port}"
469
- end
470
- # end
8
+ HEADERS = {
9
+ 'Content-Type' => 'application/json',
10
+ 'Accept' => 'application/json'
11
+ }.freeze
12
+
13
+ attr_writer :host, :port, :user, :password
14
+
15
+ def host
16
+ @host || 'localhost'
17
+ end
18
+
19
+ def port
20
+ @port || 8332
21
+ end
22
+
23
+ def user
24
+ @user || 'rpcuser'
25
+ end
26
+
27
+ def password
28
+ @password || 'rpcpassword'
29
+ end
30
+
31
+ def configure
32
+ yield self
33
+ end
34
+
35
+ # addmultisigaddress
36
+ def add_multisig_address(minimum_number_of_sigs, key_or_addresses, account = '')
37
+ payload = {
38
+ method: 'addmultisigaddress'
39
+ }
40
+ payload[:params] = [minimum_number_of_sigs.to_int, key_or_addresses.to_string, account.to_string]
41
+ request(payload)
42
+ end
43
+
44
+ # addnode
45
+ def add_node
46
+ raise NotImplementedError
47
+ end
48
+
49
+ # backupwallet
50
+ def backup_wallet
51
+ raise NotImplementedError
52
+ end
53
+
54
+ # createmultisig
55
+ def create_multisig
56
+ raise NotImplementedError
57
+ end
58
+
59
+ # createrawtransaction
60
+ def create_raw_transaction
61
+ raise NotImplementedError
62
+ end
63
+
64
+ # decoderawtransaction
65
+ def decode_raw_transaction
66
+ raise NotImplementedError
67
+ end
68
+
69
+ # dumpprivkey
70
+ def dump_priv_key
71
+ raise NotImplementedError
72
+ end
73
+
74
+ # encryptwallet
75
+ def encrypt_wallet
76
+ raise NotImplementedError
77
+ end
78
+
79
+ # getaccount
80
+ # A P2PKH or P2SH Bitcoin address belonging either to a specific account or the default account (“”)
81
+ # returns a base58 string
82
+ def account(bitcoin_address)
83
+ payload = {
84
+ method: 'getaccount'
85
+ }
86
+ payload[:params] = [bitcoin_address.to_string]
87
+ request(payload)
88
+ end
89
+
90
+ # getaddednodeinfo
91
+ def added_node_info
92
+ raise NotImplementedError
93
+ end
94
+
95
+ # getbalance
96
+ # There are additional parameters on the RPC docs to be implemented https://bitcoin.org/en/developer-reference#getbalance
97
+ def balance(account = nil)
98
+ payload = {
99
+ method: 'getbalance'
100
+ }
101
+ payload[:params] = [account] unless account.nil?
102
+ request(payload)
103
+ end
104
+
105
+ # getbestblockhash
106
+ def best_block_hash
107
+ raise NotImplementedError
108
+ end
109
+
110
+ # getblock
111
+ def block(verbosity = nil)
112
+ payload = {
113
+ method: 'getblock'
114
+ }
115
+ payload[:params] = [template_request] unless verbosity.nil?
116
+ request(payload)
117
+ end
118
+
119
+ # getblockhash
120
+ def block_hash
121
+ payload = {
122
+ method: 'getblockhash'
123
+ }
124
+ request(payload)
125
+ end
126
+
127
+ # getblockcount
128
+ def block_count
129
+ payload = {
130
+ method: 'getblockcount'
131
+ }
132
+ request(payload)
133
+ end
134
+
135
+ # getblocktemplate
136
+ def block_template(template_request = nil)
137
+ payload = {
138
+ method: 'getblocktemplate'
139
+ }
140
+ payload[:params] = [template_request] unless template_request.nil?
141
+ request(payload)
142
+ end
143
+
144
+ # getconnectioncount
145
+ def connection_count
146
+ payload = {
147
+ method: 'getconnectioncount'
148
+ }
149
+ request(payload)
150
+ end
151
+
152
+ # getdifficulty
153
+ def difficulty
154
+ payload = {
155
+ method: 'getdifficulty'
156
+ }
157
+ request(payload)
158
+ end
159
+
160
+ # getgenerate
161
+ def generate
162
+ payload = {
163
+ method: 'getgenerate'
164
+ }
165
+ request(payload)
166
+ end
167
+
168
+ def get_account_addresses(account)
169
+ payload = {
170
+ method: 'getaddressesbyaccount'
171
+ }
172
+ payload[:params] = [account]
173
+ request(payload)
174
+ end
175
+
176
+ # gethashespersec
177
+ def hashes_per_sec
178
+ raise NotImplementedError
179
+ end
180
+
181
+ # getinfo
182
+ def info
183
+ payload = {
184
+ method: 'getwalletinfo'
185
+ }
186
+ request(payload)
187
+ end
188
+
189
+ # getmempoolinfo
190
+ def memory_pool_info
191
+ payload = {
192
+ method: 'getmempoolinfo'
193
+ }
194
+ request(payload)
195
+ end
196
+ end
197
+
198
+ # getmininginfo
199
+ def mining_info
200
+ payload = {
201
+ method: 'getmininginfo'
202
+ }
203
+ request(payload)
204
+ end
205
+
206
+ # getnewaddress
207
+ def new_address(account = nil)
208
+ payload = {
209
+ method: 'getnewaddress'
210
+ }
211
+ payload[:params] = [account] unless account.nil?
212
+ request(payload)
213
+ end
214
+
215
+ # getpeerinfo
216
+ def peer_info
217
+ payload = {
218
+ method: 'getpeerinfo'
219
+ }
220
+ request(payload)
221
+ end
222
+
223
+ # getrawchangeaddress
224
+ def raw_change_address
225
+ payload = {
226
+ method: 'getrawchangeaddress'
227
+ }
228
+ request(payload)
229
+ end
230
+
231
+ # getrawmempool
232
+ def raw_mem_pool(verbose_format = false)
233
+ payload = {
234
+ method: 'getrawmempool'
235
+ }
236
+ payload[:params] = [1] if verbose_format?
237
+ request(payload)
238
+ end
239
+
240
+ # getrawtransaction
241
+ # The TXID of the transaction to get, encoded as hex in RPC byte order
242
+ def raw_transaction(txid)
243
+ payload = {
244
+ method: 'getrawtransaction'
245
+ }
246
+ payload[:params] = [txid]
247
+ request(payload)
248
+ end
249
+
250
+ # getreceivedbyaddress
251
+ '''The getreceivedbyaddress RPC returns the total amount received by the specified address in transactions with the specified number of confirmations. It does not count coinbase transactions.'''
252
+ def received_by_address(address)
253
+ payload = {
254
+ method: 'getreceivedbyaddress'
255
+ }
256
+ payload[:params] = [address]
257
+ request(payload)
258
+ end
259
+
260
+ # gettransaction
261
+ def transaction(txid)
262
+ payload = {
263
+ method: 'gettransaction',
264
+ params: [txid]
265
+ }
266
+
267
+ request(payload)
268
+ end
269
+
270
+ # gettxout
271
+ def tx_out
272
+ raise NotImplementedError
273
+ end
274
+
275
+ # gettxoutsetinfo
276
+ def tx_out_set_info
277
+ raise NotImplementedError
278
+ end
279
+
280
+ # getwork
281
+ def work
282
+ raise NotImplementedError
283
+ end
284
+
285
+ # help
286
+ def help
287
+ raise NotImplementedError
288
+ end
289
+
290
+ # importprivkey
291
+ def import_priv_key
292
+ raise NotImplementedError
293
+ end
294
+
295
+ # keypoolrefill
296
+ def keypool_refill
297
+ raise NotImplementedError
298
+ end
299
+
300
+ # listaccounts
301
+ def list_accounts(minconf = nil)
302
+ payload = {
303
+ method: 'listaccounts'
304
+ }
305
+
306
+ payload[:params] = [minconf] unless minconf.nil?
307
+
308
+ request(payload)
309
+ end
310
+
311
+ # listaddressgroupings
312
+ def list_address_groupings
313
+ raise NotImplementedError
314
+ end
315
+
316
+ # listreceivedbyaccount
317
+ def list_received_by_account
318
+ raise NotImplementedError
319
+ end
320
+
321
+ # listreceivedbyaddress
322
+ def list_received_by_address
323
+ raise NotImplementedError
324
+ end
325
+
326
+ # listsinceblock
327
+ def list_since_block
328
+ raise NotImplementedError
329
+ end
330
+
331
+ # listtransactions
332
+ def list_transactions(account = nil, count = nil, from = nil)
333
+ payload = {
334
+ method: 'listtransactions'
335
+ }
336
+ unless account.nil?
337
+ payload[:params] = [account]
338
+ payload[:params] << count unless count.nil?
339
+ payload[:params] << from unless from.nil?
340
+ end
341
+ request(payload)
342
+ end
343
+
344
+ # listunspent
345
+ def list_unspent
346
+ raise NotImplementedError
347
+ end
348
+
349
+ # listlockunspent
350
+ def list_lock_unspent
351
+ raise NotImplementedError
352
+ end
353
+
354
+ # lockunspent
355
+ def lock_unspent
356
+ raise NotImplementedError
357
+ end
358
+
359
+ # move
360
+ def move
361
+ raise NotImplementedError
362
+ end
363
+
364
+ # sendfrom
365
+ def send_from
366
+ raise NotImplementedError
367
+ end
368
+
369
+ # sendmany
370
+ def send_many
371
+ raise NotImplementedError
372
+ end
373
+
374
+ # sendrawtransaction
375
+ def send_raw_transaction
376
+ raise NotImplementedError
377
+ end
378
+
379
+ def send_money(address, amount)
380
+ payload = {
381
+ method: 'sendtoaddress',
382
+ params: [address, amount]
383
+ }
384
+ payload[:params]
385
+ request(payload)
386
+ end
387
+
388
+ def send_from_to(from_address, to_address, amount)
389
+ payload = {
390
+ method: 'move'
391
+ }
392
+
393
+ payload[:params] = [from_address, to_address, amount]
394
+
395
+ request(payload)
396
+ end
397
+
398
+ def send_from_address_to_address(from_address, to_address, amount)
399
+ payload = {
400
+ method: 'move'
401
+ }
402
+
403
+ payload[:params] = [from_address, to_address, amount]
404
+
405
+ request(payload)
406
+ end
407
+
408
+ # sendtoaddress
409
+ def send_to_address(address, amount, comment = nil, comment_to = nil)
410
+ payload = {
411
+ method: 'sendtoaddress',
412
+ params: [address, amount]
413
+ }
414
+
415
+ payload[:params] << comment unless comment.nil?
416
+ payload[:params] << comment_to unless comment_to.nil?
417
+
418
+ request(payload)
419
+ end
420
+
421
+ # setaccount
422
+ def account=(_)
423
+ raise NotImplementedError
424
+ end
425
+
426
+ # setgenerate
427
+ def generate=(_)
428
+ raise NotImplementedError
429
+ end
430
+
431
+ # settxfee
432
+ def tx_fee=(_)
433
+ raise NotImplementedError
434
+ end
435
+
436
+ # signmessage
437
+ def sign_message
438
+ raise NotImplementedError
439
+ end
440
+
441
+ # signrawtransaction
442
+ def sign_raw_transaction
443
+ raise NotImplementedError
444
+ end
445
+
446
+ # stop
447
+ def stop
448
+ raise NotImplementedError
449
+ end
450
+
451
+ # submitblock
452
+ def submit_block
453
+ raise NotImplementedError
454
+ end
455
+
456
+ # validateaddress
457
+ def validate_address(address)
458
+ payload = {
459
+ method: 'validateaddress',
460
+ params: [address]
461
+ }
462
+
463
+ request(payload)
464
+ end
465
+
466
+ # verifymessage
467
+ def verify_message
468
+ raise NotImplementedError
469
+ end
470
+
471
+ # walletlock
472
+ def wallet_lock
473
+ raise NotImplementedError
474
+ end
475
+
476
+ # walletpassphrase
477
+ def wallet_passphrase
478
+ raise NotImplementedError
479
+ end
480
+
481
+ # walletpassphrasechange
482
+ def wallet_passphrase_change
483
+ raise NotImplementedError
484
+ end
485
+
486
+ def valid_address?(address)
487
+ validate_address(address)['isvalid']
488
+ end
489
+
490
+ private
491
+
492
+ def request(payload)
493
+ response = HTTParty.post(url, body: payload.to_json, headers: HEADERS)
494
+ raise Error, response.message unless response.code == 200
495
+ JSON.parse(response.body)['result']
496
+ end
497
+
498
+ def url
499
+ "http://#{user}:#{password}@#{host}:#{port}"
471
500
  end
@@ -1,3 +1,3 @@
1
1
  module Cryptobank
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,29 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cryptobank
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Grace Christenbery
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-17 00:00:00.000000000 Z
11
+ date: 2017-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.1.0
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: httparty
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
- - - ">="
31
+ - - "~>"
18
32
  - !ruby/object:Gem::Version
19
- version: '0'
33
+ version: 0.15.6
20
34
  type: :runtime
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
- - - ">="
38
+ - - "~>"
25
39
  - !ruby/object:Gem::Version
26
- version: '0'
40
+ version: 0.15.6
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement