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
@callback verify(TransactionMessage.t(), Account.t(), AccountState.t()) :: true | false
@callback update_state(TransactionMessage.t(), Any.t(), Account.t(), map()) :: Account.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 StateDb do
@moduledoc """
Public interfaces to access the state db of forge.
"""
alias Forge.Mpt
defdelegate get(trie, address), to: Mpt, as: :get
defdelegate put(trie, address, data), to: Mpt, as: :put
end
end