dogecoin-client 0.0.3
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 +5 -0
- data/.travis.yml +18 -0
- data/Gemfile +13 -0
- data/README.rdoc +71 -0
- data/Rakefile +8 -0
- data/dogecoin-client.gemspec +28 -0
- data/lib/dogecoin/api.rb +33 -0
- data/lib/dogecoin/client.rb +279 -0
- data/lib/dogecoin/dsl.rb +270 -0
- data/lib/dogecoin/errors.rb +4 -0
- data/lib/dogecoin/request.rb +35 -0
- data/lib/dogecoin/rpc.rb +51 -0
- data/lib/dogecoin/version.rb +12 -0
- data/lib/dogecoin-client.rb +1 -0
- data/lib/dogecoin.rb +19 -0
- data/spec/fixtures/backupwallet_without_params.json +8 -0
- data/spec/fixtures/build_fixture.rb +19 -0
- data/spec/fixtures/getbalance.json +8 -0
- data/spec/fixtures/getbestblockhash.json +8 -0
- data/spec/fixtures/getblock.json +8 -0
- data/spec/fixtures/getblockcount.json +8 -0
- data/spec/fixtures/getblockhash.json +8 -0
- data/spec/fixtures/getblocknumber.json +8 -0
- data/spec/fixtures/getconnectioncount.json +8 -0
- data/spec/fixtures/getdifficulty.json +8 -0
- data/spec/fixtures/getgenerate.json +8 -0
- data/spec/fixtures/gethashespersec.json +8 -0
- data/spec/fixtures/getinfo.json +8 -0
- data/spec/fixtures/getmininginfo.json +8 -0
- data/spec/fixtures/help.json +8 -0
- data/spec/fixtures/listreceivedbyaddress_with_minconf_0.json +8 -0
- data/spec/fixtures/listreceivedbyaddress_with_minconf_0_and_includeempty_true.json +7 -0
- data/spec/fixtures/listreceivedbyaddress_without_params.json +7 -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/dogecoin/api_spec.rb +28 -0
- data/spec/lib/dogecoin/client_spec.rb +196 -0
- data/spec/lib/dogecoin/request_spec.rb +19 -0
- data/spec/lib/dogecoin_spec.rb +34 -0
- data/spec/spec_helper.rb +18 -0
- data/spec/support/fixtures_helper.rb +5 -0
- data/spec/support/rpc_service_helper.rb +34 -0
- metadata +173 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ed8a191e38c223a2ad66b5743b0a436ce9686775
|
4
|
+
data.tar.gz: b07d1916800f7c3b8c3b342bc0346b1b5a88fcb6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8c00236aa985180ee251ad90d5588f2a2e2452bd1eeeefda522b792ef77403ea56a60cf79231394b30e1a2ba5ce2a08fb06f9460a7a73516691393af4894b355
|
7
|
+
data.tar.gz: 37f5fedd23d786e170d018c01026feeb772c3979b2b065f59712b38042441631c544e7f1996f39875068ca64383e7a85762f16fd32f4a91936a2326fa5890c62
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
== dogecoin-ruby
|
2
|
+
|
3
|
+
Provides a Ruby library to the complete Dogecoin JSON-RPC API.
|
4
|
+
|
5
|
+
== Installation
|
6
|
+
|
7
|
+
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:
|
8
|
+
|
9
|
+
gem install json
|
10
|
+
|
11
|
+
== Usage
|
12
|
+
|
13
|
+
As with most Ruby gems, you first need to require the library into your project:
|
14
|
+
|
15
|
+
require 'dogecoin'
|
16
|
+
|
17
|
+
After doing this, the simplest possible usage looks like this:
|
18
|
+
|
19
|
+
Dogecoin('username', 'password').balance
|
20
|
+
# => 0.001
|
21
|
+
|
22
|
+
Or, if you prefer a somewhat more explicit representation, the following code performs the exact
|
23
|
+
same task:
|
24
|
+
|
25
|
+
client = Dogecoin::Client.new('username', 'password')
|
26
|
+
client.balance
|
27
|
+
# => 0.001
|
28
|
+
|
29
|
+
The third and final way to use the library is by taking advantage of a simple DSL:
|
30
|
+
|
31
|
+
include Dogecoin
|
32
|
+
|
33
|
+
# set up credentials
|
34
|
+
username 'username'
|
35
|
+
password 'password'
|
36
|
+
|
37
|
+
balance
|
38
|
+
# => 0.001
|
39
|
+
|
40
|
+
accounts
|
41
|
+
# => {"account" => 0.001}
|
42
|
+
|
43
|
+
== Host, Port and SSL
|
44
|
+
|
45
|
+
Here are several examples of how you can change the host information:
|
46
|
+
|
47
|
+
|
48
|
+
Dogecoin('username', 'password', :host => 'example.com', :port => 22555, :ssl => true)
|
49
|
+
client = Dogecoin::Client.new('username', 'password', :host => 'example.com')
|
50
|
+
client.port = 22555
|
51
|
+
port 22555
|
52
|
+
ssl?
|
53
|
+
# => false
|
54
|
+
ssl true
|
55
|
+
ssl?
|
56
|
+
# => true
|
57
|
+
|
58
|
+
You should see the Dogecoin::Client class documentation if you'd like to see the other options and methods
|
59
|
+
that are made available.
|
60
|
+
|
61
|
+
|
62
|
+
== Donations
|
63
|
+
|
64
|
+
If you found this library useful and feel inclined to compensate me for my trouble, I'm certainly not going to turn you down!
|
65
|
+
|
66
|
+
Dogecoin donations can be sent to:
|
67
|
+
|
68
|
+
DNjbbUqsNipNkPeoEit5maYryxAJdLCWz8
|
69
|
+
|
70
|
+
Thanks!
|
71
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "dogecoin/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.licenses = [ 'MIT' ]
|
7
|
+
s.name = "dogecoin-client"
|
8
|
+
s.version = Dogecoin::VERSION
|
9
|
+
s.authors = ["Anthony Eufemio"]
|
10
|
+
s.email = ["tymat@pris.im"]
|
11
|
+
s.homepage = "http://github.com/tymat/dogecoin-client"
|
12
|
+
s.summary = %q{Provides a Ruby library to the complete Dogecoin JSON-RPC API.}
|
13
|
+
s.description = "Provides a Ruby library to the complete Dogecoin JSON-RPC API. "
|
14
|
+
|
15
|
+
s.rubyforge_project = "dogecoin-client"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_development_dependency "rake", '~> 0.9'
|
23
|
+
s.add_development_dependency "bundler"
|
24
|
+
s.add_development_dependency "rspec", '~> 2.6'
|
25
|
+
s.add_development_dependency "fakeweb", '~> 1.3'
|
26
|
+
s.add_development_dependency "coveralls"
|
27
|
+
s.add_runtime_dependency "rest-client"
|
28
|
+
end
|
data/lib/dogecoin/api.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
class Dogecoin::API
|
2
|
+
attr_reader :options
|
3
|
+
attr_reader :params
|
4
|
+
|
5
|
+
def user; options[:user]; end
|
6
|
+
def pass; options[:pass]; end
|
7
|
+
def host; options[:host]; end
|
8
|
+
def port; options[:port]; end
|
9
|
+
def ssl; options[:ssl]; end
|
10
|
+
def ssl?; options[:ssl]; end
|
11
|
+
def user=(a); options[:user] = a; end
|
12
|
+
def pass=(a); options[:pass] = a; end
|
13
|
+
def host=(a); options[:host] = a; end
|
14
|
+
def port=(a); options[:port] = a; end
|
15
|
+
def ssl=(a); options[:ssl] = a; end
|
16
|
+
|
17
|
+
def initialize(options = {})
|
18
|
+
@options = {
|
19
|
+
:host => 'localhost',
|
20
|
+
:port => 22555,
|
21
|
+
:ssl => false
|
22
|
+
}.merge(options)
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_hash
|
26
|
+
@options.dup
|
27
|
+
end
|
28
|
+
|
29
|
+
def request(service_name, *params)
|
30
|
+
req = Dogecoin::Request.new(service_name, params)
|
31
|
+
Dogecoin::RPC.new(to_hash).dispatch(req)
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,279 @@
|
|
1
|
+
class Dogecoin::Client
|
2
|
+
attr_reader :api
|
3
|
+
def user; api.user; end
|
4
|
+
def pass; api.pass; end
|
5
|
+
def host; api.host; end
|
6
|
+
def port; api.port; end
|
7
|
+
def ssl; api.ssl; end
|
8
|
+
def ssl?; api.ssl?; end
|
9
|
+
def user=(a); api.user = a; end
|
10
|
+
def pass=(a); api.pass = a; end
|
11
|
+
def host=(a); api.host = a; end
|
12
|
+
def port=(a); api.port = a; end
|
13
|
+
def ssl=(a); api.ssl = a; end
|
14
|
+
|
15
|
+
def options
|
16
|
+
api.options
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize(user, pass, options = {})
|
20
|
+
@api = Dogecoin::API.new({ :user => user, :pass => pass }.merge(options))
|
21
|
+
end
|
22
|
+
|
23
|
+
# Safely copies wallet.dat to destination, which can be a directory or a path with filename.
|
24
|
+
def backupwallet(destination)
|
25
|
+
@api.request 'backupwallet', destination
|
26
|
+
end
|
27
|
+
|
28
|
+
# Returns the account associated with the given address.
|
29
|
+
def getaccount(dogecoinaddress)
|
30
|
+
@api.request 'getaccount', dogecoinaddress
|
31
|
+
end
|
32
|
+
|
33
|
+
# Returns the current dogecoin address for receiving payments to this account.
|
34
|
+
def getaccountaddress(account)
|
35
|
+
@api.request 'getaccountaddress', account
|
36
|
+
end
|
37
|
+
|
38
|
+
# Returns the list of addresses for the given account.
|
39
|
+
def getaddressesbyaccount(account)
|
40
|
+
@api.request 'getaddressesbyaccount', account
|
41
|
+
end
|
42
|
+
|
43
|
+
# If +account+ is not specified, returns the server's total available balance.
|
44
|
+
# If +account+ is specified, returns the balance in the account.
|
45
|
+
def getbalance(account = nil, minconf = 1)
|
46
|
+
@api.request 'getbalance', account, minconf
|
47
|
+
end
|
48
|
+
|
49
|
+
# Dumps the block existing at specified height.
|
50
|
+
# Note: this is not available in the official release
|
51
|
+
def getblockbycount(height)
|
52
|
+
@api.request 'getblockbycount', height
|
53
|
+
end
|
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
|
+
|
62
|
+
# Returns the number of blocks in the longest block chain.
|
63
|
+
def getblockcount
|
64
|
+
@api.request 'getblockcount'
|
65
|
+
end
|
66
|
+
|
67
|
+
# Returns the block number of the latest block in the longest block chain.
|
68
|
+
def getblocknumber
|
69
|
+
@api.request 'getblocknumber'
|
70
|
+
end
|
71
|
+
|
72
|
+
# Returns the number of connections to other nodes.
|
73
|
+
def getconnectioncount
|
74
|
+
@api.request 'getconnectioncount'
|
75
|
+
end
|
76
|
+
|
77
|
+
# Returns the proof-of-work difficulty as a multiple of the minimum difficulty.
|
78
|
+
def getdifficulty
|
79
|
+
@api.request 'getdifficulty'
|
80
|
+
end
|
81
|
+
|
82
|
+
# Returns true or false whether dogecoind is currently generating hashes
|
83
|
+
def getgenerate
|
84
|
+
@api.request 'getgenerate'
|
85
|
+
end
|
86
|
+
|
87
|
+
# Returns a recent hashes per second performance measurement while generating.
|
88
|
+
def gethashespersec
|
89
|
+
@api.request 'gethashespersec'
|
90
|
+
end
|
91
|
+
|
92
|
+
# Returns the hash given a block id
|
93
|
+
def getblockhash(idx)
|
94
|
+
@api.request 'getblockhash', idx
|
95
|
+
end
|
96
|
+
|
97
|
+
# Returns the hash of the best (tip) block in the longest block chain.
|
98
|
+
def getbestblockhash
|
99
|
+
@api.request 'getbestblockhash'
|
100
|
+
end
|
101
|
+
|
102
|
+
# Returns an object containing various state info.
|
103
|
+
def getinfo
|
104
|
+
@api.request 'getinfo'
|
105
|
+
end
|
106
|
+
|
107
|
+
# Returns an object containing mining info.
|
108
|
+
def getmininginfo
|
109
|
+
@api.request 'getmininginfo'
|
110
|
+
end
|
111
|
+
|
112
|
+
# Returns a new dogecoin address for receiving payments. If +account+ is specified (recommended),
|
113
|
+
# it is added to the address book so payments received with the address will be credited to +account+.
|
114
|
+
def getnewaddress(account = nil)
|
115
|
+
@api.request 'getnewaddress', account
|
116
|
+
end
|
117
|
+
|
118
|
+
# Returns the total amount received by addresses with +account+ in transactions
|
119
|
+
# with at least +minconf+ confirmations.
|
120
|
+
def getreceivedbyaccount(account, minconf = 1)
|
121
|
+
@api.request 'getreceivedbyaccount', account, minconf
|
122
|
+
end
|
123
|
+
|
124
|
+
# Returns the total amount received by +dogecoinaddress+ in transactions with at least +minconf+ confirmations.
|
125
|
+
def getreceivedbyaddress(dogecoinaddress, minconf = 1)
|
126
|
+
@api.request 'getreceivedbyaddress', dogecoinaddress, minconf
|
127
|
+
end
|
128
|
+
|
129
|
+
# Get detailed information about +txid+
|
130
|
+
def gettransaction(txid)
|
131
|
+
@api.request 'gettransaction', txid
|
132
|
+
end
|
133
|
+
|
134
|
+
# If +data+ is not specified, returns formatted hash data to work on:
|
135
|
+
#
|
136
|
+
# :midstate => precomputed hash state after hashing the first half of the data
|
137
|
+
# :data => block data
|
138
|
+
# :hash1 => formatted hash buffer for second hash
|
139
|
+
# :target => little endian hash target
|
140
|
+
#
|
141
|
+
# If +data+ is specified, tries to solve the block and returns true if it was successful.
|
142
|
+
def getwork(data = nil)
|
143
|
+
@api.request 'getwork', data
|
144
|
+
end
|
145
|
+
|
146
|
+
# List commands, or get help for a command.
|
147
|
+
def help(command = nil)
|
148
|
+
@api.request 'help', command
|
149
|
+
end
|
150
|
+
|
151
|
+
# Returns Object that has account names as keys, account balances as values.
|
152
|
+
def listaccounts(minconf = 1)
|
153
|
+
@api.request 'listaccounts', minconf
|
154
|
+
end
|
155
|
+
|
156
|
+
# Returns an array of objects containing:
|
157
|
+
#
|
158
|
+
# :account => the account of the receiving addresses
|
159
|
+
# :amount => total amount received by addresses with this account
|
160
|
+
# :confirmations => number of confirmations of the most recent transaction included
|
161
|
+
#
|
162
|
+
def listreceivedbyaccount(minconf = 1, includeempty = false)
|
163
|
+
@api.request 'listreceivedbyaccount', minconf, includeempty
|
164
|
+
end
|
165
|
+
|
166
|
+
# Returns an array of objects containing:
|
167
|
+
#
|
168
|
+
# :address => receiving address
|
169
|
+
# :account => the account of the receiving address
|
170
|
+
# :amount => total amount received by the address
|
171
|
+
# :confirmations => number of confirmations of the most recent transaction included
|
172
|
+
#
|
173
|
+
# To get a list of accounts on the system, execute dogecoind listreceivedbyaddress 0 true
|
174
|
+
def listreceivedbyaddress(minconf = 1, includeempty = false)
|
175
|
+
@api.request 'listreceivedbyaddress', minconf, includeempty
|
176
|
+
end
|
177
|
+
|
178
|
+
# Returns up to +count+ most recent transactions for account +account+.
|
179
|
+
def listtransactions(account, count = 10)
|
180
|
+
@api.request 'listtransactions', account, count
|
181
|
+
end
|
182
|
+
|
183
|
+
# Move from one account in your wallet to another.
|
184
|
+
def move(fromaccount, toaccount, amount, minconf = 1, comment = nil)
|
185
|
+
@api.request 'move', fromaccount, toaccount, amount, minconf, comment
|
186
|
+
end
|
187
|
+
|
188
|
+
# +amount+ is a real and is rounded to 8 decimal places. Returns the transaction ID if successful.
|
189
|
+
def sendfrom(fromaccount, todogecoinaddress, amount, minconf = 1, comment = nil, comment_to = nil)
|
190
|
+
@api.request 'sendfrom', fromaccount, todogecoinaddress, amount, minconf, comment, comment_to
|
191
|
+
end
|
192
|
+
|
193
|
+
# +amount+ is a real and is rounded to 8 decimal places
|
194
|
+
def sendtoaddress(dogecoinaddress, amount, comment = nil, comment_to = nil)
|
195
|
+
@api.request 'sendtoaddress', dogecoinaddress, amount, comment, comment_to
|
196
|
+
end
|
197
|
+
|
198
|
+
def sendmany(fromaccount, addresses_amounts, minconf = 1, comment = nil)
|
199
|
+
@api.request 'sendmany', fromaccount, addresses_amounts, minconf, comment
|
200
|
+
end
|
201
|
+
|
202
|
+
# Sets the account associated with the given address.
|
203
|
+
def setaccount(dogecoinaddress, account)
|
204
|
+
@api.request 'setaccount', dogecoinaddress, account
|
205
|
+
end
|
206
|
+
|
207
|
+
# +generate+ is true or false to turn generation on or off.
|
208
|
+
# Generation is limited to +genproclimit+ processors, -1 is unlimited.
|
209
|
+
def setgenerate(generate, genproclimit = -1)
|
210
|
+
@api.request 'setgenerate', generate, genproclimit
|
211
|
+
end
|
212
|
+
|
213
|
+
# Stop dogecoin server.
|
214
|
+
def stop
|
215
|
+
@api.request 'stop'
|
216
|
+
end
|
217
|
+
|
218
|
+
# Return information about +dogecoinaddress+.
|
219
|
+
def validateaddress(dogecoinaddress)
|
220
|
+
@api.request 'validateaddress', dogecoinaddress
|
221
|
+
end
|
222
|
+
|
223
|
+
# Sign a message using +dogecoinaddress+.
|
224
|
+
def signmessage(dogecoinaddress, message)
|
225
|
+
@api.request 'signmessage', dogecoinaddress, message
|
226
|
+
end
|
227
|
+
|
228
|
+
# Verify signature made by +dogecoinaddress+.
|
229
|
+
def verifymessage(dogecoinaddress, signature, message)
|
230
|
+
@api.request 'verifymessage', dogecoinaddress, signature, message
|
231
|
+
end
|
232
|
+
|
233
|
+
# Stores the wallet decryption key in memory for +timeout+ seconds.
|
234
|
+
def walletpassphrase(passphrase, timeout)
|
235
|
+
@api.request 'walletpassphrase', passphrase, timeout
|
236
|
+
end
|
237
|
+
|
238
|
+
# Removes the wallet encryption key from memory, locking the wallet.
|
239
|
+
# After calling this method, you will need to call walletpassphrase again
|
240
|
+
# before being able to call any methods which require the wallet to be
|
241
|
+
# unlocked.
|
242
|
+
def walletlock
|
243
|
+
@api.request 'walletlock'
|
244
|
+
end
|
245
|
+
|
246
|
+
alias account getaccount
|
247
|
+
alias account_address getaccountaddress
|
248
|
+
alias addresses_by_account getaddressesbyaccount
|
249
|
+
alias balance getbalance
|
250
|
+
alias block_by_count getblockbycount
|
251
|
+
alias block_count getblockcount
|
252
|
+
alias block_number getblocknumber
|
253
|
+
alias connection_count getconnectioncount
|
254
|
+
alias difficulty getdifficulty
|
255
|
+
alias generate? getgenerate
|
256
|
+
alias hashes_per_sec gethashespersec
|
257
|
+
alias info getinfo
|
258
|
+
alias new_address getnewaddress
|
259
|
+
alias received_by_account getreceivedbyaccount
|
260
|
+
alias received_by_address getreceivedbyaddress
|
261
|
+
alias transaction gettransaction
|
262
|
+
alias work getwork
|
263
|
+
alias get_work getwork
|
264
|
+
alias accounts listaccounts
|
265
|
+
alias list_received_by_account listreceivedbyaccount
|
266
|
+
alias list_received_by_address listreceivedbyaddress
|
267
|
+
alias transactions listtransactions
|
268
|
+
alias list_transactions listtransactions
|
269
|
+
alias send_from sendfrom
|
270
|
+
alias send_to_address sendtoaddress
|
271
|
+
alias send_many sendmany
|
272
|
+
alias account= setaccount
|
273
|
+
alias set_account setaccount
|
274
|
+
alias generate= setgenerate
|
275
|
+
alias set_generate setgenerate
|
276
|
+
alias validate_address validateaddress
|
277
|
+
alias sign_message signmessage
|
278
|
+
alias verify_message verifymessage
|
279
|
+
end
|