Documentation ¶
Index ¶
- Constants
- func MarshalUnitData(u UnitData) ([]byte, error)
- func NewStateNodeCounter() *stateNodeCounter
- type Action
- type CRC32Reader
- type CRC32Writer
- type Header
- type Log
- type Option
- type Options
- type ShardState
- type State
- func (s *State) AddUnitLog(id types.UnitID, transactionRecordHash []byte) error
- func (s *State) Apply(actions ...Action) error
- func (s *State) CalculateRoot() (uint64, []byte, error)
- func (s *State) Clone() *State
- func (s *State) Commit(uc *types.UnicityCertificate) error
- func (s *State) CommittedUC() *types.UnicityCertificate
- func (s *State) CreateUnitStateProof(id types.UnitID, logIndex int) (*types.UnitStateProof, error)
- func (s *State) GetUnit(id types.UnitID, committed bool) (*Unit, error)
- func (s *State) HashAlgorithm() crypto.Hash
- func (s *State) IsCommitted() bool
- func (s *State) Prune() error
- func (s *State) ReleaseToSavepoint(id int)
- func (s *State) Revert()
- func (s *State) RollbackToSavepoint(id int)
- func (s *State) Savepoint() int
- func (s *State) Serialize(writer io.Writer, header *Header, committed bool) error
- func (s *State) Traverse(traverser avl.Traverser[types.UnitID, *Unit])
- type Unit
- type UnitData
- type UnitDataConstructor
- type UpdateFunction
Constants ¶
const CBORChecksumLength = 5
Variables ¶
This section is empty.
Functions ¶
func MarshalUnitData ¶
func NewStateNodeCounter ¶
func NewStateNodeCounter() *stateNodeCounter
Types ¶
type Action ¶
type Action func(s ShardState, hashAlgorithm crypto.Hash) error
func AddUnit ¶
func AddUnit(id types.UnitID, bearer predicates.PredicateBytes, data UnitData) Action
AddUnit adds a new unit with given identifier, owner condition, unit data.
func DeleteUnit ¶
DeleteUnit removes the unit from the state with given identifier.
func SetOwner ¶
func SetOwner(id types.UnitID, bearer predicates.PredicateBytes) Action
SetOwner changes the owner of the item, leaves data as is
func UpdateUnitData ¶
func UpdateUnitData(id types.UnitID, f UpdateFunction) Action
UpdateUnitData changes the data of the item, leaves owner as is.
type CRC32Reader ¶
type CRC32Reader struct {
// contains filtered or unexported fields
}
func NewCRC32Reader ¶
func NewCRC32Reader(reader io.Reader, checksumLength int) *CRC32Reader
func (*CRC32Reader) Read ¶
func (c *CRC32Reader) Read(p []byte) (n int, err error)
A hacky way to calculate the checksum of a data stream that has checksum appended to the end. Makes sure that the last checksumLength bytes are not included in the checksum calculation.
func (*CRC32Reader) Sum ¶
func (c *CRC32Reader) Sum() uint32
type CRC32Writer ¶
type CRC32Writer struct {
// contains filtered or unexported fields
}
func NewCRC32Writer ¶
func NewCRC32Writer(writer io.Writer) *CRC32Writer
func (*CRC32Writer) Sum ¶
func (c *CRC32Writer) Sum() uint32
type Header ¶
type Header struct { SystemIdentifier types.SystemID UnicityCertificate *types.UnicityCertificate NodeRecordCount uint64 // contains filtered or unexported fields }
type Log ¶
type Log struct { TxRecordHash []byte // the hash of the transaction record that brought the unit to the state described by given log entry. UnitLedgerHeadHash []byte // the new head hash of the unit ledger NewBearer predicates.PredicateBytes NewUnitData UnitData }
Log contains a state changes of the unit during the transaction execution.
type ShardState ¶
type State ¶
type State struct {
// contains filtered or unexported fields
}
State is a data structure that keeps track of units, unit ledgers, and calculates global state tree root hash.
State can be changed by calling Apply function with one or more Action function. Savepoint method can be used to add a special marker to the state that allows all actions that are executed after savepoint was established to be rolled back. In the other words, savepoint lets you roll back part of the state changes instead of the entire state. Releasing a savepoint does NOT trigger a state root hash calculation. To calculate the root hash of the state use method CalculateRoot. Calling a Commit method commits and releases all savepoints.
func NewEmptyState ¶
func NewRecoveredState ¶
func (*State) AddUnitLog ¶
func (*State) Apply ¶
Apply applies given actions to the state. All Action functions are executed together as a single atomic operation. If any of the Action functions returns an error all previous state changes made by any of the action function will be reverted.
func (*State) Clone ¶
Clone returns a clone of the state. The original state and the cloned state can be used by different goroutines but can never be merged. The cloned state is usually used by read only operations (e.g. unit proof generation).
func (*State) Commit ¶
func (s *State) Commit(uc *types.UnicityCertificate) error
Commit commits the changes in the latest savepoint.
func (*State) CommittedUC ¶
func (s *State) CommittedUC() *types.UnicityCertificate
CommittedUC returns the Unicity Certificate of the committed state.
func (*State) CreateUnitStateProof ¶
func (*State) HashAlgorithm ¶
func (*State) IsCommitted ¶
func (*State) ReleaseToSavepoint ¶
ReleaseToSavepoint destroys all savepoints, keeping all state changes after it was created. If a savepoint with given id does not exist then this method does nothing.
Releasing savepoints does NOT trigger a state root hash calculation. To calculate the root hash of the state a Commit method must be called.
func (*State) RollbackToSavepoint ¶
RollbackToSavepoint destroys savepoints without keeping the changes in the state tree. All actions that were executed after the savepoint was established are rolled back, restoring the state to what it was at the time of the savepoint.
func (*State) Savepoint ¶
Savepoint creates a new savepoint and returns an id of the savepoint. Use RollbackToSavepoint to roll back all changes made after calling Savepoint method. Use ReleaseToSavepoint to save all changes made to the state.
type Unit ¶
type Unit struct {
// contains filtered or unexported fields
}
Unit is a node in the state tree. It is used to build state tree and unit ledgers.
func NewUnit ¶
func NewUnit(bearer predicates.PredicateBytes, data UnitData) *Unit
func (*Unit) Bearer ¶
func (u *Unit) Bearer() predicates.PredicateBytes
type UnitData ¶
type UnitData interface { Write(hasher hash.Hash) error SummaryValueInput() uint64 Copy() UnitData }
UnitData is a generic data type for the unit state.
type UnitDataConstructor ¶
UnitDataConstructor is a function that constructs an empty UnitData structure based on UnitID
type UpdateFunction ¶
UpdateFunction is a function for updating the data of an item. Taken in previous UnitData and returns new UnitData.