core

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 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 {
	Height       uint64
	Timestamp    time.Time
	PreviousHash types.Hash
	Transactions []types.Transaction
	StateRoot    types.Hash
	ValidatorSet []types.ValidatorAddress
	Signature    []byte
	Hash         types.Hash
}

func NewBlock

func NewBlock(height uint64, previousHash types.Hash, transactions []types.Transaction) *Block

func (*Block) CalculateHash

func (b *Block) CalculateHash() types.Hash

func (*Block) Decode

func (b *Block) Decode(data []byte) error

func (*Block) Encode

func (b *Block) Encode() ([]byte, error)

func (*Block) GetHeader

func (b *Block) GetHeader() BlockHeader

func (*Block) Sign

func (b *Block) Sign(privKey []byte) error

func (*Block) Size

func (b *Block) Size() uint64

func (*Block) Verify

func (b *Block) Verify() error

type BlockHeader

type BlockHeader struct {
	Height        uint64
	Timestamp     time.Time
	PreviousHash  types.Hash
	TxRoot        types.Hash
	StateRoot     types.Hash
	ValidatorRoot types.Hash
}

type Chain

type Chain struct {
	ID string
	// contains filtered or unexported fields
}

func NewChain

func NewChain(id string, store store.BlockStore, params ConsensusParams) *Chain

func (*Chain) AddBlock

func (c *Chain) AddBlock(block *Block) error

func (*Chain) AddTransaction

func (c *Chain) AddTransaction(tx types.Transaction) error

func (*Chain) GetBlock

func (c *Chain) GetBlock(height uint64) (*Block, error)

func (*Chain) GetHeight

func (c *Chain) GetHeight() uint64

func (*Chain) GetTransaction

func (c *Chain) GetTransaction(hash types.Hash) (*types.Transaction, error)

func (*Chain) Start

func (c *Chain) Start(ctx context.Context) error

type ConsensusParams

type ConsensusParams struct {
	BlockInterval   time.Duration
	MaxBlockSize    uint64
	MaxTxsPerBlock  uint64
	ValidatorQuorum float64
}

type CrossChainData

type CrossChainData struct {
	SourceHeight uint64
	SourceHash   types.Hash
	DestHeight   uint64
	ProofData    []byte
}

type Transaction

type Transaction struct {
	Version     uint32
	SourceChain string
	DestChain   string
	Nonce       uint64
	From        types.Address
	To          types.Address
	Amount      uint64
	Gas         uint64
	GasPrice    uint64
	Data        []byte
	Timestamp   time.Time
	Signature   []byte
}

func NewTransaction

func NewTransaction(
	from types.Address,
	to types.Address,
	amount uint64,
	nonce uint64,
	sourceChain string,
	destChain string,
) *Transaction

func (*Transaction) Decode

func (tx *Transaction) Decode(data []byte) error

func (*Transaction) Encode

func (tx *Transaction) Encode() ([]byte, error)

func (*Transaction) GasCost

func (tx *Transaction) GasCost() uint64

func (*Transaction) Hash

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

func (*Transaction) Sign

func (tx *Transaction) Sign(privateKey []byte) error

func (*Transaction) TotalCost

func (tx *Transaction) TotalCost() uint64

func (*Transaction) Verify

func (tx *Transaction) Verify() error

type TxPool

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

func NewTxPool

func NewTxPool(maxSize uint64) *TxPool

func (*TxPool) Add

func (p *TxPool) Add(tx types.Transaction) error

func (*TxPool) GetPending

func (p *TxPool) GetPending(limit uint64) []types.Transaction

func (*TxPool) Remove

func (p *TxPool) Remove(hash types.Hash)

Jump to

Keyboard shortcuts

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