store

package
v0.0.0-...-745f595 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2018 License: MIT Imports: 11 Imported by: 2

Documentation

Overview

Package store provides a storage implementation for the Nano block lattice.

Index

Constants

View Source
const (
	PendingKeySize = nano.AddressSize + block.HashSize
)

Variables

View Source
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")
)
View Source
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) Close

func (s *BadgerStore) Close() error

Close closes the database

func (*BadgerStore) Purge

func (s *BadgerStore) Purge() error

Purge purges any old/deleted keys from the database.

func (*BadgerStore) Update

func (s *BadgerStore) Update(fn func(txn StoreTxn) error) error

func (*BadgerStore) View

func (s *BadgerStore) View(fn func(txn StoreTxn) error) error

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 (t *BadgerStoreTxn) AddPending(destination nano.Address, hash block.Hash, pending *Pending) error

func (*BadgerStoreTxn) AddRepresentation

func (t *BadgerStoreTxn) AddRepresentation(address nano.Address, amount nano.Balance) error

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 (t *BadgerStoreTxn) DeletePending(destination nano.Address, hash block.Hash) error

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

func (t *BadgerStoreTxn) GetBlock(hash block.Hash) (block.Block, error)

GetBlock retrieves the block with the given hash from the database.

func (*BadgerStoreTxn) GetFrontier

func (t *BadgerStoreTxn) GetFrontier(hash block.Hash) (*block.Frontier, error)

func (*BadgerStoreTxn) GetFrontiers

func (t *BadgerStoreTxn) GetFrontiers() ([]*block.Frontier, error)

func (*BadgerStoreTxn) GetPending

func (t *BadgerStoreTxn) GetPending(destination nano.Address, hash block.Hash) (*Pending, error)

func (*BadgerStoreTxn) GetRepresentation

func (t *BadgerStoreTxn) GetRepresentation(address nano.Address) (nano.Balance, error)

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 (t *BadgerStoreTxn) SubRepresentation(address nano.Address, amount nano.Balance) error

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 NewLedger

func NewLedger(store Store, opts LedgerOptions) (*Ledger, error)

func (*Ledger) AddBlock

func (l *Ledger) AddBlock(blk block.Block) error

func (*Ledger) AddBlocks

func (l *Ledger) AddBlocks(blocks []block.Block) error

func (*Ledger) CountBlocks

func (l *Ledger) CountBlocks() (uint64, error)

func (*Ledger) CountUncheckedBlocks

func (l *Ledger) CountUncheckedBlocks() (uint64, error)

func (*Ledger) GetBalance

func (l *Ledger) GetBalance(address nano.Address) (nano.Balance, error)

func (*Ledger) GetFrontier

func (l *Ledger) GetFrontier(address nano.Address) (block.Hash, error)

type LedgerOptions

type LedgerOptions struct {
	Genesis genesis.Genesis
}

type Pending

type Pending struct {
	Address nano.Address
	Amount  nano.Balance
}

func (*Pending) MarshalBinary

func (p *Pending) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

func (*Pending) UnmarshalBinary

func (p *Pending) UnmarshalBinary(data []byte) error

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
)

Directories

Path Synopsis
Package genesis provides the genesis constants for the live Nano network.
Package genesis provides the genesis constants for the live Nano network.

Jump to

Keyboard shortcuts

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