Class: Ethereum::Client
- Inherits:
-
Object
- Object
- Ethereum::Client
- Defined in:
- lib/ethereum/client.rb
Direct Known Subclasses
Constant Summary collapse
- RPC_COMMANDS =
%w(web3_clientVersion web3_sha3 net_version net_peerCount net_listening eth_protocolVersion eth_syncing eth_coinbase eth_mining eth_hashrate eth_gasPrice eth_accounts eth_blockNumber eth_getBalance eth_getStorageAt eth_getTransactionCount eth_getBlockTransactionCountByHash eth_getBlockTransactionCountByNumber eth_getUncleCountByBlockHash eth_getUncleCountByBlockNumber eth_getCode eth_sign eth_sendTransaction eth_sendRawTransaction eth_call eth_estimateGas eth_getBlockByHash eth_getBlockByNumber eth_getTransactionByHash eth_getTransactionByBlockHashAndIndex eth_getTransactionByBlockNumberAndIndex eth_getTransactionReceipt eth_getUncleByBlockHashAndIndex eth_getUncleByBlockNumberAndIndex eth_getCompilers eth_compileLLL eth_compileSolidity eth_compileSerpent eth_newFilter eth_newBlockFilter eth_newPendingTransactionFilter eth_uninstallFilter eth_getFilterChanges eth_getFilterLogs eth_getLogs eth_getWork eth_submitWork eth_submitHashrate db_putString db_getString db_putHex db_getHex shh_post shh_version shh_newIdentity shh_hasIdentity shh_newGroup shh_addToGroup shh_newFilter shh_uninstallFilter shh_getFilterChanges shh_getMessages)
- RPC_MANAGEMENT_COMMANDS =
%w(admin_addPeer admin_datadir admin_nodeInfo admin_peers admin_setSolc admin_startRPC admin_startWS admin_stopRPC admin_stopWS debug_backtraceAt debug_blockProfile debug_cpuProfile debug_dumpBlock debug_gcStats debug_getBlockRlp debug_goTrace debug_memStats debug_seedHash debug_setHead debug_setBlockProfileRate debug_stacks debug_startCPUProfile debug_startGoTrace debug_stopCPUProfile debug_stopGoTrace debug_traceBlock debug_traceBlockByNumber debug_traceBlockByHash debug_traceBlockFromFile debug_traceTransaction debug_verbosity debug_vmodule debug_writeBlockProfile debug_writeMemProfile miner_hashrate miner_makeDAG miner_setExtra miner_setGasPrice miner_start miner_startAutoDAG miner_stop miner_stopAutoDAG personal_importRawKey personal_listAccounts personal_lockAccount personal_newAccount personal_unlockAccount personal_sendTransaction txpool_content txpool_inspect txpool_status)
Instance Attribute Summary collapse
-
#command ⇒ Object
Returns the value of attribute command.
-
#default_account ⇒ Object
Returns the value of attribute default_account.
-
#id ⇒ Object
Returns the value of attribute id.
-
#log ⇒ Object
Returns the value of attribute log.
-
#logger ⇒ Object
Returns the value of attribute logger.
Class Method Summary collapse
Instance Method Summary collapse
- #batch ⇒ Object
- #encode_params(params) ⇒ Object
- #get_id ⇒ Object
-
#initialize(log = false) ⇒ Client
constructor
A new instance of Client.
- #int_to_hex(n) ⇒ Object
- #reset_id ⇒ Object
Constructor Details
#initialize(log = false) ⇒ Client
Returns a new instance of Client.
10 11 12 13 14 15 16 17 18 |
# File 'lib/ethereum/client.rb', line 10 def initialize(log = false) @id = 0 @log = log @batch = nil if @log == true @logger = Logger.new("/tmp/ethereum_ruby_http.log") end end |
Instance Attribute Details
#command ⇒ Object
Returns the value of attribute command.
8 9 10 |
# File 'lib/ethereum/client.rb', line 8 def command @command end |
#default_account ⇒ Object
Returns the value of attribute default_account.
8 9 10 |
# File 'lib/ethereum/client.rb', line 8 def default_account @default_account end |
#id ⇒ Object
Returns the value of attribute id.
8 9 10 |
# File 'lib/ethereum/client.rb', line 8 def id @id end |
#log ⇒ Object
Returns the value of attribute log.
8 9 10 |
# File 'lib/ethereum/client.rb', line 8 def log @log end |
#logger ⇒ Object
Returns the value of attribute logger.
8 9 10 |
# File 'lib/ethereum/client.rb', line 8 def logger @logger end |
Class Method Details
.create(host_or_ipcpath, log = false) ⇒ Object
20 21 22 23 24 |
# File 'lib/ethereum/client.rb', line 20 def self.create(host_or_ipcpath, log = false) return IpcClient.new(host_or_ipcpath, log) if host_or_ipcpath.end_with? '.ipc' return HttpClient.new(host_or_ipcpath, log) if host_or_ipcpath.start_with? 'http' raise ArgumentError.new('Unable to detect client type') end |
Instance Method Details
#batch ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ethereum/client.rb', line 26 def batch @batch = [] yield result = send_batch(@batch) @batch = nil reset_id return result end |
#encode_params(params) ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/ethereum/client.rb', line 56 def encode_params(params) return params.map do |p| if p.is_a?(Integer) int_to_hex(p) else p end end end |
#get_id ⇒ Object
38 39 40 41 |
# File 'lib/ethereum/client.rb', line 38 def get_id @id += 1 return @id end |
#int_to_hex(n) ⇒ Object
51 52 53 |
# File 'lib/ethereum/client.rb', line 51 def int_to_hex(n) return "0x#{n.to_s(16)}" end |
#reset_id ⇒ Object
43 44 45 |
# File 'lib/ethereum/client.rb', line 43 def reset_id @id = 0 end |