core

package
v0.0.0-...-4f6389c Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2023 License: Apache-2.0 Imports: 10 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

	Transaction []Transaction
	Validator   crypto.PublicKey
	Signature   *crypto.Signature
	// contains filtered or unexported fields
}

func NewBlock

func NewBlock(h *Header, tx []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 BlockHasher

type BlockHasher struct{}

func (BlockHasher) Hash

func (BlockHasher) Hash(h *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) (err 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(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 (e *GobTxDecoder) Decode(tx *Transaction) error

type GobTxEncoder

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

func NewGotTxEncoder

func NewGotTxEncoder(w io.Writer) *GobTxEncoder

func (*GobTxEncoder) Encode

func (e *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     int64
	Height        uint32
	Nonce         uint64
}

func (*Header) Bytes

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

type MemoryStore

type MemoryStore struct{}

func NewMemoryStore

func NewMemoryStore() *MemoryStore

func (*MemoryStore) Put

func (m *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]) (err error)

func (*Transaction) Encode

func (tx *Transaction) Encode(dec Encoder[*Transaction]) (err error)

func (*Transaction) FirstSeen

func (tx *Transaction) FirstSeen() int64

func (*Transaction) Hash

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

func (*Transaction) SetFirstSeen

func (tx *Transaction) SetFirstSeen(t int64)

func (*Transaction) Sign

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

func (*Transaction) Verify

func (tx *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