Documentation ¶
Index ¶
- Constants
- type ConsensusInterface
- type NodeBlockMaker
- func (n *NodeBlockMaker) CompleteBlock() (*structures.Block, error)
- func (n *NodeBlockMaker) IsBlockPrepared() bool
- func (n *NodeBlockMaker) PrepareNewBlock() (int, error)
- func (n *NodeBlockMaker) SetDBManager(DB database.DBManager)
- func (n *NodeBlockMaker) SetLogManager(Logger *utils.LoggerMan)
- func (n *NodeBlockMaker) SetMinterAddress(minter string)
- func (n *NodeBlockMaker) SetPreparedBlock(block *structures.Block) error
- func (n *NodeBlockMaker) VerifyBlock(block *structures.Block) error
- type ProofOfWork
Constants ¶
View Source
const BlockPrepare_Done = 1
View Source
const BlockPrepare_Error = 0
View Source
const BlockPrepare_NoTransactions = 2
View Source
const BlockPrepare_NotGoodTime = 3
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConsensusInterface ¶
type ConsensusInterface interface { SetDBManager(DB database.DBManager) SetLogManager(Logger *utils.LoggerMan) SetMinterAddress(minter string) PrepareNewBlock() (int, error) SetPreparedBlock(block *structures.Block) error IsBlockPrepared() bool CompleteBlock() (*structures.Block, error) VerifyBlock(block *structures.Block) error }
func NewConsensusManager ¶
type NodeBlockMaker ¶
type NodeBlockMaker struct { DB database.DBManager Logger *utils.LoggerMan MinterAddress string // this is the wallet that will receive for mining PreparedBlock *structures.Block }
func (*NodeBlockMaker) CompleteBlock ¶
func (n *NodeBlockMaker) CompleteBlock() (*structures.Block, error)
finalise a block. in this place we do MIMING Block was prepared. Now do final work for this block. In our case it is PoW process
func (*NodeBlockMaker) IsBlockPrepared ¶
func (n *NodeBlockMaker) IsBlockPrepared() bool
check if a block was prepared already
func (*NodeBlockMaker) PrepareNewBlock ¶
func (n *NodeBlockMaker) PrepareNewBlock() (int, error)
func (*NodeBlockMaker) SetDBManager ¶
func (n *NodeBlockMaker) SetDBManager(DB database.DBManager)
func (*NodeBlockMaker) SetLogManager ¶
func (n *NodeBlockMaker) SetLogManager(Logger *utils.LoggerMan)
func (*NodeBlockMaker) SetMinterAddress ¶
func (n *NodeBlockMaker) SetMinterAddress(minter string)
func (*NodeBlockMaker) SetPreparedBlock ¶
func (n *NodeBlockMaker) SetPreparedBlock(block *structures.Block) error
func (*NodeBlockMaker) VerifyBlock ¶
func (n *NodeBlockMaker) VerifyBlock(block *structures.Block) error
Verify the block. We check if it is correct agains previous block Verify a block against blockchain RULES
- Verification is done agains blockchain branch starting from prevblock, not current top branch
- There can be only 1 transaction make reward per block
- number of transactions must be in correct ranges (reward transaction is not calculated)
- transactions can have as input other transaction from this block and it must be listed BEFORE (output must be before input in same block)
- all inputs must be in blockchain (correct unspent inputs)
- Additionally verify each transaction agains signatures, total amount, balance etc
- Verify hash is correc agains rules
type ProofOfWork ¶
type ProofOfWork struct {
// contains filtered or unexported fields
}
ProofOfWork represents a proof-of-work
func NewProofOfWork ¶
func NewProofOfWork(b *structures.Block) *ProofOfWork
NewProofOfWork builds and returns a ProofOfWork object The object can be used to find a hash for the block
func (*ProofOfWork) Run ¶
func (pow *ProofOfWork) Run() (int, []byte, error)
Run performs a proof-of-work
func (*ProofOfWork) Validate ¶
func (pow *ProofOfWork) Validate() (bool, error)
Validate validates block's PoW It calculates hash from same data and check if it is equal to block hash
Click to show internal directories.
Click to hide internal directories.