Documentation ¶
Index ¶
- Constants
- Variables
- func BlockIDToContext(ctx context.Context, blockID BlockID) context.Context
- func GenesisRootBlockProvider(index slot.Index) *advancedset.AdvancedSet[BlockID]
- func IsEmptyBlockID(blockID BlockID) bool
- func WithBlock(alias string, block *Block) options.Option[TestFramework]
- func WithCommitment(cm *commitment.Commitment) options.Option[Block]
- func WithIssuer(issuer ed25519.PublicKey) options.Option[Block]
- func WithIssuingTime(issuingTime time.Time) options.Option[Block]
- func WithLatestConfirmedSlot(index slot.Index) options.Option[Block]
- func WithLikedInsteadParents(parents BlockIDs) options.Option[Block]
- func WithNonce(nonce uint64) options.Option[Block]
- func WithParents(parents ParentBlockIDs) options.Option[Block]
- func WithPayload(p payload.Payload) options.Option[Block]
- func WithSequenceNumber(sequenceNumber uint64) options.Option[Block]
- func WithSignature(signature ed25519.Signature) options.Option[Block]
- func WithStrongParents(parents BlockIDs) options.Option[Block]
- func WithVersion(version uint8) options.Option[Block]
- func WithWeakParents(parents BlockIDs) options.Option[Block]
- type Block
- func (b *Block) Commitment() *commitment.Commitment
- func (b *Block) ContentHash() (contentHash types.Identifier, err error)
- func (b *Block) DetermineID(slotTimeProvider *slot.TimeProvider, blockIdentifier ...types.Identifier) (err error)
- func (b *Block) ForEachParent(consumer func(parent Parent))
- func (b *Block) ForEachParentByType(parentType ParentsType, consumer func(parentBlockID BlockID) bool)
- func (b *Block) IssuerID() (issuerID identity.ID)
- func (b *Block) IssuerPublicKey() ed25519.PublicKey
- func (b *Block) IssuingTime() time.Time
- func (b *Block) LatestConfirmedSlot() slot.Index
- func (b *Block) Nonce() uint64
- func (b *Block) Parents() (parents []BlockID)
- func (b *Block) ParentsByType(parentType ParentsType) BlockIDs
- func (b *Block) ParentsCountByType(parentType ParentsType) uint8
- func (b *Block) Payload() payload.Payload
- func (b *Block) SequenceNumber() uint64
- func (b *Block) SetSignature(signature ed25519.Signature)
- func (b *Block) Sign(pair *ed25519.KeyPair) error
- func (b *Block) Signature() ed25519.Signature
- func (b *Block) Size() int
- func (b *Block) String() string
- func (b *Block) StrongParents() (strongParents []BlockID)
- func (b *Block) VerifySignature() (valid bool, err error)
- func (b *Block) Version() uint8
- func (b *Block) Work() int
- type BlockID
- func (b BlockID) Alias() (alias string)
- func (b BlockID) Base58() (base58Encoded string)
- func (b BlockID) Bytes() (serialized []byte, err error)
- func (b BlockID) CompareTo(other BlockID) int
- func (b *BlockID) DecodeJSON(val any) error
- func (b BlockID) EncodeJSON() (any, error)
- func (b *BlockID) FromBase58(base58EncodedString string) (err error)
- func (b *BlockID) FromBytes(serialized []byte) (consumedBytes int, err error)
- func (b *BlockID) FromRandomness(optionalSlot ...slot.Index) (err error)
- func (b BlockID) Index() slot.Index
- func (b BlockID) Length() int
- func (b BlockID) RegisterAlias(alias string)
- func (b BlockID) String() (humanReadable string)
- func (b BlockID) UnregisterAlias()
- type BlockIDs
- func (m BlockIDs) Add(blockID BlockID) BlockIDs
- func (m BlockIDs) AddAll(blockIDs BlockIDs) BlockIDs
- func (m BlockIDs) Base58() (result []string)
- func (m BlockIDs) Bytes() (serialized []byte, err error)
- func (m BlockIDs) Clone() (clonedBlockIDs BlockIDs)
- func (m BlockIDs) Contains(target BlockID) (contains bool)
- func (m BlockIDs) Empty() (empty bool)
- func (m BlockIDs) First() BlockID
- func (m BlockIDs) FromBytes(serialized []byte) (consumedBytes int, err error)
- func (m BlockIDs) Remove(blockID BlockID) BlockIDs
- func (m BlockIDs) RemoveAll(blockIDs BlockIDs) BlockIDs
- func (m BlockIDs) Slice() []BlockID
- func (m BlockIDs) String() string
- func (m BlockIDs) Subtract(other BlockIDs) BlockIDs
- type Parent
- type ParentBlockIDs
- func (p ParentBlockIDs) Add(parentType ParentsType, blockID BlockID) ParentBlockIDs
- func (p ParentBlockIDs) AddAll(parentType ParentsType, blockIDs BlockIDs) ParentBlockIDs
- func (p ParentBlockIDs) AddStrong(blockID BlockID) ParentBlockIDs
- func (p ParentBlockIDs) CleanupReferences()
- func (p ParentBlockIDs) Clone() ParentBlockIDs
- func (p ParentBlockIDs) ForEach(callback func(parent Parent))
- func (p ParentBlockIDs) IsEmpty() bool
- type ParentsType
- type TestFramework
- func (t *TestFramework) Block(alias string) (block *Block)
- func (t *TestFramework) BlockIDs(aliases ...string) (blockIDs BlockIDs)
- func (t *TestFramework) Blocks(aliases ...string) (blocks []*Block)
- func (t *TestFramework) CreateAndSignBlock(alias string, keyPair *ed25519.KeyPair, opts ...options.Option[Block]) (block *Block)
- func (t *TestFramework) CreateBlock(alias string, opts ...options.Option[Block]) (block *Block)
- func (t *TestFramework) SetBlock(alias string, block *Block)
Constants ¶
const ( // BlockVersion defines the Version of the block structure. BlockVersion uint8 = 1 // MaxBlockSize defines the maximum size of a block in bytes. MaxBlockSize = 64 * 1024 // MaxBlockWork defines the maximum work of a block. MaxBlockWork = 1 // BlockIDLength defines the length of an BlockID. BlockIDLength = types.IdentifierLength + 8 // MinParentsCount defines the minimum number of parents each parents block must have. MinParentsCount = 1 // MaxParentsCount defines the maximum number of parents each parents block must have. MaxParentsCount = 8 // MinParentsBlocksCount defines the minimum number of parents each parents block must have. MinParentsBlocksCount = 1 // MaxParentsBlocksCount defines the maximum number of parents each parents block must have. MaxParentsBlocksCount = 4 // MinStrongParentsCount defines the minimum number of strong parents a block must have. MinStrongParentsCount = 1 )
const BlockIDContextKey = "blockID"
const ( // LastValidBlockType counts StrongParents, WeakParents, ShallowLikeParents. LastValidBlockType = ShallowLikeParentType )
Variables ¶
var ( // ErrNoStrongParents is triggered if there no strong parents. ErrNoStrongParents = errors.New("missing strong blocks in first parent block") // ErrBlockTypeIsUnknown is triggered when the block type is unknown. ErrBlockTypeIsUnknown = errors.Errorf("block types must range from %d-%d", 1, LastValidBlockType) // ErrConflictingReferenceAcrossBlocks is triggered if there conflicting references across blocks. ErrConflictingReferenceAcrossBlocks = errors.New("different blocks have conflicting references") )
Functions ¶
func BlockIDToContext ¶
BlockIDToContext adds the BlockID to the given context.
func GenesisRootBlockProvider ¶
func GenesisRootBlockProvider(index slot.Index) *advancedset.AdvancedSet[BlockID]
func IsEmptyBlockID ¶
func WithCommitment ¶
func WithCommitment(cm *commitment.Commitment) options.Option[Block]
func WithParents ¶
func WithParents(parents ParentBlockIDs) options.Option[Block]
Types ¶
type Block ¶
type Block struct { model.Storable[BlockID, Block, *Block, block] `serix:"0"` // contains filtered or unexported fields }
Block represents the core block for the base layer Mesh.
func NewEmptyBlock ¶
func (*Block) Commitment ¶
func (b *Block) Commitment() *commitment.Commitment
Commitment returns the Commitment of the block.
func (*Block) ContentHash ¶
func (b *Block) ContentHash() (contentHash types.Identifier, err error)
func (*Block) DetermineID ¶
func (b *Block) DetermineID(slotTimeProvider *slot.TimeProvider, blockIdentifier ...types.Identifier) (err error)
DetermineID calculates and sets the block's BlockID and size.
func (*Block) ForEachParent ¶
ForEachParent executes a consumer func for each parent.
func (*Block) ForEachParentByType ¶
func (b *Block) ForEachParentByType(parentType ParentsType, consumer func(parentBlockID BlockID) bool)
ForEachParentByType executes a consumer func for each strong parent.
func (*Block) IssuerPublicKey ¶
IssuerPublicKey returns the public key of the block issuer.
func (*Block) IssuingTime ¶
IssuingTime returns the time when this block was created.
func (*Block) LatestConfirmedSlot ¶
LatestConfirmedSlot returns the LatestConfirmedSlot of the block.
func (*Block) ParentsByType ¶
func (b *Block) ParentsByType(parentType ParentsType) BlockIDs
ParentsByType returns a slice of all parents of the desired type.
func (*Block) ParentsCountByType ¶
func (b *Block) ParentsCountByType(parentType ParentsType) uint8
ParentsCountByType returns the total parents count of this block.
func (*Block) SequenceNumber ¶
SequenceNumber returns the sequence number of this block.
func (*Block) SetSignature ¶
func (*Block) StrongParents ¶
StrongParents returns a copy of the strong parents of the block.
func (*Block) VerifySignature ¶
VerifySignature verifies the Signature of the block.
type BlockID ¶
type BlockID struct { Identifier types.Identifier `serix:"0"` SlotIndex slot.Index `serix:"1"` }
BlockID identifies a block via its BLAKE2b-256 hash of its bytes.
var EmptyBlockID BlockID
EmptyBlockID is an empty id.
func BlockIDFromContext ¶
BlockIDFromContext returns the BlockID from the given context.
func DetermineID ¶
DetermineID calculates the block's BlockID.
func NewBlockID ¶
func NewBlockID(contentHash types.Identifier, signature ed25519.Signature, slotIndex slot.Index) BlockID
NewBlockID returns a new BlockID for the given data.
func (BlockID) Alias ¶
Alias returns the human-readable alias of the BlockID (or the base58 encoded bytes if no alias was set).
func (BlockID) CompareTo ¶
CompareTo does a lexicographical comparison to another blockID. Returns 0 if equal, -1 if smaller, or 1 if larger than other. Passing nil as other will result in a panic.
func (*BlockID) DecodeJSON ¶
func (BlockID) EncodeJSON ¶
func (*BlockID) FromBase58 ¶
FromBase58 un-serializes a BlockID from a base58 encoded string.
func (*BlockID) FromRandomness ¶
FromRandomness generates a random BlockID.
func (BlockID) RegisterAlias ¶
RegisterAlias allows to register a human-readable alias for the BlockID which will be used as a replacement for the String method.
func (BlockID) UnregisterAlias ¶
func (b BlockID) UnregisterAlias()
UnregisterAlias allows to unregister a previously registered alias.
type BlockIDs ¶
BlockIDs is a set of BlockIDs where every BlockID is stored only once.
func NewBlockIDs ¶
NewBlockIDs construct a new BlockID collection from the optional BlockIDs.
func (BlockIDs) Add ¶
Add adds a BlockID to the collection and returns the collection to enable chaining.
func (BlockIDs) AddAll ¶
AddAll adds all BlockIDs to the collection and returns the collection to enable chaining.
func (BlockIDs) First ¶
First returns the first element in BlockIDs (not ordered). This method only makes sense if there is exactly one element in the collection.
func (BlockIDs) Remove ¶
Remove removes a BlockID from the collection and returns the collection to enable chaining.
func (BlockIDs) RemoveAll ¶
RemoveAll removes the BlockIDs from the collection and returns the collection to enable chaining.
type Parent ¶
type Parent struct { ID BlockID Type ParentsType }
Parent is a parent that can be either strong or weak.
type ParentBlockIDs ¶
type ParentBlockIDs map[ParentsType]BlockIDs
ParentBlockIDs is a map of ParentType to BlockIDs.
func NewParentBlockIDs ¶
func NewParentBlockIDs() ParentBlockIDs
NewParentBlockIDs constructs a new ParentBlockIDs.
func (ParentBlockIDs) Add ¶
func (p ParentBlockIDs) Add(parentType ParentsType, blockID BlockID) ParentBlockIDs
Add adds a parent to the map.
func (ParentBlockIDs) AddAll ¶
func (p ParentBlockIDs) AddAll(parentType ParentsType, blockIDs BlockIDs) ParentBlockIDs
AddAll adds a collection of parents to the map.
func (ParentBlockIDs) AddStrong ¶
func (p ParentBlockIDs) AddStrong(blockID BlockID) ParentBlockIDs
AddStrong adds a strong parent to the map.
func (ParentBlockIDs) CleanupReferences ¶
func (p ParentBlockIDs) CleanupReferences()
func (ParentBlockIDs) Clone ¶
func (p ParentBlockIDs) Clone() ParentBlockIDs
Clone returns a copy of map.
func (ParentBlockIDs) ForEach ¶
func (p ParentBlockIDs) ForEach(callback func(parent Parent))
ForEach executes a consumer func for each parent.
func (ParentBlockIDs) IsEmpty ¶
func (p ParentBlockIDs) IsEmpty() bool
IsEmpty returns true if the ParentBlockIDs are empty.
type ParentsType ¶
type ParentsType uint8
ParentsType is a type that defines the type of the parent.
const ( // UndefinedParentType is the undefined parent. UndefinedParentType ParentsType = iota // StrongParentType is the ParentsType for a strong parent. StrongParentType // WeakParentType is the ParentsType for a weak parent. WeakParentType // ShallowLikeParentType is the ParentsType for the shallow like parent. ShallowLikeParentType )
func (ParentsType) String ¶
func (bp ParentsType) String() string
String returns string representation of ParentsType.
type TestFramework ¶
type TestFramework struct {
// contains filtered or unexported fields
}
func NewTestFramework ¶
func NewTestFramework(slotTimeProviderFunc func() *slot.TimeProvider, opts ...options.Option[TestFramework]) *TestFramework
NewTestFramework is the constructor of the TestFramework.
func (*TestFramework) Block ¶
func (t *TestFramework) Block(alias string) (block *Block)
Block retrieves the Blocks that is associated with the given alias.
func (*TestFramework) BlockIDs ¶
func (t *TestFramework) BlockIDs(aliases ...string) (blockIDs BlockIDs)
BlockIDs retrieves the Blocks that are associated with the given aliases.
func (*TestFramework) Blocks ¶
func (t *TestFramework) Blocks(aliases ...string) (blocks []*Block)
Blocks retrieves the Blocks that are associated with the give aliases.
func (*TestFramework) CreateAndSignBlock ¶
func (t *TestFramework) CreateAndSignBlock(alias string, keyPair *ed25519.KeyPair, opts ...options.Option[Block]) (block *Block)
CreateAndSignBlock creates a Block with the given alias and BlockTestFrameworkBlockOptions and signs it with the given keyPair.
func (*TestFramework) CreateBlock ¶
CreateBlock creates a Block with the given alias and BlockTestFrameworkBlockOptions.
func (*TestFramework) SetBlock ¶
func (t *TestFramework) SetBlock(alias string, block *Block)
SetBlock set a Block with the given alias.