Class: DogeCoin::Client

Inherits:
Object
  • Object
show all
Includes:
Faraday
Defined in:
lib/doge_coin/client.rb

Constant Summary collapse

VALID_FLOAT_REGEXP =
/\A(\d)+(\.\d+)?\z/

Instance Method Summary collapse

Instance Method Details

#address_balance(address) ⇒ Object

Returns the address balance (received - sent) Raise error if address is invalid



29
30
31
32
33
34
35
# File 'lib/doge_coin/client.rb', line 29

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.



59
60
61
# File 'lib/doge_coin/client.rb', line 59

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 (“:”).



76
77
78
# File 'lib/doge_coin/client.rb', line 76

def decode_address address
  call_blockchain_api("decode_address/#{address}")
end

#get_block_countObject

Returns the current block count



10
11
12
# File 'lib/doge_coin/client.rb', line 10

def get_block_count
  call_blockchain_api('getblockcount').to_i
end

#get_difficultyObject

Returns the current difficulty



14
15
16
# File 'lib/doge_coin/client.rb', line 14

def get_difficulty
  call_blockchain_api('getdifficulty').to_f
end

#get_total_minedObject

Returns the total of mined doges



18
19
20
# File 'lib/doge_coin/client.rb', line 18

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.



64
65
66
# File 'lib/doge_coin/client.rb', line 64

def hash_to_address address
  call_blockchain_api("hashtoaddress/#{address}")
end

#total_received(address) ⇒ Object

Returns the total sent Raise error if address is invalid



39
40
41
42
43
44
45
# File 'lib/doge_coin/client.rb', line 39

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



49
50
51
52
53
54
55
# File 'lib/doge_coin/client.rb', line 49

def total_sent address
  balance = call_blockchain_api("getsentbyaddress/#{address}")

  raise DogeCoin::InvalidAddress unless is_a_float?(balance)

  balance.to_f
end

#transactionsObject

Returns the amount transactions of the last blocks as an Array object



23
24
25
# File 'lib/doge_coin/client.rb', line 23

def transactions
  JSON.parse(call_blockchain_api("transactions"))
end

#valid_address?(address) ⇒ Boolean

Returns true if the adress is valid, and false otherwise

Returns:

  • (Boolean)


69
70
71
72
73
# File 'lib/doge_coin/client.rb', line 69

def valid_address? address
  code = call_blockchain_api("checkaddress/#{address}")

  !['X5', 'SZ', 'CK'].include?(code)
end