Checkpoints valudation, PoW reward calculation and continue working on block index.
[NovacoinLibrary.git] / Novacoin / StakeModifier.cs
index e6b6f50..b3f7876 100644 (file)
@@ -144,7 +144,7 @@ namespace Novacoin
             selectedCursor = null;
             foreach (var item in sortedByTimestamp)
             {
-                CBlockStoreItem cursor = CBlockStore.Instance.GetCursor(item.Item2);
+                CBlockStoreItem cursor = CBlockStore.Instance.GetMapCursor(item.Item2);
 
                 if (cursor == null)
                 {
@@ -298,7 +298,7 @@ namespace Novacoin
         static bool GetKernelStakeModifier(uint256 hashBlockFrom, ref long nStakeModifier, ref uint nStakeModifierHeight, ref uint nStakeModifierTime)
         {
             nStakeModifier = 0;
-            var cursorFrom = CBlockStore.Instance.GetCursor(hashBlockFrom);
+            var cursorFrom = CBlockStore.Instance.GetMapCursor(hashBlockFrom);
             if (cursorFrom == null)
             {
                 return false; // Block not indexed
@@ -401,7 +401,7 @@ namespace Novacoin
 
         internal static uint GetStakeModifierChecksum(CBlockStoreItem itemTemplate)
         {
-            Contract.Assert(itemTemplate.prev != null || (uint256)itemTemplate.Hash == NetUtils.nHashGenesisBlock);
+            Contract.Assert(itemTemplate.prev != null || (uint256)itemTemplate.Hash == NetInfo.nHashGenesisBlock);
 
             // Hash previous checksum with flags, hashProofOfStake and nStakeModifier
             MemoryStream ss = new MemoryStream();
@@ -448,11 +448,16 @@ namespace Novacoin
             CTransaction txPrev = null;
             long nBlockPos = 0, nTxPos = 0;
             
-            if (!CBlockStore.Instance.GetByTransactionID(txin.prevout.hash, ref block, ref txPrev, ref nBlockPos, ref nTxPos))
+            if (!CBlockStore.Instance.GetBlockByTransactionID(txin.prevout.hash, ref block, ref txPrev, ref nBlockPos, ref nTxPos))
             {
                 return false; // unable to read block of previous transaction
             }
 
+            if (!ScriptCode.VerifyScript(txin.scriptSig, txPrev.vout[txin.prevout.n].scriptPubKey, tx, 0, (int)scriptflag.SCRIPT_VERIFY_P2SH, 0))
+            {
+                return false; // vin[0] signature check failed
+            }
+
             if (!CheckStakeKernelHash(nBits, block.header.Hash, block.header.nTime, (uint)(nTxPos - nBlockPos), txPrev, txin.prevout, tx.nTime, ref hashProofOfStake, ref targetProofOfStake))
             {
                 return false; // check kernel failed on coinstake