dogecoin_client 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dogecoin_client.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Ryan Epp
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,418 @@
1
+ # DogecoinClient
2
+
3
+ DogecoinClient is a gem that makes it easy to work with dogecoin in ruby.
4
+
5
+ ## Dependencies
6
+
7
+ The only requirement is a running dogecoin daemon ([dogecoind](https://github.com/dogecoin/dogecoin)). Make sure to check out the [doc section](https://github.com/dogecoin/dogecoin/tree/master-1.5/doc) and follow the instructions for your os.
8
+ NOTICE: by default dogecoind will only allow local connections.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ gem 'dogecoin_client'
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install dogecoin_client
19
+
20
+ ## Configuration
21
+
22
+ If you're using rails you can create an initializer. Here are the default settings:
23
+
24
+ ```ruby
25
+ # config/initializers/dogecoin_client.rb
26
+ DogecoinClient.configure do |config|
27
+ config.host = 'localhost'
28
+ config.port = 22555
29
+ config.protocol = :http
30
+ config.user = ''
31
+ config.password = ''
32
+ end
33
+ ```
34
+
35
+ You can also pass config variables as an options hash when creating a new client:
36
+
37
+ ```ruby
38
+ client = DogecoinClient.new(user: 'my_dogecoind_username', password: 'my_super_secure_password')
39
+ ```
40
+
41
+ ## Example Usage
42
+
43
+ ```ruby
44
+ # create a new instance of the client
45
+ client = DogecoinClient.new
46
+
47
+ # check that dogecoind is running and that our credentials are correct
48
+ if client.valid?
49
+ # get a new wallet address
50
+ new_wallet_addr = client.get_new_address
51
+
52
+ # get the balance of our new wallet
53
+ my_balance = client.get_balance(new_wallet_addr)
54
+ puts "I have #{my_balance} doge!"
55
+ else
56
+ puts 'Something is wrong...'
57
+ end
58
+ ```
59
+
60
+ ## Available Methods
61
+
62
+ <table>
63
+ <tr>
64
+ <th> Method </th>
65
+ <th> Params </th>
66
+ <th> Description </th>
67
+ <th>unlckd wallet req?
68
+ </th></tr>
69
+ <tr>
70
+ <td> add_multi_sig_address </td>
71
+ <td> [nrequired] ["key","key"] [account] </td>
72
+ <td> <b>Currently only available on testnet</b> Add a nrequired-to-sign multisignature address to the wallet. Each key is a dogecoin address or hex-encoded public key. If [account] is specified, assign address to [account]. </td>
73
+ <td> No
74
+ </td></tr>
75
+ <tr>
76
+ <td> backup_wallet </td>
77
+ <td> [destination] </td>
78
+ <td> Safely copies wallet.dat to destination, which can be a directory or a path with filename. </td>
79
+ <td> No
80
+ </td></tr>
81
+ <tr>
82
+ <td> dump_priv_key </td>
83
+ <td> [dogecoinaddress] </td>
84
+ <td> Reveals the private key corresponding to <dogecoinaddress< </td>
85
+ <td> Yes
86
+ </td></tr>
87
+ <tr>
88
+ <td> encrypt_wallet </td>
89
+ <td> [passphrase] </td>
90
+ <td> Encrypts the wallet with <passphrase<. </td>
91
+ <td> No
92
+ </td></tr>
93
+ <tr>
94
+ <td> get_account </td>
95
+ <td> [dogecoinaddress] </td>
96
+ <td> Returns the account associated with the given address. </td>
97
+ <td> No
98
+ </td></tr>
99
+ <tr>
100
+ <td> get_account_address </td>
101
+ <td> [account] </td>
102
+ <td> Returns the current dogecoin address for receiving payments to this account. </td>
103
+ <td> No
104
+ </td></tr>
105
+ <tr>
106
+ <td> get_addresses_by_account </td>
107
+ <td> [account] </td>
108
+ <td> Returns the list of addresses for the given account. </td>
109
+ <td> No
110
+ </td></tr>
111
+ <tr>
112
+ <td> get_balance </td>
113
+ <td> [account] [minconf=1] </td>
114
+ <td> If [account] is not specified, returns the server's total available balance.<br />If [account] is specified, returns the balance in the account. </td>
115
+ <td> No
116
+ </td></tr>
117
+ <tr>
118
+ <td> get_block </td>
119
+ <td> [hash] </td>
120
+ <td> Returns information about the given block hash. </td>
121
+ <td> No
122
+ </td></tr>
123
+ <tr>
124
+ <td> get_block_count </td>
125
+ <td> </td>
126
+ <td> Returns the number of blocks in the longest block chain. </td>
127
+ <td> No
128
+ </td></tr>
129
+ <tr>
130
+ <td> get_block_hash </td>
131
+ <td> [index] </td>
132
+ <td> Returns hash of block in best-block-chain at <index< </td>
133
+ <td> No
134
+ </td></tr>
135
+ <tr>
136
+ <td> get_block_number </td>
137
+ <td> </td>
138
+ <td> <b>Deprecated</b>. Use getblockcount. </td>
139
+ <td> No
140
+ </td></tr>
141
+ <tr>
142
+ <td> get_connection_count </td>
143
+ <td> </td>
144
+ <td> Returns the number of connections to other nodes. </td>
145
+ <td> No
146
+ </td></tr>
147
+ <tr>
148
+ <td> get_difficulty </td>
149
+ <td> </td>
150
+ <td> Returns the proof-of-work difficulty as a multiple of the minimum difficulty. </td>
151
+ <td> No
152
+ </td></tr>
153
+ <tr>
154
+ <td> get_generate </td>
155
+ <td> </td>
156
+ <td> Returns true or false whether dogecoind is currently generating hashes </td>
157
+ <td> No
158
+ </td></tr>
159
+ <tr>
160
+ <td> get_hashes_per_sec </td>
161
+ <td> </td>
162
+ <td> Returns a recent hashes per second performance measurement while generating. </td>
163
+ <td> No
164
+ </td></tr>
165
+ <tr>
166
+ <td> get_info </td>
167
+ <td> </td>
168
+ <td> Returns an object containing various state info. </td>
169
+ <td> No
170
+ </td></tr>
171
+ <tr>
172
+ <td> get_memory_pool </td>
173
+ <td> [data] </td>
174
+ <td> If [data] is not specified, returns data needed to construct a block to work on:
175
+ <ul><li> "version": block version
176
+ </li><li> "previousblockhash": hash of current highest block
177
+ </li><li> "transactions": contents of non-coinbase transactions that should be included in the next block
178
+ </li><li> "coinbasevalue": maximum allowable input to coinbase transaction, including the generation award and transaction fees
179
+ </li><li> "time": timestamp appropriate for next block
180
+ </li><li> "bits": compressed target of next block
181
+ </li></ul>
182
+ <p>If [data] is specified, tries to solve the block and returns true if it was successful.
183
+ </p>
184
+ </td>
185
+ <td> No
186
+ </td></tr>
187
+ <tr>
188
+ <td> get_mining_info </td>
189
+ <td> </td>
190
+ <td> Returns an object containing mining-related information:
191
+ <ul><li> blocks
192
+ </li><li> currentblocksize
193
+ </li><li> currentblocktx
194
+ </li><li> difficulty
195
+ </li><li> errors
196
+ </li><li> generate
197
+ </li><li> genproclimit
198
+ </li><li> hashespersec
199
+ </li><li> pooledtx
200
+ </li><li> testnet
201
+ </li></ul>
202
+ </td>
203
+ <td> No
204
+ </td></tr>
205
+ <tr>
206
+ <td> get_new_address </td>
207
+ <td> [account] </td>
208
+ <td> Returns a new dogecoin address for receiving payments. If [account] is specified (recommended), it is added to the address book so payments received with the address will be credited to [account]. </td>
209
+ <td> No
210
+ </td></tr>
211
+ <tr>
212
+ <td> get_received_by_account </td>
213
+ <td> [account] [minconf=1] </td>
214
+ <td> Returns the total amount received by addresses with [account] in transactions with at least [minconf] confirmations. If [account] not provided return will include all transactions to all accounts. (version 0.3.24-beta) </td>
215
+ <td> No
216
+ </td></tr>
217
+ <tr>
218
+ <td> get_received_by_address </td>
219
+ <td> [dogecoinaddress] [minconf=1] </td>
220
+ <td> Returns the total amount received by <dogecoinaddress< in transactions with at least [minconf] confirmations. While some might consider this obvious, value reported by this only considers *receiving* transactions. It does not check payments that have been made *from* this address. In other words, this is not "getaddressbalance". Works only for addresses in the local wallet, external addresses will always show 0. </td>
221
+ <td> No
222
+ </td></tr>
223
+ <tr>
224
+ <td> get_transaction </td>
225
+ <td> [txid] </td>
226
+ <td> Returns an object about the given transaction containing:
227
+ <ul><li> "amount": total amount of the transaction
228
+ </li><li> "confirmations": number of confirmations of the transaction
229
+ </li><li> "txid": the transaction ID
230
+ </li><li> "time": time the transaction occurred
231
+ </li><li> "details" - An array of objects containing:
232
+ <ul><li> "account"
233
+ </li><li> "address"
234
+ </li><li> "category"
235
+ </li><li> "amount"
236
+ </li></ul>
237
+ </li></ul>
238
+ </td>
239
+ <td> No
240
+ </td></tr>
241
+ <tr>
242
+ <td> get_work </td>
243
+ <td> [data] </td>
244
+ <td> If [data] is not specified, returns formatted hash data to work on:
245
+ <ul><li> "midstate": precomputed hash state after hashing the first half of the data
246
+ </li><li> "data": block data
247
+ </li><li> "hash1": formatted hash buffer for second hash
248
+ </li><li> "target": little endian hash target
249
+ </li></ul>
250
+ <p>If [data] is specified, tries to solve the block and returns true if it was successful.
251
+ </p>
252
+ </td>
253
+ <td> No
254
+ </td></tr>
255
+ <tr>
256
+ <td> help </td>
257
+ <td> [command] </td>
258
+ <td> List commands, or get help for a command. </td>
259
+ <td> No
260
+ </td></tr>
261
+ <tr>
262
+ <td> import_priv_key </td>
263
+ <td> [dogecoinprivkey] [label] </td>
264
+ <td> Adds a private key (as returned by dumpprivkey) to your wallet. </td>
265
+ <td> Yes
266
+ </td></tr>
267
+ <tr>
268
+ <td> key_pool_refill </td>
269
+ <td> </td>
270
+ <td> Fills the keypool, requires wallet passphrase to be set. </td>
271
+ <td> Yes
272
+ </td></tr>
273
+ <tr>
274
+ <td> list_accounts </td>
275
+ <td> [minconf=1] </td>
276
+ <td> Returns Object that has account names as keys, account balances as values. </td>
277
+ <td> No
278
+ </td></tr>
279
+ <tr>
280
+ <td> list_received_by_account </td>
281
+ <td> [minconf=1] [includeempty=false] </td>
282
+ <td> Returns an array of objects containing:
283
+ <ul><li> "account": the account of the receiving addresses
284
+ </li><li> "amount": total amount received by addresses with this account
285
+ </li><li> "confirmations": number of confirmations of the most recent transaction included
286
+ </li></ul>
287
+ </td>
288
+ <td> No
289
+ </td></tr>
290
+ <tr>
291
+ <td> list_received_by_address </td>
292
+ <td> [minconf=1] [includeempty=false] </td>
293
+ <td> Returns an array of objects containing:
294
+ <ul><li> "address": receiving address
295
+ </li><li> "account": the account of the receiving address
296
+ </li><li> "amount": total amount received by the address
297
+ </li><li> "confirmations": number of confirmations of the most recent transaction included
298
+ </li></ul>
299
+ <p>To get a list of accounts on the system, execute dogecoind listreceivedbyaddress 0 true
300
+ </p>
301
+ </td>
302
+ <td> No
303
+ </td></tr>
304
+ <tr>
305
+ <td> list_since_block</td>
306
+ <td> [blockhash] [target-confirmations] </td>
307
+ <td> Get all transactions in blocks since block [blockhash], or all transactions if omitted. </td>
308
+ <td> No
309
+ </td></tr>
310
+ <tr>
311
+ <td> list_transactions </td>
312
+ <td> [account] [count=10] [from=0] </td>
313
+ <td> Returns up to [count] most recent transactions skipping the first [from] transactions for account [account]. If [account] not provided will return recent transaction from all accounts.
314
+ </td>
315
+ <td> No
316
+ </td></tr>
317
+ <tr>
318
+ <td> move </td>
319
+ <td> [fromaccount] [toaccount] [amount] [minconf=1] [comment] </td>
320
+ <td> Move from one account in your wallet to another </td>
321
+ <td> No
322
+ </td></tr>
323
+ <tr>
324
+ <td> send_from </td>
325
+ <td> [fromaccount] [todogecoinaddress] [amount] [minconf=1] [comment] [comment-to] </td>
326
+ <td> <amount< is a real and is rounded to 8 decimal places. Will send the given amount to the given address, ensuring the account has a valid balance using [minconf] confirmations. Returns the transaction ID if successful (not in JSON object). </td>
327
+ <td> Yes
328
+ </td></tr>
329
+ <tr>
330
+ <td> send_many </td>
331
+ <td> [fromaccount] [address:amount,...] [minconf=1] [comment] </td>
332
+ <td> amounts are double-precision floating point numbers </td>
333
+ <td> Yes
334
+ </td></tr>
335
+ <tr>
336
+ <td> send_to_address </td>
337
+ <td> [dogecoinaddress] [amount] [comment] [comment-to] </td>
338
+ <td> <amount< is a real and is rounded to 8 decimal places. Returns the transaction ID <txid< if successful. </td>
339
+ <td> Yes
340
+ </td></tr>
341
+ <tr>
342
+ <td> set_account </td>
343
+ <td> [dogecoinaddress] [account] </td>
344
+ <td> Sets the account associated with the given address. Assigning address that is already assigned to the same account will create a new address associated with that account. </td>
345
+ <td> No
346
+ </td></tr>
347
+ <tr>
348
+ <td> set_generate </td>
349
+ <td> [generate] [genproclimit] </td>
350
+ <td> [generate] is true or false to turn generation on or off.
351
+
352
+ Generation is limited to [genproclimit] processors, -1 is unlimited. </td>
353
+ <td> No
354
+ </td></tr>
355
+ <tr>
356
+ <td> sign_message </td>
357
+ <td> [dogecoinaddress] [message] </td>
358
+ <td> Sign a message with the private key of an address. </td>
359
+ <td> Yes
360
+ </td></tr>
361
+ <tr>
362
+ <td> set_tx_fee </td>
363
+ <td> [amount] </td>
364
+ <td> [amount] is a real and is rounded to the nearest 0.00000001 </td>
365
+ <td> No
366
+ </td></tr>
367
+ <tr>
368
+ <td> stop </td>
369
+ <td> </td>
370
+ <td> Stop dogecoin server. </td>
371
+ <td> No
372
+ </td></tr>
373
+ <tr>
374
+ <td> validate_address </td>
375
+ <td> [dogecoinaddress] </td>
376
+ <td> Return information about [dogecoinaddress]. </td>
377
+ <td> No
378
+ </td></tr>
379
+ <tr>
380
+ <td> verify_message </td>
381
+ <td> [dogecoinaddress] [signature] [message] </td>
382
+ <td> Verify a signed message. </td>
383
+ <td> No
384
+ </td></tr>
385
+ <tr>
386
+ <td> wallet_lock </td>
387
+ <td> </td>
388
+ <td> Removes the wallet encryption key from memory, locking the wallet. After calling this method, you will need to call walletpassphrase again before being able to call any methods which require the wallet to be unlocked. </td>
389
+ <td> No
390
+ </td></tr>
391
+ <tr>
392
+ <td> wallet_passphrase </td>
393
+ <td> [passphrase] [timeout] </td>
394
+ <td> Stores the wallet decryption key in memory for <timeout< seconds. </td>
395
+ <td> No
396
+ </td></tr>
397
+ <tr>
398
+ <td> wallet_passphrase_change </td>
399
+ <td> [oldpassphrase] [newpassphrase] </td>
400
+ <td> Changes the wallet passphrase from <oldpassphrase< to <newpassphrase<. </td>
401
+ <td> No
402
+ </td></tr></table>
403
+
404
+ *Table stolen from [node-dogecoin](https://github.com/countable/node-dogecoin)
405
+
406
+ ## Contributing
407
+
408
+ For local testing, make sure to replace the user/password in `spec/client_spec.rb` and `spec/dogecoin_client_spec.rb` with the credentials for your local dogecoind.
409
+
410
+ 1. Fork it
411
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
412
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
413
+ 4. Push to the branch (`git push origin my-new-feature`)
414
+ 5. Create new Pull Request
415
+
416
+ ## Can't I just use a client for bitcoin or litecoin?
417
+
418
+ Perhaps, but this way you don't need to worry about any current or future api inconsistencies. Plus, why use a tool built for an inferior alt coin?
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dogecoin_client/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dogecoin_client"
8
+ spec.version = DogecoinClient::VERSION
9
+ spec.authors = ["Ryan Epp"]
10
+ spec.email = ["hey@ryanepp.com"]
11
+ spec.description = %q{A Dogecoin client for ruby. This gem is a ruby wrapper for making remote procedure calls (rpc) to a dogecoin daemon (dogecoind.)}
12
+ spec.summary = %q{DogecoinClient is a gem that makes it easy to work with dogecoin in ruby.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec", "~> 2.6"
24
+ end
@@ -0,0 +1,36 @@
1
+ require 'dogecoin_client/version'
2
+ require 'dogecoin_client/client'
3
+
4
+ class DogecoinClient
5
+
6
+ def initialize(options = {})
7
+ @client = DogecoinClient::Client.new(options)
8
+ end
9
+
10
+ # Delegate everything to the 'real' Client
11
+ def method_missing(name, *args)
12
+ @client.send(name, *args)
13
+ end
14
+
15
+ def self.configuration
16
+ @configuration ||= Configuration.new
17
+ end
18
+
19
+ def self.configure
20
+ yield(configuration) if block_given?
21
+ end
22
+
23
+ class Configuration
24
+ attr_accessor :host, :port, :protocol, :user, :password
25
+
26
+ def initialize
27
+ self.host = 'localhost'
28
+ self.port = 22555
29
+ self.protocol = :http
30
+ self.user = ''
31
+ self.password = ''
32
+ end
33
+
34
+ end
35
+
36
+ end
@@ -0,0 +1,72 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+ require 'json'
4
+ require 'dogecoin_client'
5
+ require 'dogecoin_client/methods'
6
+ require 'errors/http_error'
7
+ require 'errors/rpc_error'
8
+ require 'errors/invalid_method_error'
9
+
10
+
11
+ class DogecoinClient
12
+ class Client
13
+
14
+ attr_accessor :options
15
+
16
+ def initialize(options = {})
17
+ @options = get_defaults.merge(options)
18
+ end
19
+
20
+ def valid?
21
+ post_body = { method: 'getinfo', id: Time.now.to_i }.to_json
22
+ http_post_request(post_body).class == Net::HTTPOK rescue false
23
+ end
24
+
25
+ def method_missing(name, *args)
26
+ raise DogecoinClient::InvalidMethodError.new(name) unless DogecoinClient::METHODS.include?(name.to_s)
27
+
28
+ response = http_post_request( get_post_body(name, args) )
29
+ get_response_data(response)
30
+ end
31
+
32
+ def http_post_request(post_body)
33
+ req = Net::HTTP::Post.new(get_service_uri)
34
+ req.basic_auth @options[:user], @options[:password]
35
+ req.content_type = 'application/json'
36
+ req.body = post_body
37
+
38
+ response = Net::HTTP.start(@options[:host], @options[:port]) {|http| http.request(req) }
39
+
40
+ return response if response.class == Net::HTTPOK or response.class == Net::HTTPInternalServerError
41
+ raise DogecoinClient::HTTPError.new(response)
42
+ end
43
+
44
+ private
45
+
46
+ def get_service_uri
47
+ URI("#{@options[:protocol]}://#{@options[:host]}:#{@options[:port]}").request_uri
48
+ end
49
+
50
+ def get_post_body(name, args)
51
+ { method: de_ruby_style(name), params: args, id: Time.now.to_i }.to_json
52
+ end
53
+
54
+ def get_response_data(http_ok_response)
55
+ resp = JSON.parse( http_ok_response.body )
56
+ raise DogecoinClient::RPCError.new(resp['error']['message']) if resp['error'] and http_ok_response.class == Net::HTTPInternalServerError
57
+ resp['result']
58
+ end
59
+
60
+ def de_ruby_style(method_name)
61
+ method_name.to_s.tr('_', '').downcase.to_sym
62
+ end
63
+
64
+ def get_defaults
65
+ DogecoinClient.configuration.instance_variables.each.inject({}) {|hash, var|
66
+ hash[var.to_s.delete('@').to_sym] = DogecoinClient.configuration.instance_variable_get(var);
67
+ hash
68
+ }
69
+ end
70
+
71
+ end
72
+ end
@@ -0,0 +1,55 @@
1
+ class DogecoinClient
2
+ METHODS = %w(
3
+ add_multi_sig_address
4
+ backup_wallet
5
+ create_raw_transaction
6
+ decode_raw_transaction
7
+ dump_priv_key
8
+ encrypt_wallet
9
+ get_account
10
+ get_account_address
11
+ get_addresses_by_account
12
+ get_balance
13
+ get_block
14
+ get_block_count
15
+ get_block_hash
16
+ get_connection_count
17
+ get_difficulty
18
+ get_generate
19
+ get_hashes_per_sec
20
+ get_info
21
+ get_memory_pool
22
+ get_mining_info
23
+ get_new_address
24
+ get_raw_transaction
25
+ get_received_by_account
26
+ get_received_by_address
27
+ get_transaction
28
+ get_work
29
+ help
30
+ import_priv_key
31
+ key_pool_refill
32
+ list_accounts
33
+ list_received_by_account
34
+ list_received_by_address
35
+ list_since_block
36
+ list_transactions
37
+ list_unspent
38
+ move
39
+ send_from
40
+ send_many
41
+ send_raw_transaction
42
+ send_to_address
43
+ set_account
44
+ set_generate
45
+ set_tx_fee
46
+ sign_message
47
+ sign_raw_transaction
48
+ stop
49
+ validate_address
50
+ verify_message
51
+ wallet_lock
52
+ wallet_passphrase
53
+ wallet_passphrase_change
54
+ )
55
+ end
@@ -0,0 +1,3 @@
1
+ class DogecoinClient
2
+ VERSION = "0.5.0"
3
+ end
@@ -0,0 +1,12 @@
1
+ class DogecoinClient
2
+ class HTTPError < StandardError
3
+
4
+ attr_accessor :object, :message
5
+
6
+ def initialize(object)
7
+ @object = object
8
+ @message = "Expected NET::HTTPOK but got: #{object.class}"
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ class DogecoinClient
2
+ class InvalidMethodError < StandardError
3
+
4
+ attr_accessor :message
5
+
6
+ def initialize(method_name)
7
+ @message = "#{method_name} is not a valid method."
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ class DogecoinClient
2
+ class RPCError < StandardError
3
+
4
+ attr_accessor :message
5
+
6
+ def initialize(message)
7
+ @message = message
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,52 @@
1
+ require 'net/http'
2
+ require 'dogecoin_client/client'
3
+ require 'errors/http_error'
4
+ require 'errors/rpc_error'
5
+ require 'errors/invalid_method_error'
6
+
7
+ describe DogecoinClient::Client do
8
+
9
+ def valid_client
10
+ # For local testing ensure you have dogecoind running correctly and use your own username / password here
11
+ DogecoinClient::Client.new(user: 'dogecoinrpc', password: '5d36c07c20a43a281f54c07d72ce78cc')
12
+ end
13
+
14
+ it 'rejects bad credentials' do
15
+ bad_client = DogecoinClient::Client.new(user: 'bad_username', password: 'bad_password')
16
+ bad_client.valid?.should eql(false)
17
+ end
18
+
19
+ it 'connects to the rpc server' do
20
+ valid_client.valid?.should eql(true)
21
+ end
22
+
23
+ it 'catches requests with bad credentials' do
24
+ bad_client = DogecoinClient::Client.new(user: 'bad_username', password: 'bad_password')
25
+ expect { bad_client.get_info }.to raise_error(DogecoinClient::HTTPError)
26
+ end
27
+
28
+ it 'catches requests with bad service urls' do
29
+ bad_client = valid_client
30
+ bad_client.options[:host] = 'not_localhost'
31
+ expect { bad_client.get_info }.to raise_error
32
+
33
+ bad_client2 = valid_client
34
+ bad_client2.options[:port] = 100
35
+ expect { bad_client2.get_info }.to raise_error
36
+ end
37
+
38
+ it 'works with ruby-style method names' do
39
+ c = valid_client
40
+ c.get_info
41
+ c.get_block_count
42
+ end
43
+
44
+ it 'throws rpc_error when the params are bad' do
45
+ expect { valid_client.get_account('bad_location') }.to raise_error(DogecoinClient::RPCError)
46
+ end
47
+
48
+ it 'only allows listed methods' do
49
+ expect { valid_client.not_a_real_method }.to raise_error(DogecoinClient::InvalidMethodError)
50
+ end
51
+
52
+ end
@@ -0,0 +1,38 @@
1
+ require 'dogecoin_client/client'
2
+
3
+ describe DogecoinClient do
4
+
5
+ def valid_client
6
+ # make sure to replace these with the credentials from your own dogecoind
7
+ DogecoinClient.new(user: 'dogecoinrpc', password: '5d36c07c20a43a281f54c07d72ce78cc')
8
+ end
9
+
10
+ it 'sets up and works with a valid client' do
11
+ bad_client = DogecoinClient.new
12
+ bad_client.valid?.should eql(false)
13
+
14
+ valid_client.valid?.should eql(true)
15
+ end
16
+
17
+ it 'calls client methods correctly' do
18
+ addr = valid_client.get_new_address
19
+ addr[0].should eql('D')
20
+ end
21
+
22
+ it 'configures itself properly' do
23
+ DogecoinClient.configure do |config|
24
+ config.user = 'dogecoinrpc'
25
+ config.password = '5d36c07c20a43a281f54c07d72ce78cc'
26
+ end
27
+ client = DogecoinClient.new
28
+ client.valid?.should eql(true)
29
+ end
30
+
31
+ it 'using results as args' do
32
+ client = valid_client
33
+ new_wallet_addr = client.get_new_address
34
+ my_balance = client.get_balance(new_wallet_addr)
35
+ my_balance.should eql(0.0)
36
+ end
37
+
38
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dogecoin_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ryan Epp
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-02-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '2.6'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '2.6'
62
+ description: A Dogecoin client for ruby. This gem is a ruby wrapper for making remote
63
+ procedure calls (rpc) to a dogecoin daemon (dogecoind.)
64
+ email:
65
+ - hey@ryanepp.com
66
+ executables: []
67
+ extensions: []
68
+ extra_rdoc_files: []
69
+ files:
70
+ - .gitignore
71
+ - Gemfile
72
+ - LICENSE.txt
73
+ - README.md
74
+ - Rakefile
75
+ - dogecoin_client.gemspec
76
+ - lib/dogecoin_client.rb
77
+ - lib/dogecoin_client/client.rb
78
+ - lib/dogecoin_client/methods.rb
79
+ - lib/dogecoin_client/version.rb
80
+ - lib/errors/http_error.rb
81
+ - lib/errors/invalid_method_error.rb
82
+ - lib/errors/rpc_error.rb
83
+ - spec/client_spec.rb
84
+ - spec/dogecoin_client_spec.rb
85
+ homepage: ''
86
+ licenses:
87
+ - MIT
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ! '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 1.8.25
107
+ signing_key:
108
+ specification_version: 3
109
+ summary: DogecoinClient is a gem that makes it easy to work with dogecoin in ruby.
110
+ test_files:
111
+ - spec/client_spec.rb
112
+ - spec/dogecoin_client_spec.rb