smt

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ByteSize     = 8
	MaxU8        = 255
	MaxStackSize = 257
)
View Source
const (
	MergeNormal            byte = 1
	MergeZeros             byte = 2
	PersonSparseMerkleTree      = "ckb-default-hash"
)

Variables

View Source
var (
	StoreErrorNotExist = errors.New("not exist")
)

Functions

func Sha256

func Sha256(src string) []byte

func Verify

func Verify(root H256, proof *CompiledMerkleProof, keys, values []H256) (bool, error)

Types

type BranchKey

type BranchKey struct {
	Height  byte
	NodeKey H256
}

func (*BranchKey) GetHash

func (b *BranchKey) GetHash() string

type BranchNode

type BranchNode struct {
	Left  MergeValue `json:"l" bson:"l"`
	Right MergeValue `json:"r" bson:"r"`
}

type CompiledMerkleProof

type CompiledMerkleProof []byte

func (*CompiledMerkleProof) String

func (c *CompiledMerkleProof) String() string

type DefaultStore

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

func (*DefaultStore) GetBranch

func (d *DefaultStore) GetBranch(key BranchKey) (*BranchNode, error)

func (*DefaultStore) InsertBranch

func (d *DefaultStore) InsertBranch(key BranchKey, node BranchNode) error

func (*DefaultStore) RemoveBranch

func (d *DefaultStore) RemoveBranch(key BranchKey) error

func (*DefaultStore) Root

func (d *DefaultStore) Root() (H256, error)

func (*DefaultStore) UpdateRoot

func (d *DefaultStore) UpdateRoot(root H256) error

type H256

type H256 []byte

func AccountIdToSmtH256

func AccountIdToSmtH256(accountId string) H256

func H256Zero

func H256Zero() H256

func HashBaseNode

func HashBaseNode(height byte, baseKey, baseValue H256) H256

func (*H256) ClearBit

func (h *H256) ClearBit(height byte)

func (*H256) CopyBits

func (h *H256) CopyBits(height byte) *H256

func (*H256) CopyBits2

func (h *H256) CopyBits2(height byte) *H256

func (*H256) ForkHeight

func (h *H256) ForkHeight(key *H256) byte

func (*H256) GetBit

func (h *H256) GetBit(height byte) bool

func (*H256) IsRight

func (h *H256) IsRight(height byte) bool

func (*H256) IsZero

func (h *H256) IsZero() bool

func (*H256) ParentPath

func (h *H256) ParentPath(height byte) *H256

func (*H256) SetBit

func (h *H256) SetBit(height byte)

func (*H256) String

func (h *H256) String() string

type MergeValue

type MergeValue struct {
	Value     H256 `json:"v" bson:"v"`
	BaseNode  H256 `json:"n" bson:"n"`
	ZeroBits  H256 `json:"b" bson:"b"`
	ZeroCount byte `json:"c" bson:"c"`
}

func Merge

func Merge(height byte, nodeKey H256, lhs, rhs MergeValue) MergeValue

func MergeValueFromH256

func MergeValueFromH256(value H256) MergeValue

func MergeValueFromZero

func MergeValueFromZero() MergeValue

func MergeWithZero

func MergeWithZero(height byte, nodeKey H256, value MergeValue, setBit bool) MergeValue

func (*MergeValue) Hash

func (m *MergeValue) Hash() H256

func (*MergeValue) IsZero

func (m *MergeValue) IsZero() bool

func (*MergeValue) String

func (m *MergeValue) String() string

type MerkleProof

type MerkleProof struct {
	LeavesBitmap []H256
	MerklePath   []MergeValue
}

type MongodbRoot

type MongodbRoot struct {
	Root H256 `json:"r" bson:"r"`
}

type MongodbStore

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

func NewMongoStore

func NewMongoStore(ctx context.Context, client *mongo.Client, database, smtName string) *MongodbStore

func (*MongodbStore) Collection

func (m *MongodbStore) Collection() *mongo.Collection

func (*MongodbStore) GetBranch

func (m *MongodbStore) GetBranch(key BranchKey) (*BranchNode, error)

func (*MongodbStore) InsertBranch

func (m *MongodbStore) InsertBranch(key BranchKey, node BranchNode) error

func (*MongodbStore) RemoveBranch

func (m *MongodbStore) RemoveBranch(key BranchKey) error

func (*MongodbStore) Root

func (m *MongodbStore) Root() (H256, error)

func (*MongodbStore) UpdateRoot

func (m *MongodbStore) UpdateRoot(root H256) error

type SortH256

type SortH256 []H256

qsort

func (SortH256) Len

func (s SortH256) Len() int

func (SortH256) Less

func (s SortH256) Less(i, j int) bool

func (SortH256) Swap

func (s SortH256) Swap(i, j int)

type SparseMerkleTree

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

func NewSparseMerkleTree

func NewSparseMerkleTree(store Store) *SparseMerkleTree

func (*SparseMerkleTree) MerkleProof

func (s *SparseMerkleTree) MerkleProof(keys, values []H256) (*CompiledMerkleProof, error)

func (*SparseMerkleTree) Root

func (s *SparseMerkleTree) Root() (H256, error)

func (*SparseMerkleTree) Update

func (s *SparseMerkleTree) Update(key, value H256) error

type Store

type Store interface {
	GetBranch(key BranchKey) (*BranchNode, error)
	InsertBranch(key BranchKey, node BranchNode) error
	RemoveBranch(key BranchKey) error
	UpdateRoot(root H256) error
	Root() (H256, error)
}

Jump to

Keyboard shortcuts

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