bitcoin-client 0.0.1 → 0.0.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 +7 -0
- data/.gitignore +1 -0
- data/.travis.yml +18 -0
- data/Gemfile +9 -0
- data/README.rdoc +10 -1
- data/Rakefile +5 -6
- data/{bitcoind-client.gemspec → bitcoin-client.gemspec} +6 -4
- data/lib/bitcoin/client.rb +101 -59
- data/lib/bitcoin/dsl.rb +12 -1
- data/lib/bitcoin/rpc.rb +5 -4
- data/lib/bitcoin/version.rb +1 -1
- data/spec/fixtures/build_fixture.rb +1 -1
- data/spec/fixtures/getblock.json +8 -0
- data/spec/fixtures/getmininginfo.json +8 -0
- data/spec/fixtures/setaccount.json +8 -0
- data/spec/fixtures/signmessage_invalid_address.json +8 -0
- data/spec/fixtures/signmessage_success.json +8 -0
- data/spec/fixtures/verifymessage_failure.json +8 -0
- data/spec/fixtures/verifymessage_success.json +8 -0
- data/spec/lib/bitcoin/client_spec.rb +93 -17
- data/spec/spec_helper.rb +5 -2
- metadata +119 -60
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2a2785fa846dc9f20ccf3182be415da192ab0d7c
|
4
|
+
data.tar.gz: e20b1f1b80be6e339d8d3f736c642f09ad38a58a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3f2b6b13d4ef46bb59341526715ce88bebe0ba1058f3914b0e4c8ed24b458277e637e0c7b5d345d32bdf17653095336ad07409565fc2bcec7fb8c21a9900b7c5
|
7
|
+
data.tar.gz: cc5a52df9d85050c486ebb7a4f4ab71c183ecdf52bb05cc3882fb141144bc5a7316784d1b700ba813dafbbdfd3918d047d3f33847c961de8d9bc01c23d07d3be
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/README.rdoc
CHANGED
@@ -1,9 +1,18 @@
|
|
1
|
-
= bitcoin-client
|
1
|
+
= bitcoin-client {<img src="https://travis-ci.org/sinisterchipmunk/bitcoin-client.png?branch=master" alt="Build Status" />}[https://travis-ci.org/sinisterchipmunk/bitcoin-client] {<img src="https://codeclimate.com/github/sinisterchipmunk/bitcoin-client.png" />}[https://codeclimate.com/github/sinisterchipmunk/bitcoin-client] {<img src="https://coveralls.io/repos/sinisterchipmunk/bitcoin-client/badge.png" alt="Coverage Status" />}[https://coveralls.io/r/sinisterchipmunk/bitcoin-client]
|
2
2
|
|
3
3
|
Provides a Ruby library to the complete Bitcoin JSON-RPC API. Implements all methods listed
|
4
4
|
at {https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_Calls_list}[https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_Calls_list].
|
5
5
|
Also supports customizing the host and port number to connect to.
|
6
6
|
|
7
|
+
== Installation
|
8
|
+
|
9
|
+
On Ruby 1.9, you can just install the gem and start using it. On 1.8, the 'json' gem is also required, so you'll need to install that first:
|
10
|
+
|
11
|
+
gem install json
|
12
|
+
|
13
|
+
Or, if you're using Bundler (and you should be), just add it to the Gemfile:
|
14
|
+
|
15
|
+
gem 'json', '~> 1.5.3'
|
7
16
|
|
8
17
|
== Usage
|
9
18
|
|
data/Rakefile
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
|
+
require 'rspec/core/rake_task'
|
2
3
|
|
3
|
-
|
4
|
-
|
4
|
+
desc 'Default: run specs.'
|
5
|
+
task :default => :spec
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
t.rdoc_files.include "README.rdoc", "lib/**/*.rb"
|
9
|
-
end
|
7
|
+
desc "Run specs"
|
8
|
+
RSpec::Core::RakeTask.new
|
@@ -21,8 +21,10 @@ Gem::Specification.new do |s|
|
|
21
21
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
22
22
|
s.require_paths = ["lib"]
|
23
23
|
|
24
|
-
|
25
|
-
s.add_development_dependency "
|
26
|
-
s.add_development_dependency "
|
27
|
-
s.
|
24
|
+
s.add_development_dependency "rake", '~> 0.9'
|
25
|
+
s.add_development_dependency "bundler"
|
26
|
+
s.add_development_dependency "rspec", '~> 2.6'
|
27
|
+
s.add_development_dependency "fakeweb", '~> 1.3'
|
28
|
+
s.add_development_dependency "coveralls"
|
29
|
+
s.add_runtime_dependency "rest-client"
|
28
30
|
end
|
data/lib/bitcoin/client.rb
CHANGED
@@ -11,128 +11,140 @@ class Bitcoin::Client
|
|
11
11
|
def host=(a); api.host = a; end
|
12
12
|
def port=(a); api.port = a; end
|
13
13
|
def ssl=(a); api.ssl = a; end
|
14
|
-
|
14
|
+
|
15
15
|
def options
|
16
16
|
api.options
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
def initialize(user, pass, options = {})
|
20
20
|
@api = Bitcoin::API.new({ :user => user, :pass => pass }.merge(options))
|
21
21
|
end
|
22
|
-
|
23
|
-
# Safely copies wallet.dat to destination, which can be a directory or a path with filename.
|
22
|
+
|
23
|
+
# Safely copies wallet.dat to destination, which can be a directory or a path with filename.
|
24
24
|
def backupwallet(destination)
|
25
25
|
@api.request 'backupwallet', destination
|
26
26
|
end
|
27
|
-
|
28
|
-
# Returns the account associated with the given address.
|
27
|
+
|
28
|
+
# Returns the account associated with the given address.
|
29
29
|
def getaccount(bitcoinaddress)
|
30
30
|
@api.request 'getaccount', bitcoinaddress
|
31
31
|
end
|
32
|
-
|
33
|
-
# Returns the current bitcoin address for receiving payments to this account.
|
32
|
+
|
33
|
+
# Returns the current bitcoin address for receiving payments to this account.
|
34
34
|
def getaccountaddress(account)
|
35
35
|
@api.request 'getaccountaddress', account
|
36
36
|
end
|
37
|
-
|
38
|
-
# Returns the list of addresses for the given account.
|
37
|
+
|
38
|
+
# Returns the list of addresses for the given account.
|
39
39
|
def getaddressesbyaccount(account)
|
40
40
|
@api.request 'getaddressesbyaccount', account
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
# If +account+ is not specified, returns the server's total available balance.
|
44
44
|
# If +account+ is specified, returns the balance in the account.
|
45
45
|
def getbalance(account = nil, minconf = 1)
|
46
46
|
@api.request 'getbalance', account, minconf
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
# Dumps the block existing at specified height.
|
50
50
|
# Note: this is not available in the official release
|
51
51
|
def getblockbycount(height)
|
52
52
|
@api.request 'getblockbycount', height
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
|
+
# Dumps the block existing with specified hash.
|
56
|
+
def getblock(hash)
|
57
|
+
block = @api.request 'getblock', hash
|
58
|
+
block["time"] = Time.at(block["time"]).utc
|
59
|
+
block
|
60
|
+
end
|
61
|
+
|
55
62
|
# Returns the number of blocks in the longest block chain.
|
56
63
|
def getblockcount
|
57
64
|
@api.request 'getblockcount'
|
58
65
|
end
|
59
|
-
|
60
|
-
# Returns the block number of the latest block in the longest block chain.
|
66
|
+
|
67
|
+
# Returns the block number of the latest block in the longest block chain.
|
61
68
|
def getblocknumber
|
62
69
|
@api.request 'getblocknumber'
|
63
70
|
end
|
64
|
-
|
71
|
+
|
65
72
|
# Returns the number of connections to other nodes.
|
66
73
|
def getconnectioncount
|
67
74
|
@api.request 'getconnectioncount'
|
68
75
|
end
|
69
|
-
|
70
|
-
# Returns the proof-of-work difficulty as a multiple of the minimum difficulty.
|
76
|
+
|
77
|
+
# Returns the proof-of-work difficulty as a multiple of the minimum difficulty.
|
71
78
|
def getdifficulty
|
72
79
|
@api.request 'getdifficulty'
|
73
80
|
end
|
74
|
-
|
75
|
-
# Returns true or false whether bitcoind is currently generating hashes
|
81
|
+
|
82
|
+
# Returns true or false whether bitcoind is currently generating hashes
|
76
83
|
def getgenerate
|
77
84
|
@api.request 'getgenerate'
|
78
85
|
end
|
79
|
-
|
80
|
-
# Returns a recent hashes per second performance measurement while generating.
|
86
|
+
|
87
|
+
# Returns a recent hashes per second performance measurement while generating.
|
81
88
|
def gethashespersec
|
82
89
|
@api.request 'gethashespersec'
|
83
90
|
end
|
84
91
|
|
85
|
-
# Returns an object containing various state info.
|
92
|
+
# Returns an object containing various state info.
|
86
93
|
def getinfo
|
87
94
|
@api.request 'getinfo'
|
88
95
|
end
|
89
|
-
|
96
|
+
|
97
|
+
# Returns an object containing mining info.
|
98
|
+
def getmininginfo
|
99
|
+
@api.request 'getmininginfo'
|
100
|
+
end
|
101
|
+
|
90
102
|
# Returns a new bitcoin address for receiving payments. If +account+ is specified (recommended),
|
91
103
|
# it is added to the address book so payments received with the address will be credited to +account+.
|
92
104
|
def getnewaddress(account = nil)
|
93
105
|
@api.request 'getnewaddress', account
|
94
106
|
end
|
95
|
-
|
107
|
+
|
96
108
|
# Returns the total amount received by addresses with +account+ in transactions
|
97
|
-
# with at least +minconf+ confirmations.
|
109
|
+
# with at least +minconf+ confirmations.
|
98
110
|
def getreceivedbyaccount(account, minconf = 1)
|
99
111
|
@api.request 'getreceivedbyaccount', account, minconf
|
100
112
|
end
|
101
|
-
|
102
|
-
# Returns the total amount received by +bitcoinaddress+ in transactions with at least +minconf+ confirmations.
|
113
|
+
|
114
|
+
# Returns the total amount received by +bitcoinaddress+ in transactions with at least +minconf+ confirmations.
|
103
115
|
def getreceivedbyaddress(bitcoinaddress, minconf = 1)
|
104
116
|
@api.request 'getreceivedbyaddress', bitcoinaddress, minconf
|
105
117
|
end
|
106
|
-
|
107
|
-
# Get detailed information about +txid+
|
118
|
+
|
119
|
+
# Get detailed information about +txid+
|
108
120
|
def gettransaction(txid)
|
109
121
|
@api.request 'gettransaction', txid
|
110
122
|
end
|
111
|
-
|
123
|
+
|
112
124
|
# If +data+ is not specified, returns formatted hash data to work on:
|
113
125
|
#
|
114
126
|
# :midstate => precomputed hash state after hashing the first half of the data
|
115
127
|
# :data => block data
|
116
128
|
# :hash1 => formatted hash buffer for second hash
|
117
|
-
# :target => little endian hash target
|
129
|
+
# :target => little endian hash target
|
118
130
|
#
|
119
131
|
# If +data+ is specified, tries to solve the block and returns true if it was successful.
|
120
132
|
def getwork(data = nil)
|
121
133
|
@api.request 'getwork', data
|
122
134
|
end
|
123
|
-
|
124
|
-
# List commands, or get help for a command.
|
135
|
+
|
136
|
+
# List commands, or get help for a command.
|
125
137
|
def help(command = nil)
|
126
138
|
@api.request 'help', command
|
127
139
|
end
|
128
|
-
|
129
|
-
# Returns Object that has account names as keys, account balances as values.
|
140
|
+
|
141
|
+
# Returns Object that has account names as keys, account balances as values.
|
130
142
|
def listaccounts(minconf = 1)
|
131
143
|
@api.request 'listaccounts', minconf
|
132
144
|
end
|
133
|
-
|
145
|
+
|
134
146
|
# Returns an array of objects containing:
|
135
|
-
#
|
147
|
+
#
|
136
148
|
# :account => the account of the receiving addresses
|
137
149
|
# :amount => total amount received by addresses with this account
|
138
150
|
# :confirmations => number of confirmations of the most recent transaction included
|
@@ -140,60 +152,87 @@ class Bitcoin::Client
|
|
140
152
|
def listreceivedbyaccount(minconf = 1, includeempty = false)
|
141
153
|
@api.request 'listreceivedbyaccount', minconf, includeempty
|
142
154
|
end
|
143
|
-
|
155
|
+
|
144
156
|
# Returns an array of objects containing:
|
145
|
-
#
|
157
|
+
#
|
146
158
|
# :address => receiving address
|
147
159
|
# :account => the account of the receiving address
|
148
160
|
# :amount => total amount received by the address
|
149
|
-
# :confirmations => number of confirmations of the most recent transaction included
|
150
|
-
#
|
161
|
+
# :confirmations => number of confirmations of the most recent transaction included
|
162
|
+
#
|
151
163
|
# To get a list of accounts on the system, execute bitcoind listreceivedbyaddress 0 true
|
152
164
|
def listreceivedbyaddress(minconf = 1, includeempty = false)
|
153
165
|
@api.request 'listreceivedbyaddress', minconf, includeempty
|
154
166
|
end
|
155
|
-
|
156
|
-
# Returns up to +count+ most recent transactions for account +account+.
|
167
|
+
|
168
|
+
# Returns up to +count+ most recent transactions for account +account+.
|
157
169
|
def listtransactions(account, count = 10)
|
158
170
|
@api.request 'listtransactions', account, count
|
159
171
|
end
|
160
|
-
|
161
|
-
# Move from one account in your wallet to another.
|
172
|
+
|
173
|
+
# Move from one account in your wallet to another.
|
162
174
|
def move(fromaccount, toaccount, amount, minconf = 1, comment = nil)
|
163
175
|
@api.request 'move', fromaccount, toaccount, amount, minconf, comment
|
164
176
|
end
|
165
|
-
|
166
|
-
# +amount+ is a real and is rounded to 8 decimal places. Returns the transaction ID if successful.
|
177
|
+
|
178
|
+
# +amount+ is a real and is rounded to 8 decimal places. Returns the transaction ID if successful.
|
167
179
|
def sendfrom(fromaccount, tobitcoinaddress, amount, minconf = 1, comment = nil, comment_to = nil)
|
168
180
|
@api.request 'sendfrom', fromaccount, tobitcoinaddress, amount, minconf, comment, comment_to
|
169
181
|
end
|
170
|
-
|
171
|
-
# +amount+ is a real and is rounded to 8 decimal places
|
182
|
+
|
183
|
+
# +amount+ is a real and is rounded to 8 decimal places
|
172
184
|
def sendtoaddress(bitcoinaddress, amount, comment = nil, comment_to = nil)
|
173
185
|
@api.request 'sendtoaddress', bitcoinaddress, amount, comment, comment_to
|
174
186
|
end
|
175
|
-
|
176
|
-
|
187
|
+
|
188
|
+
def sendmany(fromaccount, addresses_amounts, minconf = 1, comment = nil)
|
189
|
+
@api.request 'sendmany', fromaccount, addresses_amounts, minconf, comment
|
190
|
+
end
|
191
|
+
|
192
|
+
# Sets the account associated with the given address.
|
177
193
|
def setaccount(bitcoinaddress, account)
|
178
|
-
@api.request '
|
194
|
+
@api.request 'setaccount', bitcoinaddress, account
|
179
195
|
end
|
180
|
-
|
196
|
+
|
181
197
|
# +generate+ is true or false to turn generation on or off.
|
182
198
|
# Generation is limited to +genproclimit+ processors, -1 is unlimited.
|
183
199
|
def setgenerate(generate, genproclimit = -1)
|
184
200
|
@api.request 'setgenerate', generate, genproclimit
|
185
201
|
end
|
186
|
-
|
187
|
-
# Stop bitcoin server.
|
202
|
+
|
203
|
+
# Stop bitcoin server.
|
188
204
|
def stop
|
189
205
|
@api.request 'stop'
|
190
206
|
end
|
191
|
-
|
192
|
-
# Return information about +bitcoinaddress+.
|
207
|
+
|
208
|
+
# Return information about +bitcoinaddress+.
|
193
209
|
def validateaddress(bitcoinaddress)
|
194
210
|
@api.request 'validateaddress', bitcoinaddress
|
195
211
|
end
|
196
|
-
|
212
|
+
|
213
|
+
# Sign a message using +bitcoinaddress+.
|
214
|
+
def signmessage(bitcoinaddress, message)
|
215
|
+
@api.request 'signmessage', bitcoinaddress, message
|
216
|
+
end
|
217
|
+
|
218
|
+
# Verify signature made by +bitcoinaddress+.
|
219
|
+
def verifymessage(bitcoinaddress, signature, message)
|
220
|
+
@api.request 'verifymessage', bitcoinaddress, signature, message
|
221
|
+
end
|
222
|
+
|
223
|
+
# Stores the wallet decryption key in memory for +timeout+ seconds.
|
224
|
+
def walletpassphrase(passphrase, timeout)
|
225
|
+
@api.request 'walletpassphrase', passphrase, timeout
|
226
|
+
end
|
227
|
+
|
228
|
+
# Removes the wallet encryption key from memory, locking the wallet.
|
229
|
+
# After calling this method, you will need to call walletpassphrase again
|
230
|
+
# before being able to call any methods which require the wallet to be
|
231
|
+
# unlocked.
|
232
|
+
def walletlock
|
233
|
+
@api.request 'walletlock'
|
234
|
+
end
|
235
|
+
|
197
236
|
alias account getaccount
|
198
237
|
alias account_address getaccountaddress
|
199
238
|
alias addresses_by_account getaddressesbyaccount
|
@@ -219,9 +258,12 @@ class Bitcoin::Client
|
|
219
258
|
alias list_transactions listtransactions
|
220
259
|
alias send_from sendfrom
|
221
260
|
alias send_to_address sendtoaddress
|
261
|
+
alias send_many sendmany
|
222
262
|
alias account= setaccount
|
223
263
|
alias set_account setaccount
|
224
264
|
alias generate= setgenerate
|
225
265
|
alias set_generate setgenerate
|
226
266
|
alias validate_address validateaddress
|
267
|
+
alias sign_message signmessage
|
268
|
+
alias verify_message verifymessage
|
227
269
|
end
|
data/lib/bitcoin/dsl.rb
CHANGED
@@ -84,6 +84,11 @@ module Bitcoin::DSL
|
|
84
84
|
bitcoin.getblockbycount height
|
85
85
|
end
|
86
86
|
|
87
|
+
# Dumps the block existing with specified hash.
|
88
|
+
def getblock(hash)
|
89
|
+
bitcoin.getblock hash
|
90
|
+
end
|
91
|
+
|
87
92
|
# Returns the number of blocks in the longest block chain.
|
88
93
|
def getblockcount
|
89
94
|
bitcoin.getblockcount
|
@@ -118,7 +123,12 @@ module Bitcoin::DSL
|
|
118
123
|
def getinfo
|
119
124
|
bitcoin.getinfo
|
120
125
|
end
|
121
|
-
|
126
|
+
|
127
|
+
# Returns an object containing various mining info.
|
128
|
+
def getmininginfo
|
129
|
+
bitcoin.getmininginfo
|
130
|
+
end
|
131
|
+
|
122
132
|
# Returns a new bitcoin address for receiving payments. If +account+ is specified (recommended),
|
123
133
|
# it is added to the address book so payments received with the address will be credited to +account+.
|
124
134
|
def getnewaddress(account = nil)
|
@@ -238,6 +248,7 @@ module Bitcoin::DSL
|
|
238
248
|
alias generate? getgenerate
|
239
249
|
alias hashes_per_sec gethashespersec
|
240
250
|
alias info getinfo
|
251
|
+
alias mininginfo getmininginfo
|
241
252
|
alias new_address getnewaddress
|
242
253
|
alias received_by_account getreceivedbyaccount
|
243
254
|
alias received_by_address getreceivedbyaddress
|
data/lib/bitcoin/rpc.rb
CHANGED
@@ -23,10 +23,11 @@ class Bitcoin::RPC
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def dispatch(request)
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
RestClient.post(service_url, request.to_post_data) do |respdata, request, result|
|
27
|
+
response = JSON.parse(respdata)
|
28
|
+
raise Bitcoin::Errors::RPCError, response['error'] if response['error']
|
29
|
+
response['result']
|
30
|
+
end
|
30
31
|
end
|
31
32
|
|
32
33
|
private
|
data/lib/bitcoin/version.rb
CHANGED
@@ -10,7 +10,7 @@ params = ARGV[2..-1].collect { |y| y == '_nil' ? nil : YAML::load(y) }
|
|
10
10
|
file_name << ".json" unless file_name =~ /\.json$/
|
11
11
|
|
12
12
|
data = { 'jsonrpc' => '1.0', 'id' => 'curltest', 'method' => service_name, 'params' => params }
|
13
|
-
command = "curl --user
|
13
|
+
command = "curl --user LovleOdnu:NajOij6DriWokEjEinaw --data-binary '#{data.to_json}' -H 'content-type: text/plain;' http://127.0.0.1:8332/ -i"
|
14
14
|
|
15
15
|
puts command, nil
|
16
16
|
result = %x[#{command}]
|
@@ -0,0 +1,8 @@
|
|
1
|
+
HTTP/1.1 200 OK
|
2
|
+
Date: Mon, 10 Jun 2013 08:36:04 +0000
|
3
|
+
Connection: keep-alive
|
4
|
+
Content-Length: 1657
|
5
|
+
Content-Type: application/json
|
6
|
+
Server: bitcoin-json-rpc/v0.8.1-beta
|
7
|
+
|
8
|
+
{"result":{"hash":"0000000000000002e004985f39f929d001448623b312185bf5e4ab50e5a8e60a","confirmations":19,"size":5227,"height":240707,"version":2,"merkleroot":"18b914e2d6bd4c3118a936af75afbd230611edb6929a607302c0d591ef49b24e","tx":["cutforsimplicity","27f99033bdcea87b07f8eea4279d7ce24e479fcb49e9f54e9ffb3721e29838ed"],"time":1370842803,"nonce":3937756309,"bits":"1a011337","difficulty":15605632.68128593,"previousblockhash":"000000000000003fa76b2abdd3036d183d7e24cfb6b543781d59cdca289f6053","nextblockhash":"0000000000000087a1e962f618f757393930e58a745165033fc9d281b7bb568a"},"error":null,"id":"curltest"}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
HTTP/1.1 200 OK
|
2
|
+
Date: Mon, 10 Jun 2013 07:49:23 +0000
|
3
|
+
Connection: keep-alive
|
4
|
+
Content-Length: 222
|
5
|
+
Content-Type: application/json
|
6
|
+
Server: bitcoin-json-rpc/v0.8.1-beta
|
7
|
+
|
8
|
+
{"result":{"blocks":237338,"currentblocksize":0,"currentblocktx":0,"difficulty":11187257.46136079,"errors":"","generate":false,"genproclimit":-1,"hashespersec":0,"pooledtx":0,"testnet":false},"error":null,"id":"curltest"}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
HTTP/1.1 500 Internal Server Error
|
2
|
+
Date: Sun, 26 Aug 2012 23:58:59 +0000
|
3
|
+
Connection: close
|
4
|
+
Content-Length: 80
|
5
|
+
Content-Type: application/json
|
6
|
+
Server: bitcoin-json-rpc/v0.6.3-beta
|
7
|
+
|
8
|
+
{"result":null,"error":{"code":-3,"message":"Invalid address"},"id":"curltest"}
|
@@ -2,18 +2,18 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Bitcoin::Client do
|
4
4
|
subject { Bitcoin::Client.new($user, $pass) }
|
5
|
-
|
5
|
+
|
6
6
|
it "defaults" do
|
7
7
|
subject.user.should == $user
|
8
8
|
subject.pass.should == $pass
|
9
9
|
subject.host.should == 'localhost'
|
10
10
|
subject.port.should == 8332
|
11
|
-
subject.
|
11
|
+
subject.should_not be_ssl
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
context "RPC" do
|
15
15
|
extend RPCServiceHelper
|
16
|
-
|
16
|
+
|
17
17
|
service 'getinfo' do
|
18
18
|
it "should produce the expected result" do
|
19
19
|
result.should == {
|
@@ -33,7 +33,47 @@ describe Bitcoin::Client do
|
|
33
33
|
}
|
34
34
|
end
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
|
+
service 'getmininginfo' do
|
38
|
+
it "should produce the expected result" do
|
39
|
+
result.should == {
|
40
|
+
'blocks' => 237338,
|
41
|
+
'currentblocksize' => 0,
|
42
|
+
'currentblocktx' => 0,
|
43
|
+
'difficulty' => 11187257.46136079,
|
44
|
+
'errors' => "",
|
45
|
+
'generate' => false,
|
46
|
+
'genproclimit' => -1,
|
47
|
+
'hashespersec' => 0,
|
48
|
+
'pooledtx' => 0,
|
49
|
+
'testnet' => false
|
50
|
+
}
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
service 'getblock' do
|
55
|
+
it "should produce the expected result" do
|
56
|
+
result("0000000000000002e004985f39f929d001448623b312185bf5e4ab50e5a8e60a").should == {
|
57
|
+
'hash' => "0000000000000002e004985f39f929d001448623b312185bf5e4ab50e5a8e60a",
|
58
|
+
'confirmations' => 19,
|
59
|
+
'size' => 5227,
|
60
|
+
'height' => 240707,
|
61
|
+
'version' => 2,
|
62
|
+
'merkleroot' => "18b914e2d6bd4c3118a936af75afbd230611edb6929a607302c0d591ef49b24e",
|
63
|
+
'tx' => [
|
64
|
+
"cutforsimplicity",
|
65
|
+
"27f99033bdcea87b07f8eea4279d7ce24e479fcb49e9f54e9ffb3721e29838ed"
|
66
|
+
],
|
67
|
+
'time' => Time.utc(2013, 6, 10, 5, 40, 3),
|
68
|
+
'nonce' => 3937756309,
|
69
|
+
"bits" => "1a011337",
|
70
|
+
"difficulty" => 15605632.68128593,
|
71
|
+
"previousblockhash" => "000000000000003fa76b2abdd3036d183d7e24cfb6b543781d59cdca289f6053",
|
72
|
+
"nextblockhash" => "0000000000000087a1e962f618f757393930e58a745165033fc9d281b7bb568a"
|
73
|
+
}
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
37
77
|
service 'getblockcount' do
|
38
78
|
it "should produce the expected result" do
|
39
79
|
result.should == 141972
|
@@ -45,50 +85,50 @@ describe Bitcoin::Client do
|
|
45
85
|
result.should == 141972
|
46
86
|
end
|
47
87
|
end
|
48
|
-
|
88
|
+
|
49
89
|
service 'getconnectioncount' do
|
50
90
|
it "should produce the expected result" do
|
51
91
|
result.should == 8
|
52
92
|
end
|
53
93
|
end
|
54
|
-
|
94
|
+
|
55
95
|
service 'getdifficulty' do
|
56
96
|
it "should produce the expected result" do
|
57
97
|
result.should == 1805700.83619367
|
58
98
|
end
|
59
99
|
end
|
60
|
-
|
100
|
+
|
61
101
|
service 'getgenerate' do
|
62
102
|
it "should produce the expected result" do
|
63
103
|
result.should be_false
|
64
104
|
end
|
65
105
|
end
|
66
|
-
|
106
|
+
|
67
107
|
service 'gethashespersec' do
|
68
108
|
it "should produce the expected result" do
|
69
109
|
result.should == 0
|
70
110
|
end
|
71
111
|
end
|
72
|
-
|
112
|
+
|
73
113
|
service 'listreceivedbyaddress' do
|
74
114
|
context 'without params' do
|
75
115
|
it "should produce the expected result" do
|
76
116
|
result.should == [{
|
77
117
|
'address' => "1234",
|
78
|
-
'account' => "",
|
118
|
+
'account' => "",
|
79
119
|
'label' => "",
|
80
|
-
'amount' => 0.001,
|
120
|
+
'amount' => 0.001,
|
81
121
|
'confirmations' => 180}]
|
82
122
|
end
|
83
123
|
end
|
84
|
-
|
124
|
+
|
85
125
|
context 'with minconf 0' do
|
86
126
|
it "should produce the expected result" do
|
87
127
|
result(0).should == [{
|
88
128
|
'address' => "1234",
|
89
|
-
'account' => "",
|
129
|
+
'account' => "",
|
90
130
|
'label' => "",
|
91
|
-
'amount' => 0.001,
|
131
|
+
'amount' => 0.001,
|
92
132
|
'confirmations' => 180}]
|
93
133
|
end
|
94
134
|
end
|
@@ -97,12 +137,48 @@ describe Bitcoin::Client do
|
|
97
137
|
it "should produce the expected result" do
|
98
138
|
result(0, true).should == [{
|
99
139
|
'address' => "1234",
|
100
|
-
'account' => "",
|
140
|
+
'account' => "",
|
101
141
|
'label' => "",
|
102
|
-
'amount' => 0.001,
|
142
|
+
'amount' => 0.001,
|
103
143
|
'confirmations' => 180}]
|
104
144
|
end
|
105
145
|
end
|
106
146
|
end
|
147
|
+
|
148
|
+
service 'setaccount' do
|
149
|
+
it 'maps the call correctly' do
|
150
|
+
subject.api.should_receive(:request).with(*%w(setaccount bitcoinaddress account))
|
151
|
+
result('bitcoinaddress', 'account').should be_nil
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
service 'signmessage' do
|
156
|
+
context 'success' do
|
157
|
+
it "should produce the expected result" do
|
158
|
+
result('valid_address', 'message').should == 'Gwz2BAaqdsLTqJsh5a4'
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
context 'invalid address' do
|
163
|
+
it "should produce the expected result" do
|
164
|
+
lambda { result('invalid_address', 'message').should }.should \
|
165
|
+
raise_error Bitcoin::Errors::RPCError
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
service 'verifymessage' do
|
171
|
+
context 'success' do
|
172
|
+
it "should produce the expected result" do
|
173
|
+
result('address', 'message', 'signature').should be_true
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
context 'failure' do
|
178
|
+
it "should produce the expected result" do
|
179
|
+
result('address', 'message', 'signature').should be_false
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
107
183
|
end
|
108
184
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
require 'coveralls'
|
2
|
+
Coveralls.wear!
|
3
|
+
|
1
4
|
require 'fakeweb'
|
2
5
|
|
3
6
|
# bitcoin user settings
|
@@ -8,8 +11,8 @@ require File.expand_path('../lib/bitcoin-client', File.dirname(__FILE__))
|
|
8
11
|
|
9
12
|
Dir[File.expand_path("support/**/*.rb", File.dirname(__FILE__))].each { |f| require f }
|
10
13
|
|
11
|
-
FakeWeb.allow_net_connect = false
|
12
|
-
|
13
14
|
RSpec.configure do |c|
|
14
15
|
c.include FixturesHelper
|
16
|
+
c.before { FakeWeb.allow_net_connect = false }
|
17
|
+
c.after { FakeWeb.allow_net_connect = true }
|
15
18
|
end
|
metadata
CHANGED
@@ -1,65 +1,114 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: bitcoin-client
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
version: 0.0.1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
6
5
|
platform: ruby
|
7
|
-
authors:
|
6
|
+
authors:
|
8
7
|
- Colin MacKenzie IV
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
date: 2013-11-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.9'
|
20
|
+
type: :development
|
17
21
|
prerelease: false
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.6'
|
24
48
|
type: :development
|
25
|
-
|
26
|
-
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
27
56
|
name: fakeweb
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.3'
|
62
|
+
type: :development
|
28
63
|
prerelease: false
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.3'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: coveralls
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
35
76
|
type: :development
|
36
|
-
version_requirements: *id002
|
37
|
-
- !ruby/object:Gem::Dependency
|
38
|
-
name: rest-client
|
39
77
|
prerelease: false
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rest-client
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
46
90
|
type: :runtime
|
47
|
-
|
48
|
-
|
49
|
-
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Provides a Ruby library to the complete Bitcoin JSON-RPC API. Implements
|
98
|
+
all methods listed at https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_Calls_list
|
99
|
+
and lets you set options such as the host and port number, and whether to use SSL.
|
100
|
+
email:
|
50
101
|
- sinisterchipmunk@gmail.com
|
51
102
|
executables: []
|
52
|
-
|
53
103
|
extensions: []
|
54
|
-
|
55
104
|
extra_rdoc_files: []
|
56
|
-
|
57
|
-
files:
|
105
|
+
files:
|
58
106
|
- .gitignore
|
107
|
+
- .travis.yml
|
59
108
|
- Gemfile
|
60
109
|
- README.rdoc
|
61
110
|
- Rakefile
|
62
|
-
-
|
111
|
+
- bitcoin-client.gemspec
|
63
112
|
- lib/bitcoin-client.rb
|
64
113
|
- lib/bitcoin.rb
|
65
114
|
- lib/bitcoin/api.rb
|
@@ -72,6 +121,7 @@ files:
|
|
72
121
|
- spec/fixtures/backupwallet_without_params.json
|
73
122
|
- spec/fixtures/build_fixture.rb
|
74
123
|
- spec/fixtures/getbalance.json
|
124
|
+
- spec/fixtures/getblock.json
|
75
125
|
- spec/fixtures/getblockcount.json
|
76
126
|
- spec/fixtures/getblocknumber.json
|
77
127
|
- spec/fixtures/getconnectioncount.json
|
@@ -79,10 +129,16 @@ files:
|
|
79
129
|
- spec/fixtures/getgenerate.json
|
80
130
|
- spec/fixtures/gethashespersec.json
|
81
131
|
- spec/fixtures/getinfo.json
|
132
|
+
- spec/fixtures/getmininginfo.json
|
82
133
|
- spec/fixtures/help.json
|
83
134
|
- spec/fixtures/listreceivedbyaddress_with_minconf_0.json
|
84
135
|
- spec/fixtures/listreceivedbyaddress_with_minconf_0_and_includeempty_true.json
|
85
136
|
- spec/fixtures/listreceivedbyaddress_without_params.json
|
137
|
+
- spec/fixtures/setaccount.json
|
138
|
+
- spec/fixtures/signmessage_invalid_address.json
|
139
|
+
- spec/fixtures/signmessage_success.json
|
140
|
+
- spec/fixtures/verifymessage_failure.json
|
141
|
+
- spec/fixtures/verifymessage_success.json
|
86
142
|
- spec/lib/bitcoin/api_spec.rb
|
87
143
|
- spec/lib/bitcoin/client_spec.rb
|
88
144
|
- spec/lib/bitcoin/request_spec.rb
|
@@ -92,35 +148,32 @@ files:
|
|
92
148
|
- spec/support/rpc_service_helper.rb
|
93
149
|
homepage: http://github.com/sinisterchipmunk/bitcoin-client
|
94
150
|
licenses: []
|
95
|
-
|
151
|
+
metadata: {}
|
96
152
|
post_install_message:
|
97
153
|
rdoc_options: []
|
98
|
-
|
99
|
-
require_paths:
|
154
|
+
require_paths:
|
100
155
|
- lib
|
101
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
- !ruby/object:Gem::Version
|
112
|
-
version: "0"
|
156
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
157
|
+
requirements:
|
158
|
+
- - '>='
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: '0'
|
161
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
162
|
+
requirements:
|
163
|
+
- - '>='
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0'
|
113
166
|
requirements: []
|
114
|
-
|
115
167
|
rubyforge_project: bitcoin-client
|
116
|
-
rubygems_version:
|
168
|
+
rubygems_version: 2.0.3
|
117
169
|
signing_key:
|
118
|
-
specification_version:
|
170
|
+
specification_version: 4
|
119
171
|
summary: Provides a Ruby library to the complete Bitcoin JSON-RPC API.
|
120
|
-
test_files:
|
172
|
+
test_files:
|
121
173
|
- spec/fixtures/backupwallet_without_params.json
|
122
174
|
- spec/fixtures/build_fixture.rb
|
123
175
|
- spec/fixtures/getbalance.json
|
176
|
+
- spec/fixtures/getblock.json
|
124
177
|
- spec/fixtures/getblockcount.json
|
125
178
|
- spec/fixtures/getblocknumber.json
|
126
179
|
- spec/fixtures/getconnectioncount.json
|
@@ -128,10 +181,16 @@ test_files:
|
|
128
181
|
- spec/fixtures/getgenerate.json
|
129
182
|
- spec/fixtures/gethashespersec.json
|
130
183
|
- spec/fixtures/getinfo.json
|
184
|
+
- spec/fixtures/getmininginfo.json
|
131
185
|
- spec/fixtures/help.json
|
132
186
|
- spec/fixtures/listreceivedbyaddress_with_minconf_0.json
|
133
187
|
- spec/fixtures/listreceivedbyaddress_with_minconf_0_and_includeempty_true.json
|
134
188
|
- spec/fixtures/listreceivedbyaddress_without_params.json
|
189
|
+
- spec/fixtures/setaccount.json
|
190
|
+
- spec/fixtures/signmessage_invalid_address.json
|
191
|
+
- spec/fixtures/signmessage_success.json
|
192
|
+
- spec/fixtures/verifymessage_failure.json
|
193
|
+
- spec/fixtures/verifymessage_success.json
|
135
194
|
- spec/lib/bitcoin/api_spec.rb
|
136
195
|
- spec/lib/bitcoin/client_spec.rb
|
137
196
|
- spec/lib/bitcoin/request_spec.rb
|