Class: Etherlite::Account
- Inherits:
-
Object
- Object
- Etherlite::Account
- Includes:
- Etherlite::Api::Address
- Defined in:
- lib/etherlite/account.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
Instance Method Summary collapse
- #call(_target, _function, *_params) ⇒ Object
-
#initialize(_connection, _normalized_address) ⇒ Account
constructor
A new instance of Account.
- #lock ⇒ Object
- #transfer_to(_target, _options = {}) ⇒ Object
- #unlock(_passphrase) ⇒ Object
Methods included from Etherlite::Api::Address
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
#connection ⇒ Object (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 = _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? && .key?(:pay) params[:value] = Utils.encode_quantity_param [:pay] end send_transaction params, end end |
#lock ⇒ Object
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, = {}) params = { from: json_encoded_address, to: Utils.encode_address_param(_target), value: Utils.encode_quantity_param(.fetch(:amount, 0)) } send_transaction params, end |
#unlock(_passphrase) ⇒ Object
12 13 14 |
# File 'lib/etherlite/account.rb', line 12 def unlock(_passphrase) @passphrase = _passphrase end |