test
This commit is contained in:
@@ -23,6 +23,8 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
#include "komodo_interest.h"
|
||||
|
||||
static bool fCreateBlank;
|
||||
static map<string,UniValue> registers;
|
||||
|
||||
@@ -322,15 +324,6 @@ vector<unsigned char> ParseHexUO(map<string,UniValue>& 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)
|
||||
{
|
||||
|
||||
41
src/komodo.h
41
src/komodo.h
@@ -21,6 +21,9 @@
|
||||
#include <pthread.h>
|
||||
#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;
|
||||
|
||||
36
src/komodo_interest.h
Normal file
36
src/komodo_interest.h
Normal file
@@ -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);
|
||||
}
|
||||
@@ -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));
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -2370,12 +2370,15 @@ bool CWallet::SelectCoins(const CAmount& nTargetValue, set<pair<const CWalletTx*
|
||||
// coin control -> 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);
|
||||
|
||||
Reference in New Issue
Block a user