Documentation ¶
Overview ¶
Package store provides a storage implementation for the Nano block lattice.
Index ¶
- Constants
- Variables
- type AddressInfo
- type BadgerStore
- type BadgerStoreTxn
- func (t *BadgerStoreTxn) AddAddress(address nano.Address, info *AddressInfo) error
- func (t *BadgerStoreTxn) AddBlock(blk block.Block) error
- func (t *BadgerStoreTxn) AddFrontier(frontier *block.Frontier) error
- func (t *BadgerStoreTxn) AddPending(destination nano.Address, hash block.Hash, pending *Pending) error
- func (t *BadgerStoreTxn) AddRepresentation(address nano.Address, amount nano.Balance) error
- func (t *BadgerStoreTxn) AddUncheckedBlock(parentHash block.Hash, blk block.Block, kind UncheckedKind) error
- func (t *BadgerStoreTxn) CountBlocks() (uint64, error)
- func (t *BadgerStoreTxn) CountFrontiers() (uint64, error)
- func (t *BadgerStoreTxn) CountUncheckedBlocks() (uint64, error)
- func (t *BadgerStoreTxn) DeleteAddress(address nano.Address) error
- func (t *BadgerStoreTxn) DeleteBlock(hash block.Hash) error
- func (t *BadgerStoreTxn) DeleteFrontier(hash block.Hash) error
- func (t *BadgerStoreTxn) DeletePending(destination nano.Address, hash block.Hash) error
- func (t *BadgerStoreTxn) DeleteUncheckedBlock(parentHash block.Hash, kind UncheckedKind) error
- func (t *BadgerStoreTxn) Empty() (bool, error)
- func (t *BadgerStoreTxn) Flush() error
- func (t *BadgerStoreTxn) GetAddress(address nano.Address) (*AddressInfo, error)
- func (t *BadgerStoreTxn) GetBlock(hash block.Hash) (block.Block, error)
- func (t *BadgerStoreTxn) GetFrontier(hash block.Hash) (*block.Frontier, error)
- func (t *BadgerStoreTxn) GetFrontiers() ([]*block.Frontier, error)
- func (t *BadgerStoreTxn) GetPending(destination nano.Address, hash block.Hash) (*Pending, error)
- func (t *BadgerStoreTxn) GetRepresentation(address nano.Address) (nano.Balance, error)
- func (t *BadgerStoreTxn) GetUncheckedBlock(parentHash block.Hash, kind UncheckedKind) (block.Block, error)
- func (t *BadgerStoreTxn) HasAddress(address nano.Address) (bool, error)
- func (t *BadgerStoreTxn) HasBlock(hash block.Hash) (bool, error)
- func (t *BadgerStoreTxn) HasUncheckedBlock(hash block.Hash, kind UncheckedKind) (bool, error)
- func (t *BadgerStoreTxn) SubRepresentation(address nano.Address, amount nano.Balance) error
- func (t *BadgerStoreTxn) UpdateAddress(address nano.Address, info *AddressInfo) error
- func (t *BadgerStoreTxn) WalkUncheckedBlocks(visit UncheckedBlockWalkFunc) error
- type Ledger
- func (l *Ledger) AddBlock(blk block.Block) error
- func (l *Ledger) AddBlocks(blocks []block.Block) error
- func (l *Ledger) CountBlocks() (uint64, error)
- func (l *Ledger) CountUncheckedBlocks() (uint64, error)
- func (l *Ledger) GetBalance(address nano.Address) (nano.Balance, error)
- func (l *Ledger) GetFrontier(address nano.Address) (block.Hash, error)
- type LedgerOptions
- type Pending
- type PendingKey
- type Store
- type StoreTxn
- type UncheckedBlockWalkFunc
- type UncheckedKind
Constants ¶
const (
PendingKeySize = nano.AddressSize + block.HashSize
)
Variables ¶
var ( ErrBadWork = errors.New("bad work") ErrBadGenesis = errors.New("genesis block in store doesn't match the given block") ErrMissingPrevious = errors.New("previous block does not exist") ErrMissingSource = errors.New("source block does not exist") ErrUnchecked = errors.New("block was added to the unchecked list") ErrFork = errors.New("a fork was detected") ErrNotFound = errors.New("item not found in the store") )
var ( ErrBlockExists = errors.New("block already exists") ErrStoreEmpty = errors.New("the store is empty") )
Functions ¶
This section is empty.
Types ¶
type AddressInfo ¶
type AddressInfo struct { HeadBlock block.Hash RepBlock block.Hash OpenBlock block.Hash Balance nano.Balance }
func (*AddressInfo) MarshalBinary ¶
func (i *AddressInfo) MarshalBinary() ([]byte, error)
MarshalBinary implements the encoding.BinaryMarshaler interface.
func (*AddressInfo) UnmarshalBinary ¶
func (i *AddressInfo) UnmarshalBinary(data []byte) error
UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
type BadgerStore ¶
type BadgerStore struct {
// contains filtered or unexported fields
}
BadgerStore represents a Nano block lattice store backed by a badger database.
func NewBadgerStore ¶
func NewBadgerStore(dir string) (*BadgerStore, error)
NewBadgerStore initializes/opens a badger database in the given directory.
func (*BadgerStore) Purge ¶
func (s *BadgerStore) Purge() error
Purge purges any old/deleted keys from the database.
type BadgerStoreTxn ¶
type BadgerStoreTxn struct {
// contains filtered or unexported fields
}
func (*BadgerStoreTxn) AddAddress ¶
func (t *BadgerStoreTxn) AddAddress(address nano.Address, info *AddressInfo) error
func (*BadgerStoreTxn) AddBlock ¶
func (t *BadgerStoreTxn) AddBlock(blk block.Block) error
AddBlock adds the given block to the database.
func (*BadgerStoreTxn) AddFrontier ¶
func (t *BadgerStoreTxn) AddFrontier(frontier *block.Frontier) error
func (*BadgerStoreTxn) AddPending ¶
func (*BadgerStoreTxn) AddRepresentation ¶
func (*BadgerStoreTxn) AddUncheckedBlock ¶
func (t *BadgerStoreTxn) AddUncheckedBlock(parentHash block.Hash, blk block.Block, kind UncheckedKind) error
AddUncheckedBlock adds the given block to the database.
func (*BadgerStoreTxn) CountBlocks ¶
func (t *BadgerStoreTxn) CountBlocks() (uint64, error)
CountBlocks returns the total amount of blocks in the database.
func (*BadgerStoreTxn) CountFrontiers ¶
func (t *BadgerStoreTxn) CountFrontiers() (uint64, error)
func (*BadgerStoreTxn) CountUncheckedBlocks ¶
func (t *BadgerStoreTxn) CountUncheckedBlocks() (uint64, error)
func (*BadgerStoreTxn) DeleteAddress ¶
func (t *BadgerStoreTxn) DeleteAddress(address nano.Address) error
func (*BadgerStoreTxn) DeleteBlock ¶
func (t *BadgerStoreTxn) DeleteBlock(hash block.Hash) error
func (*BadgerStoreTxn) DeleteFrontier ¶
func (t *BadgerStoreTxn) DeleteFrontier(hash block.Hash) error
func (*BadgerStoreTxn) DeletePending ¶
func (*BadgerStoreTxn) DeleteUncheckedBlock ¶
func (t *BadgerStoreTxn) DeleteUncheckedBlock(parentHash block.Hash, kind UncheckedKind) error
func (*BadgerStoreTxn) Empty ¶
func (t *BadgerStoreTxn) Empty() (bool, error)
Empty reports whether the database is empty or not.
func (*BadgerStoreTxn) Flush ¶
func (t *BadgerStoreTxn) Flush() error
func (*BadgerStoreTxn) GetAddress ¶
func (t *BadgerStoreTxn) GetAddress(address nano.Address) (*AddressInfo, error)
func (*BadgerStoreTxn) GetBlock ¶
GetBlock retrieves the block with the given hash from the database.
func (*BadgerStoreTxn) GetFrontier ¶
func (*BadgerStoreTxn) GetFrontiers ¶
func (t *BadgerStoreTxn) GetFrontiers() ([]*block.Frontier, error)
func (*BadgerStoreTxn) GetPending ¶
func (*BadgerStoreTxn) GetRepresentation ¶
func (*BadgerStoreTxn) GetUncheckedBlock ¶
func (t *BadgerStoreTxn) GetUncheckedBlock(parentHash block.Hash, kind UncheckedKind) (block.Block, error)
GetUncheckedBlock retrieves the block with the given hash from the database.
func (*BadgerStoreTxn) HasAddress ¶
func (t *BadgerStoreTxn) HasAddress(address nano.Address) (bool, error)
func (*BadgerStoreTxn) HasBlock ¶
func (t *BadgerStoreTxn) HasBlock(hash block.Hash) (bool, error)
HasBlock reports whether the database contains a block with the given hash.
func (*BadgerStoreTxn) HasUncheckedBlock ¶
func (t *BadgerStoreTxn) HasUncheckedBlock(hash block.Hash, kind UncheckedKind) (bool, error)
HasUncheckedBlock reports whether the database contains a block with the given hash.
func (*BadgerStoreTxn) SubRepresentation ¶
func (*BadgerStoreTxn) UpdateAddress ¶
func (t *BadgerStoreTxn) UpdateAddress(address nano.Address, info *AddressInfo) error
func (*BadgerStoreTxn) WalkUncheckedBlocks ¶
func (t *BadgerStoreTxn) WalkUncheckedBlocks(visit UncheckedBlockWalkFunc) error
type Ledger ¶
type Ledger struct {
// contains filtered or unexported fields
}
func (*Ledger) CountBlocks ¶
func (*Ledger) CountUncheckedBlocks ¶
type LedgerOptions ¶
type Pending ¶
func (*Pending) MarshalBinary ¶
MarshalBinary implements the encoding.BinaryMarshaler interface.
func (*Pending) UnmarshalBinary ¶
UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
type PendingKey ¶
type PendingKey [PendingKeySize]byte
type Store ¶
type Store interface { Close() error Purge() error View(fn func(txn StoreTxn) error) error Update(fn func(txn StoreTxn) error) error }
Store is an interface that all Nano block lattice stores need to implement.
type StoreTxn ¶
type StoreTxn interface { Empty() (bool, error) Flush() error AddBlock(blk block.Block) error GetBlock(hash block.Hash) (block.Block, error) DeleteBlock(hash block.Hash) error HasBlock(hash block.Hash) (bool, error) CountBlocks() (uint64, error) AddUncheckedBlock(parentHash block.Hash, blk block.Block, kind UncheckedKind) error GetUncheckedBlock(parentHash block.Hash, kind UncheckedKind) (block.Block, error) DeleteUncheckedBlock(parentHash block.Hash, kind UncheckedKind) error HasUncheckedBlock(hash block.Hash, kind UncheckedKind) (bool, error) WalkUncheckedBlocks(visit UncheckedBlockWalkFunc) error CountUncheckedBlocks() (uint64, error) AddAddress(address nano.Address, info *AddressInfo) error GetAddress(address nano.Address) (*AddressInfo, error) UpdateAddress(address nano.Address, info *AddressInfo) error DeleteAddress(address nano.Address) error HasAddress(address nano.Address) (bool, error) AddFrontier(frontier *block.Frontier) error GetFrontier(hash block.Hash) (*block.Frontier, error) GetFrontiers() ([]*block.Frontier, error) DeleteFrontier(hash block.Hash) error CountFrontiers() (uint64, error) AddPending(destination nano.Address, hash block.Hash, pending *Pending) error GetPending(destination nano.Address, hash block.Hash) (*Pending, error) DeletePending(destination nano.Address, hash block.Hash) error AddRepresentation(address nano.Address, amount nano.Balance) error SubRepresentation(address nano.Address, amount nano.Balance) error GetRepresentation(address nano.Address) (nano.Balance, error) }
type UncheckedBlockWalkFunc ¶
type UncheckedBlockWalkFunc func(block block.Block, kind UncheckedKind) error
UncheckedBlockWalkFunc is the type of the function called for each unchecked block visited by WalkUncheckedBlocks.
type UncheckedKind ¶
type UncheckedKind byte
const ( UncheckedKindPrevious UncheckedKind = iota UncheckedKindSource )