View Source Etherex.Contract.Manager (Etherex v1.1.0)

This module provides an abstraction layer over the default Etherex contract. This abstraction allows the user to interact with contracts only using addresses and transaction hashes.

Link to this section Summary

Functions

Performs a call to a function of a deployed contract. This call does not generate a transaction in the blockchain.

Performs a call to a function of a deployed contract, This call generates a transaction in the blockchain.

Returns a specification to start this module under a supervisor.

Deploys a contract of a given type in the blockchain. This contract should be previously registered. Returns the transaction in which the contract will be deployed.

Retrieves the address of the given transaction if it is already in a mined.

Given the registered name, retrieves the contract information once compiled.

Given a transaction, retrieves the list of events logged in it for all known contracts. Returns [] if no events. Returns nil if transaction is pending.

Callback implementation for GenServer.init/1.

Compiles and registers a contract in the process.

Starts the contract manager process.

Stops the contract manager process.

Link to this section Types

@type address() :: Etherex.address()
@type block_parameter() :: Etherex.block_parameter()
@type bytecode() :: Etherex.bytecode()
@type call_transaction() :: %{caller: address(), function: String.t(), arguments: []}
@type contract() :: Etherex.contract()
@type error() :: Etherex.error()
@type event() :: Etherex.event()
@type hash() :: Etherex.hash()
@type opts() :: Etherex.opts()
@type state() :: %{
  contracts: MapSet.t(atom()),
  deployed: MapSet.t(address()),
  errors: %{required(hash()) => String.t()}
}

Link to this section Functions

Link to this function

call(contract, caller, function, arguments, opts \\ [])

View Source
@spec call(
  contract :: address(),
  caller :: address(),
  function :: atom(),
  arguments :: list(),
  opts()
) :: {:ok, any()} | {:error, error()}

Performs a call to a function of a deployed contract. This call does not generate a transaction in the blockchain.

Link to this function

call_transaction(contract, caller, function, arguments, opts \\ [])

View Source
@spec call_transaction(
  contract :: address(),
  caller :: address(),
  function :: atom(),
  list(),
  opts()
) :: {:ok, hash()} | {:error, error()}

Performs a call to a function of a deployed contract, This call generates a transaction in the blockchain.

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

deploy(name, caller, arguments, opts \\ [])

View Source
@spec deploy(name :: atom(), caller :: address(), arguments :: list(), opts()) ::
  {:ok, hash()} | {:error, error()}

Deploys a contract of a given type in the blockchain. This contract should be previously registered. Returns the transaction in which the contract will be deployed.

@spec get_address(hash()) :: {:ok, address()} | {:error, error()}

Retrieves the address of the given transaction if it is already in a mined.

@spec get_bytecode(atom()) :: {:ok, bytecode()} | {:error, error()}

Given the registered name, retrieves the contract information once compiled.

@spec get_events(hash()) :: {:ok, [event()] | nil} | {:error, error()}

Given a transaction, retrieves the list of events logged in it for all known contracts. Returns [] if no events. Returns nil if transaction is pending.

Events are not returned in order.

@spec get_revert_reason(hash()) :: {:ok, String.t()} | {:error, error()}
@spec init([]) :: {:ok, state()}

Callback implementation for GenServer.init/1.

@spec register(name :: atom(), path :: Path.t()) :: :ok

Compiles and registers a contract in the process.

@spec start() :: {:ok, pid()}

Starts the contract manager process.

Link to this function

stop(reason \\ :normal, timeout \\ :infinity)

View Source

Stops the contract manager process.