smt

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2023 License: MIT Imports: 13 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"
)
View Source
const (
	GetSmtRoot        = "get_smt_root"
	DeleteSmt         = "delete_smt"
	UpdateMemorySmt   = "update_memory_smt"
	UpdateDbSmt       = "update_db_smt"
	UpdateDbSmtMiddle = "update_db_smt_middle"

	RetryNumber = 3
	RetryTime   = time.Second * 3
	TimeOut     = time.Second * 20
)

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 ToSmtH256 added in v1.0.1

func ToSmtH256(src string) 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 JsonRpcError added in v1.0.1

type JsonRpcError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

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 SmtKv added in v1.0.1

type SmtKv struct {
	Key   H256
	Value H256
}

type SmtKvHex added in v1.0.1

type SmtKvHex struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

type SmtOpt added in v1.0.1

type SmtOpt struct {
	GetProof bool `json:"get_proof"`
	GetRoot  bool `json:"get_root"`
}

type SmtServer added in v1.0.1

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

func NewSmtSrv added in v1.0.1

func NewSmtSrv(url, smtName string) *SmtServer

func (*SmtServer) DeleteSmt added in v1.0.1

func (s *SmtServer) DeleteSmt() (bool, error)

func (*SmtServer) DeleteSmtWithTimeOut added in v1.0.1

func (s *SmtServer) DeleteSmtWithTimeOut(timeout time.Duration) (bool, error)

func (*SmtServer) GetSmtRoot added in v1.0.1

func (s *SmtServer) GetSmtRoot() (H256, error)

func (*SmtServer) GetSmtUrl added in v1.0.1

func (s *SmtServer) GetSmtUrl() string

func (*SmtServer) UpdateMiddleSmt added in v1.0.1

func (s *SmtServer) UpdateMiddleSmt(kv []SmtKv, opt SmtOpt) (*UpdateMiddleSmtOut, error)

func (*SmtServer) UpdateSmt added in v1.0.1

func (s *SmtServer) UpdateSmt(kv []SmtKv, opt SmtOpt) (*UpdateSmtOut, 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)
}

type UpdateMiddleResult added in v1.0.1

type UpdateMiddleResult struct {
	Roots  map[string]string `json:"roots"`
	Proofs map[string]string `json:"proofs"`
}

type UpdateMiddleSmtOut added in v1.0.1

type UpdateMiddleSmtOut struct {
	Roots  map[string]H256   `json:"root"`
	Proofs map[string]string `json:"proofs"`
}

type UpdateResult added in v1.0.1

type UpdateResult struct {
	Root   string            `json:"root"`
	Proofs map[string]string `json:"proofs"`
}

type UpdateSmtOut added in v1.0.1

type UpdateSmtOut struct {
	Root   H256              `json:"root"`
	Proofs map[string]string `json:"proofs"`
}

type UpdateSmtParam added in v1.0.1

type UpdateSmtParam struct {
	Opt     SmtOpt     `json:"opt"`
	Data    []SmtKvHex `json:"data"`
	SmtName string     `json:"smt_name"`
}

Jump to

Keyboard shortcuts

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