Documentation ¶
Overview ¶
nolint
Index ¶
- Constants
- Variables
- func IntrinsicGas(baseGas uint64, tx []byte) uint64
- func MaxGas(baseGas, fixedGas uint64, tx []byte) uint64
- func SigningBody(genesis, tx []byte) []byte
- func SizeGas(gas uint64, size int) uint64
- func TxDataGas(size int) uint64
- 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 ( // TXDATA is a cost for storing transaction data included into the block. Charged per 8 byte. TXDATA uint64 = 128 // TX is an intrinsic cost for every transaction. TX uint64 = 20000 // SPAWN is an intrinsic cost for every spawn, on top of TX cost. SPAWN uint64 = 30000 // STORE is a cost for storing new data, in precompiles charged only for SPAWN. STORE uint64 = 5000 // UPDATE is a cost of updating mutable state (nonce, amount of coins, precompile specific state). UPDATE uint64 = 725 // LOAD is a cost for loading immutable and mutable state from disk. LOAD uint64 = 182 // ACCOUNT_ACCESS is a cost of the account access. ACCOUNT_ACCESS uint64 = 2500 // EDVERIFY is a cost for running ed25519 single signature verification. EDVERIFY uint64 = 3000 )
const ( PUBLIC_KEY_SIZE = 32 ACCOUNT_HEADER_SIZE = 36 // includes balance (8), nonce (8) and template address (24) ACCOUNT_BALANCE_SIZE = 8 )
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 IntrinsicGas ¶
IntrinsicGas 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 Gas struct { BaseGas uint64 FixedGas uint64 } 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) // BaseGas is an intrinsic cost for executing a transaction. If this cost is not covered // transaction will be ineffective. BaseGas(uint8) uint64 // LoadGas is a cost to load account from disk. LoadGas() uint64 // ExecGas is a cost to execution a method. ExecGas(uint8) uint64 // Verify security of the transaction. Verify(Host, []byte, *scale.Decoder) bool }
Template is a concrete Template type initialized with mutable and immutable state.