lib/etherlite/contract/base.rb in etherlite-0.1.6 vs lib/etherlite/contract/base.rb in etherlite-0.1.7
- old
+ new
@@ -1,64 +1,48 @@
module Etherlite::Contract
- ##
- # The base class for etherlite contract classes
- #
class Base
include Etherlite::Api::Address
- # The contract's registered functions
def self.functions
@functions ||= []
end
- # The contract's registered events
def self.events
@events ||= []
end
- # The contract's compiled bytecode in binary format (stored as hex)
+ def self.unlinked_binary
+ '0x0'
+ end
+
+ def self.constructor
+ nil
+ end
+
def self.binary
@binary ||= begin
if /__[^_]+_+/ === unlinked_binary
raise UnlinkedContractError, 'compiled contract contains unresolved library references'
end
unlinked_binary
end
end
- ##
- # Deploys the contract and waits for the creation transaction to be mined.
- #
- # This method can be given a source account or client. If an account is given, the it will be
- # used to send the creation transaction. If instead a client is given, the client
- # `default_account` will be used to send the transaction. If no account nor client is given,
- # then the default_account from the default client will be used (if configured).
- #
- # @param as (Object) The source account
- # @param client (Object) The source client (no effect if :as is given)
- # @param timeout (Integer) The transaction mining timeout in seconds, defaults to 120 seconds.
- #
- # This method also takes any parameters the underlying account.send_transaction accepts, like
- # :gas, :gas_price, etc.
- #
- # @return [Object] instance of the contract class pointing the newly deployed contract address.
- #
- def self.deploy(_options = {})
- as = _options[:as] || _options[:client].try(:default_account) || Etherlite.default_account
+ def self.deploy(*_args)
+ options = _args.last.is_a?(Hash) ? _args.pop : {}
+ as = options[:as] || options[:client].try(:default_account) || Etherlite.default_account
- tx = as.send_transaction({ data: binary }.merge(_options))
- if tx.wait_for_block(timeout: _options.fetch(:timeout, 120))
+ tx_data = binary
+ tx_data += constructor.encode(_args) unless constructor.nil?
+
+ tx = as.send_transaction({ data: tx_data }.merge(options))
+ if tx.wait_for_block(timeout: options.fetch(:timeout, 120))
at tx.contract_address, as: as
end
end
- ##
- # Creates a new instance of the contract class that points to a given address.
- #
- #
- #
def self.at(_address, client: nil, as: nil)
_address = Etherlite::Utils.normalize_address_param _address
if as
new(as.connection, _address, as)
@@ -74,14 +58,9 @@
@connection = _connection
@normalized_address = _normalized_address
@default_account = _default_account
end
- ##
- # Searches for event logs emitted by this contract
- #
- #
- #
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)