Class: Bitcoind::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/bitcoind/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(user, pass) ⇒ Client

Returns a new instance of Client.



3
4
5
# File 'lib/bitcoind/client.rb', line 3

def initialize(user, pass)
  @endpoint = "http://#{user}:#{pass}@localhost:8332"
end

Instance Method Details

#accountsObject



11
12
13
14
# File 'lib/bitcoind/client.rb', line 11

def accounts
  balance_hash = request 'listaccounts'
  AccountHash.new self, balance_hash
end

#balanceObject



7
8
9
# File 'lib/bitcoind/client.rb', line 7

def balance
  request 'getbalance'
end

#inspectObject



24
25
26
# File 'lib/bitcoind/client.rb', line 24

def inspect
  "#<Bitcoind::Client #{@endpoint.inspect} >"
end

#request(method, *args) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/bitcoind/client.rb', line 16

def request(method, *args)
  body = { 'id'=>'jsonrpc', 'method'=>method}
  body['params'] = args unless args.empty?
  response_json = RestClient.post @endpoint, body.to_json
  response = JSON.parse response_json
  return response['result']
end