test
This commit is contained in:
@@ -386,9 +386,10 @@ const CScript &CCoinsViewCache::GetSpendFor(const CTxIn& input) const
|
||||
uint32_t komodo_txtime(uint256 hash);
|
||||
uint64_t komodo_interest(uint64_t nValue,uint32_t nLockTime,uint32_t tiptime);
|
||||
|
||||
CAmount CCoinsViewCache::GetValueIn(const CTransaction& tx,uint32_t tiptime) const
|
||||
CAmount CCoinsViewCache::GetValueIn(int64_t *interestp,const CTransaction& tx,uint32_t tiptime) const
|
||||
{
|
||||
uint32_t timestamp,minutes;
|
||||
uint32_t timestamp,minutes; int64_t interest;
|
||||
*interestp = 0;
|
||||
if ( tx.IsCoinBase() != 0 )
|
||||
return 0;
|
||||
CAmount value,nResult = 0;
|
||||
@@ -396,7 +397,9 @@ CAmount CCoinsViewCache::GetValueIn(const CTransaction& tx,uint32_t tiptime) con
|
||||
{
|
||||
value = GetOutputFor(tx.vin[i]).nValue;
|
||||
nResult += value;
|
||||
nResult += komodo_interest(value,komodo_txtime(tx.vin[i].prevout.hash),tiptime);
|
||||
interest = komodo_interest(value,komodo_txtime(tx.vin[i].prevout.hash),tiptime);
|
||||
nResult += interest;
|
||||
(*interestp) += interest;
|
||||
}
|
||||
nResult += tx.GetJoinSplitValueIn();
|
||||
|
||||
|
||||
@@ -512,7 +512,7 @@ public:
|
||||
* @param[in] tx transaction for which we are checking input total
|
||||
* @return Sum of value of all inputs (scriptSigs)
|
||||
*/
|
||||
CAmount GetValueIn(const CTransaction& tx,uint32_t prevblocktime) const;
|
||||
CAmount GetValueIn(int64_t *interestp,const CTransaction& tx,uint32_t prevblocktime) const;
|
||||
|
||||
//! Check whether all prevouts of the transaction are present in the UTXO set represented by this view
|
||||
bool HaveInputs(const CTransaction& tx) const;
|
||||
|
||||
@@ -278,8 +278,7 @@ uint64_t komodo_interest(uint64_t nValue,uint32_t nLockTime,uint32_t tiptime)
|
||||
{
|
||||
minutes = (tiptime - nLockTime) / 60;
|
||||
days = minutes / (24 * 60);
|
||||
if ( days > 0 )
|
||||
interest = (nValue * 5000000) / (365 * 1000000 / days);
|
||||
interest = (nValue * 5000000) / ((365 * 1000000 * 24 * 60) / minutes);
|
||||
fprintf(stderr,"komodo_interest %lld %.8f nLockTime.%u tiptime.%u minutes.%d days.%d interest %lld %.8f\n",(long long)nValue,(double)nValue/100000000.,nLockTime,tiptime,minutes,days,(long long)interest,(double)interest/100000000);
|
||||
}
|
||||
return(interest * 0);
|
||||
|
||||
11
src/main.cpp
11
src/main.cpp
@@ -1097,7 +1097,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
|
||||
{
|
||||
CCoinsView dummy;
|
||||
CCoinsViewCache view(&dummy);
|
||||
|
||||
int64_t interest;
|
||||
CAmount nValueIn = 0;
|
||||
{
|
||||
LOCK(pool.cs);
|
||||
@@ -1132,7 +1132,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
|
||||
// Bring the best block into scope
|
||||
view.GetBestBlock();
|
||||
|
||||
nValueIn = view.GetValueIn(tx,chainActive.Tip()->nTime);
|
||||
nValueIn = view.GetValueIn(&interest,tx,chainActive.Tip()->nTime);
|
||||
|
||||
// we have all inputs cached now, so switch back to dummy, so we don't need to keep lock on mempool
|
||||
view.SetBackend(dummy);
|
||||
@@ -2100,6 +2100,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
|
||||
int64_t nTimeStart = GetTimeMicros();
|
||||
CAmount nFees = 0;
|
||||
int nInputs = 0;
|
||||
int64_t interest,sum = 0;
|
||||
unsigned int nSigOps = 0;
|
||||
CDiskTxPos pos(pindex->GetBlockPos(), GetSizeOfCompactSize(block.vtx.size()));
|
||||
std::vector<std::pair<uint256, CDiskTxPos> > vPos;
|
||||
@@ -2153,14 +2154,14 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
|
||||
return state.DoS(100, error("ConnectBlock(): too many sigops"),
|
||||
REJECT_INVALID, "bad-blk-sigops");
|
||||
|
||||
nFees += view.GetValueIn(tx,chainActive.Tip()->nTime)-tx.GetValueOut();
|
||||
|
||||
nFees += view.GetValueIn(&interest,tx,chainActive.Tip()->nTime) - tx.GetValueOut();
|
||||
sum += interest;
|
||||
std::vector<CScriptCheck> vChecks;
|
||||
if (!ContextualCheckInputs(tx, state, view, fScriptChecks, flags, false, chainparams.GetConsensus(), nScriptCheckThreads ? &vChecks : NULL))
|
||||
return false;
|
||||
control.Add(vChecks);
|
||||
}
|
||||
|
||||
komodo_accrued_interest(pindex->nHeight,sum);
|
||||
CTxUndo undoDummy;
|
||||
if (i > 0) {
|
||||
blockundo.vtxundo.push_back(CTxUndo());
|
||||
|
||||
@@ -228,6 +228,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
||||
// Collect transactions into block
|
||||
uint64_t nBlockSize = 1000;
|
||||
uint64_t nBlockTx = 0;
|
||||
int64_t interest;
|
||||
int nBlockSigOps = 100;
|
||||
bool fSortedByFee = (nBlockPrioritySize <= 0);
|
||||
|
||||
@@ -275,7 +276,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
||||
if (!view.HaveInputs(tx))
|
||||
continue;
|
||||
|
||||
CAmount nTxFees = view.GetValueIn(tx,chainActive.Tip()->nTime)-tx.GetValueOut();
|
||||
CAmount nTxFees = view.GetValueIn(&interest,tx,chainActive.Tip()->nTime)-tx.GetValueOut();
|
||||
|
||||
nTxSigOps += GetP2SHSigOpCount(tx, view);
|
||||
if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS)
|
||||
|
||||
@@ -520,9 +520,9 @@ BOOST_AUTO_TEST_CASE(test_Get)
|
||||
t1.vout.resize(2);
|
||||
t1.vout[0].nValue = 90*CENT;
|
||||
t1.vout[0].scriptPubKey << OP_1;
|
||||
|
||||
int64_t interest;
|
||||
BOOST_CHECK(AreInputsStandard(t1, coins));
|
||||
BOOST_CHECK_EQUAL(coins.GetValueIn(t1,0), (50+21+22)*CENT);
|
||||
BOOST_CHECK_EQUAL(coins.GetValueIn(&interest,t1,0), (50+21+22)*CENT);
|
||||
|
||||
// Adding extra junk to the scriptSig should make it non-standard:
|
||||
t1.vin[0].scriptSig << OP_11;
|
||||
|
||||
Reference in New Issue
Block a user