blockdb

package
v0.0.0-...-9802667 Latest Latest
Warning

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

Go to latest
Published: May 27, 2018 License: Apache-2.0 Imports: 8 Imported by: 0

README

This stores blocks (and signatures)

  • stores blocks by hash
  • maintains an index of blocks
  • maintains an index of the unspent output set (or allowed calculation of the unspent output set from snapshots)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewErrUnspentNotExist

func NewErrUnspentNotExist(uxID string) error

NewErrUnspentNotExist creates ErrUnspentNotExist from a UxID

Types

type BlockSigs

type BlockSigs interface {
	AddWithTx(*bolt.Tx, cipher.SHA256, cipher.Sig) error
	Get(hash cipher.SHA256) (cipher.Sig, bool, error)
}

BlockSigs block signature storage

type BlockTree

type BlockTree interface {
	AddBlockWithTx(tx *bolt.Tx, b *coin.Block) error
	GetBlock(hash cipher.SHA256) *coin.Block
	GetBlockInDepth(dep uint64, filter func(hps []coin.HashPair) cipher.SHA256) *coin.Block
}

BlockTree block storage

type Blockchain

type Blockchain struct {
	sync.RWMutex // cache lock
	// contains filtered or unexported fields
}

Blockchain maintain the buckets for blockchain

func NewBlockchain

func NewBlockchain(db *bolt.DB, walker Walker) (*Blockchain, error)

NewBlockchain creates a new blockchain instance

func (*Blockchain) AddBlockWithTx

func (bc *Blockchain) AddBlockWithTx(tx *bolt.Tx, sb *coin.SignedBlock) error

AddBlockWithTx adds signed block

func (*Blockchain) GetBlockByHash

func (bc *Blockchain) GetBlockByHash(hash cipher.SHA256) (*coin.SignedBlock, error)

GetBlockByHash returns signed block of given hash

func (*Blockchain) GetBlockBySeq

func (bc *Blockchain) GetBlockBySeq(seq uint64) (*coin.SignedBlock, error)

GetBlockBySeq returns signed block of given seq

func (*Blockchain) GetGenesisBlock

func (bc *Blockchain) GetGenesisBlock() *coin.SignedBlock

GetGenesisBlock returns genesis block

func (*Blockchain) Head

func (bc *Blockchain) Head() (*coin.SignedBlock, error)

Head returns head block, returns error if no block does exist

func (*Blockchain) HeadSeq

func (bc *Blockchain) HeadSeq() uint64

HeadSeq returns the head block sequence

func (*Blockchain) Len

func (bc *Blockchain) Len() uint64

Len returns blockchain length

func (*Blockchain) UnspentPool

func (bc *Blockchain) UnspentPool() UnspentPool

UnspentPool returns the unspent pool

type ErrMissingSignature

type ErrMissingSignature struct {
	Seq  uint64
	Hash string
}

ErrMissingSignature is returned if no matching signature is found for a block in the db

func (ErrMissingSignature) Error

func (e ErrMissingSignature) Error() string

type ErrUnspentNotExist

type ErrUnspentNotExist struct {
	UxID string
}

ErrUnspentNotExist is returned if an unspent is not found in the pool

func (ErrUnspentNotExist) Error

func (e ErrUnspentNotExist) Error() string

type UnspentGetter

type UnspentGetter interface {
	// GetUnspentsOfAddrs returns all unspent outputs of given addresses
	GetUnspentsOfAddrs(addrs []cipher.Address) coin.AddressUxOuts
	Get(cipher.SHA256) (coin.UxOut, bool)
}

UnspentGetter provides unspend pool related querying methods

type UnspentPool

type UnspentPool interface {
	Len() uint64                          // Len returns the length of unspent outputs pool
	Get(cipher.SHA256) (coin.UxOut, bool) // Get returns outpus
	GetAll() (coin.UxArray, error)
	GetArray(hashes []cipher.SHA256) (coin.UxArray, error)
	GetUxHash() cipher.SHA256
	GetUnspentsOfAddrs(addrs []cipher.Address) coin.AddressUxOuts
	ProcessBlock(*coin.SignedBlock) bucket.TxHandler
	Contains(cipher.SHA256) bool
}

UnspentPool unspent outputs pool

type Unspents

type Unspents struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Unspents unspent outputs pool

func NewUnspentPool

func NewUnspentPool(db *bolt.DB) (*Unspents, error)

NewUnspentPool creates new unspent pool instance

func (*Unspents) Contains

func (up *Unspents) Contains(h cipher.SHA256) bool

Contains check if the hash of uxout does exist in the pool

func (*Unspents) Get

func (up *Unspents) Get(h cipher.SHA256) (coin.UxOut, bool)

Get returns the uxout value of given hash

func (*Unspents) GetAll

func (up *Unspents) GetAll() (coin.UxArray, error)

GetAll returns Pool as an array. Note: they are not in any particular order.

func (*Unspents) GetArray

func (up *Unspents) GetArray(hashes []cipher.SHA256) (coin.UxArray, error)

GetArray returns UxOut by given hash array, will return error when if any of the hashes do not exist. It MUST return this error, to prevent double spend attacks.

func (*Unspents) GetUnspentsOfAddrs

func (up *Unspents) GetUnspentsOfAddrs(addrs []cipher.Address) coin.AddressUxOuts

GetUnspentsOfAddrs returns unspent outputs map of given addresses, the address as return map key, unspent outputs as value.

func (*Unspents) GetUxHash

func (up *Unspents) GetUxHash() cipher.SHA256

GetUxHash returns unspent output checksum for the Block. Must be called after Block is fully initialized, and before its outputs are added to the unspent pool

func (*Unspents) Len

func (up *Unspents) Len() uint64

Len returns the unspent outputs num

func (*Unspents) ProcessBlock

func (up *Unspents) ProcessBlock(b *coin.SignedBlock) bucket.TxHandler

ProcessBlock updates the unspent pool based upon the published block

type Walker

type Walker func(hps []coin.HashPair) cipher.SHA256

Walker function for go through blockchain

Jump to

Keyboard shortcuts

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