class Etherlite::Account::Base
Attributes
connection[R]
normalized_address[R]
Public Class Methods
new(_connection, _normalized_address = nil)
click to toggle source
# File lib/etherlite/account/base.rb, line 7 def initialize(_connection, _normalized_address = nil) @connection = _connection @normalized_address = _normalized_address end
Public Instance Methods
==(_other)
click to toggle source
# File lib/etherlite/account/base.rb, line 45 def ==(_other) normalized_address == _other.normalized_address end
call(_target, _function, *_params)
click to toggle source
# File lib/etherlite/account/base.rb, line 25 def call(_target, _function, *_params) _function = parse_function(_function) if _function.is_a? String options = _params.last.is_a?(Hash) ? _params.pop.clone : {} if _function.constant? call_constant _target, _function, _params, options else value = options.fetch(:pay, 0) raise 'function is not payable' if value > 0 && !_function.payable? send_transaction options.merge( to: _target, data: _function.encode(_params), value: value ) end end
next_nonce()
click to toggle source
# File lib/etherlite/account/base.rb, line 12 def next_nonce if @connection.use_parity @connection.parity_next_nonce(address) else # https://github.com/ethereum/go-ethereum/issues/2736 @connection.eth_get_transaction_count(address, 'pending') end end
send_transaction(_options = {})
click to toggle source
# File lib/etherlite/account/base.rb, line 41 def send_transaction(_options = {}) raise Etherlite::NotSupportedError, 'transactions are not supported by this kind of account' end
transfer_to(_target, _options = {})
click to toggle source
# File lib/etherlite/account/base.rb, line 21 def transfer_to(_target, _options = {}) send_transaction _options.merge(to: _target, value: _options.fetch(:amount, 0)) end
Private Instance Methods
call_constant(_target, _function, _params, _options)
click to toggle source
# File lib/etherlite/account/base.rb, line 51 def call_constant(_target, _function, _params, _options) params = { to: Etherlite::Utils.encode_address_param(_target), data: _function.encode(_params) } params[:from] = json_encoded_address if @normalized_address.present? block = Etherlite::Utils.encode_block_param _options.fetch(:block, :latest) _function.decode @connection, @connection.eth_call(params, block) end
parse_function(_signature)
click to toggle source
# File lib/etherlite/account/base.rb, line 64 def parse_function(_signature) Abi::LoadFunction.for signature: _signature end