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) 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(p peer.Peer) error
- func (s *State) NetRequestPeerMempool(p peer.Peer) ([]database.BlockTx, error)
- func (s *State) NetRequestPeerStatus(p 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) QueryBlocksByNumber(from, to uint64) []database.Block
- func (s *State) RemoveKnownPeer(peer peer.Peer)
- 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 algorithms that can be used.
const QueryLatest = ^uint64(0) >> 1
QueryLatest represents to query the latest block in the chain.
Variables ¶
var ErrNoTransactions = errors.New("no transactions in the mempool")
ErrNoTransactions is returned when there are no transactions
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { BeneficiaryID database.AccountID Host string Storage database.Storage Genesis genesis.Genesis KnownPeers *peer.PeerSet SelectStrategy string 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 adds a new peer to the known peer list.
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. Used by the PoA selection algorithm.
func (*State) LatestBlock ¶
LatestBlock returns a copy of the current latest block.
func (*State) MempoolLength ¶
MempoolLength returns the number of transactions in 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 for blocks this node does not have and writes them to disk
func (*State) NetRequestPeerMempool ¶
NetRequestPeerMempool asks the peer for the transactions in its 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 take the new mined block and sends it to all the known 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, if valid, adds the block to the local blockchain.
func (*State) QueryAccount ¶
QueryAccount returns a copy of the account from the database.
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 removes a peer from the known peer list.
func (*State) UpsertMempool ¶
UpsertMempool adds a new transaction to the mempool
func (*State) UpsertNodeTransaction ¶
UpsertNodeTransaction accepts a transaction from a node for inclusion.