Documentation ¶
Index ¶
- func CalculateDataHash(txx []Transaction) (hash types.Hash, err error)
- type Block
- type BlockChain
- type BlockHasher
- type BlockValidator
- type Decoder
- type Encoder
- type GobTxDecoder
- type GobTxEncoder
- type Hasher
- type Header
- type MemoryStore
- type Storage
- type Transaction
- func (tx *Transaction) Decode(dec Decoder[*Transaction]) error
- func (tx *Transaction) Encode(enc Encoder[*Transaction]) error
- func (tx *Transaction) GetFirstSeen() int64
- func (tx *Transaction) Hash(h Hasher[*Transaction]) types.Hash
- func (tx *Transaction) SetFirstSeen(t int64)
- func (tx *Transaction) Sign(privKey crypto.PrivateKey) error
- func (tx *Transaction) Verify() error
- type TxHasher
- type Validator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CalculateDataHash ¶
func CalculateDataHash(txx []Transaction) (hash types.Hash, err error)
Types ¶
type Block ¶
type Block struct { *Header Transactions []Transaction Validator crypto.PublicKey Signature *crypto.Signature // contains filtered or unexported fields }
Hold the transactions and the header information
func NewBlockFromHeader ¶
func NewBlockFromHeader(prevHeader *Header, txx []Transaction) (*Block, error)
func (*Block) AddTransaction ¶
func (b *Block) AddTransaction(tx *Transaction)
type BlockChain ¶
func NewBlockChain ¶
func NewBlockChain(genesis *Block) (*BlockChain, error)
func (*BlockChain) AddBlock ¶
func (bc *BlockChain) AddBlock(b *Block) error
func (*BlockChain) HasBlock ¶
func (bc *BlockChain) HasBlock(heigh uint32) bool
func (*BlockChain) SetValidator ¶
func (bc *BlockChain) SetValidator(v Validator)
type BlockHasher ¶
type BlockHasher struct{}
type BlockValidator ¶
type BlockValidator struct {
Bc *BlockChain
}
func NewBlockValidator ¶
func NewBlockValidator(bc *BlockChain) *BlockValidator
func (*BlockValidator) ValidateBlock ¶
func (v *BlockValidator) ValidateBlock(b *Block) error
type GobTxDecoder ¶
func NewGobDecoder ¶
func NewGobDecoder(r io.Reader) *GobTxDecoder
func (*GobTxDecoder) Decode ¶
func (d *GobTxDecoder) Decode(tx *Transaction) error
type GobTxEncoder ¶
func NewGobEncoder ¶
func NewGobEncoder(w io.Writer) *GobTxEncoder
func (*GobTxEncoder) Encode ¶
func (e *GobTxEncoder) Encode(tx *Transaction) error
type Header ¶
type Header struct { Version uint32 PrevBlockHash types.Hash Timestamp uint64 Height uint32 DataHash types.Hash }
To save space we just hash the header
type MemoryStore ¶
type MemoryStore struct{}
func NewMemStore ¶
func NewMemStore() *MemoryStore
func (*MemoryStore) Put ¶
func (ms *MemoryStore) Put(b *Block) error
type Transaction ¶
type Transaction struct { Data []byte From crypto.PublicKey Signature *crypto.Signature //cached version of tx data hash CacheHash types.Hash // firstSeen is the tmiestamp of when this tx is first seen localy FirstSeen int64 }
func NewTransaction ¶
func NewTransaction(data []byte) *Transaction
func (*Transaction) Decode ¶
func (tx *Transaction) Decode(dec Decoder[*Transaction]) error
func (*Transaction) Encode ¶
func (tx *Transaction) Encode(enc Encoder[*Transaction]) error
func (*Transaction) Hash ¶
func (tx *Transaction) Hash(h Hasher[*Transaction]) types.Hash
func (*Transaction) Sign ¶
func (tx *Transaction) Sign(privKey crypto.PrivateKey) error
func (*Transaction) Verify ¶
func (tx *Transaction) Verify() error
Click to show internal directories.
Click to hide internal directories.