Class: Etherlite::Connection

Inherits:
Object
  • Object
show all
Includes:
Api::ParityRpc, Api::Rpc
Defined in:
lib/etherlite/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Api::ParityRpc

#parity_next_nonce

Methods included from Api::Rpc

#eth_block_number, #eth_call, #eth_gas_price, #eth_get_balance, #eth_get_transaction_by_hash, #eth_get_transaction_count, #eth_get_transaction_receipt, #eth_send_raw_transaction, #eth_send_transaction, #evm_increase_time, #evm_mine, #evm_revert, #evm_snapshot, #personal_send_transaction

Constructor Details

#initialize(_uri, _options = {}) ⇒ Connection

Returns a new instance of Connection.



8
9
10
11
12
# File 'lib/etherlite/connection.rb', line 8

def initialize(_uri, _options = {})
  @uri = _uri
  @chain_id = _options[:chain_id]
  @use_parity = _options[:use_parity]
end

Instance Attribute Details

#chain_idObject (readonly)

Returns the value of attribute chain_id.



6
7
8
# File 'lib/etherlite/connection.rb', line 6

def chain_id
  @chain_id
end

#use_parityObject (readonly)

Returns the value of attribute use_parity.



6
7
8
# File 'lib/etherlite/connection.rb', line 6

def use_parity
  @use_parity
end

Instance Method Details

#ipc_call(_method, *_params) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/etherlite/connection.rb', line 14

def ipc_call(_method, *_params)
  id = new_unique_id
  payload = { jsonrpc: "2.0", method: _method, params: _params, id: id }

  # TODO: support ipc
  Net::HTTP.start(@uri.hostname, @uri.port, use_ssl: use_ssl?) do |http|
    return handle_response http.post(
      @uri.path.empty? ? '/' : @uri.path,
      payload.to_json,
      "Content-Type" => "application/json"
    ), id
  end
end