core

package
v0.0.0-...-768c81a Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2024 License: MIT Imports: 9 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, txx []Transaction) *Block

func (*Block) AddTransaction

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

func (*Block) Decode

func (b *Block) Decode(dec Decoder[*Block]) error

func (*Block) Encode

func (b *Block) Encode(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 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(h 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 BlockHasher

type BlockHasher struct{}

func (BlockHasher) Hash

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

type BlockValidator

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

func (*BlockValidator) ValidateBlock

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

type Decoder

type Decoder[T any] interface {
	Decode(T) error
}

type Encoder

type Encoder[T any] interface {
	Encode(T) error
}

type GobTxDecoder

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

func NewGobTxDecoder

func NewGobTxDecoder(r io.Reader) *GobTxDecoder

func (*GobTxDecoder) Decode

func (en *GobTxDecoder) Decode(tx *Transaction) error

type GobTxEncoder

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

func NewGobTxEncoder

func NewGobTxEncoder(w io.Writer) *GobTxEncoder

func (*GobTxEncoder) Encode

func (en *GobTxEncoder) Encode(tx *Transaction) error

type Hasher

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

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
	// contains filtered or unexported fields
}

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) FirstSeen

func (t *Transaction) FirstSeen() int64

func (*Transaction) Hash

func (t *Transaction) Hash(hasher Hasher[*Transaction]) types.Hash

func (*Transaction) SetFirstSeen

func (t *Transaction) SetFirstSeen(time int64)

func (*Transaction) Sign

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

func (*Transaction) Verify

func (t *Transaction) Verify() error

type TxHasher

type TxHasher struct{}

func (TxHasher) Hash

func (TxHasher) Hash(tx *Transaction) types.Hash

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