Class: Platon::IpcClient
Constant Summary collapse
- IPC_PATHS =
[ "#{ENV['HOME']}/platon-node/data/platon.ipc", "#{ENV['HOME']}/alaya-node/data/platon.ipc" ]
Constants inherited from Client
Client::DEFAULT_GAS_LIMIT, Client::DEFAULT_GAS_PRICE, Client::PLATON_RPC_COMMANDS, Client::RPC_COMMANDS, Client::RPC_MANAGEMENT_COMMANDS
Instance Attribute Summary collapse
-
#ipcpath ⇒ Object
Returns the value of attribute ipcpath.
Attributes inherited from Client
#chain_id, #command, #default_account, #gas_limit, #gas_price, #hrp, #id, #logger, #ppos
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(ipcpath = nil) ⇒ IpcClient
constructor
A new instance of IpcClient.
-
#send_batch(batch) ⇒ Object
Note: Guarantees the results are in the same order as defined in batch call.
- #send_single(payload) ⇒ Object
Methods inherited from Client
#batch, create, #encode_params, #get_id, #get_nonce, #int_to_hex, #reset_id, #send_command, #set_network, #transfer, #transfer_and_wait, #transfer_to, #transfer_to_and_wait, #update_setting, #wait_for
Constructor Details
#initialize(ipcpath = nil) ⇒ IpcClient
Returns a new instance of IpcClient.
11 12 13 14 15 |
# File 'lib/platon/ipc_client.rb', line 11 def initialize(ipcpath = nil) super(nil) ipcpath ||= IpcClient.default_path @ipcpath = ipcpath end |
Instance Attribute Details
#ipcpath ⇒ Object
Returns the value of attribute ipcpath.
4 5 6 |
# File 'lib/platon/ipc_client.rb', line 4 def ipcpath @ipcpath end |
Class Method Details
.default_path(paths = IPC_PATHS) ⇒ Object
17 18 19 20 |
# File 'lib/platon/ipc_client.rb', line 17 def self.default_path(paths = IPC_PATHS) path = paths.select { |path| File.exist?(path) }.first path || raise("Ipc file not found. Please pass in the file path explicitly to IpcClient initializer") end |
Instance Method Details
#send_batch(batch) ⇒ Object
Note: Guarantees the results are in the same order as defined in batch call. client.batch do
client.platon_block_number
client.platon_mining
end
> [“id”=>1, “result”=>“0x26”, “id”=>2, “result”=>false]
36 37 38 39 40 41 42 43 |
# File 'lib/platon/ipc_client.rb', line 36 def send_batch(batch) result = send_single(batch.to_json) result = JSON.parse(result) # Make sure the order is the same as it was when batching calls # See 6 Batch here http://www.jsonrpc.org/specification return result.sort_by! { |c| c['id'] } end |
#send_single(payload) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/platon/ipc_client.rb', line 22 def send_single(payload) socket = UNIXSocket.new(@ipcpath) socket.puts(payload) read = socket.recvmsg(nil)[0] socket.close return read end |