Documentation ¶
Overview ¶
Package state is the core API for the blockchain and implements all the business rules and processing.
Index ¶
- Constants
- Variables
- type Config
- type EventHandler
- type State
- func (s *State) Accounts() map[database.AccountID]database.Account
- func (s *State) AddKnownPeer(peer peer.Peer) bool
- func (s *State) Consensus() string
- func (s *State) Genesis() genesis.Genesis
- func (s *State) Host() string
- func (s *State) IsMiningAllowed() bool
- func (s *State) KnownExternalPeers() []peer.Peer
- func (s *State) KnownPeers() []peer.Peer
- func (s *State) LatestBlock() database.Block
- func (s *State) Mempool() []database.BlockTx
- func (s *State) MempoolLength() int
- func (s *State) MineNewBlock(ctx context.Context) (database.Block, error)
- func (s *State) NetRequestPeerBlocks(pr peer.Peer) error
- func (s *State) NetRequestPeerMempool(pr peer.Peer) ([]database.BlockTx, error)
- func (s *State) NetRequestPeerStatus(pr peer.Peer) (peer.PeerStatus, error)
- func (s *State) NetSendBlockToPeers(block database.Block) error
- func (s *State) NetSendNodeAvailableToPeers()
- func (s *State) NetSendTxToPeers(tx database.BlockTx)
- func (s *State) ProcessProposedBlock(block database.Block) error
- func (s *State) QueryAccount(account database.AccountID) (database.Account, error)
- func (s *State) QueryBlocksByAccount(accountID database.AccountID) ([]database.Block, error)
- func (s *State) QueryBlocksByNumber(from uint64, to uint64) []database.Block
- func (s *State) RemoveKnownPeer(peer peer.Peer)
- func (s *State) Reorganize() error
- func (s *State) Shutdown() error
- func (s *State) UpsertMempool(tx database.BlockTx) error
- func (s *State) UpsertNodeTransaction(tx database.BlockTx) error
- func (s *State) UpsertWalletTransaction(signedTx database.SignedTx) error
- type Worker
Constants ¶
const ( ConsensusPOW = "POW" ConsensusPOA = "POA" )
The set of different consensus protocols that can be used.
const QueryLastest = ^uint64(0) >> 1
QueryLastest represents to query the latest block in the chain.
Variables ¶
var ErrNoTransactions = errors.New("no transactions in mempool")
ErrNoTransactions is returned when a block is requested to be created and there are not enough transactions.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { BeneficiaryID database.AccountID Host string Storage database.Storage Genesis genesis.Genesis SelectStrategy string KnownPeers *peer.PeerSet EvHandler EventHandler Consensus string }
Config represents the configuration required to start the blockchain node.
type EventHandler ¶
EventHandler defines a function that is called when events occur in the processing of persisting blocks.
type State ¶
type State struct { Worker Worker // contains filtered or unexported fields }
State manages the blockchain database.
func (*State) AddKnownPeer ¶
AddKnownPeer provides the ability to add a new peer to the known peer list.
func (*State) IsMiningAllowed ¶
IsMiningAllowed identifies if we are allowed to mine blocks. This might be turned off if the blockchain needs to be re-synced.
func (*State) KnownExternalPeers ¶
KnownExternalPeers retrieves a copy of the known peer list without including this node.
func (*State) KnownPeers ¶
KnownPeers retrieves a copy of the full known peer list which includes this node as well. Used by the PoA selection algorithm.
func (*State) LatestBlock ¶
LatestBlock returns a copy the current latest block.
func (*State) MempoolLength ¶
MempoolLength returns the current length of the mempool.
func (*State) MineNewBlock ¶
MineNewBlock attempts to create a new block with a proper hash that can become the next block in the chain.
func (*State) NetRequestPeerBlocks ¶
NetRequestPeerBlocks queries the specified node asking for blocks this node does not have, then writes them to disk.
func (*State) NetRequestPeerMempool ¶
NetRequestPeerMempool asks the peer for the transactions in their mempool.
func (*State) NetRequestPeerStatus ¶
NetRequestPeerStatus looks for new nodes on the blockchain by asking known nodes for their peer list. New nodes are added to the list.
func (*State) NetSendBlockToPeers ¶
NetSendBlockToPeers takes the new mined block and sends it to all know peers.
func (*State) NetSendNodeAvailableToPeers ¶
func (s *State) NetSendNodeAvailableToPeers()
NetSendNodeAvailableToPeers shares this node is available to participate in the network with the known peers.
func (*State) NetSendTxToPeers ¶
NetSendTxToPeers shares a new block transaction with the known peers.
func (*State) ProcessProposedBlock ¶
ProcessProposedBlock takes a block received from a peer, validates it and if that passes, adds the block to the local blockchain.
func (*State) QueryAccount ¶
QueryAccount returns a copy of the account from the database.
func (*State) QueryBlocksByAccount ¶
QueryBlocksByAccount returns the set of blocks by account. If the account is empty, all blocks are returned. This function reads the blockchain from disk first.
func (*State) QueryBlocksByNumber ¶
QueryBlocksByNumber returns the set of blocks based on block numbers. This function reads the blockchain from disk first.
func (*State) RemoveKnownPeer ¶
RemoveKnownPeer provides the ability to remove a peer from the known peer list.
func (*State) Reorganize ¶
Reorganize corrects an identified fork. No mining is allowed to take place while this process is running. New transactions can be placed into the mempool.
func (*State) UpsertMempool ¶
UpsertMempool adds a new transaction to the mempool.
func (*State) UpsertNodeTransaction ¶
UpsertNodeTransaction accepts a transaction from a node for inclusion.