Class: Web3::Eth::Contract
- Inherits:
-
Object
- Object
- Web3::Eth::Contract
- Defined in:
- lib/web3ethereum/contract.rb
Defined Under Namespace
Classes: ContractInstance, ContractMethod
Instance Attribute Summary collapse
-
#abi ⇒ Object
readonly
Returns the value of attribute abi.
-
#constructor ⇒ Object
readonly
Returns the value of attribute constructor.
-
#events ⇒ Object
readonly
Returns the value of attribute events.
-
#events_by_hash ⇒ Object
readonly
Returns the value of attribute events_by_hash.
-
#functions ⇒ Object
readonly
Returns the value of attribute functions.
-
#functions_by_hash ⇒ Object
readonly
Returns the value of attribute functions_by_hash.
-
#web3_rpc ⇒ Object
readonly
Returns the value of attribute web3_rpc.
Instance Method Summary collapse
- #at(address) ⇒ Object
- #call_contract(contract_address, method_name, args) ⇒ Object
- #find_event_by_hash(method_hash) ⇒ Object
- #find_function_by_hash(method_hash) ⇒ Object
-
#initialize(abi, web_rpc = nil) ⇒ Contract
constructor
A new instance of Contract.
- #parse_call_args(transaction) ⇒ Object
- #parse_constructor_args(transaction) ⇒ Object
- #parse_log_args(log) ⇒ Object
Constructor Details
#initialize(abi, web_rpc = nil) ⇒ Contract
Returns a new instance of Contract.
100 101 102 103 104 |
# 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 |
Instance Attribute Details
#abi ⇒ Object (readonly)
Returns the value of attribute abi.
98 99 100 |
# File 'lib/web3ethereum/contract.rb', line 98 def abi @abi end |
#constructor ⇒ Object (readonly)
Returns the value of attribute constructor.
98 99 100 |
# File 'lib/web3ethereum/contract.rb', line 98 def constructor @constructor end |
#events ⇒ Object (readonly)
Returns the value of attribute events.
98 99 100 |
# File 'lib/web3ethereum/contract.rb', line 98 def events @events end |
#events_by_hash ⇒ Object (readonly)
Returns the value of attribute events_by_hash.
98 99 100 |
# File 'lib/web3ethereum/contract.rb', line 98 def events_by_hash @events_by_hash end |
#functions ⇒ Object (readonly)
Returns the value of attribute functions.
98 99 100 |
# File 'lib/web3ethereum/contract.rb', line 98 def functions @functions end |
#functions_by_hash ⇒ Object (readonly)
Returns the value of attribute functions_by_hash.
98 99 100 |
# File 'lib/web3ethereum/contract.rb', line 98 def functions_by_hash @functions_by_hash end |
#web3_rpc ⇒ Object (readonly)
Returns the value of attribute web3_rpc.
98 99 100 |
# File 'lib/web3ethereum/contract.rb', line 98 def web3_rpc @web3_rpc end |
Instance Method Details
#at(address) ⇒ Object
106 107 108 |
# File 'lib/web3ethereum/contract.rb', line 106 def at address ContractInstance.new self, address end |
#call_contract(contract_address, method_name, args) ⇒ Object
110 111 112 113 114 115 |
# 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) ⇒ Object
117 118 119 |
# 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) ⇒ Object
121 122 123 |
# File 'lib/web3ethereum/contract.rb', line 121 def find_function_by_hash method_hash @functions_by_hash[method_hash] end |
#parse_call_args(transaction) ⇒ Object
131 132 133 134 135 |
# 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) ⇒ Object
138 139 140 |
# File 'lib/web3ethereum/contract.rb', line 138 def parse_constructor_args transaction constructor ? constructor.parse_method_args(transaction) : [] end |
#parse_log_args(log) ⇒ Object
125 126 127 128 129 |
# 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 |