This commit is contained in:
jl777
2016-10-21 17:28:28 -03:00
parent 75b751ec17
commit 0f24f24562
6 changed files with 24 additions and 10 deletions

View File

@@ -385,7 +385,7 @@ const CScript &CCoinsViewCache::GetSpendFor(const CTxIn& input) const
uint32_t komodo_txtime(uint256 hash); uint32_t komodo_txtime(uint256 hash);
CAmount CCoinsViewCache::GetValueIn(const CTransaction& tx,uint32_t prevblocktime) const CAmount CCoinsViewCache::GetValueIn(const CTransaction& tx,uint32_t tiptime) const
{ {
uint32_t timestamp,minutes; uint32_t timestamp,minutes;
if ( tx.IsCoinBase() != 0 ) if ( tx.IsCoinBase() != 0 )
@@ -395,11 +395,7 @@ CAmount CCoinsViewCache::GetValueIn(const CTransaction& tx,uint32_t prevblocktim
{ {
value = GetOutputFor(tx.vin[i]).nValue; value = GetOutputFor(tx.vin[i]).nValue;
nResult += value; nResult += value;
if ( (timestamp= komodo_txtime(tx.vin[i].prevout.hash)) != 0 && timestamp < prevblocktime-3600*24*7 && value >= COIN ) nResult += komodo_interest(value,komodo_txtime(tx.vin[i].prevout.hash),tiptime);
{
minutes = (prevblocktime - timestamp) / 60;
fprintf(stderr,"GetValueIn %lld i.%d time.%u minutes.%d\n",(long long)value,i,timestamp,minutes);
}
} }
nResult += tx.GetJoinSplitValueIn(); nResult += tx.GetJoinSplitValueIn();

View File

@@ -255,7 +255,7 @@ uint32_t komodo_txtime(uint256 hash)
//printf("null GetTransaction\n"); //printf("null GetTransaction\n");
return(tx.nLockTime); return(tx.nLockTime);
} }
if (!hashBlock.IsNull()) { /*if (!hashBlock.IsNull()) {
BlockMap::iterator mi = mapBlockIndex.find(hashBlock); BlockMap::iterator mi = mapBlockIndex.find(hashBlock);
if (mi != mapBlockIndex.end() && (*mi).second) if (mi != mapBlockIndex.end() && (*mi).second)
{ {
@@ -264,9 +264,20 @@ uint32_t komodo_txtime(uint256 hash)
return(pindex->GetBlockTime()); return(pindex->GetBlockTime());
} }
//printf("cant find in iterator\n"); //printf("cant find in iterator\n");
} }*/
//printf("null hashBlock\n"); //printf("null hashBlock\n");
return(tx.nLockTime); return(0);
}
int64_t komodo_interest(uint64_t nValue,uint32_t nLockTime,uint32_t tiptime)
{
int32_t minutes;
if ( nLockTime >= LOCKTIME_THRESHOLD && tiptime != 0 && nLockTime < tiptime && nValue >= COIN )
{
minutes = (tiptime - nLockTime) / 60;
fprintf(stderr,"komodo_interest %lld nLockTime.%u tiptime.%u minutes.%d\n",(long long)nValue,nLockTime,tiptime,minutes);
}
return(0);
} }
void komodo_nutxoadd(int32_t addflag,int32_t height,int32_t notaryid,uint256 txhash,uint64_t voutmask,int32_t numvouts) void komodo_nutxoadd(int32_t addflag,int32_t height,int32_t notaryid,uint256 txhash,uint64_t voutmask,int32_t numvouts)
@@ -719,4 +730,5 @@ void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height)
} }
} }
#endif #endif

View File

@@ -380,6 +380,7 @@ Value gettxoutsetinfo(const Array& params, bool fHelp)
return ret; return ret;
} }
int64_t komodo_interest(uint64_t nValue,uint32_t pastlocktime,uint32_t tiptime);
Value gettxout(const Array& params, bool fHelp) Value gettxout(const Array& params, bool fHelp)
{ {
if (fHelp || params.size() < 2 || params.size() > 3) if (fHelp || params.size() < 2 || params.size() > 3)
@@ -451,6 +452,7 @@ Value gettxout(const Array& params, bool fHelp)
else else
ret.push_back(Pair("confirmations", pindex->nHeight - coins.nHeight + 1)); ret.push_back(Pair("confirmations", pindex->nHeight - coins.nHeight + 1));
ret.push_back(Pair("value", ValueFromAmount(coins.vout[n].nValue))); 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))));
Object o; Object o;
ScriptPubKeyToJSON(coins.vout[n].scriptPubKey, o, true); ScriptPubKeyToJSON(coins.vout[n].scriptPubKey, o, true);
ret.push_back(Pair("scriptPubKey", o)); ret.push_back(Pair("scriptPubKey", o));

View File

@@ -96,6 +96,7 @@ Array TxJoinSplitToJSON(const CTransaction& tx) {
return vjoinsplit; return vjoinsplit;
} }
int64_t komodo_interest(uint64_t nValue,uint32_t pastlocktime,uint32_t tiptime);
void TxToJSON(const CTransaction& tx, const uint256 hashBlock, Object& entry) void TxToJSON(const CTransaction& tx, const uint256 hashBlock, Object& entry)
{ {
entry.push_back(Pair("txid", tx.GetHash().GetHex())); entry.push_back(Pair("txid", tx.GetHash().GetHex()));
@@ -123,6 +124,7 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, Object& entry)
const CTxOut& txout = tx.vout[i]; const CTxOut& txout = tx.vout[i];
Object out; Object out;
out.push_back(Pair("value", ValueFromAmount(txout.nValue))); 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("n", (int64_t)i)); out.push_back(Pair("n", (int64_t)i));
Object o; Object o;
ScriptPubKeyToJSON(txout.scriptPubKey, o, true); ScriptPubKeyToJSON(txout.scriptPubKey, o, true);

View File

@@ -522,7 +522,7 @@ BOOST_AUTO_TEST_CASE(test_Get)
t1.vout[0].scriptPubKey << OP_1; t1.vout[0].scriptPubKey << OP_1;
BOOST_CHECK(AreInputsStandard(t1, coins)); BOOST_CHECK(AreInputsStandard(t1, coins));
BOOST_CHECK_EQUAL(coins.GetValueIn(t1), (50+21+22)*CENT); BOOST_CHECK_EQUAL(coins.GetValueIn(t1,0), (50+21+22)*CENT);
// Adding extra junk to the scriptSig should make it non-standard: // Adding extra junk to the scriptSig should make it non-standard:
t1.vin[0].scriptSig << OP_11; t1.vin[0].scriptSig << OP_11;

View File

@@ -2259,6 +2259,7 @@ Value resendwallettransactions(const Array& params, bool fHelp)
return result; return result;
} }
int64_t komodo_interest(uint64_t nValue,uint32_t pastlocktime,uint32_t tiptime);
Value listunspent(const Array& params, bool fHelp) Value listunspent(const Array& params, bool fHelp)
{ {
if (!EnsureWalletIsAvailable(fHelp)) if (!EnsureWalletIsAvailable(fHelp))
@@ -2363,6 +2364,7 @@ Value listunspent(const Array& params, bool fHelp)
} }
} }
entry.push_back(Pair("amount",ValueFromAmount(nValue))); entry.push_back(Pair("amount",ValueFromAmount(nValue)));
entry.push_back(Pair("interest",ValueFromAmount(komodo_interest(nValue,out.tx->nLockTime,activeChain.Tip()->nTime))));
entry.push_back(Pair("confirmations",out.nDepth)); entry.push_back(Pair("confirmations",out.nDepth));
entry.push_back(Pair("spendable", out.fSpendable)); entry.push_back(Pair("spendable", out.fSpendable));
results.push_back(entry); results.push_back(entry);