store

package
v0.4.9-rc9 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProtocolVersionLen = 2
	ProtocolInfoLen    = 4
)

Variables

View Source
var (
	ErrInvalidProtocolInfo     = errors.New("invalid protocol info")
	ErrUnknownProtocolVersion  = errors.New("unknown protocol version")
	ErrCodeNotFound            = errors.New("code not found")
	ErrInvalidStorageKey       = errors.New("invalid storage key")
	ErrTooManyProperties       = errors.New("aspect property limit exceeds")
	ErrInvalidBinding          = errors.New("invalid binding")
	ErrStorageCorrupted        = errors.New("storage corrupted")
	ErrNoJoinPoint             = errors.New("cannot bind with no-joinpoint aspect")
	ErrBindingLimitExceeded    = errors.New("binding limit exceeded")
	ErrAlreadyBound            = errors.New("aspect already bound")
	ErrInvalidStoreContext     = errors.New("invalid store context")
	ErrPropertyReserved        = errors.New("property key reserved")
	ErrInvalidExtension        = errors.New("invalid extension")
	ErrInvalidVersionMeta      = errors.New("invalid version meta")
	ErrSerdeFail               = errors.New("serialize or deserialize fail")
	ErrBoundNonVerifierWithEOA = errors.New("binding non-verifier aspect with EOA")
	ErrInvalidJoinPoint        = errors.New("invalid join point")
)
View Source
var (
	GlobalScope  = byte(0xff)
	AccountScope = byte(0xee)
	AspectScope  = byte(0xdd)
)

scope prefixes

View Source
var (
	AspectProtocolInfoKeyPrefix = []byte{GlobalScope, 0x01}
)

global keys, shouldn't be changed in the future

Functions

func GetAccountStore

func GetAccountStore(ctx *aspectmoduletypes.AccountStoreContext) (current AccountStore, new AccountStore, err error)

GetAccountStore returns the account store for the given account, account store is used to store account related info like bound aspects. This function will return 2 stores, the current store and the new store. New store will be nil if no migration needed, otherwise it will be the instance of the new version store.

func GetAspectMetaStore

func GetAspectMetaStore(ctx *aspectmoduletypes.AspectStoreContext) (current AspectMetaStore, new AspectMetaStore, err error)

GetAspectMetaStore returns the aspect meta store for the given aspect id

func RegisterAccountStore

func RegisterAccountStore(version ProtocolVersion, constructor AccountStoreConstructor)

func RegisterAspectMetaStore

func RegisterAspectMetaStore(version ProtocolVersion, constructor AspectMetaStoreConstructor)

func RegisterAspectStateStore

func RegisterAspectStateStore(version ProtocolVersion, constructor AspectStateStoreConstructor)

Types

type AccountStore

type AccountStore interface {
	// LoadAccountBoundAspects returns the aspects bound to the account,
	LoadAccountBoundAspects(filter aspectmoduletypes.BindingFilter) ([]aspectmoduletypes.Binding, error)
	// StoreBinding adds the binding of the given aspect to the account
	StoreBinding(aspectID common.Address, version uint64, joinPoint uint64, priority int8, isCA bool) error
	// RemoveBinding removes the binding of the given aspect from the account
	RemoveBinding(aspectID common.Address, joinPoint uint64, isCA bool) error

	// Used returns true if this given version of store has been used before
	Used() (bool, error)
	// MigrateFrom migrates the data from the old store to the new store
	MigrateFrom(old AccountStore) error
	// Init initializes the store
	Init() error
	// Version returns the version of the store
	Version() ProtocolVersion

	GasMeteredStore
}

AccountStore is the store for each account that using aspect

type AccountStoreConstructor

type AccountStoreConstructor = func(ctx *aspectmoduletypes.AccountStoreContext) AccountStore

type AspectInfo

type AspectInfo struct {
	MetaVersion  ProtocolVersion
	StateVersion ProtocolVersion
	// contains filtered or unexported fields
}

func (AspectInfo) MarshalText

func (a AspectInfo) MarshalText() ([]byte, error)

func (*AspectInfo) Offset

func (a *AspectInfo) Offset() uint64

func (*AspectInfo) UnmarshalText

func (a *AspectInfo) UnmarshalText(text []byte) error

type AspectMetaStore

type AspectMetaStore interface {
	// GetCode returns the code for the given version
	GetCode(version uint64) ([]byte, error)
	// GetVersionMeta returns the meta for the given version
	GetVersionMeta(version uint64) (*aspectmoduletypes.VersionMeta, error)
	// GetMeta returns the meta for the aspect
	GetMeta() (*aspectmoduletypes.AspectMeta, error)
	// GetLatestVersion returns the latest version of the aspect
	GetLatestVersion() (uint64, error)
	// GetProperty returns the properties for the given version
	GetProperty(version uint64, key string) ([]byte, error)
	// LoadAspectBoundAccounts returns the accounts bound to the aspect
	LoadAspectBoundAccounts() ([]aspectmoduletypes.Binding, error)

	// BumpVersion bumps the version of the aspect
	BumpVersion() (uint64, error)
	// StoreVersionMeta stores the meta for the given version
	StoreVersionMeta(version uint64, meta *aspectmoduletypes.VersionMeta) error
	// StoreMeta stores the meta for the aspect
	StoreMeta(meta *aspectmoduletypes.AspectMeta) error
	// StoreCode stores the code for the given version
	StoreCode(version uint64, code []byte) error
	// StoreProperties stores the properties for the given version
	StoreProperties(version uint64, properties []aspectmoduletypes.Property) error
	// StoreBinding stores the binding for the given account
	StoreBinding(account common.Address, version uint64, joinPoint uint64, priority int8) error
	// RemoveBinding removes the binding for the given account
	RemoveBinding(account common.Address) error

	// Version returns the version of the store
	Version() ProtocolVersion
	// MigrateFrom migrates the data from the old store to the new store
	MigrateFrom(old AspectMetaStore) error
	// Used returns true if this given version of store has been used before
	Used() (bool, error)
	// Init initializes the store
	Init() error

	GasMeteredStore
}

AspectMetaStore is the store for aspect metadata

type AspectMetaStoreConstructor

type AspectMetaStoreConstructor = func(ctx *aspectmoduletypes.AspectStoreContext, protocolExtension []byte) AspectMetaStore

type AspectStateStore

type AspectStateStore interface {
	// GetState returns the value for the given key
	GetState(key []byte) []byte
	// SetState sets the value for the given key
	SetState(key []byte, value []byte)
	// Version returns the version of the store
	Version() ProtocolVersion
}

AspectStateStore is the store for aspect state related info

type AspectStateStoreConstructor

type AspectStateStoreConstructor = func(ctx *aspectmoduletypes.AspectStoreContext) AspectStateStore

type GasMeteredStore

type GasMeteredStore interface {
	// Gas returns the gas remains in the store
	Gas() uint64
	// TransferGasFrom transfers the gas from another store
	TransferGasFrom(store GasMeteredStore)
}

type KeyBuilder

type KeyBuilder struct {
	// contains filtered or unexported fields
}

func NewKeyBuilder

func NewKeyBuilder(prefix []byte) *KeyBuilder

func (*KeyBuilder) AppendByte

func (k *KeyBuilder) AppendByte(key byte) *KeyBuilder

func (*KeyBuilder) AppendBytes

func (k *KeyBuilder) AppendBytes(key []byte) *KeyBuilder

func (*KeyBuilder) AppendString

func (k *KeyBuilder) AppendString(key string) *KeyBuilder

func (*KeyBuilder) AppendUint64

func (k *KeyBuilder) AppendUint64(key uint64) *KeyBuilder

func (*KeyBuilder) AppendUint8

func (k *KeyBuilder) AppendUint8(key uint8) *KeyBuilder

func (*KeyBuilder) Build

func (k *KeyBuilder) Build() []byte

func (*KeyBuilder) String

func (k *KeyBuilder) String() string

type ProtocolVersion

type ProtocolVersion uint16

func (ProtocolVersion) MarshalText

func (p ProtocolVersion) MarshalText() ([]byte, error)

func (ProtocolVersion) Offset

func (p ProtocolVersion) Offset() uint64

func (*ProtocolVersion) UnmarshalText

func (p *ProtocolVersion) UnmarshalText(text []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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