Documentation ¶
Index ¶
- Constants
- Variables
- func BloomContains(b []byte, tx cid.Cid) (bool, error)
- func MakeBloom(tx []cid.Cid) ([]byte, error)
- type Block
- type BlockID
- type BlockState
- type GenesisInfo
- type MemStore
- func (m *MemStore) AllTx(ctx context.Context, b *Block) (map[tx.TxID]*tx.Tx, error)
- func (m *MemStore) ApplyGenesis(gen *GenesisInfo) error
- func (m *MemStore) ApplyTx(ctx context.Context, id tx.TxID, t *tx.Tx) error
- func (m *MemStore) Claims(_ context.Context, id string) ([]*tx.Tx, error)
- func (m *MemStore) CompleteTest(context.Context) error
- func (m *MemStore) DIDHistory(_ context.Context, id string) ([]*tx.Tx, error)
- func (m *MemStore) GetBlock(ctx context.Context, id BlockID) (*Block, error)
- func (m *MemStore) GetLastApplied(ctx context.Context) (*Block, error)
- func (m *MemStore) GetSet(ctx context.Context, id cid.Cid) (*TxSet, error)
- func (m *MemStore) GetTx(ctx context.Context, id tx.TxID) (*tx.Tx, error)
- func (m *MemStore) GetTxBlock(ctx context.Context, id tx.TxID) (*Block, error)
- func (m *MemStore) HasGenesisApplied() bool
- func (m *MemStore) LookupDID(_ context.Context, id string) (*w3cdid.Document, error)
- func (m *MemStore) MarkBlock(ctx context.Context, b BlockID, s BlockState) error
- func (m *MemStore) Node(ctx context.Context, id string) (*tx.Node, error)
- func (m *MemStore) Nodes() ([]string, error)
- func (m *MemStore) PutBlock(ctx context.Context, b *Block) (cid.Cid, error)
- func (m *MemStore) PutSet(ctx context.Context, txt *TxSet) (cid.Cid, error)
- func (m *MemStore) PutTx(ctx context.Context, tx *tx.Tx) (cid.Cid, error)
- func (m *MemStore) StartTest(context.Context) (Store, error)
- func (m *MemStore) Stop() error
- func (m *MemStore) UpdateLastApplied(_ context.Context, id BlockID) error
- type MetadataProvider
- type Store
- type TxSet
- type TxValidator
- type Validator
Constants ¶
const ( MaxBlockTxCount = 1000 MaxSetSize = 100 Version = 1 )
const ( BlockStateUnvalidated = iota BlockStateValidated BlockStateAccepted )
const ( CIDEncodingTx = 0x87 CIDEncodingBlock = 0x88 CIDEncodingSet = 0x89 )
Variables ¶
var ( ErrNotFound = errors.New("not found") ErrDIDAlreadyExists = errors.New("DID already exists") ErrDIDInvalid = errors.New("DID is invalid") ErrDIDInvalidSignature = errors.New("tx signature not signed by key in DID") ErrOpNotSupported = errors.New("operation not supported on tx type") ErrTxVersionNotSupported = errors.New("tx version not supported") ErrTxMissingTimestamp = errors.New("tx missing timestamp") ErrTxMissingFrom = errors.New("tx missing from did") ErrTxUnsupportedType = errors.New("unsupported tx type") ErrTxMissingData = errors.New("tx missing data") )
Functions ¶
func BloomContains ¶
BloomContains checks if the given bloom filter contains the CID
Types ¶
type Block ¶
type Block struct { Version uint32 `msgpack:"v"` ID BlockID `magpack:"i"` Parent BlockID `msgpack:"p"` Height uint64 `msgpack:"h"` CreatedAt int64 `msgpack:"t"` Proposer string `msgpack:"w"` Signature []byte `msgpack:"s"` Nonce [32]byte `msgpack:"n"` Bloom []byte `msgpack:"b"` TxRoot cid.Cid `msgpack:"x"` }
type BlockState ¶
type BlockState int
type GenesisInfo ¶
type GenesisInfo struct { ChainID string `msgpack:"chain"` Block Block `magpack:"block"` Txs []*tx.Tx `msgpack:"txs"` }
GenesisInfo provides enough information to be used as the genesis block of the block chain. It does not provide a TxSet assuming that the block definition stores the root of the CID Merkle Tree and the storage engine needs to check if the TXs aligns with the TxSet root when applying the TXs with a metadata store. A ChainID is also provided
type MemStore ¶
type MemStore struct {
// contains filtered or unexported fields
}
MemStore implements an in-memory store and metadata store primarily used for testing
func (*MemStore) ApplyGenesis ¶
func (m *MemStore) ApplyGenesis(gen *GenesisInfo) error
func (*MemStore) DIDHistory ¶
func (*MemStore) GetLastApplied ¶
func (*MemStore) GetTxBlock ¶
func (*MemStore) HasGenesisApplied ¶
type MetadataProvider ¶
type MetadataProvider interface { LookupDID(context.Context, string) (*w3cdid.Document, error) DIDHistory(context.Context, string) ([]*tx.Tx, error) Claims(context.Context, string) ([]*tx.Tx, error) //TODO(tcfw): vc type Nodes() ([]string, error) Node(context.Context, string) (*tx.Node, error) HasGenesisApplied() bool ApplyGenesis(*GenesisInfo) error ApplyTx(context.Context, tx.TxID, *tx.Tx) error StartTest(context.Context) (Store, error) CompleteTest(context.Context) error }
MetadataProvider provides indexes and metadata for TXs that have been successfully validates and applied in the block chain The information should be maintainable and rebuildable without a metadata store and should be used as a performance measure for reading blockchain records
type Store ¶
type Store interface { MetadataProvider PutTx(context.Context, *tx.Tx) (cid.Cid, error) GetTx(context.Context, tx.TxID) (*tx.Tx, error) PutBlock(context.Context, *Block) (cid.Cid, error) GetBlock(context.Context, BlockID) (*Block, error) AllTx(context.Context, *Block) (map[tx.TxID]*tx.Tx, error) PutSet(context.Context, *TxSet) (cid.Cid, error) GetSet(context.Context, cid.Cid) (*TxSet, error) GetTxBlock(context.Context, tx.TxID) (*Block, error) MarkBlock(context.Context, BlockID, BlockState) error UpdateLastApplied(context.Context, BlockID) error GetLastApplied(context.Context) (*Block, error) Stop() error }
Store provides a means of storing individual components in the blockchain such as blocks, tx, txsets and the like as well as storing the consensus state for persistance between node restarts
type TxSet ¶
type TxSet struct { Children []cid.Cid `msgpack:"c"` Tx *cid.Cid `msgpack:"t"` // contains filtered or unexported fields }
type TxValidator ¶
type TxValidator struct {
// contains filtered or unexported fields
}
func NewTxValidator ¶
func NewTxValidator(s Store) *TxValidator
func (*TxValidator) ApplyFromTip ¶
func (v *TxValidator) ApplyFromTip(ctx context.Context, id BlockID) error