Class: Etherlite::Contract::Base
- Inherits:
-
Object
- Object
- Etherlite::Contract::Base
- Includes:
- Api::Address
- Defined in:
- lib/etherlite/contract/base.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
Class Method Summary collapse
Instance Method Summary collapse
- #get_logs(events: nil, from_block: :earliest, to_block: :latest) ⇒ Object
-
#initialize(_connection, _normalized_address, _default_account) ⇒ Base
constructor
A new instance of Base.
Methods included from Api::Address
Constructor Details
#initialize(_connection, _normalized_address, _default_account) ⇒ Base
Returns a new instance of Base.
25 26 27 28 29 |
# File 'lib/etherlite/contract/base.rb', line 25 def initialize(_connection, _normalized_address, _default_account) @connection = _connection @normalized_address = _normalized_address @default_account = _default_account end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
23 24 25 |
# File 'lib/etherlite/contract/base.rb', line 23 def connection @connection end |
Class Method Details
.at(_address, client: nil, as: nil) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/etherlite/contract/base.rb', line 13 def self.at(_address, client: nil, as: nil) client ||= ::Etherlite # use default client if no client is provided new( client.connection, Etherlite::Utils.normalize_address_param(_address), as || client.first_account ) end |
.events ⇒ Object
9 10 11 |
# File 'lib/etherlite/contract/base.rb', line 9 def self.events @events ||= [] end |
.functions ⇒ Object
5 6 7 |
# File 'lib/etherlite/contract/base.rb', line 5 def self.functions @functions ||= [] end |
Instance Method Details
#get_logs(events: nil, from_block: :earliest, to_block: :latest) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/etherlite/contract/base.rb', line 31 def get_logs(events: nil, from_block: :earliest, to_block: :latest) params = { address: json_encoded_address, fromBlock: Etherlite::Utils.encode_block_param(from_block), toBlock: Etherlite::Utils.encode_block_param(to_block) } params[:topics] = [events.map { |e| event_topic e }] unless events.nil? event_map = Hash[(events || self.class.events).map { |e| [event_topic(e), e] }] logs = @connection.ipc_call(:eth_getLogs, params) logs.map do |log| event = event_map[log["topics"].first] # TODO: support anonymous events! event.decode(@connection, log) unless event.nil? end end |