class Etherlite::Contract::Base

Attributes

connection[R]
default_account[R]
normalized_address[R]

Public Class Methods

at(_address, client: nil, as: nil) click to toggle source
# File lib/etherlite/contract/base.rb, line 41
def self.at(_address, client: nil, as: nil)
  _address = Etherlite::Utils.normalize_address_param _address

  if as
    new(as.connection, _address, as)
  else
    client ||= ::Etherlite
    new(client.connection, _address, client.default_account)
  end
end
bytecode() click to toggle source
# File lib/etherlite/contract/base.rb, line 21
def self.bytecode
  @bytecode ||= begin
    if /__[^_]+_+/.match? unlinked_bytecode
      raise UnlinkedContractError, 'compiled contract contains unresolved library references'
    end

    unlinked_bytecode
  end
end
constructor() click to toggle source
# File lib/etherlite/contract/base.rb, line 17
def self.constructor
  nil
end
deploy(*_args) click to toggle source
# File lib/etherlite/contract/base.rb, line 31
def self.deploy(*_args)
  options = _args.last.is_a?(Hash) ? _args.pop : {}
  as = options[:as] || options[:client].try(:default_account) || Etherlite.default_account

  tx_data = options.fetch(:bytecode, bytecode)
  tx_data += constructor.encode(_args) unless constructor.nil?

  as.send_transaction({ data: tx_data }.merge(options))
end
events() click to toggle source
# File lib/etherlite/contract/base.rb, line 9
def self.events
  @events ||= []
end
functions() click to toggle source
# File lib/etherlite/contract/base.rb, line 5
def self.functions
  @functions ||= []
end
new(_connection, _normalized_address, _default_account) click to toggle source
# File lib/etherlite/contract/base.rb, line 54
def initialize(_connection, _normalized_address, _default_account)
  @connection = _connection
  @normalized_address = _normalized_address
  @default_account = _default_account
end
unlinked_bytecode() click to toggle source
# File lib/etherlite/contract/base.rb, line 13
def self.unlinked_bytecode
  '0x0'
end

Public Instance Methods

get_logs(events: nil, from_block: :earliest, to_block: :latest) click to toggle source
# File lib/etherlite/contract/base.rb, line 60
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(&:topic)] unless events.nil?

  logs = @connection.ipc_call(:eth_getLogs, params)
  ::Etherlite::EventProvider.parse_raw_logs(@connection, logs)
end