Class: Web3::Eth::Contract
- Inherits:
-
Object
- Object
- Web3::Eth::Contract
- Defined in:
- lib/web3/eth/contract.rb
Defined Under Namespace
Classes: ContractConstructor, 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.
154 155 156 157 158 |
# File 'lib/web3/eth/contract.rb', line 154 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.
152 153 154 |
# File 'lib/web3/eth/contract.rb', line 152 def abi @abi end |
#constructor ⇒ Object (readonly)
Returns the value of attribute constructor.
152 153 154 |
# File 'lib/web3/eth/contract.rb', line 152 def constructor @constructor end |
#events ⇒ Object (readonly)
Returns the value of attribute events.
152 153 154 |
# File 'lib/web3/eth/contract.rb', line 152 def events @events end |
#events_by_hash ⇒ Object (readonly)
Returns the value of attribute events_by_hash.
152 153 154 |
# File 'lib/web3/eth/contract.rb', line 152 def events_by_hash @events_by_hash end |
#functions ⇒ Object (readonly)
Returns the value of attribute functions.
152 153 154 |
# File 'lib/web3/eth/contract.rb', line 152 def functions @functions end |
#functions_by_hash ⇒ Object (readonly)
Returns the value of attribute functions_by_hash.
152 153 154 |
# File 'lib/web3/eth/contract.rb', line 152 def functions_by_hash @functions_by_hash end |
#web3_rpc ⇒ Object (readonly)
Returns the value of attribute web3_rpc.
152 153 154 |
# File 'lib/web3/eth/contract.rb', line 152 def web3_rpc @web3_rpc end |
Instance Method Details
#at(address) ⇒ Object
160 161 162 |
# File 'lib/web3/eth/contract.rb', line 160 def at address ContractInstance.new self, address end |
#call_contract(contract_address, method_name, args) ⇒ Object
164 165 166 167 168 169 |
# File 'lib/web3/eth/contract.rb', line 164 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
171 172 173 |
# File 'lib/web3/eth/contract.rb', line 171 def find_event_by_hash method_hash @events_by_hash[method_hash] end |
#find_function_by_hash(method_hash) ⇒ Object
175 176 177 |
# File 'lib/web3/eth/contract.rb', line 175 def find_function_by_hash method_hash @functions_by_hash[method_hash] end |
#parse_call_args(transaction) ⇒ Object
185 186 187 188 189 |
# File 'lib/web3/eth/contract.rb', line 185 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
192 193 194 |
# File 'lib/web3/eth/contract.rb', line 192 def parse_constructor_args transaction constructor ? constructor.parse_method_args(transaction) : [] end |
#parse_log_args(log) ⇒ Object
179 180 181 182 183 |
# File 'lib/web3/eth/contract.rb', line 179 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 |