a94ace22ce73c6a21c2cdd56557be48993a2c4ca
[novacoin.git] / src / kernel.h
1 // Copyright (c) 2012-2013 The PPCoin developers
2 // Distributed under the MIT/X11 software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 #ifndef PPCOIN_KERNEL_H
5 #define PPCOIN_KERNEL_H
6
7 #include "main.h"
8 #include "wallet.h"
9
10 // ChainDB upgrade time
11 extern unsigned int nModifierUpgradeTime;
12
13 // MODIFIER_INTERVAL: time to elapse before new modifier is computed
14 extern unsigned int nModifierInterval;
15
16 extern bool fCoinsDataActual;
17
18 // MODIFIER_INTERVAL_RATIO:
19 // ratio of group interval length between the last group and the first group
20 static const int MODIFIER_INTERVAL_RATIO = 3;
21
22 // Whether the given block is subject to new modifier protocol
23 bool IsFixedModifierInterval(unsigned int nTimeBlock);
24
25 // Compute the hash modifier for proof-of-stake
26 bool ComputeNextStakeModifier(const CBlockIndex* pindexCurrent, uint64_t& nStakeModifier, bool& fGeneratedStakeModifier);
27
28 // The stake modifier used to hash for a stake kernel is chosen as the stake
29 // modifier about a selection interval later than the coin generating the kernel
30 bool GetKernelStakeModifier(uint256 hashBlockFrom, uint64_t& nStakeModifier);
31
32 // Check whether stake kernel meets hash target
33 // Sets hashProofOfStake on success return
34 bool CheckStakeKernelHash(unsigned int nBits, const CBlock& blockFrom, uint32_t nTxPrevOffset, const CTransaction& txPrev, const COutPoint& prevout, uint32_t nTimeTx, uint256& hashProofOfStake, uint256& targetProofOfStake, bool fPrintProofOfStake=false);
35
36 // Scan given coins set for kernel solution
37 bool ScanForStakeKernelHash(MetaMap &mapMeta, uint32_t nBits, uint32_t nTime, uint32_t nSearchInterval, CoinsSet::value_type &kernelcoin, uint32_t &nTimeTx, uint32_t &nBlockTime, uint64_t &nKernelsTried, uint64_t &nCoinDaysTried);
38
39 // Precompute hashing state for static part of kernel
40 void GetKernelMidstate(uint64_t nStakeModifier, uint32_t nBlockTime, uint32_t nTxOffset, uint32_t nInputTxTime, uint32_t nOut, SHA256_CTX &ctx);
41
42 // Scan given midstate for kernel solutions
43 bool ScanMidstateForward(SHA256_CTX &ctx, uint32_t nBits, uint32_t nInputTxTime, int64_t nValueIn, std::pair<uint32_t, uint32_t> &SearchInterval, std::pair<uint256, uint32_t> &solution);
44
45 // Check kernel hash target and coinstake signature
46 // Sets hashProofOfStake on success return
47 bool CheckProofOfStake(const CTransaction& tx, unsigned int nBits, uint256& hashProofOfStake, uint256& targetProofOfStake);
48
49 // Get stake modifier checksum
50 uint32_t GetStakeModifierChecksum(const CBlockIndex* pindex);
51
52 // Check stake modifier hard checkpoints
53 bool CheckStakeModifierCheckpoints(int nHeight, uint32_t nStakeModifierChecksum);
54
55 // Get time weight using supplied timestamps
56 int64_t GetWeight(int64_t nIntervalBeginning, int64_t nIntervalEnd);
57
58 #endif // PPCOIN_KERNEL_H