class Web3::Hpb::Contract
Attributes
abi[R]
constructor[R]
events[R]
events_by_hash[R]
fucntions_by_hash[R]
functions[R]
web3_rpc[R]
Public Class Methods
new(abi, web_rpc = nil)
click to toggle source
# File lib/web3/hpb/contract.rb, line 100 def initialize(abi, web_rpc = nil) @web3_rpc = web_rpc # parse to json format @abi = abi.is_a?(String) ? JSON.parse(abi) : abi parse_abi(@abi) end
Public Instance Methods
at(address)
click to toggle source
# File lib/web3/hpb/contract.rb, line 107 def at(address) ContractInstance.new(self, address) end
call_contract(contract_address, method_name, args)
click to toggle source
# File lib/web3/hpb/contract.rb, line 111 def call_contract(contract_address, method_name, args) function = functions[method_name] raise "No method found in ABI: #{method_name}" unless function raise "Function #{method_name} is not constant: #{method_name}, requires to sign transaction" unless function.constant function.do_call(web3_rpc, contract_address, args) end
find_event_by_hash(method_hash)
click to toggle source
# File lib/web3/hpb/contract.rb, line 118 def find_event_by_hash(method_hash) @events_by_hash[method_hash] end
find_function_by_hash(method_hash)
click to toggle source
# File lib/web3/hpb/contract.rb, line 122 def find_function_by_hash(method_hash) @functions_by_hash[method_hash] end
parse_call_args(transaction)
click to toggle source
# File lib/web3/hpb/contract.rb, line 132 def parse_call_args(transaction) function = find_function_by_hash transaction.method_hash raise "No function found by hash #{transaction.method_hash}, probably ABI is not related to call" unless function function.parse_method_args transaction end
parse_constructor_args(transaction)
click to toggle source
# File lib/web3/hpb/contract.rb, line 138 def parse_constructor_args(transaction) constructor ? constructor.parse_method_args(transaction) : [] end
parse_log_args(log)
click to toggle source
# File lib/web3/hpb/contract.rb, line 126 def parse_log_args(log) event = find_event_by_hash(log.method_hash) raise "No event found by hash #{log.method_hash}, probably ABI is not related to log event" unless event event.parse_method_args(log) end
Private Instance Methods
parse_abi(abi)
click to toggle source
# File lib/web3/hpb/contract.rb, line 144 def parse_abi(abi) @functions = {} @events = {} @functions_by_hash = {} @events_by_hash = {} abi.each do |a| case a['type'] when 'function' method = ContractMethod.new(a) @functions[method.name] = method puts @functions @functions_by_hash[method.signature_hash] = method when 'event' method = ContractMethod.new(a) @events[method.name] = method @events_by_hash[method.signature_hash] = method when 'constructor' method = ContractMethod.new(a) @constructor = method end end end