Browse Source

test

pull/4/head
jl777 8 years ago
parent
commit
0fec0cc4b3
  1. 10
      src/coins.cpp
  2. 8
      src/komodo_interest.h
  3. 25
      src/rpcblockchain.cpp
  4. 24
      src/rpcrawtransaction.cpp
  5. 6
      src/wallet/rpcwallet.cpp
  6. 6
      src/wallet/wallet.cpp

10
src/coins.cpp

@ -388,7 +388,6 @@ extern char ASSETCHAINS_SYMBOL[16];
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;
if ( tx.IsCoinBase() != 0 )
return 0;
@ -397,18 +396,19 @@ CAmount CCoinsViewCache::GetValueIn(int32_t nHeight,int64_t *interestp,const CTr
{
value = GetOutputFor(tx.vin[i]).nValue;
nResult += value;
interest = komodo_interest(nHeight,value,tx.nLockTime,tiptime);
#ifdef KOMODO_ENABLE_INTEREST
if ( ASSETCHAINS_SYMBOL[0] == 0 && nHeight >= 60000 )
if ( strcmp(ASSETCHAINS_SYMBOL,"REVS") == 0 )//&& nHeight >= 60000 )
{
//if ( interest != 0 )
int64_t interest;
interest = komodo_interest(nHeight,value,tx.nLockTime,tiptime);
if ( interest != 0 || value >= COIN*100 )
{
printf("nResult %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)nResult/COIN,(double)interest/COIN,nHeight,tx.nLockTime,tiptime);
fprintf(stderr,"nResult %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)nResult/COIN,(double)interest/COIN,nHeight,tx.nLockTime,tiptime);
}
nResult += interest;
(*interestp) += interest;
}
(*interestp) += interest;
#endif
}
nResult += tx.GetJoinSplitValueIn();

8
src/komodo_interest.h

@ -15,7 +15,7 @@
#define KOMODO_INTEREST ((uint64_t)(0.05 * COIN)) // 5%
uint64_t komodo_accrued_interest(int32_t height,int64_t paidinterest)
uint64_t komodo_earned_interest(int32_t height,int64_t paidinterest)
{
static uint64_t *interests; static int32_t maxheight;
uint64_t total; int32_t ind,incr = 100000;
@ -50,15 +50,15 @@ uint64_t komodo_accrued_interest(int32_t height,int64_t paidinterest)
uint64_t komodo_moneysupply(int32_t height)
{
if ( height <= 1 )
if ( height <= 1 || ASSETCHAINS_SYMBOL[0] == 0 )
return(0);
else return(COIN * 100000000 + (height-1) * 3 + komodo_accrued_interest(height,-1));
else return(COIN * 100000000 + (height-1) * 3 + komodo_earned_interest(height,-1));
}
uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime)
{
int32_t minutes; uint64_t numerator,denominator,interest = 0;
if ( komodo_moneysupply(txheight) < MAX_MONEY && nLockTime >= LOCKTIME_THRESHOLD && tiptime != 0 && nLockTime < tiptime && nValue >= COIN )
if ( komodo_moneysupply(txheight) < MAX_MONEY && nLockTime >= LOCKTIME_THRESHOLD && tiptime != 0 && nLockTime < tiptime && nValue >= 100*COIN )
{
if ( (minutes= (tiptime - nLockTime) / 60) > 60 )
{

25
src/rpcblockchain.cpp

@ -380,6 +380,7 @@ Value gettxoutsetinfo(const Array& params, bool fHelp)
return ret;
}
uint32_t komodo_interest_args(int32_t *prevblockheightp,int32_t *prevblocktimep,uint64_t *valuep,uint256 hash,int32_t n);
uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime);
uint32_t komodo_txtime(uint256 hash);
uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uint64_t basevolume);
@ -504,6 +505,18 @@ Value paxprices(const Array& params, bool fHelp)
return ret;
}
uint64_t komodo_accrued_interest(uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue)
{
uint64_t value; int32_t txheight; uint32_t locktime,prevblocktime;
if ( (locktime= komodo_interest_args(&txheight,&prevblocktime,&value,hash,n)) != 0 )
{
if ( (checkvalue == 0 || value == checkvalue) && (checkheight == 0 || txheight == checkheight) )
return(komodo_interest(txheight,value,locktime,prevblocktime));
//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);
} else fprintf(stderr,"komodo_accrued_interest value mismatch %llu vs %llu or height mismatch %d vs %d\n",(long long)value,(long long)checkvalue,txheight,checkheight);
return(0);
}
Value gettxout(const Array& params, bool fHelp)
{
if (fHelp || params.size() < 2 || params.size() > 3)
@ -574,16 +587,8 @@ Value gettxout(const Array& params, bool fHelp)
ret.push_back(Pair("confirmations", 0));
else ret.push_back(Pair("confirmations", pindex->nHeight - coins.nHeight + 1));
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; // 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)));
if ( (interest= komodo_accrued_interest(hash,n,coins.nHeight,coins.vout[n].nValue)) != 0 )
ret.push_back(Pair("interest", ValueFromAmount(interest)));
Object o;
ScriptPubKeyToJSON(coins.vout[n].scriptPubKey, o, true);
ret.push_back(Pair("scriptPubKey", o));

24
src/rpcrawtransaction.cpp

@ -122,16 +122,17 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, Object& entry)
entry.push_back(Pair("vin", vin));
Array vout;
BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock());
CBlockIndex *pindex = it->second;
CBlockIndex *tipindex,*pindex = it->second;
uint64_t interest;
for (unsigned int i = 0; i < tx.vout.size(); i++) {
const CTxOut& txout = tx.vout[i];
Object out;
out.push_back(Pair("value", ValueFromAmount(txout.nValue)));
if ( pindex != 0 && tx.nLockTime != 0 )
if ( pindex != 0 && tx.nLockTime != 0 && (tipindex= chainActive.Tip()) != 0 )
{
interest = komodo_interest(pindex->nHeight,txout.nValue,tx.nLockTime,pindex->nTime);
//fprintf(stderr,"TxtoJSON interest %llu %.8f\n",(long long)interest,(double)interest/COIN);
interest = komodo_interest(pindex->nHeight,txout.nValue,tx.nLockTime,tipindex->nTime);
if ( strcmp("REVS",ASSETCHAINS_SYMBOL) == 0 )
fprintf(stderr,"TxtoJSON interest %llu %.8f (%d %llu %u %u)\n",(long long)interest,(double)interest/COIN,(int32_t)pindex->nHeight,(long long)txout.nValue,(uint32_t)tx.nLockTime,(int32_t)pcoinsTip->nTime);
out.push_back(Pair("interest", ValueFromAmount(interest)));
}
out.push_back(Pair("n", (int64_t)i));
@ -251,19 +252,22 @@ Value getrawtransaction(const Array& params, bool fHelp)
return result;
}
uint32_t komodo_interest_args(int32_t *prevblockheightp,int32_t *prevblocktimep,uint64_t *valuep,uint256 hash,int32_t n)
uint32_t komodo_interest_args(int32_t *txheightp,int32_t *tiptimep,uint64_t *valuep,uint256 hash,int32_t n)
{
//interest = komodo_interest(pindex->nHeight,txout.nValue,tx.nLockTime,pindex->nTime);
LOCK(cs_main);
CTransaction tx;
uint256 hashBlock;
CTransaction tx; uint256 hashBlock; CBlockIndex *pindex,*tipindex;
if ( !GetTransaction(hash,tx,hashBlock,true) )
return(0);
uint32_t locktime = 0;
if ( n < tx.vout.size() )
{
locktime = tx.nLockTime;
//TxToJSON(tx,hashBlock,result);
if ( (pindex= map[hashBlock]) != 0 && (tipindex= chainActive.Tip()) != 0 )
{
*valuep = tx.vout[n].nValue;
*txheightp = pindex->nHeight;
*tiptimep = tipindex->nTime;
locktime = tx.nLockTime;
}
}
return(locktime);
}

6
src/wallet/rpcwallet.cpp

@ -2473,11 +2473,11 @@ Value listunspent(const Array& params, bool fHelp)
if ( out.tx->nLockTime != 0 )
{
BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock());
CBlockIndex *pindex = it->second;
CBlockIndex *tipindex,*pindex = it->second;
uint64_t interest;
if ( pindex != 0 )
if ( pindex != 0 && (tipindex= chainActive.Tip()) != 0 )
{
interest = komodo_interest(pindex->nHeight,nValue,out.tx->nLockTime,pindex->nTime);
interest = komodo_interest(pindex->nHeight,nValue,out.tx->nLockTime,tipindex->nTime);
entry.push_back(Pair("interest",ValueFromAmount(interest)));
}
}

6
src/wallet/wallet.cpp

@ -2399,11 +2399,11 @@ bool CWallet::SelectCoins(const CAmount& nTargetValue, set<pair<const CWalletTx*
if(!out.fSpendable)
continue;
nValueRet += out.tx->vout[out.i].nValue;
interest = komodo_interest(chainActive.Tip()->nHeight+1,out.tx->vout[out.i].nValue,out.tx->nLockTime,chainActive.Tip()->nTime);
#ifdef KOMODO_ENABLE_INTEREST
if ( ASSETCHAINS_SYMBOL[0] == 0 && chainActive.Tip()->nHeight+1 >= 60000 )
if ( strcmp(ASSETCHAINS_SYMBOL,"REVS") == 0 )//&& chainActive.Tip()->nHeight+1 >= 60000 )
{
//if ( interest != 0 )
interest = komodo_interest(chainActive.Tip()->nHeight+1,out.tx->vout[out.i].nValue,out.tx->nLockTime,chainActive.Tip()->nTime);
if ( interest != 0 || value >= COIN*100 )
{
printf("nValueRet %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)out.tx->vout[out.i].nValue/COIN,(double)interest/COIN,chainActive.Tip()->nHeight+1,out.tx->nLockTime,chainActive.Tip()->nTime);
fprintf(stderr,"nValueRet %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)nValueRet/COIN,(double)interest/COIN,chainActive.Tip()->nHeight+1,out.tx->nLockTime,chainActive.Tip()->nTime);

Loading…
Cancel
Save