rma

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: May 10, 2023 License: AGPL-3.0, ISC Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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")
)
View Source
var ErrUnitNotFound = goerrors.New("unit not found")

Functions

This section is empty.

Types

type Action added in v0.1.1

type Action func(tree *Tree) error

func AddItem added in v0.1.1

func AddItem(id *uint256.Int, owner Predicate, data UnitData, stateHash []byte) Action

AddItem adds new element to the state. Id must not exist in the state

func DeleteItem added in v0.1.1

func DeleteItem(id *uint256.Int) Action

DeleteItem removes the item from the state

func SetOwner added in v0.1.1

func SetOwner(id *uint256.Int, owner Predicate, stateHash []byte) Action

SetOwner changes the owner of the item, leaves data as is

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 Config

type Config struct {
	HashAlgorithm crypto.Hash // Mandatory, hash algorithm used for calculating the tree hash root and the proofs.
}

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 (n *Node) LeftChildHash() []byte

func (*Node) LeftChildSummary

func (n *Node) LeftChildSummary() SummaryValue

func (*Node) RightChildHash

func (n *Node) RightChildHash() []byte

func (*Node) RightChildSummary

func (n *Node) RightChildSummary() SummaryValue

func (*Node) String

func (n *Node) String() string

String returns a string representation of the node

type Predicate

type Predicate []byte

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 New

func New(config *Config) (*Tree, error)

New creates new RMA Tree

func (*Tree) AtomicUpdate added in v0.1.1

func (tree *Tree) AtomicUpdate(actions ...Action) error

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 *Tree) ContainsUncommittedChanges() bool

func (*Tree) ExtractCertificate

func (tree *Tree) ExtractCertificate(id *uint256.Int) (*certificate, error)

ExtractCertificate creates a RMA tree certificate.

func (*Tree) GetRootHash

func (tree *Tree) GetRootHash() []byte

GetRootHash starts computation of the tree and returns the root node hash value.

func (*Tree) GetUnit

func (tree *Tree) GetUnit(id *uint256.Int) (*Unit, error)

func (*Tree) Revert

func (tree *Tree) Revert()

Revert reverts all changes since the last Commit.

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 Unit

type Unit struct {
	Bearer    Predicate // The owner predicate of the Item/Node
	Data      UnitData  // The Data part of the Item/Node
	StateHash []byte    // The hash of the transaction and previous transaction. See spec 'Unit Ledger' for details.
}

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

type UpdateFunction func(data UnitData) (newData UnitData)

UpdateFunction is a function for updating the data of an item. Taken in previous UnitData and returns new UnitData.

Jump to

Keyboard shortcuts

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