rallet 0.1.4 → 0.1.5

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
  SHA1:
3
- metadata.gz: c83939720cfd00298725ba8fb26ec2552fb419a2
4
- data.tar.gz: 511cfbf9475fa8fb4833528e4525bf2cfbeaa00e
3
+ metadata.gz: eef3e14a8c055f537ff2102351d966ca4d0eccb9
4
+ data.tar.gz: 4714b446bd39b5eb5c80f0c3af4bda344091a688
5
5
  SHA512:
6
- metadata.gz: 59c62840231bbc502019bb47d5894706f108179235b86ae3818d058c6a863e0a502c81cbd325523530cd37c050c87c445cf917b0f5803d0049c0d5a7d38e939d
7
- data.tar.gz: 0e6eacb9dec621bb39aa0c13399e7f121637b446e439168cd32ee127895afce61d6b07c11b00dfca593d7ace98c1d32c867ca1d619f612cbc8f502c5ba6eda32
6
+ metadata.gz: b482b50ef393506ac3c7e66574959bf8f4aec5c37b114a13f07423f1ce81a8e563524c0a6d5ac8b38db137e1a1ea89d963464deb6b5a1d31e7ac1c374ec450e7
7
+ data.tar.gz: b6f0a876a9c1887c5b6f9158a9ed4a658c62c3cf7c83e2a8faa697a0cd3adb676ca6ab554b7e48d26234cc56c9256a1a899429d527a1120a68e89430072307a7
@@ -1,32 +1,16 @@
1
- require 'rest_client'
1
+ require 'rpcjson'
2
2
 
3
3
  module Rallet
4
4
  class Client
5
- attr_reader :uri
5
+ attr_reader :client
6
6
 
7
- def initialize(service_url)
8
- @uri = service_url
7
+ def initialize(service_url, rpc_version = 1.1)
8
+ @client = RPC::JSON::Client.new(service_url, rpc_version)
9
9
  end
10
10
 
11
11
  # Call any method with any args from RPC service
12
12
  def request(name, *args)
13
- if args && index = args.index(nil)
14
- args = args[0...index]
15
- end
16
- request_body = { 'method' => name, 'params' => args, 'id' => 'jsonrpc' }.to_json
17
- response = JSON.parse(make_request(request_body))
18
- raise JSONRPCError, response['error'] if response['error']
19
- response['result']
13
+ client.send(name, *args)
20
14
  end
21
-
22
- private
23
- # Make RPC call
24
- def make_request(request_body)
25
- RestClient.post(@uri, request_body, content_type: :json)
26
- end
27
-
28
- # Error handler
29
- class JSONRPCError < RuntimeError; end
30
-
31
15
  end
32
16
  end
@@ -1,3 +1,3 @@
1
1
  module Rallet
2
- VERSION = '0.1.4'
2
+ VERSION = '0.1.5'
3
3
  end
@@ -1,3 +1,5 @@
1
+ require 'rpcjson'
2
+
1
3
  module Rallet
2
4
  module Wallets
3
5
  # Extracted from https://github.com/sinisterchipmunk/bitcoin-client/blob/master/lib/bitcoin-client/client.rb
@@ -6,150 +8,150 @@ module Rallet
6
8
  attr_reader :client
7
9
 
8
10
  # Sample http://user:pass@localhost:2082
9
- def initialize(service_url)
10
- @client = Rallet::Client.new(service_url)
11
+ def initialize(service_url, rpc_version = 1.1)
12
+ @client = RPC::JSON::Client.new(service_url, rpc_version)
11
13
  end
12
14
 
13
15
  # Safely copies wallet.dat to destination, which can be a directory or a path with filename.
14
16
  def backupwallet(destination)
15
- @client.request 'backupwallet', destination
17
+ @client.send 'backupwallet', destination
16
18
  end
17
19
 
18
20
  # Creates a multi-signature address and returns a json object
19
21
  def createmultisig(nrequired, keys)
20
- @client.request 'createmultisig', nrequired, keys
22
+ @client.send 'createmultisig', nrequired, keys
21
23
  end
22
24
 
23
25
  # nCreate a transaction spending given inputs
24
26
  # (array of objects containing transaction id and output number), sending to given address(es)
25
27
  def createrawtransaction(transactionid = nil, address_amount)
26
- @client.request 'createrawtransaction', transactionid, address_amount
28
+ @client.send 'createrawtransaction', transactionid, address_amount
27
29
  end
28
30
 
29
31
  # Return a JSON object representing the serialized, hex-encoded transaction.
30
32
  def decoderawtransaction(hexstring)
31
- @client.request 'decoderawtransaction', hexstring
33
+ @client.send 'decoderawtransaction', hexstring
32
34
  end
33
35
 
34
36
  # Returns the account associated with the given address.
35
37
  def getaccount(bitcoinaddress)
36
- @client.request 'getaccount', bitcoinaddress
38
+ @client.send 'getaccount', bitcoinaddress
37
39
  end
38
40
 
39
41
  # Returns the current bitcoin address for receiving payments to this account.
40
42
  def getaccountaddress(account)
41
- @client.request 'getaccountaddress', account
43
+ @client.send 'getaccountaddress', account
42
44
  end
43
45
 
44
46
  # Returns the list of addresses for the given account.
45
47
  def getaddressesbyaccount(account)
46
- @client.request 'getaddressesbyaccount', account
48
+ @client.send 'getaddressesbyaccount', account
47
49
  end
48
50
 
49
51
  # If +account+ is not specified, returns the server's total available balance.
50
52
  # If +account+ is specified, returns the balance in the account.
51
53
  def getbalance(account = nil, minconf = 1)
52
- @client.request 'getbalance', account, minconf
54
+ @client.send 'getbalance', account, minconf
53
55
  end
54
56
 
55
57
  def getbestblockhash
56
- @client.request 'getbestblockhash'
58
+ @client.send 'getbestblockhash'
57
59
  end
58
60
 
59
61
  # Dumps the block existing at specified height.
60
62
  # Note: this is not available in the official release
61
63
  def getblockbycount(height)
62
- @client.request 'getblockbycount', height
64
+ @client.send 'getblockbycount', height
63
65
  end
64
66
 
65
67
  # Dumps the block existing with specified hash.
66
68
  def getblock(hash)
67
- block = @client.request 'getblock', hash
69
+ block = @client.send 'getblock', hash
68
70
  block["time"] = Time.at(block["time"]).utc
69
71
  block
70
72
  end
71
73
 
72
74
  # Returns the number of blocks in the longest block chain.
73
75
  def getblockcount
74
- @client.request 'getblockcount'
76
+ @client.send 'getblockcount'
75
77
  end
76
78
 
77
79
  # Returns the block number of the latest block in the longest block chain.
78
80
  def getblocknumber
79
- @client.request 'getblocknumber'
81
+ @client.send 'getblocknumber'
80
82
  end
81
83
 
82
84
  # Returns hash of block in best-block-chain at <index>; index 0 is the genesis block
83
85
  def getblockhash(index)
84
- @client.request 'getblockhash', index
86
+ @client.send 'getblockhash', index
85
87
  end
86
88
 
87
89
  # Returns the number of connections to other nodes.
88
90
  def getconnectioncount
89
- @client.request 'getconnectioncount'
91
+ @client.send 'getconnectioncount'
90
92
  end
91
93
 
92
94
  # Returns the proof-of-work difficulty as a multiple of the minimum difficulty.
93
95
  def getdifficulty
94
- @client.request 'getdifficulty'
96
+ @client.send 'getdifficulty'
95
97
  end
96
98
 
97
99
  # Returns true or false whether bitcoind is currently generating hashes
98
100
  def getgenerate
99
- @client.request 'getgenerate'
101
+ @client.send 'getgenerate'
100
102
  end
101
103
 
102
104
  # Returns a recent hashes per second performance measurement while generating.
103
105
  def gethashespersec
104
- @client.request 'gethashespersec'
106
+ @client.send 'gethashespersec'
105
107
  end
106
108
 
107
109
  # Returns an object containing various state info.
108
110
  def getinfo
109
- @client.request 'getinfo'
111
+ @client.send 'getinfo'
110
112
  end
111
113
 
112
114
  # Returns data about each connected network node.
113
115
  def getpeerinfo
114
- @client.request 'getpeerinfo'
116
+ @client.send 'getpeerinfo'
115
117
  end
116
118
 
117
119
  # Returns an object containing mining info.
118
120
  def getmininginfo
119
- @client.request 'getmininginfo'
121
+ @client.send 'getmininginfo'
120
122
  end
121
123
 
122
124
  # Returns a new bitcoin address for receiving payments. If +account+ is specified (recommended),
123
125
  # it is added to the address book so payments received with the address will be credited to +account+.
124
126
  def getnewaddress(account = nil)
125
- @client.request 'getnewaddress', account
127
+ @client.send 'getnewaddress', account
126
128
  end
127
129
 
128
130
  # Returns the total amount received by addresses with +account+ in transactions
129
131
  # with at least +minconf+ confirmations.
130
132
  def getreceivedbyaccount(account, minconf = 1)
131
- @client.request 'getreceivedbyaccount', account, minconf
133
+ @client.send 'getreceivedbyaccount', account, minconf
132
134
  end
133
135
 
134
136
  # Returns the total amount received by +bitcoinaddress+ in transactions with at least +minconf+ confirmations.
135
137
  def getreceivedbyaddress(bitcoinaddress, minconf = 1)
136
- @client.request 'getreceivedbyaddress', bitcoinaddress, minconf
138
+ @client.send 'getreceivedbyaddress', bitcoinaddress, minconf
137
139
  end
138
140
 
139
141
  # Get detailed information about +txid+
140
142
  def gettransaction(txid)
141
- @client.request 'gettransaction', txid
143
+ @client.send 'gettransaction', txid
142
144
  end
143
145
 
144
146
  # Get raw transaction bout +txid+. It outputs the whole transaction chain by default in HEX. If you want JSON, set verbose to 1.
145
147
  # When in the bitcoind config is set txindex=1, after reindexing, you can ask about any transaction (not included in your wallet), with this command.
146
148
  def getrawtransaction(txid, verbose = 0)
147
- @client.request 'getrawtransaction', txid, verbose
149
+ @client.send 'getrawtransaction', txid, verbose
148
150
  end
149
151
 
150
152
  # Gets all mempool txs (pedning/waiting to be added in a block)
151
153
  def getrawmempool
152
- @client.request 'getrawmempool'
154
+ @client.send 'getrawmempool'
153
155
  end
154
156
  # If +data+ is not specified, returns formatted hash data to work on:
155
157
  #
@@ -160,22 +162,22 @@ module Rallet
160
162
  #
161
163
  # If +data+ is specified, tries to solve the block and returns true if it was successful.
162
164
  def getwork(data = nil)
163
- @client.request 'getwork', data
165
+ @client.send 'getwork', data
164
166
  end
165
167
 
166
168
  # List commands, or get help for a command.
167
169
  def help(command = nil)
168
- @client.request 'help', command
170
+ @client.send 'help', command
169
171
  end
170
172
 
171
173
  # Adds a private key (as returned by dumpprivkey) to your wallet.
172
174
  def importprivkey(bitcoinprivkey, label = nil, rescan = true)
173
- @client.request 'importprivkey', bitcoinprivkey, label, rescan
175
+ @client.send 'importprivkey', bitcoinprivkey, label, rescan
174
176
  end
175
177
 
176
178
  # Returns Object that has account names as keys, account balances as values.
177
179
  def listaccounts(minconf = 1)
178
- @client.request 'listaccounts', minconf
180
+ @client.send 'listaccounts', minconf
179
181
  end
180
182
 
181
183
  # Returns an array of objects containing:
@@ -185,7 +187,7 @@ module Rallet
185
187
  # :confirmations => number of confirmations of the most recent transaction included
186
188
  #
187
189
  def listreceivedbyaccount(minconf = 1, includeempty = false)
188
- @client.request 'listreceivedbyaccount', minconf, includeempty
190
+ @client.send 'listreceivedbyaccount', minconf, includeempty
189
191
  end
190
192
 
191
193
  # Returns an array of objects containing:
@@ -197,87 +199,87 @@ module Rallet
197
199
  #
198
200
  # To get a list of accounts on the system, execute bitcoind listreceivedbyaddress 0 true
199
201
  def listreceivedbyaddress(minconf = 1, includeempty = false)
200
- @client.request 'listreceivedbyaddress', minconf, includeempty
202
+ @client.send 'listreceivedbyaddress', minconf, includeempty
201
203
  end
202
204
 
203
205
  # Returns up to +count+ most recent transactions for account +account+.
204
206
  def listtransactions(account = '' , count = 10, from = 0)
205
- @client.request 'listtransactions', account, count, from
207
+ @client.send 'listtransactions', account, count, from
206
208
  end
207
209
 
208
210
  # Returns transactions since <hash> block
209
211
  def listsinceblock(hash)
210
- @client.request 'listsinceblock', hash
212
+ @client.send 'listsinceblock', hash
211
213
  end
212
214
 
213
215
 
214
216
  # Move from one account in your wallet to another.
215
217
  def move(fromaccount, toaccount, amount, minconf = 1, comment = nil)
216
- @client.request 'move', fromaccount, toaccount, amount, minconf, comment
218
+ @client.send 'move', fromaccount, toaccount, amount, minconf, comment
217
219
  end
218
220
 
219
221
  # Return count transactions with <address> present in their scriptSig, skipping skip at the beginning. The ordering is oldest transaction first; if skip is negative the order returned is newest transaction first and skip+1 transactions are skipped. If verbose=0 only txids are returned rather than the full transactions.
220
222
  def searchrawtransactions(bitcoinaddress, verbose=1)
221
- @client.request 'searchrawtransactions', bitcoinaddress, verbose
223
+ @client.send 'searchrawtransactions', bitcoinaddress, verbose
222
224
  end
223
225
 
224
226
  # +amount+ is a real and is rounded to 8 decimal places. Returns the transaction ID if successful.
225
227
  def sendfrom(fromaccount, tobitcoinaddress, amount, minconf = 1, comment = nil, comment_to = nil)
226
- @client.request 'sendfrom', fromaccount, tobitcoinaddress, amount, minconf, comment, comment_to
228
+ @client.send 'sendfrom', fromaccount, tobitcoinaddress, amount, minconf, comment, comment_to
227
229
  end
228
230
 
229
231
  # Submits raw transaction (serialized, hex-encoded) to local node and network.
230
232
  def sendrawtransaction(hexstring)
231
- @client.request 'sendrawtransaction', hexstring
233
+ @client.send 'sendrawtransaction', hexstring
232
234
  end
233
235
  # +amount+ is a real and is rounded to 8 decimal places
234
236
  def sendtoaddress(bitcoinaddress, amount, comment = nil, comment_to = nil)
235
- @client.request 'sendtoaddress', bitcoinaddress, amount, comment, comment_to
237
+ @client.send 'sendtoaddress', bitcoinaddress, amount, comment, comment_to
236
238
  end
237
239
 
238
240
  def sendmany(fromaccount, addresses_amounts, minconf = 1, comment = nil)
239
- @client.request 'sendmany', fromaccount, addresses_amounts, minconf, comment
241
+ @client.send 'sendmany', fromaccount, addresses_amounts, minconf, comment
240
242
  end
241
243
 
242
244
  # Sets the account associated with the given address.
243
245
  def setaccount(bitcoinaddress, account)
244
- @client.request 'setaccount', bitcoinaddress, account
246
+ @client.send 'setaccount', bitcoinaddress, account
245
247
  end
246
248
 
247
249
  # +generate+ is true or false to turn generation on or off.
248
250
  # Generation is limited to +genproclimit+ processors, -1 is unlimited.
249
251
  def setgenerate(generate, genproclimit = -1)
250
- @client.request 'setgenerate', generate, genproclimit
252
+ @client.send 'setgenerate', generate, genproclimit
251
253
  end
252
254
 
253
255
  # Sign inputs for raw transaction (serialized, hex-encoded).
254
256
  def signrawtransaction(hexstring, transaction = nil, privatekey =nil, sighashtype = "ALL")
255
- @client.request 'signrawtransaction', hexstring, transaction, privatekey, sighashtype
257
+ @client.send 'signrawtransaction', hexstring, transaction, privatekey, sighashtype
256
258
  end
257
259
 
258
260
  # Stop bitcoin server.
259
261
  def stop
260
- @client.request 'stop'
262
+ @client.send 'stop'
261
263
  end
262
264
 
263
265
  # Return information about +bitcoinaddress+.
264
266
  def validateaddress(bitcoinaddress)
265
- @client.request 'validateaddress', bitcoinaddress
267
+ @client.send 'validateaddress', bitcoinaddress
266
268
  end
267
269
 
268
270
  # Sign a message using +bitcoinaddress+.
269
271
  def signmessage(bitcoinaddress, message)
270
- @client.request 'signmessage', bitcoinaddress, message
272
+ @client.send 'signmessage', bitcoinaddress, message
271
273
  end
272
274
 
273
275
  # Verify signature made by +bitcoinaddress+.
274
276
  def verifymessage(bitcoinaddress, signature, message)
275
- @client.request 'verifymessage', bitcoinaddress, signature, message
277
+ @client.send 'verifymessage', bitcoinaddress, signature, message
276
278
  end
277
279
 
278
280
  # Stores the wallet decryption key in memory for +timeout+ seconds.
279
281
  def walletpassphrase(passphrase, timeout)
280
- @client.request 'walletpassphrase', passphrase, timeout
282
+ @client.send 'walletpassphrase', passphrase, timeout
281
283
  end
282
284
 
283
285
  # Removes the wallet encryption key from memory, locking the wallet.
@@ -285,7 +287,7 @@ module Rallet
285
287
  # before being able to call any methods which require the wallet to be
286
288
  # unlocked.
287
289
  def walletlock
288
- @client.request 'walletlock'
290
+ @client.send 'walletlock'
289
291
  end
290
292
 
291
293
  alias account getaccount
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ['lib']
20
20
 
21
- spec.add_runtime_dependency 'rest-client', '~> 1.7', '>= 1.7.2'
21
+ spec.add_runtime_dependency 'rpcjson'
22
22
  spec.add_development_dependency 'bundler', '~> 1.3'
23
23
  spec.add_development_dependency 'rake', '~> 10.1'
24
24
  end
metadata CHANGED
@@ -1,35 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rallet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mustafa Turan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-07 00:00:00.000000000 Z
11
+ date: 2015-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rest-client
14
+ name: rpcjson
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '1.7'
20
17
  - - ">="
21
18
  - !ruby/object:Gem::Version
22
- version: 1.7.2
19
+ version: '0'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
- - - "~>"
28
- - !ruby/object:Gem::Version
29
- version: '1.7'
30
24
  - - ">="
31
25
  - !ruby/object:Gem::Version
32
- version: 1.7.2
26
+ version: '0'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: bundler
35
29
  requirement: !ruby/object:Gem::Requirement