class Ethereum::Client
Constants
- DEFAULT_GAS_LIMIT
- DEFAULT_GAS_PRICE
- RPC_COMMANDS
- RPC_MANAGEMENT_COMMANDS
Attributes
command[RW]
default_account[RW]
gas_limit[RW]
gas_price[RW]
id[RW]
log[RW]
logger[RW]
Public Class Methods
new()
click to toggle source
# File lib/elchapo/ethereum/client.rb, line 16 def initialize @id = 0 @log = log @batch = nil # @formatter = Ethereum::Formatter.new @gas_price = DEFAULT_GAS_PRICE @gas_limit = DEFAULT_GAS_LIMIT if @log == true @logger = Logger.new("/tmp/ethereum_ruby_http.log") end end
Public Instance Methods
encode_params(params)
click to toggle source
# File lib/elchapo/ethereum/client.rb, line 41 def encode_params(params) params.map(&method(:int_to_hex)) end
get_id()
click to toggle source
# File lib/elchapo/ethereum/client.rb, line 28 def get_id @id += 1 return @id end
int_to_hex(p)
click to toggle source
# File lib/elchapo/ethereum/client.rb, line 37 def int_to_hex(p) p.is_a?(Integer) ? "0x#{p.to_s(16)}" : p end
reset_id()
click to toggle source
# File lib/elchapo/ethereum/client.rb, line 33 def reset_id @id = 0 end
send_command(command,args)
click to toggle source
# File lib/elchapo/ethereum/client.rb, line 45 def send_command(command,args) if ["eth_getBalance", "eth_call"].include?(command) args << "latest" end payload = {jsonrpc: "2.0", method: command, params: encode_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