Documentation ¶
Index ¶
- Variables
- func NewGenesisBlock(h hasher.Hasher) *bcpb.Block
- type BlockStorage
- type BlockValidator
- type Blockchain
- func (bc *Blockchain) Append(blk *bcpb.Block, txs []*bcpb.Tx) (bcpb.Digest, error)
- func (bc *Blockchain) Commit(id bcpb.Digest) error
- func (bc *Blockchain) Genesis() *bcpb.Block
- func (bc *Blockchain) GetTXO(txi *bcpb.TxInput) (*bcpb.TxOutput, error)
- func (bc *Blockchain) GetTXOByDataKey(key bcpb.DataKey) (*bcpb.TxOutput, error)
- func (bc *Blockchain) Hasher() hasher.Hasher
- func (bc *Blockchain) Last() *bcpb.Block
- func (bc *Blockchain) NewTxInput(key bcpb.DataKey) (*bcpb.TxInput, error)
- func (bc *Blockchain) SetBlockValidator(bv BlockValidator)
- func (bc *Blockchain) SetGenesis(genesis *bcpb.Block, txs []*bcpb.Tx) error
- func (bc *Blockchain) SetLastExec(digest bcpb.Digest) error
- type Config
- type DataKeyIndex
- type TxInputOutputValidator
- type TxStorage
Constants ¶
This section is empty.
Variables ¶
var ( // ErrPrevBlockMismatch is returned when a block references a previous // block that is not the actual previous block ErrPrevBlockMismatch = errors.New("previous block mismatch") )
Functions ¶
Types ¶
type BlockStorage ¶
type BlockStorage interface { // Get a block by its digest id Get(bcpb.Digest) (*bcpb.Block, error) // Returns the genesis block Genesis() (bcpb.Digest, *bcpb.Block) // Last block in the ledger Last() (bcpb.Digest, *bcpb.Block) // Get last executed LastExec() (bcpb.Digest, *bcpb.Block) // Sets the genesis block digest. It assumes the actual block is already in // in the store SetGenesis(bcpb.Digest) error // Set last block digest. It assumes the actual block is already in // in the store SetLast(bcpb.Digest) error // Sets the last executed block. It assumes the actual block is already in // in the store SetLastExec(bcpb.Digest) error // Returns true if the block by the given digest exists Exists(bcpb.Digest) bool // Adds a block to the ledger returning an error if it already exists Add(*bcpb.Block) (bcpb.Digest, error) // Iter iterates of each block in the ledger Iter(f stores.BlockIterator) error }
BlockStorage implements a store for ledger blocks
type BlockValidator ¶
type BlockValidator func(*bcpb.BlockHeader) error
BlockValidator is the validator function called to validate a block before signatures a verfified
type Blockchain ¶
type Blockchain struct {
// contains filtered or unexported fields
}
Blockchain is a blockchain instance that is able to perform all verification but does not include the consensus logic
func New ¶
func New(conf *Config) *Blockchain
New instantiates a new blockchain. By default block validation is disabled
func (*Blockchain) Append ¶
Append appends the block and txs to the ledger. The supplied transactions must be part of the block. This does not update the last block reference or index any of the txos
func (*Blockchain) Commit ¶
func (bc *Blockchain) Commit(id bcpb.Digest) error
Commit commits the block given by the id. It ensures it is the next in line i.e. the previous hash matches the current last block, sets the last block to the given id and indexes all transaction outputs in the block
func (*Blockchain) Genesis ¶
func (bc *Blockchain) Genesis() *bcpb.Block
Genesis returns the genesis block or nil if the blockchain has not been initialized
func (*Blockchain) GetTXO ¶
GetTXO returns the txo referenced by the TxInput. It returns an error if access is not authorized, any validation fails or is a base tx
func (*Blockchain) GetTXOByDataKey ¶
GetTXOByDataKey returns the TxOutput for the given key. It is the DataKey's last state
func (*Blockchain) Hasher ¶
func (bc *Blockchain) Hasher() hasher.Hasher
Hasher returns the configured hash function used by the block chain.
func (*Blockchain) Last ¶
func (bc *Blockchain) Last() *bcpb.Block
Last returns the last commited block in the chain
func (*Blockchain) NewTxInput ¶
NewTxInput returns a new TxInput for the given key to use in a tx
func (*Blockchain) SetBlockValidator ¶
func (bc *Blockchain) SetBlockValidator(bv BlockValidator)
SetBlockValidator sets the block validator function
func (*Blockchain) SetGenesis ¶
SetGenesis sets the genesis block and the associated transactions
func (*Blockchain) SetLastExec ¶
func (bc *Blockchain) SetLastExec(digest bcpb.Digest) error
SetLastExec marks the given digest as the last executed block
type Config ¶
type Config struct { // Hash function to use Hasher hasher.Hasher // Elliptic curve for verification Curve elliptic.Curve // These need to be specified by the user and are required BlockStorage BlockStorage TxStorage TxStorage DataKeyIndex DataKeyIndex }
Config holds the blockchain config
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns a config with the default hasher and elliptic curve
type DataKeyIndex ¶
type DataKeyIndex interface { Get(key bcpb.DataKey) (bcpb.Digest, int32, error) Set(key bcpb.DataKey, ref bcpb.Digest, idx int32) error Iter(prefix bcpb.DataKey, iter stores.DataKeyIterator) error }
DataKeyIndex is an index of DataKey to the txref and output index of all unspent outputs.
type TxInputOutputValidator ¶
TxInputOutputValidator validates a single input. It takes the referenced output and the associated input as arguments. TxOutput <- TxInput
type TxStorage ¶
type TxStorage interface { // Get a transaction Get(bcpb.Digest) (*bcpb.Tx, error) // Set a transaction Set(*bcpb.Tx) error // Set a batch of transactions SetBatch([]*bcpb.Tx) error // Iterate over all transactions Iter(func(bcpb.Tx) error) }
TxStorage implements a transaction store