Class: Infurarb::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/infurarb/request.rb

Constant Summary collapse

RPC_METHODS =
%i[
  eth_accounts
  eth_blockNumber
  eth_gasPrice
  eth_getBalance
  eth_getBlockByHash
  eth_getBlockByNumber
  eth_getTransactionReceipt
  eth_getBlockTransactionCountByHash
  eth_getBlockTransactionCountByNumber
  eth_getCode
  eth_getLogs
  eth_getStorageAt
  eth_getTransactionByBlockHashAndIndex
  eth_getTransactionByBlockNumberAndIndex
  eth_getUncleByBlockNumberAndIndex
  eth_getUncleCountByBlockHash
  eth_getUncleCountByBlockNumber
  eth_getWork
  eth_hashrate
  eth_mining
  eth_protocolVersion
  eth_syncing
  eth_getTransactionByHash
  eth_getTransactionCount
  web3_clientVersion
  eth_call
  eth_estimateGas
  eth_sendRawTransaction
  eth_submitHashrate
  eth_submitWork
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(endpoint:, method_name:, params: []) ⇒ Request

Returns a new instance of Request.



37
38
39
40
41
# File 'lib/infurarb/request.rb', line 37

def initialize(endpoint:, method_name:, params: [])
  @endpoint = endpoint
  @method_name = method_name
  @params = params
end

Instance Attribute Details

#endpointObject (readonly)

Returns the value of attribute endpoint.



36
37
38
# File 'lib/infurarb/request.rb', line 36

def endpoint
  @endpoint
end

#method_nameObject (readonly)

Returns the value of attribute method_name.



36
37
38
# File 'lib/infurarb/request.rb', line 36

def method_name
  @method_name
end

#paramsObject (readonly)

Returns the value of attribute params.



36
37
38
# File 'lib/infurarb/request.rb', line 36

def params
  @params
end

Instance Method Details

#callObject



43
44
45
46
47
48
49
50
51
# File 'lib/infurarb/request.rb', line 43

def call
  Response.new(
    HTTP.post(
      endpoint,
      json: { jsonrpc: '2.0', method: method_name, params: params, id: 1 }
    ),
    self
  )
end