store

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2025 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound  = errors.New("not found")
	ErrBadOffset = errors.New("offset is out of range")
)

Functions

This section is empty.

Types

type CommittedBlock

type CommittedBlock struct {
	BlockHash hash.Hash
	Height    uint32
	Data      []byte
	// contains filtered or unexported fields
}

func (*CommittedBlock) ToBlock

func (s *CommittedBlock) ToBlock() (*block.Block, error)

type CommittedTx

type CommittedTx struct {
	TxID      tx.ID
	Height    uint32
	BlockTime uint32
	Data      []byte
	// contains filtered or unexported fields
}

func (*CommittedTx) ToTx

func (s *CommittedTx) ToTx() (*tx.Tx, error)

type Config

type Config struct {
	Path          string `toml:"path"`
	RetentionDays uint32 `toml:"retention_days"`

	// Private configs
	TxCacheWindow      uint32                  `toml:"-"`
	SeedCacheWindow    uint32                  `toml:"-"`
	AccountCacheSize   int                     `toml:"-"`
	PublicKeyCacheSize int                     `toml:"-"`
	BannedAddrs        map[crypto.Address]bool `toml:"-"`
}

func DefaultConfig

func DefaultConfig() *Config

func (*Config) BasicCheck

func (conf *Config) BasicCheck() error

BasicCheck performs basic checks on the configuration.

func (*Config) DataPath

func (conf *Config) DataPath() string

func (*Config) RetentionBlocks

func (conf *Config) RetentionBlocks() uint32

func (*Config) StorePath

func (conf *Config) StorePath() string

type ConfigError

type ConfigError struct {
	Reason string
}

ConfigError is returned when the store configuration is invalid.

func (ConfigError) Error

func (e ConfigError) Error() string

type MockStore

type MockStore struct {
	Blocks     map[uint32]*block.Block
	Accounts   map[crypto.Address]*account.Account
	Validators map[crypto.Address]*validator.Validator
	LastCert   *certificate.Certificate
	LastHeight uint32
	// contains filtered or unexported fields
}

func MockingStore

func MockingStore(ts *testsuite.TestSuite) *MockStore

func (*MockStore) Account

func (m *MockStore) Account(addr crypto.Address) (*account.Account, error)

func (*MockStore) AccountByNumber

func (m *MockStore) AccountByNumber(number int32) (*account.Account, error)

func (*MockStore) ActiveValidators

func (m *MockStore) ActiveValidators() int32

func (*MockStore) AddTestAccount

func (m *MockStore) AddTestAccount(options ...func(*testsuite.AccountMaker)) (crypto.Address, *account.Account)

func (*MockStore) AddTestBlock

func (m *MockStore) AddTestBlock(height uint32) *block.Block

func (*MockStore) AddTestValidator

func (m *MockStore) AddTestValidator(options ...func(*testsuite.ValidatorMaker)) *validator.Validator

func (*MockStore) Block

func (m *MockStore) Block(height uint32) (*CommittedBlock, error)

func (*MockStore) BlockHash

func (m *MockStore) BlockHash(height uint32) hash.Hash

func (*MockStore) BlockHeight

func (m *MockStore) BlockHeight(h hash.Hash) uint32

func (*MockStore) Close

func (*MockStore) Close()

func (*MockStore) HasAccount

func (m *MockStore) HasAccount(addr crypto.Address) bool

func (*MockStore) HasAnyBlock

func (m *MockStore) HasAnyBlock() bool

func (*MockStore) HasPublicKey

func (m *MockStore) HasPublicKey(addr crypto.Address) bool

func (*MockStore) HasValidator

func (m *MockStore) HasValidator(addr crypto.Address) bool

func (*MockStore) IsBanned

func (*MockStore) IsBanned(_ crypto.Address) bool

func (*MockStore) IsPruned

func (*MockStore) IsPruned() bool

func (*MockStore) IterateAccounts

func (m *MockStore) IterateAccounts(consumer func(crypto.Address, *account.Account) (stop bool))

func (*MockStore) IterateValidators

func (m *MockStore) IterateValidators(consumer func(*validator.Validator) (stop bool))

func (*MockStore) LastCertificate

func (m *MockStore) LastCertificate() *certificate.Certificate

func (*MockStore) Prune

func (*MockStore) Prune(_ func(_ bool, _ uint32) bool) error

func (*MockStore) PruningHeight

func (*MockStore) PruningHeight() uint32

func (*MockStore) PublicKey

func (m *MockStore) PublicKey(addr crypto.Address) (crypto.PublicKey, error)

func (*MockStore) RandomTestAcc

func (m *MockStore) RandomTestAcc() (crypto.Address, *account.Account)

func (*MockStore) RandomTestVal

func (m *MockStore) RandomTestVal() *validator.Validator

func (*MockStore) RecentTransaction

func (m *MockStore) RecentTransaction(txID tx.ID) bool

func (*MockStore) SaveBlock

func (m *MockStore) SaveBlock(blk *block.Block, cert *certificate.Certificate)

func (*MockStore) SortitionSeed

func (m *MockStore) SortitionSeed(blockHeight uint32) *sortition.VerifiableSeed

func (*MockStore) TotalAccounts

func (m *MockStore) TotalAccounts() int32

func (*MockStore) TotalValidators

func (m *MockStore) TotalValidators() int32

func (*MockStore) Transaction

func (m *MockStore) Transaction(txID tx.ID) (*CommittedTx, error)

func (*MockStore) UpdateAccount

func (m *MockStore) UpdateAccount(addr crypto.Address, acc *account.Account)

func (*MockStore) UpdateValidator

func (m *MockStore) UpdateValidator(val *validator.Validator)

func (*MockStore) UpdateValidatorProtocolVersion

func (m *MockStore) UpdateValidatorProtocolVersion(addr crypto.Address, ver protocol.Version)

func (*MockStore) Validator

func (m *MockStore) Validator(addr crypto.Address) (*validator.Validator, error)

func (*MockStore) ValidatorAddresses

func (m *MockStore) ValidatorAddresses() []crypto.Address

func (*MockStore) ValidatorByNumber

func (m *MockStore) ValidatorByNumber(num int32) (*validator.Validator, error)

func (*MockStore) WriteBatch

func (*MockStore) WriteBatch() error

type PublicKeyNotFoundError

type PublicKeyNotFoundError struct {
	Address crypto.Address
}

PublicKeyNotFoundError is returned when the public key associated with an address is not found in the store.

func (PublicKeyNotFoundError) Error

func (e PublicKeyNotFoundError) Error() string

type Reader

type Reader interface {
	Block(height uint32) (*CommittedBlock, error)
	BlockHeight(h hash.Hash) uint32
	BlockHash(height uint32) hash.Hash
	SortitionSeed(blockHeight uint32) *sortition.VerifiableSeed
	Transaction(txID tx.ID) (*CommittedTx, error)
	RecentTransaction(txID tx.ID) bool
	PublicKey(addr crypto.Address) (crypto.PublicKey, error)
	HasPublicKey(addr crypto.Address) bool
	HasAccount(crypto.Address) bool
	Account(addr crypto.Address) (*account.Account, error)
	TotalAccounts() int32
	HasValidator(addr crypto.Address) bool
	ValidatorAddresses() []crypto.Address
	Validator(addr crypto.Address) (*validator.Validator, error)
	ValidatorByNumber(num int32) (*validator.Validator, error)
	IterateValidators(consumer func(*validator.Validator) (stop bool))
	IterateAccounts(consumer func(crypto.Address, *account.Account) (stop bool))
	TotalValidators() int32
	ActiveValidators() int32
	LastCertificate() *certificate.Certificate
	IsBanned(addr crypto.Address) bool
	IsPruned() bool
	PruningHeight() uint32
}

type Store

type Store interface {
	Reader

	UpdateAccount(addr crypto.Address, acc *account.Account)
	UpdateValidator(val *validator.Validator)
	UpdateValidatorProtocolVersion(addr crypto.Address, ver protocol.Version)
	SaveBlock(blk *block.Block, cert *certificate.Certificate)
	Prune(callback func(pruned bool, pruningHeight uint32) bool) error
	WriteBatch() error
	Close()
}

func NewStore

func NewStore(conf *Config) (Store, error)

Jump to

Keyboard shortcuts

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