Class: Etherlite::Account

Inherits:
Object
  • Object
show all
Includes:
Etherlite::Api::Address
Defined in:
lib/etherlite/account.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Etherlite::Api::Address

#address, #get_balance

Constructor Details

#initialize(_connection, _normalized_address) ⇒ Account

Returns a new instance of Account.



7
8
9
10
# File 'lib/etherlite/account.rb', line 7

def initialize(_connection, _normalized_address)
  @connection = _connection
  @normalized_address = _normalized_address
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



5
6
7
# File 'lib/etherlite/account.rb', line 5

def connection
  @connection
end

Instance Method Details

#call(_target, _function, *_params) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/etherlite/account.rb', line 30

def call(_target, _function, *_params)
  _function = Utils.parse_function(_function) unless _function.is_a? Contract::Function
  options = _params.last.is_a?(Hash) ? _params.pop : {}

  params = {
    from: json_encoded_address,
    to: Utils.encode_address_param(_target),
    data: _function.encode(_params)
  }

  if _function.constant?
    _function.decode @connection, @connection.ipc_call(:eth_call, params, "latest")
  else
    if _function.payable? && options.key?(:pay)
      params[:value] = Utils.encode_quantity_param options[:pay]
    end

    send_transaction params, options
  end
end

#lockObject



16
17
18
# File 'lib/etherlite/account.rb', line 16

def lock
  @passphrase = nil
end

#transfer_to(_target, _options = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/etherlite/account.rb', line 20

def transfer_to(_target, _options = {})
  params = {
    from: json_encoded_address,
    to: Utils.encode_address_param(_target),
    value: Utils.encode_quantity_param(_options.fetch(:amount, 0))
  }

  send_transaction params, _options
end

#unlock(_passphrase) ⇒ Object



12
13
14
# File 'lib/etherlite/account.rb', line 12

def unlock(_passphrase)
  @passphrase = _passphrase
end