mpt

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2023 License: MIT Imports: 14 Imported by: 2

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 DeserializeArgs added in v1.2.0

func DeserializeArgs(source []byte) ([]byte, []byte, *big.Int, error)

func FromNibbles

func FromNibbles(data []byte) []byte

func HashChildren added in v1.2.0

func HashChildren(v, hash []byte) []byte

func HashLeaf added in v1.2.0

func HashLeaf(value []byte) []byte

func MerkleProve added in v1.2.0

func MerkleProve(path, root []byte) ([]byte, error)

func ReadBytes added in v1.2.0

func ReadBytes(buffer []byte, offset int, count int) ([]byte, int, error)

func ReadUInt255 added in v1.2.0

func ReadUInt255(buffer []byte, offset int) (*big.Int, int, error)

func ReadVarBytes added in v1.2.0

func ReadVarBytes(buffer []byte, offset int) ([]byte, int, error)

func ReadVarUInt added in v1.2.0

func ReadVarUInt(buffer []byte, offset int) (uint64, int, error)

func ReadVarUInt16 added in v1.2.0

func ReadVarUInt16(buffer []byte, offset int) (uint64, int, error)

func ReadVarUInt32 added in v1.2.0

func ReadVarUInt32(buffer []byte, offset int) (uint64, int, error)

func ReadVarUInt64 added in v1.2.0

func ReadVarUInt64(buffer []byte, offset int) (uint64, int, error)

func ReadVarUInt8 added in v1.2.0

func ReadVarUInt8(buffer []byte, offset int) (uint64, int, error)

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 CrossChainTxParameter added in v1.2.0

type CrossChainTxParameter struct {
	TxHash       []byte // source chain tx hash, when FromChainID = 2 (eth), it's a key
	CrossChainID []byte
	FromContract []byte

	ToChainID  uint64
	ToContract []byte
	Method     []byte
	Args       []byte
}

func DeserializeCrossChainTxParameter added in v1.2.0

func DeserializeCrossChainTxParameter(source []byte, offset int) (*CrossChainTxParameter, error)

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 added in v0.3.3

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

func (*StateRoot) GetScriptHashesForVerifying added in v0.3.3

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

func (*StateRoot) GetSize added in v0.3.3

func (sr *StateRoot) GetSize() int

func (*StateRoot) GetWitnesses added in v0.3.3

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 added in v0.3.3

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

type ToMerkleValue added in v1.2.0

type ToMerkleValue struct {
	TxHash      []byte // poly chain tx hash
	FromChainID uint64
	TxParam     *CrossChainTxParameter
}

func DeserializeMerkleValue added in v1.2.0

func DeserializeMerkleValue(source []byte) (*ToMerkleValue, error)

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