core

package
v0.0.0-...-96774e6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 22, 2023 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Block

type Block struct {
	*Header
	Transactions []Transaction
	Validator    crypto.PublicKey
	Signature    *crypto.Signature
	// contains filtered or unexported fields
}

func NewBlock

func NewBlock(h *Header, txs []Transaction) *Block

func (*Block) AddTransaction

func (b *Block) AddTransaction(tx *Transaction)

func (*Block) Decode

func (b *Block) Decode(r io.Reader, dec Decoder[*Block]) error

func (*Block) Encode

func (b *Block) Encode(w io.Writer, enc Encoder[*Block]) error

func (*Block) Hash

func (b *Block) Hash(hasher Hasher[*Header]) types.Hash

func (*Block) Sign

func (b *Block) Sign(privKey crypto.PrivateKey) error

func (*Block) Verify

func (b *Block) Verify() error

type BlockHasher

type BlockHasher struct{}

func (BlockHasher) Hash

func (BlockHasher) Hash(b *Header) types.Hash

type BlockValidator

type BlockValidator struct {
	// contains filtered or unexported fields
}

func NewBlockValidator

func NewBlockValidator(bc *Blockchain) *BlockValidator

func (*BlockValidator) ValidateBlock

func (v *BlockValidator) ValidateBlock(b *Block) error

type Blockchain

type Blockchain struct {
	// contains filtered or unexported fields
}

func NewBlockchain

func NewBlockchain(genesis *Block) (*Blockchain, error)

func (*Blockchain) AddBlock

func (bc *Blockchain) AddBlock(b *Block) error

func (*Blockchain) GetHeader

func (bc *Blockchain) GetHeader(height uint32) (*Header, error)

func (*Blockchain) HasBlock

func (bc *Blockchain) HasBlock(height uint32) bool

func (*Blockchain) Height

func (bc *Blockchain) Height() uint32

func (*Blockchain) SetValidator

func (bc *Blockchain) SetValidator(v Validator)

type Decoder

type Decoder[T any] interface {
	Decode(io.Reader, T) error
}

type Encoder

type Encoder[T any] interface {
	Encode(io.Writer, T) error
}

type Hasher

type Hasher[T any] interface {
	Hash(T) types.Hash
}
type Header struct {
	Version       uint32
	PrevBlockHash types.Hash
	DataHash      types.Hash
	Height        uint32
	Timestamp     int64
}

func (*Header) Bytes

func (h *Header) Bytes() []byte

type MemoryStore

type MemoryStore struct {
}

func NewMemoryStore

func NewMemoryStore() *MemoryStore

func (*MemoryStore) Put

func (s *MemoryStore) Put(b *Block) error

type Storage

type Storage interface {
	Put(*Block) error
}

type Transaction

type Transaction struct {
	Data []byte

	From      crypto.PublicKey
	Signature *crypto.Signature
}

func (*Transaction) Sign

func (tx *Transaction) Sign(privKey crypto.PrivateKey) error

func (*Transaction) Verify

func (tx *Transaction) Verify() error

type Validator

type Validator interface {
	ValidateBlock(*Block) error
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL