PIVX Core  5.6.99
P2P Digital Currency
kernel.h
Go to the documentation of this file.
1 // Copyright (c) 2011-2013 The PPCoin developers
2 // Copyright (c) 2013-2014 The NovaCoin Developers
3 // Copyright (c) 2014-2018 The BlackCoin Developers
4 // Copyright (c) 2015-2020 The PIVX Core developers
5 // Distributed under the MIT/X11 software license, see the accompanying
6 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
7 
8 #ifndef PIVX_KERNEL_H
9 #define PIVX_KERNEL_H
10 
11 #include "stakeinput.h"
12 
13 class CStakeKernel {
14 public:
23  CStakeKernel(const CBlockIndex* const pindexPrev, CStakeInput* stakeInput, unsigned int nBits, int nTimeTx);
24 
25  // Return stake kernel hash
26  uint256 GetHash() const;
27 
28  // Check that the kernel hash meets the target required
29  bool CheckKernelHash(bool fSkipLog = false) const;
30 
31 private:
32  // kernel message hashed
36  int nTime{0};
37  // hash target
38  unsigned int nBits{0}; // difficulty for the target
39  CAmount stakeValue{0}; // target multiplier
40 };
41 
42 /* PoS Validation */
43 
44 /*
45  * Stake Check if stakeInput can stake a block on top of pindexPrev
46  *
47  * @param[in] pindexPrev index of the parent block of the block being staked
48  * @param[in] stakeInput input for the coinstake
49  * @param[in] nBits target difficulty bits
50  * @param[in] nTimeTx new blocktime
51  * @return bool true if stake kernel hash meets target protocol
52  */
53 bool Stake(const CBlockIndex* pindexPrev, CStakeInput* stakeInput, unsigned int nBits, int64_t& nTimeTx);
54 
55 /*
56  * CheckProofOfStake Check if block has valid proof of stake
57  *
58  * @param[in] block block with the proof being verified
59  * @param[out] strError string returning error message (if any, else empty)
60  * @param[in] pindexPrev index of the parent block
61  * (if nullptr, it will be searched in mapBlockIndex)
62  * @return bool true if the block has a valid proof of stake
63  */
64 bool CheckProofOfStake(const CBlock& block, std::string& strError, const CBlockIndex* pindexPrev = nullptr);
65 
66 /*
67  * GetStakeKernelHash Return stake kernel of a block
68  *
69  * @param[out] hashRet hash of the kernel (set by this function)
70  * @param[in] block block with the kernel to return
71  * @param[in] pindexPrev index of the parent block
72  * (if nullptr, it will be searched in mapBlockIndex)
73  * @return bool false if kernel cannot be initialized, true otherwise
74  */
75 bool GetStakeKernelHash(uint256& hashRet, const CBlock& block, const CBlockIndex* pindexPrev = nullptr);
76 
77 #endif // PIVX_KERNEL_H
int64_t CAmount
Amount in PIV (Can be negative)
Definition: amount.h:13
Definition: block.h:80
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: chain.h:139
unsigned int nBits
Definition: kernel.h:38
CDataStream stakeModifier
Definition: kernel.h:33
bool CheckKernelHash(bool fSkipLog=false) const
Definition: kernel.cpp:58
CDataStream stakeUniqueness
Definition: kernel.h:35
uint256 GetHash() const
Definition: kernel.cpp:50
CStakeKernel(const CBlockIndex *const pindexPrev, CStakeInput *stakeInput, unsigned int nBits, int nTimeTx)
CStakeKernel Constructor.
Definition: kernel.cpp:28
int nTimeBlockFrom
Definition: kernel.h:34
CAmount stakeValue
Definition: kernel.h:39
int nTime
Definition: kernel.h:36
256-bit opaque blob.
Definition: uint256.h:138
bool Stake(const CBlockIndex *pindexPrev, CStakeInput *stakeInput, unsigned int nBits, int64_t &nTimeTx)
Definition: kernel.cpp:115
bool GetStakeKernelHash(uint256 &hashRet, const CBlock &block, const CBlockIndex *pindexPrev=nullptr)
Definition: kernel.cpp:188
bool CheckProofOfStake(const CBlock &block, std::string &strError, const CBlockIndex *pindexPrev=nullptr)
Definition: kernel.cpp:139
@ SER_GETHASH
Definition: serialize.h:176