core

package
v0.0.0-...-7cc22e0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BlockMaxTransactions = 4
)

Variables

This section is empty.

Functions

func MinerReward

func MinerReward(miner types.Address, amount int) *types.Transaction

func NewValidator

func NewValidator(c *Chain) *validator

Types

type BlkIterator

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

func NewIter

func NewIter(iterType IterType, start, stop interface{}, db database.DB) *BlkIterator

func (*BlkIterator) Next

func (i *BlkIterator) Next() (*types.Block, error)

func (*BlkIterator) Run

func (i *BlkIterator) Run() ([]*types.Block, error)

type Chain

type Chain struct {
	Mu *sync.Mutex

	ChainId     types.Chainid
	Node        *types.Node
	Config      config.Config
	ChainHeight uint64
	LastBlock   types.Block
	TxPool      pool
	ChainState  chainstate
	DB          database.DB
	Engine      consensus.Engin
	Validator   Validator
	MinerAdd    types.Address
	Miner       miner

	DBPath string
	Port   int

	MinedBlockCh chan *types.Block
}

TODO: add memChain in Chain struct

func Loadchain

func Loadchain(dbPath string, port int, miner []byte) (*Chain, error)

load blockchain and chain state from database

func NewChain

func NewChain(path string, port int, miner []byte) (*Chain, error)

func (*Chain) SetupChain

func (c *Chain) SetupChain() error

type IterType

type IterType int
const (
	IterByHash IterType = iota
	IterByIndex
)

type MemSet

type MemSet struct {
	Mu     *sync.Mutex
	Tokens map[types.Account][]*tmpUtxo
}

func NewMemSet

func NewMemSet() *MemSet

func (*MemSet) ConvertMem2Stable

func (ms *MemSet) ConvertMem2Stable() *types.UtxoSet

func (*MemSet) SnapShot

func (ms *MemSet) SnapShot() *MemSet

type Miner

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

func NewMiner

func NewMiner(c *Chain) *Miner

func (*Miner) Handler

func (m *Miner) Handler(wg *sync.WaitGroup)

func (*Miner) IsRunning

func (m *Miner) IsRunning() bool

func (*Miner) MineGenesis

func (m *Miner) MineGenesis(tx *types.Transaction)

func (*Miner) Start

func (m *Miner) Start(txs []*types.Transaction, wg *sync.WaitGroup)

func (*Miner) StartTime

func (m *Miner) StartTime() time.Duration

type State

type State struct {
	DB database.DB
	// contains filtered or unexported fields
}

func NewState

func NewState(c *Chain) *State

func (*State) GenesisUpdate

func (s *State) GenesisUpdate(b *types.Block)

func (*State) GetMemTokens

func (s *State) GetMemTokens(account types.Account) []*types.UTXO

func (*State) GetStableSet

func (s *State) GetStableSet() *types.UtxoSet

func (*State) GetTokens

func (s *State) GetTokens(account types.Account) []*types.UTXO

func (*State) Handler

func (s *State) Handler(wg *sync.WaitGroup)

func (*State) Load

func (s *State) Load() error

func (*State) MinerIsStarting

func (s *State) MinerIsStarting(start bool)

func (*State) StateTransition

func (s *State) StateTransition(o any, local bool)

func (*State) SyncMemSet

func (s *State) SyncMemSet(tokens map[types.Account][]*types.UTXO)

type Transactions

type Transactions map[txid]*types.Transaction

type TxPool

type TxPool struct {
	Mu *sync.Mutex

	WG *sync.WaitGroup
	// contains filtered or unexported fields
}

func NewTxPool

func NewTxPool(c *Chain) *TxPool

func (*TxPool) ContinueHandler

func (tp *TxPool) ContinueHandler(cont bool)

func (*TxPool) GetPending

func (tp *TxPool) GetPending() []*types.Transaction

func (*TxPool) GetQueue

func (tp *TxPool) GetQueue() []*types.Transaction

func (*TxPool) GetWaitGroup

func (tp *TxPool) GetWaitGroup() *sync.WaitGroup

func (*TxPool) Handler

func (tp *TxPool) Handler(wg *sync.WaitGroup)

func (*TxPool) UpdatePool

func (tp *TxPool) UpdatePool(o any, local bool)

this function add transactions that added to mined block that recieved from other nodes

type Validator

type Validator interface {
	ValidateTX(tx *types.Transaction) bool

	// sned block snapshot for preventing data race
	ValidateBlk(b *types.Block) bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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