Current section
Files
Jump to
Current section
Files
lib/forge.ex
defmodule Forge do
@moduledoc """
Public interfaces for using Forge
"""
defmodule Handler do
@moduledoc """
Forge handler behavior
"""
alias Forge.{Account, AccountState, Context, HandlerResponse, TransactionMessage}
alias Google.Protobuf.Any
@callback verify(TransactionMessage.t(), Account.t(), AccountState.t()) :: true | false
@callback update_state(String.t(), Any.t(), Account.t(), Context.t()) :: HandlerResponse.t()
end
defmodule Context do
@moduledoc false
@typedoc """
The context passed into the application handler by forge. It contains keys as folows:
* `:tx_hash`: the hash of the transaction that being handled. Application can record this in their state as a reference.
* `:block_height`: the height of the current block.
* `:block_time`: the deterministic time (in google protobuf timestamp format) of the current block.
* `:address`: the self address of the state.
* `:owner`: the owner address of the state, if any.
"""
@type t :: %__MODULE__{
tx_hash: String.t(),
block_height: non_neg_integer(),
block_time: Google.Protobuf.Timestamp.t(),
address: String.t(),
owner: String.t()
}
defstruct [:tx_hash, :block_height, :block_time, :address, :owner]
end
defmodule HandlerResponse do
@moduledoc false
alias Forge.Account
@typedoc """
The response from handler. It contains keys as follows:
* `:trie`: the account state db
* `:data`: the data returned by the handler to put into tendermint transaction
* `:info`: the info returned by the handler to put into tendermint transaction
* `:log`: the log returned by the handler to put into tendermint transaction
* `:gas_wanted`: the gas wanted by the handler
* `:gas_used`: the gas used by the handler
* `:tags`: the tags returned by the handler, for indexing purpose
"""
@type t :: %__MODULE__{
trie: Account.t(),
data: String.t(),
info: String.t(),
log: String.t(),
gas_wanted: non_neg_integer(),
gas_used: non_neg_integer(),
tags: [String.t()]
}
defstruct trie: nil, data: "", info: "", log: "", gas_wanted: 0, gas_used: 0, tags: []
def new(attrs) do
struct(%__MODULE__{}, attrs)
end
end
end