From 6ef202b24a20d563311ad0ac14d7ba6fcfde0e13 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 22 Oct 2016 10:24:06 -0300 Subject: [PATCH] test --- src/bitcoin-tx.cpp | 11 ++--------- src/komodo.h | 41 +++------------------------------------ src/komodo_interest.h | 36 ++++++++++++++++++++++++++++++++++ src/rpcblockchain.cpp | 2 +- src/rpcrawtransaction.cpp | 2 +- src/wallet/rpcwallet.cpp | 2 +- src/wallet/wallet.cpp | 5 ++++- 7 files changed, 48 insertions(+), 51 deletions(-) create mode 100644 src/komodo_interest.h diff --git a/src/bitcoin-tx.cpp b/src/bitcoin-tx.cpp index 42e5ebea7..19f838908 100644 --- a/src/bitcoin-tx.cpp +++ b/src/bitcoin-tx.cpp @@ -23,6 +23,8 @@ using namespace std; +#include "komodo_interest.h" + static bool fCreateBlank; static map registers; @@ -322,15 +324,6 @@ vector ParseHexUO(map& o, string strKey) return ParseHexUV(o[strKey], strKey); } -uint32_t komodo_txtime(uint256 hash) -{ - return(0); -} - -uint64_t komodo_interest(uint64_t nValue,uint32_t nLockTime,uint32_t tiptime) -{ - return(0); -} static void MutateTxSign(CMutableTransaction& tx, const string& flagStr) { diff --git a/src/komodo.h b/src/komodo.h index 174a13e1a..c8104efaa 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -21,6 +21,9 @@ #include #include "uthash.h" +#define KOMODO_INTEREST ((uint64_t)0.05 * COIN) +#include "komodo_interest.h" + #define KOMODO_TESTNET_EXPIRATION 60000 #define KOMODO_ELECTION_GAP 1000 #define KOMODO_PUBKEYS_HEIGHT(height) ((int32_t)(((((height)+KOMODO_ELECTION_GAP*.5)/KOMODO_ELECTION_GAP) + 1) * KOMODO_ELECTION_GAP)) @@ -246,44 +249,6 @@ int32_t komodo_threshold(int32_t height,uint64_t signedmask) else return(0); } -uint32_t komodo_txtime(uint256 hash) -{ - CTransaction tx; - uint256 hashBlock; - if (!GetTransaction(hash, tx, hashBlock, true)) - { - //printf("null GetTransaction\n"); - return(tx.nLockTime); - } - /*if (!hashBlock.IsNull()) { - BlockMap::iterator mi = mapBlockIndex.find(hashBlock); - if (mi != mapBlockIndex.end() && (*mi).second) - { - CBlockIndex* pindex = (*mi).second; - if (chainActive.Contains(pindex)) - return(pindex->GetBlockTime()); - } - //printf("cant find in iterator\n"); - }*/ - //printf("null hashBlock\n"); - return(0); -} - -uint64_t komodo_interest(uint64_t nValue,uint32_t nLockTime,uint32_t tiptime) -{ - int32_t minutes,days; uint64_t interest = 0; - if ( tiptime == 0 ) - tiptime = chainActive.Tip()->nTime; - if ( nLockTime >= LOCKTIME_THRESHOLD && tiptime != 0 && nLockTime < tiptime && nValue >= COIN ) - { - minutes = (tiptime - nLockTime) / 60; - days = minutes / (24 * 60); - interest = (nValue * 5000000) / (((uint64_t)365 * 100000000 * 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); -} - void komodo_nutxoadd(int32_t addflag,int32_t height,int32_t notaryid,uint256 txhash,uint64_t voutmask,int32_t numvouts) { struct nutxo_entry *np; diff --git a/src/komodo_interest.h b/src/komodo_interest.h new file mode 100644 index 000000000..f95540274 --- /dev/null +++ b/src/komodo_interest.h @@ -0,0 +1,36 @@ +uint32_t komodo_txtime(uint256 hash) +{ + CTransaction tx; + uint256 hashBlock; + if (!GetTransaction(hash, tx, hashBlock, true)) + { + //printf("null GetTransaction\n"); + return(tx.nLockTime); + } + /*if (!hashBlock.IsNull()) { + BlockMap::iterator mi = mapBlockIndex.find(hashBlock); + if (mi != mapBlockIndex.end() && (*mi).second) + { + CBlockIndex* pindex = (*mi).second; + if (chainActive.Contains(pindex)) + return(pindex->GetBlockTime()); + } + //printf("cant find in iterator\n"); + }*/ + //printf("null hashBlock\n"); + return(0); +} + +uint64_t komodo_interest(uint64_t nValue,uint32_t nLockTime,uint32_t tiptime) +{ + int32_t minutes; uint64_t interest = 0; + if ( tiptime == 0 ) + tiptime = chainActive.Tip()->nTime; + if ( nLockTime >= LOCKTIME_THRESHOLD && tiptime != 0 && nLockTime < tiptime && nValue >= COIN ) + { + minutes = (tiptime - nLockTime) / 60; + interest = (nValue * KOMODO_INTEREST) / (((uint64_t)365 * 100000000 * 24 * 60) / minutes); + fprintf(stderr,"komodo_interest %lld %.8f nLockTime.%u tiptime.%u minutes.%d interest %lld %.8f\n",(long long)nValue,(double)nValue/100000000.,nLockTime,tiptime,minutes,(long long)interest,(double)interest/100000000); + } + return(interest * 0); +} diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 297755e3d..f8df14b6d 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -452,7 +452,7 @@ Value gettxout(const Array& params, bool fHelp) else ret.push_back(Pair("confirmations", pindex->nHeight - coins.nHeight + 1)); ret.push_back(Pair("value", ValueFromAmount(coins.vout[n].nValue))); - ret.push_back(Pair("interest", ValueFromAmount(komodo_interest(coins.vout[n].nValue,coins.nLockTime,chainActive.Tip()->nTime)))); + ret.push_back(Pair("interest", ValueFromAmount(komodo_interest(coins.vout[n].nValue,coins.nLockTime,pcoinsTip->nTime)))); Object o; ScriptPubKeyToJSON(coins.vout[n].scriptPubKey, o, true); ret.push_back(Pair("scriptPubKey", o)); diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index 9d688af1c..e6f374f72 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -124,7 +124,7 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, Object& entry) const CTxOut& txout = tx.vout[i]; Object out; out.push_back(Pair("value", ValueFromAmount(txout.nValue))); - out.push_back(Pair("interest", ValueFromAmount(komodo_interest(txout.nValue,tx.nLockTime,chainActive.Tip()->nTime)))); + out.push_back(Pair("interest", ValueFromAmount(komodo_interest(txout.nValue,tx.nLockTime,pcoinsTip->nTime)))); out.push_back(Pair("n", (int64_t)i)); Object o; ScriptPubKeyToJSON(txout.scriptPubKey, o, true); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 1568ffb33..914155d66 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2364,7 +2364,7 @@ Value listunspent(const Array& params, bool fHelp) } } entry.push_back(Pair("amount",ValueFromAmount(nValue))); - entry.push_back(Pair("interest",ValueFromAmount(komodo_interest(nValue,out.tx->nLockTime,0)))); + entry.push_back(Pair("interest",ValueFromAmount(komodo_interest(nValue,out.tx->nLockTime,chainActive.Tip()->nTime)))); entry.push_back(Pair("confirmations",out.nDepth)); entry.push_back(Pair("spendable", out.fSpendable)); results.push_back(entry); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index ad8976c70..c8b2f4a1f 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2370,12 +2370,15 @@ bool CWallet::SelectCoins(const CAmount& nTargetValue, set return all selected outputs (we want all selected to go into the transaction for sure) if (coinControl && coinControl->HasSelected()) { + uint64_t interest; BOOST_FOREACH(const COutput& out, vCoins) { if(!out.fSpendable) continue; nValueRet += out.tx->vout[out.i].nValue; - nValueRet += komodo_interest(out.tx->vout[out.i].nValue,out.tx->nLockTime,chainActive.Tip()->nTime); + interest = komodo_interest(out.tx->vout[out.i].nValue,out.tx->nLockTime,pcoinsTip->nTime); + nValueRet += interest; + fprintf(stderr,"interest %llu from %llu lock.%u tip.%u\n",(long long)interest,(long long)out.tx->vout[out.i].nValue,out.tx->nLockTime,chainActive.Tip()->nTime); setCoinsRet.insert(make_pair(out.tx, out.i)); } return (nValueRet >= nTargetValue);