Documentation
¶
Index ¶
- type Block
- func (b *Block) CalculateHash() ([]byte, error)
- func (b *Block) Clone() interfaces.Block
- func (b *Block) ComputeHash() ([]byte, error)
- func (b *Block) GetCachedHash() []byte
- func (b *Block) GetData() []byte
- func (b *Block) GetDifficulty() any
- func (b *Block) GetDifficultyUint64() uint64
- func (b *Block) GetHashAlgorithm() string
- func (b *Block) GetHashBytes() []byte
- func (b *Block) GetHashString() string
- func (b *Block) GetHashableBytes() ([]byte, error)
- func (b *Block) GetIndex() uint64
- func (b *Block) GetMetadata() map[string]any
- func (b *Block) GetNonce() uint64
- func (b *Block) GetPreviousHash() string
- func (b *Block) GetPreviousHashBytes() []byte
- func (b *Block) GetProof() []byte
- func (b *Block) GetProposer() string
- func (b *Block) GetSize() int
- func (b *Block) GetTimestamp() time.Time
- func (b *Block) GetTransactions() [][]byte
- func (b *Block) InvalidateCache()
- func (b *Block) IsValid() bool
- func (b *Block) Serialize() ([]byte, error)
- func (b *Block) SetData(data []byte)
- func (b *Block) SetDifficulty(difficulty any)
- func (b *Block) SetHashBytes(hash []byte)
- func (b *Block) SetHashFromBytes(hash []byte)
- func (b *Block) SetMetadata(metadata map[string]any)
- func (b *Block) SetNonce(nonce uint64)
- func (b *Block) SetProof(proof []byte)
- func (b *Block) SetProposer(proposer string)
- func (b *Block) Validate() error
- func (b *Block) Verify(hash []byte) (bool, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Block ¶
type Block struct {
Index uint64
Timestamp time.Time
Data []byte
PreviousHash []byte
Hash []byte
Nonce uint64
Difficulty uint64
Proposer string
Proof []byte
Metadata map[string]any
// contains filtered or unexported fields
}
Block represents a Proof of Work block
func (*Block) CalculateHash ¶
CalculateHash computes the block's hash based on its contents
func (*Block) ComputeHash ¶
ComputeHash calculates and returns the hash of the block
func (*Block) GetCachedHash ¶
GetCachedHash returns the cached hash if available
func (*Block) GetDifficulty ¶
GetDifficulty returns the mining difficulty as any
func (*Block) GetDifficultyUint64 ¶
GetDifficultyUint64 returns the mining difficulty as uint64
func (*Block) GetHashAlgorithm ¶
GetHashAlgorithm returns the preferred hash algorithm for this block
func (*Block) GetHashBytes ¶
GetHashBytes returns the hash as bytes
func (*Block) GetHashString ¶
GetHashString is a helper method to get hash as hex string (not from interface)
func (*Block) GetHashableBytes ¶
GetHashableBytes returns the byte representation for hashing
func (*Block) GetMetadata ¶
GetMetadata returns additional block metadata
func (*Block) GetPreviousHash ¶
GetPreviousHash returns the previous block's hash as hex string
func (*Block) GetPreviousHashBytes ¶
GetPreviousHashBytes returns the previous hash as bytes
func (*Block) GetProposer ¶
GetProposer returns who proposed this block
func (*Block) GetTimestamp ¶
GetTimestamp returns when the block was created
func (*Block) GetTransactions ¶
GetTransactions returns the transactions in the block
func (*Block) InvalidateCache ¶
func (b *Block) InvalidateCache()
InvalidateCache clears the cached hash value
func (*Block) SetDifficulty ¶
SetDifficulty sets the mining difficulty from any
func (*Block) SetHashBytes ¶
SetHashBytes sets the hash directly from bytes
func (*Block) SetHashFromBytes ¶
SetHashBytes sets the block's hash directly from bytes (not from interface) This is useful when loading blocks from storage
func (*Block) SetMetadata ¶
SetMetadata sets additional block metadata
func (*Block) SetProposer ¶
SetProposer sets who proposed this block