#include "policy/fees.h"
#include "komodo_defs.h"
#include "importcoin.h"
+#include "pbaas/notarization.h"
+#include "pbaas/reserves.h"
#include <assert.h>
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 )
//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
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
{
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;
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);
+ }
}
}