Module: Etherlite::Api::Node

Extended by:
Forwardable
Includes:
Address
Included in:
Etherlite, Client
Defined in:
lib/etherlite/api/node.rb

Instance Method Summary collapse

Methods included from Address

#address, #get_balance

Instance Method Details

#account_from_pk(_pk) ⇒ Object



63
64
65
66
67
68
69
70
# File 'lib/etherlite/api/node.rb', line 63

def (_pk)
  Etherlite.logger.warn(
    "use of 'account_from_pk' is deprecated and will be removed in next version, \
use 'load_account' instead"
  )

  (from_pk: _pk)
end

#accountsObject



49
50
51
52
53
# File 'lib/etherlite/api/node.rb', line 49

def accounts
  connection.ipc_call(:eth_accounts).map do |address|
    Etherlite::Account::Local.new @connection, Etherlite::Utils.normalize_address(address)
  end
end

#anonymous_accountObject



59
60
61
# File 'lib/etherlite/api/node.rb', line 59

def 
  @anonymous_account ||= Etherlite::Account::Anonymous.new(connection)
end

#default_accountObject



55
56
57
# File 'lib/etherlite/api/node.rb', line 55

def 
  @default_account ||= (accounts.first || )
end

#get_block_numberObject



7
8
9
# File 'lib/etherlite/api/node.rb', line 7

def get_block_number
  connection.eth_block_number
end

#get_gas_priceObject



11
12
13
# File 'lib/etherlite/api/node.rb', line 11

def get_gas_price
  connection.eth_gas_price
end

#get_logs(events: nil, address: nil, from_block: :earliest, to_block: :latest) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/etherlite/api/node.rb', line 19

def get_logs(events: nil, address: nil, from_block: :earliest, to_block: :latest)
  params = {
    fromBlock: Etherlite::Utils.encode_block_param(from_block),
    toBlock: Etherlite::Utils.encode_block_param(to_block)
  }

  params[:topics] = [Array(events).map(&:topic)] unless events.nil?
  params[:address] = Etherlite::Utils.encode_address_param(address) unless address.nil?

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

#get_transaction(*_args) ⇒ Object



15
16
17
# File 'lib/etherlite/api/node.rb', line 15

def get_transaction(*_args)
  load_transaction(*_args).refresh
end

#load_account(from_pk: nil) ⇒ Object



36
37
38
# File 'lib/etherlite/api/node.rb', line 36

def (from_pk: nil)
  Etherlite::Account::PrivateKey.new connection, from_pk
end

#load_address(_address) ⇒ Object



40
41
42
# File 'lib/etherlite/api/node.rb', line 40

def load_address(_address)
  Etherlite::Address.new(connection, Etherlite::Utils.normalize_address_param(_address))
end

#load_transaction(_hash) ⇒ Object



32
33
34
# File 'lib/etherlite/api/node.rb', line 32

def load_transaction(_hash)
  Transaction.new(connection, _hash)
end

#register_account(_passphrase) ⇒ Object



44
45
46
47
# File 'lib/etherlite/api/node.rb', line 44

def (_passphrase)
  address = connection.ipc_call(:personal_newAccount, _passphrase)
  Etherlite::Account::Local.new @connection, Etherlite::Utils.normalize_address(address)
end