dao

package
v0.117.0 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2026 License: MIT Imports: 21 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrAlreadyExists is returned when the transaction exists in dao.
	ErrAlreadyExists = errors.New("transaction already exists")
	// ErrHasConflicts is returned when the transaction is in the list of conflicting
	// transactions which are already in dao.
	ErrHasConflicts = errors.New("transaction has conflicts")
	// ErrInternalDBInconsistency is returned when the format of the retrieved DAO
	// record is unexpected.
	ErrInternalDBInconsistency = errors.New("internal DB inconsistency")
)

HasTransaction errors.

Functions

This section is empty.

Types

type NativeContractCache added in v0.99.0

type NativeContractCache interface {
	// Copy returns a copy of native cache item that can safely be changed within
	// the subsequent DAO operations.
	Copy() NativeContractCache
}

NativeContractCache is an interface representing cache for a native contract. Cache can be copied to create a wrapper around current DAO layer. Wrapped cache can be persisted to the underlying DAO native cache.

type Simple

type Simple struct {
	Version Version
	Store   *storage.MemCachedStore
	// contains filtered or unexported fields
}

Simple is memCached wrapper around DB, simple DAO implementation.

func NewSimple

func NewSimple(backend storage.Store, stateRootInHeader bool) *Simple

NewSimple creates a new simple dao using the provided backend store.

func (*Simple) DeleteBlock added in v0.92.0

func (dao *Simple) DeleteBlock(h util.Uint256) (uint64, error)

DeleteBlock removes the block from dao. It's not atomic, so make sure you're using private MemCached instance here. It returns block timestamp for GC convenience.

func (*Simple) DeleteHeaderHashesHead added in v0.111.0

func (dao *Simple) DeleteHeaderHashesHead(since uint32, batchSize int)

DeleteHeaderHashesHead removes batches of header hashes starting from the one that contains header with index `since` up to the most recent batch. It assumes that all stored batches contain `batchSize` hashes.

func (*Simple) DeleteStorageItem

func (dao *Simple) DeleteStorageItem(id int32, key []byte)

DeleteStorageItem drops a storage item for the given id with the given key from the store.

func (*Simple) GetAndDecode

func (dao *Simple) GetAndDecode(entity io.Serializable, key []byte) error

GetAndDecode performs get operation and decoding with serializable structures.

func (*Simple) GetAppExecResults added in v0.92.0

func (dao *Simple) GetAppExecResults(hash util.Uint256, trig trigger.Type) ([]state.AppExecResult, error)

GetAppExecResults gets application execution results with the specified trigger from the given store.

func (*Simple) GetBatch

func (dao *Simple) GetBatch() *storage.MemBatch

GetBatch returns the currently accumulated DB changeset.

func (*Simple) GetBlock

func (dao *Simple) GetBlock(hash util.Uint256) (*block.Block, error)

GetBlock returns Block by the given hash if it exists in the store.

func (*Simple) GetCurrentBlockHeight

func (dao *Simple) GetCurrentBlockHeight() (uint32, error)

GetCurrentBlockHeight returns the current block height found in the underlying store.

func (*Simple) GetCurrentHeaderHeight

func (dao *Simple) GetCurrentHeaderHeight() (i uint32, h util.Uint256, err error)

GetCurrentHeaderHeight returns the current header height and hash from the underlying store.

func (*Simple) GetHeaderHashes

func (dao *Simple) GetHeaderHashes(height uint32) ([]util.Uint256, error)

GetHeaderHashes returns a page of header hashes retrieved from the given underlying store.

func (*Simple) GetInt added in v0.109.0

func (dao *Simple) GetInt(id int32, key []byte) (int64, error)

GetInt retrieves integer by the specified contract ID and key.

func (*Simple) GetItemCtx added in v0.99.0

func (dao *Simple) GetItemCtx() *stackitem.SerializationContext

func (*Simple) GetPrivate added in v0.98.2

func (dao *Simple) GetPrivate() *Simple

GetPrivate returns a new DAO instance with another layer of private MemCachedStore around the current DAO Store.

func (*Simple) GetROCache added in v0.99.0

func (dao *Simple) GetROCache(id int32) NativeContractCache

GetROCache returns native contact cache. The cache CAN NOT be modified by the caller. It's the caller's duty to keep it unmodified.

func (*Simple) GetRWCache added in v0.99.0

func (dao *Simple) GetRWCache(id int32) NativeContractCache

GetRWCache returns native contact cache. The cache CAN BE safely modified by the caller.

func (*Simple) GetStateSyncCheckpoint added in v0.110.0

func (dao *Simple) GetStateSyncCheckpoint() (StateSyncCheckpoint, error)

GetStateSyncCheckpoint returns the current StateSyncCheckpoint.

func (*Simple) GetStateSyncCurrentBlockHeight added in v0.97.2

func (dao *Simple) GetStateSyncCurrentBlockHeight() (uint32, error)

GetStateSyncCurrentBlockHeight returns the current block height stored during state synchronization process.

func (*Simple) GetStateSyncPoint added in v0.97.2

func (dao *Simple) GetStateSyncPoint() (uint32, error)

GetStateSyncPoint returns current state synchronization point P.

func (*Simple) GetStorageConvertible added in v0.115.0

func (dao *Simple) GetStorageConvertible(id int32, key []byte, conv stackitem.Convertible) error

GetStorageConvertible deserializes the stackitem.Convertible entry retrieved by the provided key from the contract storage.

func (*Simple) GetStorageItem

func (dao *Simple) GetStorageItem(id int32, key []byte) state.StorageItem

GetStorageItem returns StorageItem if it exists in the given store.

func (*Simple) GetTokenTransferInfo added in v0.98.0

func (dao *Simple) GetTokenTransferInfo(acc util.Uint160) (*state.TokenTransferInfo, error)

GetTokenTransferInfo retrieves NEP-17 transfer info from the cache.

func (*Simple) GetTokenTransferLog added in v0.98.0

func (dao *Simple) GetTokenTransferLog(acc util.Uint160, newestTimestamp uint64, index uint32, isNEP11 bool) (*state.TokenTransferLog, error)

GetTokenTransferLog retrieves transfer log from the cache.

func (*Simple) GetTransaction

func (dao *Simple) GetTransaction(hash util.Uint256) (*transaction.Transaction, uint32, error)

GetTransaction returns Transaction and its height by the given hash if it exists in the store. It does not return conflict record stubs.

func (*Simple) GetTxExecResult added in v0.99.0

func (dao *Simple) GetTxExecResult(hash util.Uint256) (uint32, *transaction.Transaction, *state.AppExecResult, error)

GetTxExecResult gets application execution result of the specified transaction and returns the transaction itself, its height and its AppExecResult.

func (*Simple) GetVersion

func (dao *Simple) GetVersion() (Version, error)

GetVersion attempts to get the current version stored in the underlying store.

func (*Simple) GetWrapped

func (dao *Simple) GetWrapped() *Simple

GetWrapped returns a new DAO instance with another layer of wrapped MemCachedStore around the current DAO Store.

func (*Simple) HasTransaction

func (dao *Simple) HasTransaction(hash util.Uint256, signers []transaction.Signer, currentIndex uint32, maxTraceableBlocks uint32) error

HasTransaction returns nil if the given store does not contain the given Transaction hash. It returns an error in case the transaction is in chain or in the list of conflicting transactions. If non-zero signers are specified, then additional check against the conflicting transaction signers intersection is held. Do not omit signers in case if it's important to check the validity of a supposedly conflicting on-chain transaction. The retrieved conflict isn't checked against the maxTraceableBlocks setting if signers are omitted. HasTransaction does not consider the case of block executable.

func (*Simple) Persist

func (dao *Simple) Persist() (int, error)

Persist flushes all the changes made into the (supposedly) persistent underlying store. It doesn't block accesses to DAO from other threads.

func (*Simple) PersistPrivate added in v0.110.0

func (dao *Simple) PersistPrivate(private ...*Simple) int

PersistPrivate flushes all the changes made in the provided set of private Simple to the DAO. It assumes that every private is a private wrapper around method receiver. It relies on fact that method receiver is used as a persistent storage for native cache of every private. It doesn't block accesses to DAO from other threads for the most time. Every private must not be used during PersistPrivate since PersistPrivate doesn't lock native cache of every private.

func (*Simple) PersistSync added in v0.98.0

func (dao *Simple) PersistSync() (int, error)

PersistSync flushes all the changes made into the (supposedly) persistent underlying store. It's a synchronous version of Persist that doesn't allow other threads to work with DAO while flushing the Store.

func (*Simple) PurgeHeader added in v0.99.7

func (dao *Simple) PurgeHeader(h util.Uint256)

PurgeHeader completely removes specified header from dao. It differs from DeleteBlock in that it removes header anyway and does nothing except removing header. It does no checks for header existence.

func (*Simple) PutBigInt added in v0.99.0

func (dao *Simple) PutBigInt(id int32, key []byte, n *big.Int)

PutBigInt serializaed and puts the given integer for the given id with the given key into the given store.

func (*Simple) PutCurrentHeader

func (dao *Simple) PutCurrentHeader(h util.Uint256, index uint32)

PutCurrentHeader stores the current header.

func (*Simple) PutStateSyncCheckpoint added in v0.110.0

func (dao *Simple) PutStateSyncCheckpoint(checkpoint StateSyncCheckpoint)

PutStateSyncCheckpoint stores the current StateSyncCheckpoint.

func (*Simple) PutStateSyncCurrentBlockHeight added in v0.97.2

func (dao *Simple) PutStateSyncCurrentBlockHeight(h uint32)

PutStateSyncCurrentBlockHeight stores the current block height during state synchronization process.

func (*Simple) PutStateSyncPoint added in v0.97.2

func (dao *Simple) PutStateSyncPoint(p uint32)

PutStateSyncPoint stores the current state synchronization point P.

func (*Simple) PutStorageConvertible added in v0.115.0

func (dao *Simple) PutStorageConvertible(id int32, key []byte, conv stackitem.Convertible) error

PutStorageConvertible serializes the provided stackitem.Convertible using DAO's serialization context and puts it to the specified contract storage.

func (*Simple) PutStorageItem

func (dao *Simple) PutStorageItem(id int32, key []byte, si state.StorageItem)

PutStorageItem puts the given StorageItem for the given id with the given key into the given store.

func (*Simple) PutTokenTransferInfo added in v0.98.0

func (dao *Simple) PutTokenTransferInfo(acc util.Uint160, bs *state.TokenTransferInfo) error

PutTokenTransferInfo saves NEP-17 transfer info in the cache.

func (*Simple) PutTokenTransferLog added in v0.98.0

func (dao *Simple) PutTokenTransferLog(acc util.Uint160, start uint64, index uint32, isNEP11 bool, lg *state.TokenTransferLog)

PutTokenTransferLog saves the given transfer log in the cache.

func (*Simple) PutVersion

func (dao *Simple) PutVersion(v Version)

PutVersion stores the given version in the underlying store.

func (*Simple) Seek added in v0.92.0

func (dao *Simple) Seek(id int32, rng storage.SeekRange, f func(k, v []byte) bool)

Seek executes f for all storage items matching the given `rng` (matching the given prefix and starting from the point specified). If the key or the value is to be used outside of f, they may not be copied. Seek continues iterating until false is returned from f. A requested prefix (if any non-empty) is trimmed before passing to f.

func (*Simple) SeekAsync added in v0.98.0

func (dao *Simple) SeekAsync(ctx context.Context, id int32, rng storage.SeekRange) chan storage.KeyValue

SeekAsync sends all storage items matching the given `rng` (matching the given prefix and starting from the point specified) to a channel and returns the channel. Resulting keys and values may not be copied.

func (*Simple) SeekNEP11TransferLog added in v0.98.1

func (dao *Simple) SeekNEP11TransferLog(acc util.Uint160, newestTimestamp uint64, f func(*state.NEP11Transfer) (bool, error)) error

SeekNEP11TransferLog executes f for each NEP-11 transfer in log starting from the transfer with the newest timestamp up to the oldest transfer. It continues iteration until false is returned from f. The last non-nil error is returned.

func (*Simple) SeekNEP17TransferLog added in v0.98.1

func (dao *Simple) SeekNEP17TransferLog(acc util.Uint160, newestTimestamp uint64, f func(*state.NEP17Transfer) (bool, error)) error

SeekNEP17TransferLog executes f for each NEP-17 transfer in log starting from the transfer with the newest timestamp up to the oldest transfer. It continues iteration until false is returned from f. The last non-nil error is returned.

func (*Simple) SetCache added in v0.99.0

func (dao *Simple) SetCache(id int32, v NativeContractCache)

SetCache adds native contract cache to the cache map.

func (*Simple) StoreAsBlock

func (dao *Simple) StoreAsBlock(block *block.Block, aer1 *state.AppExecResult, aer2 *state.AppExecResult) error

StoreAsBlock stores given block as DataBlock. It can reuse given buffer for the purpose of value serialization.

func (*Simple) StoreAsCurrentBlock

func (dao *Simple) StoreAsCurrentBlock(block *block.Block)

StoreAsCurrentBlock stores the hash of the given block with prefix SYSCurrentBlock.

func (*Simple) StoreAsTransaction

func (dao *Simple) StoreAsTransaction(tx *transaction.Transaction, index uint32, aer *state.AppExecResult) error

StoreAsTransaction stores the given TX as DataTransaction. It also stores conflict records (hashes of transactions the given tx has conflicts with) as DataTransaction with value containing only five bytes: 1-byte storage.ExecTransaction executable prefix + 4-bytes-LE block index. It can reuse the given buffer for the purpose of value serialization.

func (*Simple) StoreHeader added in v0.98.2

func (dao *Simple) StoreHeader(h *block.Header) error

StoreHeader saves the block header into the store.

func (*Simple) StoreHeaderHashes added in v0.98.2

func (dao *Simple) StoreHeaderHashes(hashes []util.Uint256, height uint32) error

StoreHeaderHashes pushes a batch of header hashes into the store.

type StateSyncCheckpoint added in v0.110.0

type StateSyncCheckpoint struct {
	// IntermediateRoot is a computed intermediate root of non-complete MPT
	// at the StateSyncCheckpoint.
	IntermediateRoot util.Uint256
	// Root is the actual state root at the StateSyncPoint.
	Root util.Uint256
	// Witness is the actual witness of state root at the StateSyncPoint, it
	// may be empty if the state object doesn't contain it.
	Witness transaction.Witness
	// LastStoredKey is the last processed storage key.
	LastStoredKey []byte
}

StateSyncCheckpoint stores the state of an interrupted contract storage state sync in ContractStorageBased mode.

func (*StateSyncCheckpoint) DecodeBinary added in v0.110.0

func (s *StateSyncCheckpoint) DecodeBinary(br *io.BinReader)

DecodeBinary decodes StateSyncCheckpoint from binary format.

func (*StateSyncCheckpoint) EncodeBinary added in v0.110.0

func (s *StateSyncCheckpoint) EncodeBinary(w *io.BinWriter)

EncodeBinary encodes StateSyncCheckpoint to binary format.

type Version added in v0.98.0

type Version struct {
	StoragePrefix              storage.KeyPrefix
	StateRootInHeader          bool
	P2PSigExtensions           bool
	P2PStateExchangeExtensions bool
	KeepOnlyLatestState        bool
	Magic                      uint32
	Value                      string
	SaveInvocations            bool
}

Version represents the current dao version.

func (*Version) Bytes added in v0.98.0

func (v *Version) Bytes() []byte

Bytes encodes v to a byte-slice.

func (*Version) FromBytes added in v0.98.0

func (v *Version) FromBytes(data []byte) error

FromBytes decodes v from a byte-slice.

Jump to

Keyboard shortcuts

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