X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fmain.h;h=f6db3b35ced297dd0503d7e1316b8a859f57e33d;hb=93f81f3b329ed32acfa6fa4bc1f10661199e5820;hp=3ad6a0428fb7a3842b2085403910c037727e54d9;hpb=ec238d8a644d11b08d17fdb81a31851c07df3dac;p=novacoin.git diff --git a/src/main.h b/src/main.h index 3ad6a04..f6db3b3 100644 --- a/src/main.h +++ b/src/main.h @@ -53,6 +53,7 @@ static const int fHaveUPnP = false; extern CCriticalSection cs_main; extern std::map mapBlockIndex; +extern std::set setStakeSeen; extern uint256 hashGenesisBlock; extern CBlockIndex* pindexGenesisBlock; extern int nBestHeight; @@ -360,7 +361,13 @@ public: return (nValue == -1); } - bool IsCoinStake() const + bool SetEmpty() + { + nValue = 0; + scriptPubKey.clear(); + } + + bool IsEmpty() const { return (nValue == 0 && scriptPubKey.empty()); } @@ -383,7 +390,7 @@ public: std::string ToString() const { - if (IsCoinStake()) return "CTxOut(coinstake)"; + if (IsEmpty()) return "CTxOut(empty)"; if (scriptPubKey.size() < 6) return "CTxOut(error)"; return strprintf("CTxOut(nValue=%s, scriptPubKey=%s)", FormatMoney(nValue).c_str(), scriptPubKey.ToString().substr(0,30).c_str()); @@ -504,7 +511,7 @@ public: bool IsCoinStake() const { // ppcoin: the coin stake transaction is marked with the first output empty - return (vout.size() == 2 && vout[0].IsCoinStake()); + return (vin.size() > 0 && vout.size() == 2 && vout[0].IsEmpty()); } int GetSigOpCount() const @@ -632,7 +639,8 @@ public: std::string ToString() const { std::string str; - str += strprintf("CTransaction(hash=%s, nTime=%d, ver=%d, vin.size=%d, vout.size=%d, nLockTime=%d)\n", + str += IsCoinBase()? "Coinbase" : (IsCoinStake()? "Coinstake" : "CTransaction"); + str += strprintf("(hash=%s, nTime=%d, ver=%d, vin.size=%d, vout.size=%d, nLockTime=%d)\n", GetHash().ToString().substr(0,10).c_str(), nTime, nVersion, @@ -667,7 +675,7 @@ protected: public: bool RemoveFromMemoryPool(); bool GetCoinAge(CTxDB& txdb, uint64& nCoinAge) const; // ppcoin: get transaction coin age - bool CheckProofOfStake(CTxDB& txdb, unsigned int nBits) const; + bool CheckProofOfStake(unsigned int nBits) const; }; @@ -889,6 +897,11 @@ public: return !IsProofOfStake(); } + COutPoint GetProofOfStake() const + { + return IsProofOfStake()? vtx[1].vin[0].prevout : COutPoint(); + } + // ppcoin: get max transaction timestamp int64 GetMaxTransactionTime() const { @@ -1004,7 +1017,7 @@ public: filein >> *this; // Check the header - if (!CheckProofOfWork(GetHash(), nBits)) + if (fReadTransactions && IsProofOfWork() && !CheckProofOfWork(GetHash(), nBits)) return error("CBlock::ReadFromDisk() : errors in block header"); return true; @@ -1037,8 +1050,9 @@ public: bool SignBlock(const CKeyStore& keystore) { std::vector > vSolution; + const CTxOut& txout = IsProofOfStake()? vtx[1].vout[1] : vtx[0].vout[0]; - if (!Solver(vtx[0].vout[0].scriptPubKey, vSolution)) + if (!Solver(txout.scriptPubKey, vSolution)) return false; BOOST_FOREACH(PAIRTYPE(opcodetype, valtype)& item, vSolution) { @@ -1063,8 +1077,9 @@ public: return vchBlockSig.empty(); std::vector > vSolution; + const CTxOut& txout = IsProofOfStake()? vtx[1].vout[1] : vtx[0].vout[0]; - if (!Solver(vtx[0].vout[0].scriptPubKey, vSolution)) + if (!Solver(txout.scriptPubKey, vSolution)) return false; BOOST_FOREACH(PAIRTYPE(opcodetype, valtype)& item, vSolution) { @@ -1117,6 +1132,7 @@ public: int nHeight; int nCheckpoint; // ppcoin: chain auto checkpoint height bool fProofOfStake; // ppcoin: is the block of proof-of-stake type + COutPoint prevoutStake; // block header int nVersion; @@ -1137,6 +1153,7 @@ public: nChainTrust = 0; nCheckpoint = 0; fProofOfStake = true; + prevoutStake.SetNull(); nVersion = 0; hashMerkleRoot = 0; @@ -1156,6 +1173,10 @@ public: nChainTrust = 0; nCheckpoint = 0; fProofOfStake = block.IsProofOfStake(); + if (fProofOfStake) + prevoutStake = block.vtx[1].vin[0].prevout; + else + prevoutStake.SetNull(); nVersion = block.nVersion; hashMerkleRoot = block.hashMerkleRoot; @@ -1199,7 +1220,7 @@ public: bool CheckIndex() const { - return CheckProofOfWork(GetBlockHash(), nBits); + return IsProofOfWork() ? CheckProofOfWork(GetBlockHash(), nBits) : true; } bool EraseBlockFromDisk() @@ -1257,8 +1278,9 @@ public: std::string ToString() const { - return strprintf("CBlockIndex(nprev=%08x, pnext=%08x, nFile=%d, nBlockPos=%-6d nChainTrust=%"PRI64d" nHeight=%d, nCheckpoint=%d, fProofOfStake=%d merkle=%s, hashBlock=%s)", - pprev, pnext, nFile, nBlockPos, nChainTrust, nHeight, nCheckpoint, fProofOfStake, + return strprintf("CBlockIndex(nprev=%08x, pnext=%08x, nFile=%d, nBlockPos=%-6d nChainTrust=%"PRI64d" nHeight=%d, nCheckpoint=%d, fProofOfStake=%d prevoutStake=(%s) merkle=%s, hashBlock=%s)", + pprev, pnext, nFile, nBlockPos, nChainTrust, nHeight, nCheckpoint, + fProofOfStake, prevoutStake.ToString().c_str(), hashMerkleRoot.ToString().substr(0,10).c_str(), GetBlockHash().ToString().substr(0,20).c_str()); } @@ -1304,6 +1326,7 @@ public: READWRITE(nHeight); READWRITE(nCheckpoint); READWRITE(fProofOfStake); + READWRITE(prevoutStake); // block header READWRITE(this->nVersion);