kernel

package
v0.0.0-...-496aa91 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KeySize     = 1024 // num bits
	MempoolSize = 1000 // max num txs in mempool

	TXsSize     = 32   // num txs in block
	PayloadSize = 1024 // num bytes in tx.payload

	BlocksPath  = "blocks.db"
	TXsPath     = "txs.db"
	MempoolPath = "mempool.db"

	KeyHeight = "chain.blocks.height"
	KeyBlock  = "chain.blocks.block[%d]"
	KeyTX     = "chain.txs.tx[%X]"

	KeyMempoolHeight   = "chain.mempool.height"
	KeyMempoolTX       = "chain.mempool.tx[%X]"
	KeyMempoolPrefixTX = "chain.mempool.tx["
)

Variables

This section is empty.

Functions

func GetKeyBlock

func GetKeyBlock(height Height) []byte

func GetKeyHeight

func GetKeyHeight() []byte

func GetKeyMempoolHeight

func GetKeyMempoolHeight() []byte

func GetKeyMempoolTX

func GetKeyMempoolTX(hash Hash) []byte

func GetKeyTX

func GetKeyTX(hash Hash) []byte

Types

type Block

type Block interface {
	PrevHash() Hash
	Transactions() []Transaction

	Wrapper
	Hasher
}

func LoadBlock

func LoadBlock(blockBytes []byte) Block

func NewBlock

func NewBlock(prevHash []byte, txs []Transaction) Block

type BlockT

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

func (*BlockT) Bytes

func (block *BlockT) Bytes() []byte

func (*BlockT) Hash

func (block *BlockT) Hash() Hash

func (*BlockT) IsValid

func (block *BlockT) IsValid() bool

func (*BlockT) PrevHash

func (block *BlockT) PrevHash() Hash

func (*BlockT) String

func (block *BlockT) String() string

func (*BlockT) Transactions

func (block *BlockT) Transactions() []Transaction

type Chain

type Chain interface {
	Accept(Block) bool
	Merge(Height, []Transaction) bool
	Rollback(uint64) bool

	Height() Height
	TX(Hash) Transaction
	Block(Height) Block

	Mempool() Mempool
	Close()
}

func LoadChain

func LoadChain(path string) Chain

func NewChain

func NewChain(path string, genesis Block) Chain

type ChainT

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

func (*ChainT) Accept

func (chain *ChainT) Accept(block Block) bool

func (*ChainT) Block

func (chain *ChainT) Block(height Height) Block

func (*ChainT) Close

func (chain *ChainT) Close()

func (*ChainT) Height

func (chain *ChainT) Height() Height

func (*ChainT) Mempool

func (chain *ChainT) Mempool() Mempool

func (*ChainT) Merge

func (chain *ChainT) Merge(height Height, txs []Transaction) bool

func (*ChainT) Rollback

func (chain *ChainT) Rollback(ptr uint64) bool

func (*ChainT) TX

func (chain *ChainT) TX(hash Hash) Transaction

type Hash

type Hash []byte

type Hasher

type Hasher interface {
	Hash() Hash
	IsValid() bool
}

type Height

type Height uint64

type Iterator

type Iterator interface {
	Next() bool
	Key() []byte
	Value() []byte
	Close()
}

type IteratorT

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

func (*IteratorT) Close

func (iter *IteratorT) Close()

func (*IteratorT) Key

func (iter *IteratorT) Key() []byte

func (*IteratorT) Next

func (iter *IteratorT) Next() bool

func (*IteratorT) Value

func (iter *IteratorT) Value() []byte

type KeyValueDB

type KeyValueDB interface {
	Iter([]byte) Iterator
	Set([]byte, []byte)
	Get([]byte) []byte
	Del([]byte)
	Close()
}

func NewDB

func NewDB(path string) KeyValueDB

type KeyValueDBT

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

func (*KeyValueDBT) Close

func (db *KeyValueDBT) Close()

func (*KeyValueDBT) Del

func (db *KeyValueDBT) Del(key []byte)

func (*KeyValueDBT) Get

func (db *KeyValueDBT) Get(key []byte) []byte

func (*KeyValueDBT) Iter

func (db *KeyValueDBT) Iter(prefix []byte) Iterator

func (*KeyValueDBT) Set

func (db *KeyValueDBT) Set(key []byte, value []byte)

type Mempool

type Mempool interface {
	Height() Height
	TX(Hash) Transaction

	Push(Transaction)
	Pop() []Transaction

	Delete(Hash)
	Clear()
}

type MempoolT

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

func (*MempoolT) Clear

func (mempool *MempoolT) Clear()

func (*MempoolT) Delete

func (mempool *MempoolT) Delete(hash Hash)

func (*MempoolT) Height

func (mempool *MempoolT) Height() Height

func (*MempoolT) Pop

func (mempool *MempoolT) Pop() []Transaction

func (*MempoolT) Push

func (mempool *MempoolT) Push(tx Transaction)

func (*MempoolT) TX

func (mempool *MempoolT) TX(hash Hash) Transaction

type PrivKey

type PrivKey crypto.PrivKey

type PubKey

type PubKey crypto.PubKey

type Sign

type Sign []byte

type Signifier

type Signifier interface {
	Sign() Sign
	Validator() PubKey

	Hasher
}

type Transaction

type Transaction interface {
	PayLoad() []byte

	Wrapper
	Signifier
}

func LoadTransaction

func LoadTransaction(txbytes []byte) Transaction

func NewTransaction

func NewTransaction(priv PrivKey, payLoad []byte) Transaction

type TransactionT

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

func (*TransactionT) Bytes

func (tx *TransactionT) Bytes() []byte

func (*TransactionT) Hash

func (tx *TransactionT) Hash() Hash

func (*TransactionT) IsValid

func (tx *TransactionT) IsValid() bool

func (*TransactionT) PayLoad

func (tx *TransactionT) PayLoad() []byte

func (*TransactionT) Sign

func (tx *TransactionT) Sign() Sign

func (*TransactionT) String

func (tx *TransactionT) String() string

func (*TransactionT) Validator

func (tx *TransactionT) Validator() PubKey

type Wrapper

type Wrapper interface {
	Bytes() []byte
	String() string
}

Jump to

Keyboard shortcuts

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