From 17878015bb3b4227127c5ceb1f8637c62ef42f14 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 22 Oct 2016 13:23:25 -0300 Subject: [PATCH] test --- src/coins.cpp | 6 ++--- src/coins.h | 2 +- src/komodo.h | 32 ------------------------- src/komodo_interest.h | 43 ++++++++++++++++++++++++++++++++-- src/main.cpp | 4 ++-- src/miner.cpp | 2 +- src/rpcblockchain.cpp | 9 ++++--- src/rpcrawtransaction.cpp | 4 ++-- src/test/transaction_tests.cpp | 2 +- src/wallet/rpcwallet.cpp | 5 ++-- src/wallet/wallet.cpp | 4 ++-- 11 files changed, 60 insertions(+), 53 deletions(-) diff --git a/src/coins.cpp b/src/coins.cpp index 858e04b15..4272ed611 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -383,9 +383,9 @@ const CScript &CCoinsViewCache::GetSpendFor(const CTxIn& input) const return coins->vout[input.prevout.n].scriptPubKey; } -uint64_t komodo_interest(uint64_t nValue,uint32_t nLockTime,uint32_t tiptime); +uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime); -CAmount CCoinsViewCache::GetValueIn(int64_t *interestp,const CTransaction& tx,uint32_t tiptime) const +CAmount CCoinsViewCache::GetValueIn(int32_t nHeight,int64_t *interestp,const CTransaction& tx,uint32_t tiptime) const { uint32_t timestamp,minutes; int64_t interest; *interestp = 0; @@ -396,7 +396,7 @@ CAmount CCoinsViewCache::GetValueIn(int64_t *interestp,const CTransaction& tx,ui { value = GetOutputFor(tx.vin[i]).nValue; nResult += value; - interest = komodo_interest(value,tx.nLockTime,tiptime); + interest = komodo_interest(nHeight,value,tx.nLockTime,tiptime); #ifdef KOMODO_ENABLE_INTEREST nResult += interest; #endif diff --git a/src/coins.h b/src/coins.h index bf4bc7af3..123d8b4eb 100644 --- a/src/coins.h +++ b/src/coins.h @@ -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(int64_t *interestp,const CTransaction& tx,uint32_t prevblocktime) const; + CAmount GetValueIn(int32_t nHeight,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; diff --git a/src/komodo.h b/src/komodo.h index 76c277596..42a632827 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -83,38 +83,6 @@ const char *Notaries[][2] = { "titomane_SH", "035f49d7a308dd9a209e894321f010d21b7793461b0c89d6d9231a3fe5f68d9960" }, }; -uint64_t komodo_accrued_interest(int32_t height,int64_t paidinterest) -{ - static uint64_t *interests; static int32_t maxheight; - int32_t ind,incr = 100000; - if ( height >= maxheight ) - { - interests = (uint64_t *)realloc(interests,(maxheight + incr) * sizeof(*interests) * 2); - memset(&interests[maxheight << 1],0,incr * sizeof(*interests) * 2); - maxheight += incr; - } - ind = (height << 1); - if ( paidinterest < 0 ) // request - return(interests[ind]); - else - { - if ( interests[ind + 1] != paidinterest ) - { - interests[ind + 1] = paidinterest; - if ( height == 0 ) - height++; - for (; height= maxheight ) + { + interests = (uint64_t *)realloc(interests,(maxheight + incr) * sizeof(*interests) * 2); + memset(&interests[maxheight << 1],0,incr * sizeof(*interests) * 2); + maxheight += incr; + } + ind = (height << 1); + if ( paidinterest < 0 ) // request + return(interests[ind]); + else + { + if ( interests[ind + 1] != paidinterest ) + { + interests[ind + 1] = paidinterest; + if ( height == 0 ) + interests[ind] = interests[ind + 1]; + else interests[ind] = interests[ind - 2] + interests[ind + 1]; + total = interests[ind]; + for (++height; height= LOCKTIME_THRESHOLD && tiptime != 0 && nLockTime < tiptime && nValue >= COIN ) + if ( komodo_moneysupply(txheight) < MAX_MONEY && nLockTime >= LOCKTIME_THRESHOLD && tiptime != 0 && nLockTime < tiptime && nValue >= COIN ) { minutes = (tiptime - nLockTime) / 60; numerator = (nValue * KOMODO_INTEREST); diff --git a/src/main.cpp b/src/main.cpp index 254053a90..45e617a9c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1132,7 +1132,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa // Bring the best block into scope view.GetBestBlock(); - nValueIn = view.GetValueIn(&interest,tx,chainActive.Tip()->nTime); + nValueIn = view.GetValueIn(chainActive.Tip()->nHeight,&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); @@ -2154,7 +2154,7 @@ 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(&interest,tx,chainActive.Tip()->nTime) - tx.GetValueOut(); + nFees += view.GetValueIn(chainActive.Tip()->nHeight,&interest,tx,chainActive.Tip()->nTime) - tx.GetValueOut(); sum += interest; std::vector vChecks; if (!ContextualCheckInputs(tx, state, view, fScriptChecks, flags, false, chainparams.GetConsensus(), nScriptCheckThreads ? &vChecks : NULL)) diff --git a/src/miner.cpp b/src/miner.cpp index 5691a225c..c5a4fa3dc 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -276,7 +276,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) if (!view.HaveInputs(tx)) continue; - CAmount nTxFees = view.GetValueIn(&interest,tx,chainActive.Tip()->nTime)-tx.GetValueOut(); + CAmount nTxFees = view.GetValueIn(chainActive.Tip()->nHeight,&interest,tx,chainActive.Tip()->nTime)-tx.GetValueOut(); nTxSigOps += GetP2SHSigOpCount(tx, view); if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 07c20cb2f..9664e085b 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -380,7 +380,7 @@ Value gettxoutsetinfo(const Array& params, bool fHelp) return ret; } -uint64_t komodo_interest(uint64_t nValue,uint32_t pastlocktime,uint32_t tiptime); +uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime); uint32_t komodo_txtime(uint256 hash); Value gettxout(const Array& params, bool fHelp) @@ -455,12 +455,11 @@ Value gettxout(const Array& params, bool fHelp) ret.push_back(Pair("value", ValueFromAmount(coins.vout[n].nValue))); CBlockIndex *pblockindex = chainActive[coins.nHeight]; - uint64_t interest; uint32_t timestamp=0; if ( pblockindex != 0 ) - timestamp = pblockindex->nTime; - interest = komodo_interest(coins.vout[n].nValue,timestamp,pindex->nTime); - fprintf(stderr,"nValue %llu lock.%u:%u nTime.%u -> %llu\n",(long long)coins.vout[n].nValue,coins.nLockTime,timestamp,pindex->nTime,(long long)interest); + timestamp = pblockindex->nTime; // this is approx, but cant figure out how to get tx here + interest = komodo_interest(coins.nHeight,coins.vout[n].nValue,timestamp,pindex->nTime); + //fprintf(stderr,"nValue %llu lock.%u:%u nTime.%u -> %llu\n",(long long)coins.vout[n].nValue,coins.nLockTime,timestamp,pindex->nTime,(long long)interest); ret.push_back(Pair("interest", ValueFromAmount(interest))); Object o; diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index 93d7b0e2d..46340b5a4 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -96,7 +96,7 @@ Array TxJoinSplitToJSON(const CTransaction& tx) { return vjoinsplit; } -uint64_t komodo_interest(uint64_t nValue,uint32_t pastlocktime,uint32_t tiptime); +uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime); void TxToJSON(const CTransaction& tx, const uint256 hashBlock, Object& entry) { @@ -130,7 +130,7 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, Object& entry) out.push_back(Pair("value", ValueFromAmount(txout.nValue))); if ( pindex != 0 && tx.nLockTime != 0 ) { - interest = komodo_interest(txout.nValue,tx.nLockTime,pindex->nTime); + interest = komodo_interest(pindex->nHeight,txout.nValue,tx.nLockTime,pindex->nTime); fprintf(stderr,"TxtoJSON interest %llu %.8f\n",(long long)interest,(double)interest/COIN); out.push_back(Pair("interest", ValueFromAmount(interest))); } diff --git a/src/test/transaction_tests.cpp b/src/test/transaction_tests.cpp index 3de71ca14..55e7983e5 100644 --- a/src/test/transaction_tests.cpp +++ b/src/test/transaction_tests.cpp @@ -522,7 +522,7 @@ BOOST_AUTO_TEST_CASE(test_Get) t1.vout[0].scriptPubKey << OP_1; int64_t interest; BOOST_CHECK(AreInputsStandard(t1, coins)); - BOOST_CHECK_EQUAL(coins.GetValueIn(&interest,t1,0), (50+21+22)*CENT); + BOOST_CHECK_EQUAL(coins.GetValueIn(0,&interest,t1,0), (50+21+22)*CENT); // Adding extra junk to the scriptSig should make it non-standard: t1.vin[0].scriptSig << OP_11; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index d95dea463..a609881f6 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2259,7 +2259,8 @@ Value resendwallettransactions(const Array& params, bool fHelp) return result; } -uint64_t komodo_interest(uint64_t nValue,uint32_t pastlocktime,uint32_t tiptime); +uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime); + Value listunspent(const Array& params, bool fHelp) { if (!EnsureWalletIsAvailable(fHelp)) @@ -2371,7 +2372,7 @@ Value listunspent(const Array& params, bool fHelp) uint64_t interest; if ( pindex != 0 ) { - interest = komodo_interest(nValue,out.tx->nLockTime,pindex->nTime); + interest = komodo_interest(out.tx->nHeight,nValue,out.tx->nLockTime,pindex->nTime); entry.push_back(Pair("interest",ValueFromAmount(interest))); } } diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index dadb566d0..4a6385b9d 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2333,7 +2333,7 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int return true; } -uint64_t komodo_interest(uint64_t nValue,uint32_t nLockTime,uint32_t tiptime); +uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime); bool CWallet::SelectCoins(const CAmount& nTargetValue, set >& setCoinsRet, CAmount& nValueRet, bool& fOnlyCoinbaseCoinsRet, bool& fNeedCoinbaseCoinsRet, const CCoinControl* coinControl) const { @@ -2377,7 +2377,7 @@ bool CWallet::SelectCoins(const CAmount& nTargetValue, setvout[out.i].nValue; - interest = komodo_interest(out.tx->vout[out.i].nValue,out.tx->nLockTime,chainActive.Tip()->nTime); + interest = komodo_interest(out.tx->nHeight,out.tx->vout[out.i].nValue,out.tx->nLockTime,chainActive.Tip()->nTime); #ifdef KOMODO_ENABLE_INTEREST nValueRet += interest; #endif