]> Git Repo - VerusCoin.git/blobdiff - src/coins.cpp
Complete block reserve conversion solution, final update and import remaining
[VerusCoin.git] / src / coins.cpp
index 306e2278fc63940c88169da3fd0e1c7effece722..06162c9a5284a75afc2215dea07763e9dc2f3f3d 100644 (file)
@@ -10,6 +10,8 @@
 #include "policy/fees.h"
 #include "komodo_defs.h"
 #include "importcoin.h"
+#include "pbaas/notarization.h"
+#include "pbaas/reserves.h"
 
 #include <assert.h>
 
@@ -589,7 +591,17 @@ CAmount CCoinsViewCache::GetValueIn(int32_t nHeight,int64_t *interestp,const CTr
         return 0;
     for (unsigned int i = 0; i < tx.vin.size(); i++)
     {
-        value = GetOutputFor(tx.vin[i]).nValue;
+        value = 0;
+        const CCoins* coins = AccessCoins(tx.vin[i].prevout.hash);
+        if (coins && coins->IsAvailable(tx.vin[i].prevout.n))
+        {
+            value = coins->vout[tx.vin[i].prevout.n].nValue;
+        }
+        else
+        {
+            return 0;
+        }
+
         nResult += value;
 #ifdef KOMODO_ENABLE_INTEREST
         if ( ASSETCHAINS_SYMBOL[0] == 0 && nHeight >= 60000 )
@@ -601,7 +613,8 @@ CAmount CCoinsViewCache::GetValueIn(int32_t nHeight,int64_t *interestp,const CTr
                 //printf("nResult %.8f += val %.8f interest %.8f ht.%d lock.%u tip.%u\n",(double)nResult/COIN,(double)value/COIN,(double)interest/COIN,txheight,locktime,tiptime);
                 //fprintf(stderr,"nResult %.8f += val %.8f interest %.8f ht.%d lock.%u tip.%u\n",(double)nResult/COIN,(double)value/COIN,(double)interest/COIN,txheight,locktime,tiptime);
                 nResult += interest;
-                (*interestp) += interest;
+                if (interestp)
+                    (*interestp) += interest;
             }
         }
 #endif
@@ -611,6 +624,44 @@ CAmount CCoinsViewCache::GetValueIn(int32_t nHeight,int64_t *interestp,const CTr
     return nResult;
 }
 
+CAmount CCoinsViewCache::GetReserveValueIn(int32_t nHeight, const CTransaction& tx) const
+{
+    CAmount value, nResult = 0;
+
+    /* we don't support this coin import, so we should add reserve import support and uncomment
+    if ( tx.IsCoinImport() )
+        return GetCoinImportValue(tx);
+    */
+
+    // coinbases have no inputs
+    if ( tx.IsCoinBase() != 0 )
+        return 0;
+
+    for (unsigned int i = 0; i < tx.vin.size(); i++)
+    {
+        value = 0;
+        const CCoins* coins = AccessCoins(tx.vin[i].prevout.hash);
+        if (coins && coins->IsAvailable(tx.vin[i].prevout.n))
+        {
+            COptCCParams p;
+            if (::IsPayToCryptoCondition(coins->vout[tx.vin[i].prevout.n].scriptPubKey, p) && p.evalCode == EVAL_RESERVE_OUTPUT && p.vData.size())
+            {
+                CReserveOutput ro(p.vData[0]);
+                if (ro.IsValid())
+                {
+                    value = ro.nValue;
+                }
+            }
+        }
+        else
+        {
+            return 0;
+        }
+
+        nResult += value;
+    }
+    return nResult;
+}
 
 bool CCoinsViewCache::HaveJoinSplitRequirements(const CTransaction& tx) const
 {
@@ -671,7 +722,7 @@ bool CCoinsViewCache::HaveInputs(const CTransaction& tx) const
     return true;
 }
 
-double CCoinsViewCache::GetPriority(const CTransaction &tx, int nHeight) const
+double CCoinsViewCache::GetPriority(const CTransaction &tx, int nHeight, const CReserveTransactionDescriptor *desc, const CCurrencyState *currencyState) const
 {
     if (tx.IsCoinBase())
         return 0.0;
@@ -693,7 +744,26 @@ double CCoinsViewCache::GetPriority(const CTransaction &tx, int nHeight) const
         assert(coins);
         if (!coins->IsAvailable(txin.prevout.n)) continue;
         if (coins->nHeight < nHeight) {
-            dResult += coins->vout[txin.prevout.n].nValue * (nHeight-coins->nHeight);
+            if (currencyState && desc)
+            {
+                if (coins->nHeight < nHeight) {
+                    double confs = nHeight - coins->nHeight;
+                    CAmount nativeVal = coins->vout[txin.prevout.n].nValue;
+                    CAmount reserveVal = coins->vout[txin.prevout.n].ReserveOutValue();
+                    if (nativeVal)
+                    {
+                        dResult += nativeVal * confs;
+                    }
+                    if (reserveVal)
+                    {
+                        dResult += reserveVal * confs;
+                    }
+                }
+            }
+            else
+            {
+                dResult += coins->vout[txin.prevout.n].nValue * (nHeight-coins->nHeight);
+            }
         }
     }
 
This page took 0.023585 seconds and 4 git commands to generate.