mpt

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const BranchChildCount int = 17
View Source
const MaxKeyLength = (64 + 4) * 2
View Source
const MaxValueLength = 3 + 65535 + 1

Variables

This section is empty.

Functions

func FromNibbles

func FromNibbles(data []byte) []byte

func ResolveProof

func ResolveProof(proofBytes []byte) (id int, key []byte, proof [][]byte, err error)

ResolveProof get key and proofs from proofdata

func ToNibbles

func ToNibbles(data []byte) []byte

ToNibbles ..

func VerifyProof

func VerifyProof(root *helper.UInt256, id int, key []byte, proof [][]byte) ([]byte, error)

VerifyProof directly verify proof

Types

type IKVReadOnlyDb

type IKVReadOnlyDb interface {
	Get(key []byte) ([]byte, error)
}

IKVReadOnlyDb to store data

type Node

type Node struct {
	Reference int

	// BranchNode
	Children []Node

	// ExtensionNode
	Key  []byte
	Next *Node

	// LeafNode
	Value []byte
	// contains filtered or unexported fields
}

func NewBranchNode

func NewBranchNode() *Node

func NewExtensionNode

func NewExtensionNode(key []byte, next *Node) *Node

func NewHashNode

func NewHashNode(hash *helper.UInt256) *Node

func NewLeafNode

func NewLeafNode(value []byte) *Node

func NewNode

func NewNode() *Node

func (*Node) Deserialize

func (n *Node) Deserialize(br *io.BinaryReader)

func (*Node) GetHash

func (n *Node) GetHash() *helper.UInt256

func (*Node) GetNodeType

func (n *Node) GetNodeType() NodeType

func (*Node) IsEmpty

func (n *Node) IsEmpty() bool

func (*Node) Serialize

func (n *Node) Serialize(bw *io.BinaryWriter)

func (*Node) SerializeAsChild

func (n *Node) SerializeAsChild(bw *io.BinaryWriter)

func (*Node) SetDirty

func (n *Node) SetDirty()

func (*Node) Size

func (n *Node) Size() int

func (*Node) SizeAsChild

func (n *Node) SizeAsChild() int

func (*Node) ToArrayWithoutReference

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

type NodeType

type NodeType byte
const (
	BranchNode    NodeType = 0x00
	ExtensionNode NodeType = 0x01
	LeafNode      NodeType = 0x02
	HashNode      NodeType = 0x03
	Empty         NodeType = 0x04
)

type ProofDb

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

ProofDb a db to use for verify

func NewProofDb

func NewProofDb(proof [][]byte) *ProofDb

NewProofDb new instance of ProofDb from a string list

func (*ProofDb) Get

func (pd *ProofDb) Get(key []byte) ([]byte, error)

Get for TrieDb

type StateRoot

type StateRoot struct {
	Version   byte                `json:"version"`
	Index     uint32              `json:"index"`
	RootHash  string              `json:"roothash"`
	Witnesses []models.RpcWitness `json:"witnesses"`
}

StateRoot truct of StateRoot message

func (*StateRoot) Deserialize

func (sr *StateRoot) Deserialize(br *io.BinaryReader)

func (*StateRoot) DeserializeUnsigned

func (sr *StateRoot) DeserializeUnsigned(br *io.BinaryReader)

func (*StateRoot) GetHash

func (sr *StateRoot) GetHash() *helper.UInt256

func (*StateRoot) GetScriptHashesForVerifying

func (sr *StateRoot) GetScriptHashesForVerifying() []helper.UInt160

func (*StateRoot) GetSize

func (sr *StateRoot) GetSize() int

func (*StateRoot) GetWitnesses

func (sr *StateRoot) GetWitnesses() []tx.Witness

func (*StateRoot) Serialize

func (sr *StateRoot) Serialize(bw *io.BinaryWriter)

func (*StateRoot) SerializeUnsigned

func (sr *StateRoot) SerializeUnsigned(bw *io.BinaryWriter)

func (*StateRoot) SetWitnesses

func (sr *StateRoot) SetWitnesses(data []tx.Witness)

type Trie

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

Trie mpt tree

func NewTrie

func NewTrie(root *helper.UInt256, db IKVReadOnlyDb) (*Trie, error)

NewTrie new a trie instance

func (*Trie) Get

func (t *Trie) Get(key []byte) ([]byte, error)

Get try get value

Jump to

Keyboard shortcuts

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