Class: DogeCoin::Client
- Inherits:
-
Object
- Object
- DogeCoin::Client
- Includes:
- Faraday
- Defined in:
- lib/doge_coin/client.rb
Constant Summary collapse
- VALID_FLOAT_REGEXP =
/\A(\d)+(\.\d+)?\z/
Instance Method Summary collapse
-
#address_balance(address) ⇒ Object
Returns the address balance (received - sent) Raise error if address is invalid.
-
#address_to_hash(address) ⇒ Object
Shows the 160-bit hash encoded in ADDRESS.
-
#decode_address(address) ⇒ Object
Shows ADDRESS’s version byte(s) and public key hash as hex strings separated by colon (“:”).
-
#get_block_count ⇒ Object
Returns the current block count.
-
#get_difficulty ⇒ Object
Returns the current difficulty.
-
#get_total_mined ⇒ Object
Returns the total of mined doges.
-
#hash_to_address(address) ⇒ Object
Converts a 160-bit hash and address version to an address.
-
#nethash(interval = 500, start = 0, stop = false) ⇒ Object
shows statistics about difficulty and network power.
-
#total_received(address) ⇒ Object
Returns the total sent Raise error if address is invalid.
-
#total_sent(address) ⇒ Object
Returns the total sent Raise error if address is invalid.
-
#transactions ⇒ Object
Returns the amount transactions of the last blocks as an Array object.
-
#valid_address?(address) ⇒ Boolean
Returns true if the adress is valid, and false otherwise.
Instance Method Details
#address_balance(address) ⇒ Object
Returns the address balance (received - sent) Raise error if address is invalid
30 31 32 33 34 35 36 |
# File 'lib/doge_coin/client.rb', line 30 def address_balance address balance = call_blockchain_api("addressbalance/#{address}") raise DogeCoin::InvalidAddress unless is_a_float?(balance) balance.to_f end |
#address_to_hash(address) ⇒ Object
Shows the 160-bit hash encoded in ADDRESS. For BBE compatibility, the address is not checked for validity.
71 72 73 |
# File 'lib/doge_coin/client.rb', line 71 def address_to_hash address call_blockchain_api("addresstohash/#{address}") end |
#decode_address(address) ⇒ Object
Shows ADDRESS’s version byte(s) and public key hash as hex strings separated by colon (“:”).
88 89 90 |
# File 'lib/doge_coin/client.rb', line 88 def decode_address address call_blockchain_api("decode_address/#{address}") end |
#get_block_count ⇒ Object
Returns the current block count
11 12 13 |
# File 'lib/doge_coin/client.rb', line 11 def get_block_count call_blockchain_api('getblockcount').to_i end |
#get_difficulty ⇒ Object
Returns the current difficulty
15 16 17 |
# File 'lib/doge_coin/client.rb', line 15 def get_difficulty call_blockchain_api('getdifficulty').to_f end |
#get_total_mined ⇒ Object
Returns the total of mined doges
19 20 21 |
# File 'lib/doge_coin/client.rb', line 19 def get_total_mined call_blockchain_api('totalbc').to_f end |
#hash_to_address(address) ⇒ Object
Converts a 160-bit hash and address version to an address.
76 77 78 |
# File 'lib/doge_coin/client.rb', line 76 def hash_to_address address call_blockchain_api("hashtoaddress/#{address}") end |
#nethash(interval = 500, start = 0, stop = false) ⇒ Object
shows statistics about difficulty and network power
/nethash/INTERVAL/START/STOP Default INTERVAL=500, START=0, STOP=infinity.
44 45 46 47 |
# File 'lib/doge_coin/client.rb', line 44 def nethash interval = 500, start = 0, stop = false suffixe = stop ? "/#{stop}" : '' JSON.parse(call_blockchain_api("nethash/#{interval}/#{start}#{suffixe}?format=json")) end |
#total_received(address) ⇒ Object
Returns the total sent Raise error if address is invalid
51 52 53 54 55 56 57 |
# File 'lib/doge_coin/client.rb', line 51 def total_received address balance = call_blockchain_api("getreceivedbyaddress/#{address}") raise DogeCoin::InvalidAddress unless is_a_float?(balance) balance.to_f end |
#total_sent(address) ⇒ Object
Returns the total sent Raise error if address is invalid
61 62 63 64 65 66 67 |
# File 'lib/doge_coin/client.rb', line 61 def total_sent address balance = call_blockchain_api("getsentbyaddress/#{address}") raise DogeCoin::InvalidAddress unless is_a_float?(balance) balance.to_f end |
#transactions ⇒ Object
Returns the amount transactions of the last blocks as an Array object
24 25 26 |
# File 'lib/doge_coin/client.rb', line 24 def transactions JSON.parse(call_blockchain_api("transactions")) end |
#valid_address?(address) ⇒ Boolean
Returns true if the adress is valid, and false otherwise
81 82 83 84 85 |
# File 'lib/doge_coin/client.rb', line 81 def valid_address? address code = call_blockchain_api("checkaddress/#{address}") !['X5', 'SZ', 'CK'].include?(code) end |