Class: Bitbank::Client
- Inherits:
-
Object
- Object
- Bitbank::Client
- Defined in:
- lib/bitbank/client.rb
Instance Method Summary collapse
- #accounts ⇒ Object
- #balance(account_name = nil) ⇒ Object
-
#block_count ⇒ Object
Returns the number of blocks in the longest block chain.
-
#difficulty ⇒ Object
Returns the proof-of-work difficulty as a multiple of the minimum difficulty.
- #get_work(data = nil) ⇒ Object
- #info ⇒ Object
-
#initialize(config = {}) ⇒ Client
constructor
A new instance of Client.
- #new_address(account_name = nil) ⇒ Object
- #request(method, *args) ⇒ Object
- #transactions(account_name = nil, count = 10) ⇒ Object
Constructor Details
#initialize(config = {}) ⇒ Client
Returns a new instance of Client.
3 4 5 6 7 |
# File 'lib/bitbank/client.rb', line 3 def initialize(config={}) @config = config @endpoint = "http://#{config[:username]}:#{config[:password]}" + "@#{config[:host]}:#{config[:port]}" end |
Instance Method Details
#accounts ⇒ Object
9 10 11 12 13 14 |
# File 'lib/bitbank/client.rb', line 9 def accounts account_data = request('listaccounts') account_data.map do |account_name, account_value| Account.new(self, account_name, account_value) end end |
#balance(account_name = nil) ⇒ Object
16 17 18 |
# File 'lib/bitbank/client.rb', line 16 def balance(account_name=nil) request('getbalance', account_name) end |
#block_count ⇒ Object
Returns the number of blocks in the longest block chain.
21 22 23 |
# File 'lib/bitbank/client.rb', line 21 def block_count request('getblockcount') end |
#difficulty ⇒ Object
Returns the proof-of-work difficulty as a multiple of the minimum difficulty.
26 27 28 |
# File 'lib/bitbank/client.rb', line 26 def difficulty request('getdifficulty') end |
#get_work(data = nil) ⇒ Object
30 31 32 |
# File 'lib/bitbank/client.rb', line 30 def get_work(data=nil) request('getwork', data) end |
#info ⇒ Object
34 35 36 |
# File 'lib/bitbank/client.rb', line 34 def info request('getinfo') end |
#new_address(account_name = nil) ⇒ Object
38 39 40 |
# File 'lib/bitbank/client.rb', line 38 def new_address(account_name=nil) request('getnewaddress', account_name) end |
#request(method, *args) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/bitbank/client.rb', line 49 def request(method, *args) body = { 'id' => 'jsonrpc', 'method' => method } body['params'] = args unless args.empty? || args.first.nil? response_json = RestClient.post(@endpoint, body.to_json) response = JSON.parse(response_json) response['result'] end |
#transactions(account_name = nil, count = 10) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/bitbank/client.rb', line 42 def transactions(account_name=nil, count=10) transaction_data = request('listtransactions', account_name, count) transaction_data.map do |txdata| Transaction.new(self, txdata['txid'], txdata) end end |