class Web3::Eth::Contract
Attributes
abi[R]
constructor[R]
events[R]
events_by_hash[R]
functions[R]
functions_by_hash[R]
web3_rpc[R]
Public Class Methods
new(abi, web_rpc = nil)
click to toggle source
# File lib/web3ethereum/contract.rb, line 100 def initialize abi, web_rpc = nil @web3_rpc = web_rpc @abi = abi.kind_of?(String) ? JSON.parse(abi) : abi parse_abi @abi end
Public Instance Methods
at(address)
click to toggle source
# File lib/web3ethereum/contract.rb, line 106 def at address ContractInstance.new self, address end
call_contract(contract_address, method_name, args)
click to toggle source
# File lib/web3ethereum/contract.rb, line 110 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/web3ethereum/contract.rb, line 117 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/web3ethereum/contract.rb, line 121 def find_function_by_hash method_hash @functions_by_hash[method_hash] end
parse_call_args(transaction)
click to toggle source
# File lib/web3ethereum/contract.rb, line 131 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/web3ethereum/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/web3ethereum/contract.rb, line 125 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_event_args log end
Private Instance Methods
parse_abi(abi)
click to toggle source
# File lib/web3ethereum/contract.rb, line 144 def parse_abi abi @functions = {} @events = {} @functions_by_hash = {} @events_by_hash = {} abi.each{|a| case a['type'] when 'function' method = ContractMethod.new(a) @functions[method.name] = method @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