datastore

package
v0.0.0-...-4b4fa20 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Hash

func Hash(data string) string

Hash generates a SHA-256 hash of the input data

Types

type BloomFilter

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

BloomFilter represents a Bloom filter for efficient data lookups

func NewBloomFilter

func NewBloomFilter(size int, hashFunctions int) *BloomFilter

NewBloomFilter creates a new Bloom filter

func (*BloomFilter) Add

func (bf *BloomFilter) Add(data string)

Add adds an item to the Bloom filter

func (*BloomFilter) Contains

func (bf *BloomFilter) Contains(data string) bool

Contains checks if an item might be in the Bloom filter

type DataStore

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

DataStore represents the key-value store with LevelDB and Redis

func NewDataStore

func NewDataStore(dbPath string, redisAddr string) (*DataStore, error)

NewDataStore initializes a new DataStore

func (*DataStore) Close

func (ds *DataStore) Close()

Close closes the database connections

func (*DataStore) GetAllKeys

func (ds *DataStore) GetAllKeys() ([]string, error)

GetAllKeys returns all keys in the database

func (*DataStore) GetAllTransactions

func (ds *DataStore) GetAllTransactions() ([]*protoc.Transaction, error)

func (*DataStore) GetDBPath

func (d *DataStore) GetDBPath() string

func (*DataStore) GetData

func (ds *DataStore) GetData(key string) (string, error)

GetData retrieves data from Redis cache or LevelDB

func (*DataStore) GetKeysByPrefix

func (ds *DataStore) GetKeysByPrefix(prefix string) ([]string, error)

GetKeysByPrefix returns all keys with a given prefix

func (*DataStore) GetMerkleRoot

func (ds *DataStore) GetMerkleRoot() string

GetMerkleRoot returns the root hash of the Merkle tree

func (*DataStore) StoreData

func (ds *DataStore) StoreData(key string, value string) error

StoreData stores data in LevelDB and Redis cache, and updates the Merkle tree

func (*DataStore) VerifyData

func (ds *DataStore) VerifyData(key string, value string) bool

VerifyData verifies if a key-value pair exists in the store

type MerkleNode

type MerkleNode struct {
	Hash  string
	Left  *MerkleNode
	Right *MerkleNode
	Data  string // Only leaf nodes have data
}

MerkleNode represents a node in the Merkle tree

func NewMerkleNode

func NewMerkleNode(left, right *MerkleNode, data string) *MerkleNode

NewMerkleNode creates a new Merkle node

type MerkleTree

type MerkleTree struct {
	Root *MerkleNode
	// contains filtered or unexported fields
}

MerkleTree represents a Merkle tree structure for data integrity validation

func NewMerkleTree

func NewMerkleTree() *MerkleTree

NewMerkleTree creates a new Merkle tree

func (*MerkleTree) AddLeaf

func (mt *MerkleTree) AddLeaf(data string) error

AddLeaf adds a new leaf node to the Merkle tree

func (*MerkleTree) GetRoot

func (mt *MerkleTree) GetRoot() string

GetRoot returns the root hash of the Merkle tree

func (*MerkleTree) VerifyData

func (mt *MerkleTree) VerifyData(data string) bool

VerifyData verifies if data exists in the Merkle tree

Jump to

Keyboard shortcuts

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