Class: Bitcoin::Client

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

Direct Known Subclasses

HttpConnection

Constant Summary collapse

RPC_COMMANDS =
%w(addmultisigaddress addnode backupwallet createmultisig createrawtransaction decoderawtransaction dumpprivkey dumpwallet encryptwallet getaccount getaccountaddress getaddednodeinfo getaddressesbyaccount getbalance getbestblockhash getblock getblockcount getblockhash getblocknumber getblocktemplate getconnectioncount getdifficulty getgenerate gethashespersec getinfo getmemorypool getmininginfo getnewaddress getpeerinfo getrawchangeaddress getrawmempool getrawtransaction getreceivedbyaccount getreceivedbyaddress gettransaction gettxout gettxoutsetinfo getwork help importprivkey invalidateblock keypoolrefill listaccounts listaddressgroupings listreceivedbyaccount listreceivedbyaddress listsinceblock listtransactions listunspent listlockunspent lockunspent move sendfrom sendmany sendrawtransaction sendtoaddress setaccount setgenerate settxfee signmessage signrawtransaction stop submitblock validateaddress verifymessage walletlock walletpassphrase walletpassphrasechange)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeClient

Returns a new instance of Client.



9
10
11
# File 'lib/elchapo/bitcoin/client.rb', line 9

def initialize
  @id = 0
end

Instance Attribute Details

#commandObject

Returns the value of attribute command.



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

def command
  @command
end

#default_accountObject

Returns the value of attribute default_account.



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

def 
  @default_account
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

Instance Method Details

#get_idObject



13
14
15
16
# File 'lib/elchapo/bitcoin/client.rb', line 13

def get_id
  @id += 1
  return @id
end

#reset_idObject



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

def reset_id
  @id = 0
end

#send_command(command, args) ⇒ Object

Raises:

  • (IOError)


22
23
24
25
26
27
28
29
30
31
# File 'lib/elchapo/bitcoin/client.rb', line 22

def send_command(command,args)
  payload = {jsonrpc: "2.0", method: command, params: args, id: get_id}
  @logger.info("Sending #{payload.to_json}") if @log

  output = JSON.parse(send_single(payload.to_json))
  @logger.info("Received #{output.to_json}") if @log
  reset_id
  raise IOError, output["error"]["message"] if output["error"]
  return output["result"]
end