Documentation ¶
Overview ¶
nolint
Index ¶
- Constants
- Variables
- func ComputeGasCost(baseGas, fixedGas uint64, tx []byte, storageFactor uint64) uint64
- func ComputeIntrinsicGasCost(baseGas uint64, tx []byte, storageFactor uint64) uint64
- func SigningBody(genesis, tx []byte) []byte
- type Account
- type AccountLoader
- type AccountUpdater
- type Address
- type Context
- func (c *Context) Apply(updater AccountUpdater) error
- func (c *Context) Consume(gas uint64) (err error)
- func (c *Context) Consumed() uint64
- func (c *Context) Fee() uint64
- func (c *Context) GetGenesisID() Hash20
- func (c *Context) Handler() Handler
- func (c *Context) Layer() LayerID
- func (c *Context) Principal() Address
- func (c *Context) Relay(remoteTemplate, address Address, call func(Host) error) error
- func (c *Context) Spawn(args scale.Encodable) error
- func (c *Context) Template() Template
- func (c *Context) Transfer(to Address, amount uint64) error
- func (c *Context) Updated() []types.Address
- type DBLoader
- type Handler
- type HandlerRegistry
- type Hash20
- type Hash32
- type Header
- type Host
- type LayerID
- type Nonce
- type ParseOutput
- type Payload
- type PublicKey
- type RemoteContext
- type Signature
- type StagedCache
- type Template
Constants ¶
const ( // MethodSpawn ... MethodSpawn = 0 // MethodSpend ... MethodSpend = 16 )
const TxSizeLimit = 1024
Variables ¶
var ( // ErrInternal raised on any unexpected error due to internal conditions. // Most likely due to the disk failures. ErrInternal = errors.New("internal") // ErrMalformed raised if transaction cannot be decoded properly. ErrMalformed = errors.New("malformed tx") // ErrInvalidNonce raised due to the expected nonce mismatch. ErrInvalidNonce = errors.New("invalid nonce") // ErrNoBalance raised if transaction run out of balance during execution. ErrNoBalance = errors.New("no balance") // ErrMaxGas raised if tx consumed over MaxGas value. ErrMaxGas = errors.New("max gas") // ErrMaxSpend raised if tx transferred over MaxSpend value. ErrMaxSpend = errors.New("max spend") // ErrSpawned raised if account already spawned. ErrSpawned = errors.New("account already spawned") // ErrNotSpawned raised if account is not spawned. ErrNotSpawned = errors.New("account is not spawned") // ErrMismatchedTemplate raised if target account doesn't match template account. ErrTemplateMismatch = errors.New("relay template mismatch") // ErrTxLimit overflows max tx size. ErrTxLimit = errors.New("overflows tx limit") )
Functions ¶
func ComputeGasCost ¶
ComputeGasCost computes total gas cost by adding fixed gas to intrinsic gas cost.
func ComputeIntrinsicGasCost ¶
ComputeIntrinsicGasCost computes intrinsic gas from base gas and storage cost.
func SigningBody ¶
Types ¶
type AccountLoader ¶
AccountLoader is an interface for loading accounts.
type AccountUpdater ¶
AccountUpdater is an interface for updating accounts.
type Address ¶
Address is an alias to types.Address.
func ComputePrincipal ¶
ComputePrincipal address as the last 20 bytes from blake3(scale(template || args)).
type Context ¶
type Context struct { Registry HandlerRegistry Loader AccountLoader // LayerID of the block. LayerID LayerID GenesisID types.Hash20 PrincipalHandler Handler PrincipalTemplate Template PrincipalAccount Account ParseOutput ParseOutput Header Header Args scale.Encodable // contains filtered or unexported fields }
Context serves 2 purposes: - maintains changes to the system state, that will be applied only after succeful execution - accumulates set of reusable objects and data.
func (*Context) Apply ¶
func (c *Context) Apply(updater AccountUpdater) error
Apply is executed if transaction was consumed.
func (*Context) GetGenesisID ¶
GetGenesisID returns genesis id.
type Handler ¶
type Handler interface { // Parse header and arguments from the payload. Parse(Host, uint8, *scale.Decoder) (ParseOutput, error) // Args returns method arguments for the method. Args(uint8) scale.Type // Exec dispatches execution request based on the method selector. Exec(Host, uint8, scale.Encodable) error // New instantiates Template from spawn arguments. New(any) (Template, error) // Load template with stored immutable state. Load([]byte) (Template, error) }
Handler provides set of static templates method that are not directly attached to the state.
type HandlerRegistry ¶
HandlerRegistry stores handlers for templates.
type Host ¶
type Host interface { Consume(uint64) error Spawn(scale.Encodable) error Transfer(Address, uint64) error Relay(expectedTemplate, address Address, call func(Host) error) error Principal() Address Handler() Handler Template() Template Layer() LayerID GetGenesisID() Hash20 }
Host API with methods and data that are required by templates.
type ParseOutput ¶
ParseOutput contains all fields that are returned by Parse call.
type Payload ¶
Payload is a generic payload for all transactions.
func (*Payload) DecodeScale ¶
func (*Payload) EncodeScale ¶
type RemoteContext ¶
type RemoteContext struct { *Context // contains filtered or unexported fields }
RemoteContext ...
type StagedCache ¶
type StagedCache struct {
// contains filtered or unexported fields
}
StagedCache is a passthrough cache for accounts state and enforces order for updated accounts.
func NewStagedCache ¶
func NewStagedCache(loader AccountLoader) *StagedCache
NewStagedCache returns instance of the staged cache.
func (*StagedCache) Get ¶
func (ss *StagedCache) Get(address Address) (Account, error)
Get a copy of the Account state for the address.
func (*StagedCache) IterateChanged ¶
func (ss *StagedCache) IterateChanged(f func(*Account) bool)
IterateChanged accounts in the order they were updated.
func (*StagedCache) Update ¶
func (ss *StagedCache) Update(account Account) error
Update cache with a copy of the account state.
type Template ¶
type Template interface { // Template needs to implement scale.Encodable as mutable and immutable state will be stored as a blob of bytes. scale.Encodable // MaxSpend decodes MaxSpend value for the transaction. Transaction will fail // if it spends more than that. MaxSpend(uint8, any) (uint64, error) // Verify security of the transaction. Verify(Host, []byte, *scale.Decoder) bool }
Template is a concrete Template type initialized with mutable and immutable state.