Issue to be dealt with in the near future.
[NovacoinLibrary.git] / Novacoin / CBlockStore.cs
index 97ce54e..133a18e 100644 (file)
@@ -260,7 +260,7 @@ namespace Novacoin
 
                 var inputsKey = new COutPoint(item.TransactionHash, item.nOut);
 
-                item.IsSpent = true;
+//                item.IsSpent = true;
 
                 // Add output data to dictionary
                 inputs.Add(inputsKey, (TxOutItem)item);
@@ -703,8 +703,11 @@ namespace Novacoin
 
                 for (var i = 0u; i < tx.vout.Length; i++)
                 {
-                    var mNode = new CMerkleNode(cursor.ItemID, nTxPos, tx);
-                    queuedMerkleNodes.Add(hashTx, mNode);
+                    if (!queuedMerkleNodes.ContainsKey(hashTx))
+                    {
+                        var mNode = new CMerkleNode(cursor.ItemID, nTxPos, tx);
+                        queuedMerkleNodes.Add(hashTx, mNode);
+                    }
 
                     var outKey = new COutPoint(hashTx, i);
                     var outData = new TxOutItem();
@@ -713,7 +716,6 @@ namespace Novacoin
                     outData.scriptPubKey = tx.vout[i].scriptPubKey;
                     outData.nOut = i;
 
-
                     outData.IsSpent = false;
 
                     queued.Add(outKey, outData);
@@ -758,6 +760,9 @@ namespace Novacoin
                 }
                 else
                 {
+                    // TODO: Bug here, we shouldn't mix new and already existent outpoints in the same dictionary.
+
+
                     merkleNode = queuedMerkleNodes[txID];
                     if (!SaveMerkleNode(ref merkleNode))
                     {
@@ -904,10 +909,9 @@ namespace Novacoin
                         return false; // unable to get coin age for coinstake
                     }
 
-                    int nTxSize = (tx.nTime > NetInfo.nStakeValidationSwitchTime) ? tx.Size : 0;
                     ulong nReward = tx.nValueOut - nValueIn;
 
-                    ulong nCalculatedReward = CBlock.GetProofOfStakeReward(nCoinAge, cursorBlock.nBits, tx.nTime) - CTransaction.GetMinFee(1, false, CTransaction.MinFeeMode.GMF_BLOCK, nTxSize) + CTransaction.nCent;
+                    ulong nCalculatedReward = CBlock.GetProofOfStakeReward(nCoinAge, cursorBlock.nBits, tx.nTime) - tx.GetMinFee(1, false, CTransaction.MinFeeMode.GMF_BLOCK) + CTransaction.nCent;
 
                     if (nReward > nCalculatedReward)
                     {
@@ -1135,6 +1139,8 @@ namespace Novacoin
                 var results = blockMap.Where(x => x.Value.ItemID == merkleNode.nParentBlockID).Select(x => x.Value).ToArray();
 
                 blockCursor = results[0];
+
+                return merkleNode;
             }
 
             // Nothing found.