core

package
v0.2.17-beta.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 14, 2022 License: MIT Imports: 8 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
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")
	// ErrSpawn raised to block regular spawn.
	ErrSpawn = errors.New("spawn is not supported")
	// ErrNotSpawned raised if account is not spawned.
	ErrNotSpawned = errors.New("account is not spawned")
)

Functions

This section is empty.

Types

type Account

type Account = types.Account

Account is an alis to types.Account.

type AccountLoader

type AccountLoader interface {
	Get(Address) (Account, error)
}

AccountLoader is an interface for loading accounts.

type AccountUpdater

type AccountUpdater interface {
	Update(Account) error
}

AccountUpdater is an interface for updating accounts.

type Address

type Address = types.Address

Address is an alias to types.Address.

func ComputePrincipal

func ComputePrincipal(template Address, args scale.Encodable) Address

ComputePrincipal address as the last 20 bytes from sha256(scale(template || args)).

type Context

type Context struct {
	Loader   AccountLoader
	Handler  Handler
	Template Template

	Account Account

	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) (uint64, error)

Apply is executed if transaction was consumed.

func (*Context) Consume

func (c *Context) Consume(gas uint64) (err error)

Consume gas from the account after validation passes.

func (*Context) Spawn

func (c *Context) Spawn(template Address, args scale.Encodable) error

Spawn account.

func (*Context) Transfer

func (c *Context) Transfer(to Address, amount uint64) error

Transfer amount to the address after validation passes.

type Handler

type Handler interface {
	// Parse header and arguments from the payload.
	Parse(*Context, uint8, *scale.Decoder) (Header, scale.Encodable, error)
	// Init instance of the template either by decoding state into Template type or from arguments in case of spawn.
	Init(uint8, any, []byte) (Template, error)
	// Exec dispatches execution request based on the method selector.
	Exec(*Context, uint8, scale.Encodable) error
}

Handler provides set of static templates method that are not directly attached to the state.

type Hash32

type Hash32 = types.Hash32

Hash32 is an alias to types.Hash32.

func Hash

func Hash(bufs ...[]byte) Hash32

Hash bytes into sha256 hash.

type Header = types.TxHeader

Header is an alias to types.TxHeader.

type Nonce

type Nonce = types.Nonce

Nonce is an alias to types.Nonce.

type PublicKey

type PublicKey = types.Hash32

PublicKey is an alias to Hash32.

type Signature

type Signature = types.Bytes64

Signature is an alias to types.Bytes64.

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(db sql.Executor) *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(*Context, []byte) bool
}

Template is a concrete Template type initialized with mutable and immutable state.

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL