Documentation ¶
Index ¶
- Variables
- type Action
- type Config
- type Node
- type Predicate
- type SummaryValue
- type Tree
- func (tree *Tree) AtomicUpdate(actions ...Action) error
- func (tree *Tree) Commit()
- func (tree *Tree) ContainsUncommittedChanges() bool
- func (tree *Tree) ExtractCertificate(id *uint256.Int) (*certificate, error)
- func (tree *Tree) GetRootHash() []byte
- func (tree *Tree) GetUnit(id *uint256.Int) (*Unit, error)
- func (tree *Tree) Revert()
- func (tree *Tree) TotalValue() SummaryValue
- type Uint64SummaryValue
- type Unit
- type UnitData
- type UpdateFunction
Constants ¶
This section is empty.
Variables ¶
var ( ZeroIdentifier = uint256.NewInt(0) ErrIdIsNil = errors.New("id is nil") ErrZIsNil = errors.New("z is nil") ErrSummaryValueIsNil = errors.New("summary value is nil") ErrRootNodeIsNil = errors.New("root is nil") ErrRootNotCalculated = errors.New("root not calculated") ErrInvalidCertificate = errors.New("invalid certificate") )
var ErrUnitNotFound = goerrors.New("unit not found")
Functions ¶
This section is empty.
Types ¶
type Action ¶ added in v0.1.1
func AddItem ¶ added in v0.1.1
AddItem adds new element to the state. Id must not exist in the state
func DeleteItem ¶ added in v0.1.1
DeleteItem removes the item from the state
func UpdateData ¶ added in v0.1.1
func UpdateData(id *uint256.Int, f UpdateFunction, stateHash []byte) Action
UpdateData changes the data of the item, leaves owner as is.
type Node ¶
type Node struct { ID *uint256.Int // The identifier of the Item/Node Content *Unit // Content that moves together with Node SummaryValue SummaryValue // Calculated SummaryValue of the Item/Node Hash []byte // The hash of the node inside the tree. See spec 'State Invariants and Parameters' for details. Parent *Node // The parent node Children [2]*Node // The children (0 - left, 1 - right) // contains filtered or unexported fields }
func (*Node) LeftChildHash ¶
func (*Node) LeftChildSummary ¶
func (n *Node) LeftChildSummary() SummaryValue
func (*Node) RightChildHash ¶
func (*Node) RightChildSummary ¶
func (n *Node) RightChildSummary() SummaryValue
type SummaryValue ¶
type SummaryValue interface { // AddToHasher adds the value of summary value to the hasher. AddToHasher(hasher hash.Hash) // Concatenate calculates new SummaryValue by concatenating this, left and right. Concatenate(left, right SummaryValue) SummaryValue // Bytes returns bytes of the SummaryValue Bytes() []byte }
SummaryValue is different from UnitData. It is derived from UnitData with UnitData.Value function.
type Tree ¶
type Tree struct {
// contains filtered or unexported fields
}
Tree Revertible Merkle AVL Tree. Holds any type of units. Changes can be reverted, tree is balanced in AVL tree manner and Merkle proofs can be generated.
func (*Tree) AtomicUpdate ¶ added in v0.1.1
AtomicUpdate applies changes to the state tree. If any of the change functions returns an error all of them will be rolled back
func (*Tree) Commit ¶
func (tree *Tree) Commit()
Commit commits the changes, making these not revertible. Changes done before the Commit cannot be reverted anymore. Changes done after the last Commit can be reverted by Revert method.
func (*Tree) ContainsUncommittedChanges ¶
func (*Tree) ExtractCertificate ¶
ExtractCertificate creates a RMA tree certificate.
func (*Tree) GetRootHash ¶
GetRootHash starts computation of the tree and returns the root node hash value.
func (*Tree) TotalValue ¶
func (tree *Tree) TotalValue() SummaryValue
TotalValue starts computation of the tree and returns the SummaryValue of the root node.
type Uint64SummaryValue ¶
type Uint64SummaryValue uint64
func (Uint64SummaryValue) AddToHasher ¶
func (t Uint64SummaryValue) AddToHasher(hasher hash.Hash)
func (Uint64SummaryValue) Bytes ¶
func (t Uint64SummaryValue) Bytes() []byte
func (Uint64SummaryValue) Concatenate ¶
func (t Uint64SummaryValue) Concatenate(left, right SummaryValue) SummaryValue
func (Uint64SummaryValue) Value ¶
func (t Uint64SummaryValue) Value() uint64
type UnitData ¶
type UnitData interface { // AddToHasher adds the unit data to the hasher. AddToHasher(hasher hash.Hash) // Value returns the SummaryValue of this single UnitData. Value() SummaryValue }
UnitData is generic datatype for the tree. Is connected to SummaryValue through the Value function.
type UpdateFunction ¶
UpdateFunction is a function for updating the data of an item. Taken in previous UnitData and returns new UnitData.