src/validation.cpp
// novacoin: attempt to generate suitable proof-of-stake
attempt to generate suitable proof-of-stake
attempt to generate suitable proof - of - stake
bool SignBlock(std::shared_ptr<CBlock> pblock, CWallet& wallet, const CAmount& nTotalFees, uint32_t nTime, std::set<std::pair<const CWalletTx*,unsigned int> >& setCoins, std::vector<COutPoint>& setSelectedCoins, std::vector<COutPoint>& setDelegateCoins, bool selectedOnly, bool tryOnly)
{
    if (!CheckFirstCoinstakeOutput(*pblock))
        return false;
    if (pblock->IsProofOfStake() && !pblock->vchBlockSigDlgt.empty())
        return true;
    CKey key;
    CMutableTransaction txCoinStake(*pblock->vtx[1]);
    uint32_t nTimeBlock = nTime;
    std::vector<unsigned char> vchPoD;
    COutPoint headerPrevout;
    if(wallet.IsStakeClosing()) return false;
    LOCK(wallet.cs_wallet);
    LegacyScriptPubKeyMan* spk_man = wallet.GetLegacyScriptPubKeyMan();
    uint32_t nHeight = ::ChainActive().Height() + 1;
    const Consensus::Params& consensusParams = Params().GetConsensus();
    nTimeBlock &= ~consensusParams.StakeTimestampMask(nHeight);
    if(!spk_man)
        return false;
    if (wallet.CreateCoinStake(*spk_man, pblock->nBits, nTotalFees, nTimeBlock, txCoinStake, key, setCoins, setSelectedCoins, setDelegateCoins, selectedOnly, vchPoD, headerPrevout))
    {
        if (nTimeBlock >= ::ChainActive().Tip()->GetMedianTimePast()+1)
        {
            pblock->nTime = nTimeBlock;
            pblock->vtx[1] = MakeTransactionRef(std::move(txCoinStake));
            pblock->hashMerkleRoot = BlockMerkleRoot(*pblock);
            pblock->prevoutStake = headerPrevout;
            if(tryOnly)
                return true;
            if(pblock->GetBlockTime() <= ::ChainActive().Tip()->GetBlockTime() || FutureDrift(pblock->GetBlockTime(), nHeight, consensusParams) < ::ChainActive().Tip()->GetBlockTime())
            {
                return false;
            }
            if (::ChainActive().Height() + 1 >= consensusParams.nOfflineStakeHeight)
            {
                if(vchPoD.size() > 0)
                    pblock->SetProofOfDelegation(vchPoD);
                std::vector<unsigned char> vchSig;
                bool isSigned = key.SignCompact(pblock->GetHashWithoutSign(), vchSig);
                pblock->SetBlockSignature(vchSig);
                return isSigned && CheckHeaderPoS(*pblock, consensusParams);
            }
            else
            {
                return key.Sign(pblock->GetHashWithoutSign(), pblock->vchBlockSigDlgt) &&
                           EnsureLowS(pblock->vchBlockSigDlgt) &&
                           CheckHeaderPoS(*pblock, consensusParams);
            }
        }
    }
    return false;
}
bool SignBlock ( std :: shared_ptr < CBlock > pblock , CWallet & wallet , const CAmount & nTotalFees , uint32_t nTime , std :: set < std :: pair < const CWalletTx * , unsigned int > > & setCoins , std :: vector < COutPoint > & setSelectedCoins , std :: vector < COutPoint > & setDelegateCoins , bool selectedOnly , bool tryOnly ) { if ( ! CheckFirstCoinstakeOutput ( * pblock ) ) return false ; if ( pblock -> IsProofOfStake ( ) && ! pblock -> vchBlockSigDlgt . empty ( ) ) return true ; CKey key ; CMutableTransaction txCoinStake ( * pblock -> vtx [ 1 ] ) ; uint32_t nTimeBlock = nTime ; std :: vector < unsigned char > vchPoD ; COutPoint headerPrevout ; if ( wallet . IsStakeClosing ( ) ) return false ; LOCK ( wallet . cs_wallet ) ; LegacyScriptPubKeyMan * spk_man = wallet . GetLegacyScriptPubKeyMan ( ) ; uint32_t nHeight = :: ChainActive ( ) . Height ( ) + 1 ; const Consensus :: Params & consensusParams = Params ( ) . GetConsensus ( ) ; nTimeBlock &= ~ consensusParams . StakeTimestampMask ( nHeight ) ; if ( ! spk_man ) return false ; if ( wallet . CreateCoinStake ( * spk_man , pblock -> nBits , nTotalFees , nTimeBlock , txCoinStake , key , setCoins , setSelectedCoins , setDelegateCoins , selectedOnly , vchPoD , headerPrevout ) ) { if ( nTimeBlock >= :: ChainActive ( ) . Tip ( ) -> GetMedianTimePast ( ) + 1 ) { pblock -> nTime = nTimeBlock ; pblock -> vtx [ 1 ] = MakeTransactionRef ( std :: move ( txCoinStake ) ) ; pblock -> hashMerkleRoot = BlockMerkleRoot ( * pblock ) ; pblock -> prevoutStake = headerPrevout ; if ( tryOnly ) return true ; if ( pblock -> GetBlockTime ( ) <= :: ChainActive ( ) . Tip ( ) -> GetBlockTime ( ) || FutureDrift ( pblock -> GetBlockTime ( ) , nHeight , consensusParams ) < :: ChainActive ( ) . Tip ( ) -> GetBlockTime ( ) ) { return false ; } if ( :: ChainActive ( ) . Height ( ) + 1 >= consensusParams . nOfflineStakeHeight ) { if ( vchPoD . size ( ) > 0 ) pblock -> SetProofOfDelegation ( vchPoD ) ; std :: vector < unsigned char > vchSig ; bool isSigned = key . SignCompact ( pblock -> GetHashWithoutSign ( ) , vchSig ) ; pblock -> SetBlockSignature ( vchSig ) ; return isSigned && CheckHeaderPoS ( * pblock , consensusParams ) ; } else { return key . Sign ( pblock -> GetHashWithoutSign ( ) , pblock -> vchBlockSigDlgt ) && EnsureLowS ( pblock -> vchBlockSigDlgt ) && CheckHeaderPoS ( * pblock , consensusParams ) ; } } } return false ; }
novacoin: attempt to generate suitable proof-of-stake
novacoin : attempt to generate suitable proof - of - stake
// if we are trying to sign //    something except proof-of-stake block template // if we are trying to sign //    a complete proof-of-stake block //original line: //int64_t nSearchInterval = IsProtocolV2(nBestHeight+1) ? 1 : nSearchTime - nLastCoinStakeSearchTime; //IsProtocolV2 mean POS 2 or higher, so the modified line is: // make sure coinstake would meet timestamp protocol //    as it would be the same as the block timestamp // Check timestamp against prev // Sign block // append PoD to the end of the block header // append a signature to our block and ensure that is compact // check block header // append a signature to our block and ensure that is LowS