From b1c247f28fdc688898174d94c45e0137734bb9f1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Oct 2016 13:47:00 -0300 Subject: [PATCH 001/101] test --- src/komodo.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index cc4a085b2..807309d7a 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -252,7 +252,7 @@ uint32_t komodo_txtime(uint256 hash) uint256 hashBlock; if (!GetTransaction(hash, tx, hashBlock, true)) { - //printf("null GetTransaction\n"); + printf("null GetTransaction\n"); return(0); } if (!hashBlock.IsNull()) { @@ -263,9 +263,9 @@ uint32_t komodo_txtime(uint256 hash) if (chainActive.Contains(pindex)) return(pindex->GetBlockTime()); } - //printf("cant find in iterator\n"); + printf("cant find in iterator\n"); } - //printf("null hashBlock\n"); + printf("null hashBlock\n"); return(0); } From e19d8b3dee546887f57de8b0cebdce6173cd43aa Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Oct 2016 15:20:30 -0300 Subject: [PATCH 002/101] test --- src/coins.cpp | 2 +- src/komodo.h | 10 ++++----- src/main.cpp | 2 ++ src/wallet/wallet.cpp | 49 ++++++++++++++++++++++++------------------- 4 files changed, 36 insertions(+), 27 deletions(-) diff --git a/src/coins.cpp b/src/coins.cpp index fbc088d5f..147c68872 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -393,7 +393,7 @@ CAmount CCoinsViewCache::GetValueIn(const CTransaction& tx) const CAmount nResult = 0; for (unsigned int i = 0; i < tx.vin.size(); i++) { - //fprintf(stderr,"i.%d time.%u\n",i,komodo_txtime(tx.vin[i].prevout.hash)); + fprintf(stderr,"i.%d time.%u\n",i,komodo_txtime(tx.vin[i].prevout.hash)); nResult += GetOutputFor(tx.vin[i]).nValue; } nResult += tx.GetJoinSplitValueIn(); diff --git a/src/komodo.h b/src/komodo.h index 807309d7a..90e2527c8 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -252,8 +252,8 @@ uint32_t komodo_txtime(uint256 hash) uint256 hashBlock; if (!GetTransaction(hash, tx, hashBlock, true)) { - printf("null GetTransaction\n"); - return(0); + //printf("null GetTransaction\n"); + return(tx.nLockTime); } if (!hashBlock.IsNull()) { BlockMap::iterator mi = mapBlockIndex.find(hashBlock); @@ -263,10 +263,10 @@ uint32_t komodo_txtime(uint256 hash) if (chainActive.Contains(pindex)) return(pindex->GetBlockTime()); } - printf("cant find in iterator\n"); + //printf("cant find in iterator\n"); } - printf("null hashBlock\n"); - return(0); + //printf("null hashBlock\n"); + return(tx.nLockTime); } void komodo_nutxoadd(int32_t addflag,int32_t height,int32_t notaryid,uint256 txhash,uint64_t voutmask,int32_t numvouts) diff --git a/src/main.cpp b/src/main.cpp index 8331c9f1a..29afc109e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -699,6 +699,8 @@ bool IsFinalTx(const CTransaction &tx, int nBlockHeight, int64_t nBlockTime) return true; if ((int64_t)tx.nLockTime < ((int64_t)tx.nLockTime < LOCKTIME_THRESHOLD ? (int64_t)nBlockHeight : nBlockTime)) return true; + if ( (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD && (int64_t)tx.nLockTime < nBlockTime-3600 ) + return(false); // need to prevent pastdating tx BOOST_FOREACH(const CTxIn& txin, tx.vin) if (!txin.IsFinal()) return false; diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 1a865a966..b33888a29 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2411,27 +2411,34 @@ bool CWallet::CreateTransaction(const vector& vecSend, wtxNew.BindWallet(this); CMutableTransaction txNew; - // Discourage fee sniping. - // - // However because of a off-by-one-error in previous versions we need to - // neuter it by setting nLockTime to at least one less than nBestHeight. - // Secondly currently propagation of transactions created for block heights - // corresponding to blocks that were just mined may be iffy - transactions - // aren't re-accepted into the mempool - we additionally neuter the code by - // going ten blocks back. Doesn't yet do anything for sniping, but does act - // to shake out wallet bugs like not showing nLockTime'd transactions at - // all. - txNew.nLockTime = std::max(0, chainActive.Height() - 10); - - // Secondly occasionally randomly pick a nLockTime even further back, so - // that transactions that are delayed after signing for whatever reason, - // e.g. high-latency mix networks and some CoinJoin implementations, have - // better privacy. - if (GetRandInt(10) == 0) - txNew.nLockTime = std::max(0, (int)txNew.nLockTime - GetRandInt(100)); - - assert(txNew.nLockTime <= (unsigned int)chainActive.Height()); - assert(txNew.nLockTime < LOCKTIME_THRESHOLD); + if ( 0 ) + { + // Discourage fee sniping. + // + // However because of a off-by-one-error in previous versions we need to + // neuter it by setting nLockTime to at least one less than nBestHeight. + // Secondly currently propagation of transactions created for block heights + // corresponding to blocks that were just mined may be iffy - transactions + // aren't re-accepted into the mempool - we additionally neuter the code by + // going ten blocks back. Doesn't yet do anything for sniping, but does act + // to shake out wallet bugs like not showing nLockTime'd transactions at + // all. + txNew.nLockTime = std::max(0, chainActive.Height() - 10); + + // Secondly occasionally randomly pick a nLockTime even further back, so + // that transactions that are delayed after signing for whatever reason, + // e.g. high-latency mix networks and some CoinJoin implementations, have + // better privacy. + if (GetRandInt(10) == 0) + txNew.nLockTime = std::max(0, (int)txNew.nLockTime - GetRandInt(100)); + + assert(txNew.nLockTime <= (unsigned int)chainActive.Height()); + assert(txNew.nLockTime < LOCKTIME_THRESHOLD); + } + else + { + txNew.nLockTime = (uint32_t)time(NULL) - 1800; // set to a time close to now + } { LOCK2(cs_main, cs_wallet); From 8c8552a2abe87a95cc3d6bc725e318239b1d4f18 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Oct 2016 15:48:46 -0300 Subject: [PATCH 003/101] test --- src/coins.cpp | 25 +++++++++++++++++++++++-- src/komodo.h | 23 ----------------------- src/main.cpp | 2 +- src/miner.cpp | 2 +- src/wallet/wallet.cpp | 2 +- 5 files changed, 26 insertions(+), 28 deletions(-) diff --git a/src/coins.cpp b/src/coins.cpp index 147c68872..3385ebd6b 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -383,7 +383,28 @@ const CScript &CCoinsViewCache::GetSpendFor(const CTxIn& input) const return coins->vout[input.prevout.n].scriptPubKey; } -uint32_t komodo_txtime(uint256 hash); +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(tx.nLockTime); +} CAmount CCoinsViewCache::GetValueIn(const CTransaction& tx) const { @@ -393,7 +414,7 @@ CAmount CCoinsViewCache::GetValueIn(const CTransaction& tx) const CAmount nResult = 0; for (unsigned int i = 0; i < tx.vin.size(); i++) { - fprintf(stderr,"i.%d time.%u\n",i,komodo_txtime(tx.vin[i].prevout.hash)); + fprintf(stderr,"GetValueIn i.%d time.%u\n",i,komodo_txtime(tx.vin[i].prevout.hash)); nResult += GetOutputFor(tx.vin[i]).nValue; } nResult += tx.GetJoinSplitValueIn(); diff --git a/src/komodo.h b/src/komodo.h index 90e2527c8..41703845a 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -246,29 +246,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(tx.nLockTime); -} - 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/main.cpp b/src/main.cpp index 29afc109e..f781a8d6d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2133,7 +2133,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin if (nSigOps > MAX_BLOCK_SIGOPS) return state.DoS(100, error("ConnectBlock(): too many sigops"), REJECT_INVALID, "bad-blk-sigops"); - +fprintf(stderr,"ht.%d vout0 t%u\n",pindex->nHeight,tx.nLockTime); if (!tx.IsCoinBase()) { if (!view.HaveInputs(tx)) diff --git a/src/miner.cpp b/src/miner.cpp index 56a6aa515..c65dcff41 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -329,6 +329,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) // Create coinbase tx CMutableTransaction txNew; + txNew.nLockTime = (uint32_t)time(NULL) - 60; txNew.vin.resize(1); txNew.vin[0].prevout.SetNull(); txNew.vout.resize(1); @@ -499,7 +500,6 @@ void static BitcoinMiner(CWallet *pwallet) } CBlock *pblock = &pblocktemplate->block; IncrementExtraNonce(pblock, pindexPrev, nExtraNonce); - LogPrintf("Running ZcashMiner with %u transactions in block (%u bytes)\n", pblock->vtx.size(), ::GetSerializeSize(*pblock, SER_NETWORK, PROTOCOL_VERSION)); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index b33888a29..194299472 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2437,7 +2437,7 @@ bool CWallet::CreateTransaction(const vector& vecSend, } else { - txNew.nLockTime = (uint32_t)time(NULL) - 1800; // set to a time close to now + txNew.nLockTime = (uint32_t)time(NULL) - 60; // set to a time close to now } { From 420af8fda7a19ab2ecd7191bbffa7efca200a496 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Oct 2016 15:54:04 -0300 Subject: [PATCH 004/101] test --- src/coins.cpp | 2 +- src/komodo.h | 1 + src/main.cpp | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/coins.cpp b/src/coins.cpp index 3385ebd6b..19283ebb8 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -414,7 +414,7 @@ CAmount CCoinsViewCache::GetValueIn(const CTransaction& tx) const CAmount nResult = 0; for (unsigned int i = 0; i < tx.vin.size(); i++) { - fprintf(stderr,"GetValueIn i.%d time.%u\n",i,komodo_txtime(tx.vin[i].prevout.hash)); + //fprintf(stderr,"GetValueIn i.%d time.%u\n",i,komodo_txtime(tx.vin[i].prevout.hash)); nResult += GetOutputFor(tx.vin[i]).nValue; } nResult += tx.GetJoinSplitValueIn(); diff --git a/src/komodo.h b/src/komodo.h index 41703845a..9b5a9dca4 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -37,6 +37,7 @@ struct knotaries_entry { int32_t height,numnotaries; struct knotary_entry *Notar struct notarized_checkpoint { uint256 notarized_hash,notarized_btctxid; int32_t nHeight,notarized_height; } *NPOINTS; int32_t NUM_NPOINTS; int32_t komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts); +uint32_t komodo_txtime(uint256 hash); // add opreturn funcid // pricefeeds diff --git a/src/main.cpp b/src/main.cpp index f781a8d6d..bf7952d88 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2133,7 +2133,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin if (nSigOps > MAX_BLOCK_SIGOPS) return state.DoS(100, error("ConnectBlock(): too many sigops"), REJECT_INVALID, "bad-blk-sigops"); -fprintf(stderr,"ht.%d vout0 t%u\n",pindex->nHeight,tx.nLockTime); +//fprintf(stderr,"ht.%d vout0 t%u\n",pindex->nHeight,tx.nLockTime); if (!tx.IsCoinBase()) { if (!view.HaveInputs(tx)) From 63a9f52633c8ceeded1b40b69c723a8ce82c7196 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Oct 2016 16:08:37 -0300 Subject: [PATCH 005/101] test --- src/coins.cpp | 17 +++++++++++------ src/coins.h | 2 +- src/main.cpp | 2 +- src/miner.cpp | 2 +- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/coins.cpp b/src/coins.cpp index 19283ebb8..0fb9d4611 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -406,16 +406,21 @@ uint32_t komodo_txtime(uint256 hash) return(tx.nLockTime); } -CAmount CCoinsViewCache::GetValueIn(const CTransaction& tx) const +CAmount CCoinsViewCache::GetValueIn(const CTransaction& tx,uint32_t blocktime) const { - if (tx.IsCoinBase()) + uint32_t timestamp,minutes; + if ( tx.IsCoinBase() != 0 ) return 0; - - CAmount nResult = 0; + CAmount value,nResult = 0; for (unsigned int i = 0; i < tx.vin.size(); i++) { - //fprintf(stderr,"GetValueIn i.%d time.%u\n",i,komodo_txtime(tx.vin[i].prevout.hash)); - nResult += GetOutputFor(tx.vin[i]).nValue; + value = GetOutputFor(tx.vin[i]).nValue; + nResult += value; + if ( (timestamp= komodo_txtime(tx.vin[i].prevout.hash)) != 0 && timestamp < blocktime-3600*24*7 && value >= COIN ) + { + minutes = (blocktime - timestamp) / 60; + fprintf(stderr,"GetValueIn %lld i.%d time.%u minutes.%d\n",(long long)value,i,timestamp,minutes); + } } nResult += tx.GetJoinSplitValueIn(); diff --git a/src/coins.h b/src/coins.h index 7f1fc6124..93fe1d965 100644 --- a/src/coins.h +++ b/src/coins.h @@ -510,7 +510,7 @@ public: * @param[in] tx transaction for which we are checking input total * @return Sum of value of all inputs (scriptSigs) */ - CAmount GetValueIn(const CTransaction& tx) const; + CAmount GetValueIn(const CTransaction& tx,uint32_t blocktime) 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/main.cpp b/src/main.cpp index bf7952d88..290f64ac6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2153,7 +2153,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(tx)-tx.GetValueOut(); + nFees += view.GetValueIn(tx,pindex->nTime)-tx.GetValueOut(); 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 c65dcff41..faac50bc4 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -275,7 +275,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) if (!view.HaveInputs(tx)) continue; - CAmount nTxFees = view.GetValueIn(tx)-tx.GetValueOut(); + CAmount nTxFees = view.GetValueIn(tx,pblock->nTime)-tx.GetValueOut(); nTxSigOps += GetP2SHSigOpCount(tx, view); if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS) From 2fe65b37f5529b0dfa43712aab62406e63bccea7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Oct 2016 16:17:26 -0300 Subject: [PATCH 006/101] test --- src/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 290f64ac6..a4c9ce722 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1042,6 +1042,7 @@ CAmount GetMinRelayFee(const CTransaction& tx, unsigned int nBytes, bool fAllowF bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransaction &tx, bool fLimitFree, bool* pfMissingInputs, bool fRejectAbsurdFee) { + uint32_t blocktime = (uint32_t)time(NULL); AssertLockHeld(cs_main); if (pfMissingInputs) *pfMissingInputs = false; @@ -1132,7 +1133,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa // Bring the best block into scope view.GetBestBlock(); - nValueIn = view.GetValueIn(tx); + nValueIn = view.GetValueIn(tx,blocktime); // we have all inputs cached now, so switch back to dummy, so we don't need to keep lock on mempool view.SetBackend(dummy); From 8a9bc02778f67ac6b709cfdb2ebfec9023f6265b Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Oct 2016 16:44:49 -0300 Subject: [PATCH 007/101] test --- src/bitcoin-tx.cpp | 5 +++++ src/coins.cpp | 23 +---------------------- src/komodo.h | 24 +++++++++++++++++++++++- src/primitives/transaction.h | 3 +-- src/rest.cpp | 1 + 5 files changed, 31 insertions(+), 25 deletions(-) diff --git a/src/bitcoin-tx.cpp b/src/bitcoin-tx.cpp index 319be2991..89a54d846 100644 --- a/src/bitcoin-tx.cpp +++ b/src/bitcoin-tx.cpp @@ -322,6 +322,11 @@ vector ParseHexUO(map& o, string strKey) return ParseHexUV(o[strKey], strKey); } +uint32_t komodo_txtime(uint256 hash) +{ + return(0); +} + static void MutateTxSign(CMutableTransaction& tx, const string& flagStr) { int nHashType = SIGHASH_ALL; diff --git a/src/coins.cpp b/src/coins.cpp index 0fb9d4611..e5a744674 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -383,28 +383,7 @@ const CScript &CCoinsViewCache::GetSpendFor(const CTxIn& input) const return coins->vout[input.prevout.n].scriptPubKey; } -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(tx.nLockTime); -} +uint32_t komodo_txtime(uint256 hash); CAmount CCoinsViewCache::GetValueIn(const CTransaction& tx,uint32_t blocktime) const { diff --git a/src/komodo.h b/src/komodo.h index 9b5a9dca4..90e2527c8 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -37,7 +37,6 @@ struct knotaries_entry { int32_t height,numnotaries; struct knotary_entry *Notar struct notarized_checkpoint { uint256 notarized_hash,notarized_btctxid; int32_t nHeight,notarized_height; } *NPOINTS; int32_t NUM_NPOINTS; int32_t komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts); -uint32_t komodo_txtime(uint256 hash); // add opreturn funcid // pricefeeds @@ -247,6 +246,29 @@ 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(tx.nLockTime); +} + 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/primitives/transaction.h b/src/primitives/transaction.h index 2e83773c4..61e756b2f 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -267,8 +267,7 @@ public: friend bool operator==(const CTxOut& a, const CTxOut& b) { - return (a.nValue == b.nValue && - a.scriptPubKey == b.scriptPubKey); + return (a.nValue == b.nValue && a.scriptPubKey == b.scriptPubKey); } friend bool operator!=(const CTxOut& a, const CTxOut& b) diff --git a/src/rest.cpp b/src/rest.cpp index 7c238d506..d278198b4 100644 --- a/src/rest.cpp +++ b/src/rest.cpp @@ -506,6 +506,7 @@ static bool rest_getutxos(AcceptedConnection* conn, utxo.push_back(Pair("txvers", (int32_t)coin.nTxVer)); utxo.push_back(Pair("height", (int32_t)coin.nHeight)); utxo.push_back(Pair("value", ValueFromAmount(coin.out.nValue))); + //utxo.push_back(Pair("interest", ValueFromAmount(komodo_interest(coin.out.nValue,coin.nLockTime,chainActive.Tip()->nTime)))); // include the script in a json output Object o; From f0eb47af80c7658083c312163b2422b51a849ff2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Oct 2016 16:50:17 -0300 Subject: [PATCH 008/101] test --- src/coins.cpp | 6 +++--- src/coins.h | 2 +- src/main.cpp | 5 ++--- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/coins.cpp b/src/coins.cpp index e5a744674..82729c952 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -385,7 +385,7 @@ const CScript &CCoinsViewCache::GetSpendFor(const CTxIn& input) const uint32_t komodo_txtime(uint256 hash); -CAmount CCoinsViewCache::GetValueIn(const CTransaction& tx,uint32_t blocktime) const +CAmount CCoinsViewCache::GetValueIn(const CTransaction& tx,uint32_t prevblocktime) const { uint32_t timestamp,minutes; if ( tx.IsCoinBase() != 0 ) @@ -395,9 +395,9 @@ CAmount CCoinsViewCache::GetValueIn(const CTransaction& tx,uint32_t blocktime) c { value = GetOutputFor(tx.vin[i]).nValue; nResult += value; - if ( (timestamp= komodo_txtime(tx.vin[i].prevout.hash)) != 0 && timestamp < blocktime-3600*24*7 && value >= COIN ) + if ( (timestamp= komodo_txtime(tx.vin[i].prevout.hash)) != 0 && timestamp < prevblocktime-3600*24*7 && value >= COIN ) { - minutes = (blocktime - timestamp) / 60; + minutes = (prevblocktime - timestamp) / 60; fprintf(stderr,"GetValueIn %lld i.%d time.%u minutes.%d\n",(long long)value,i,timestamp,minutes); } } diff --git a/src/coins.h b/src/coins.h index 93fe1d965..da201a91c 100644 --- a/src/coins.h +++ b/src/coins.h @@ -510,7 +510,7 @@ public: * @param[in] tx transaction for which we are checking input total * @return Sum of value of all inputs (scriptSigs) */ - CAmount GetValueIn(const CTransaction& tx,uint32_t blocktime) const; + CAmount GetValueIn(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/main.cpp b/src/main.cpp index a4c9ce722..00180caa0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1042,7 +1042,6 @@ CAmount GetMinRelayFee(const CTransaction& tx, unsigned int nBytes, bool fAllowF bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransaction &tx, bool fLimitFree, bool* pfMissingInputs, bool fRejectAbsurdFee) { - uint32_t blocktime = (uint32_t)time(NULL); AssertLockHeld(cs_main); if (pfMissingInputs) *pfMissingInputs = false; @@ -1133,7 +1132,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa // Bring the best block into scope view.GetBestBlock(); - nValueIn = view.GetValueIn(tx,blocktime); + nValueIn = view.GetValueIn(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 +2153,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(tx,pindex->nTime)-tx.GetValueOut(); + nFees += view.GetValueIn(tx,pindex->pprev->nTime)-tx.GetValueOut(); std::vector vChecks; if (!ContextualCheckInputs(tx, state, view, fScriptChecks, flags, false, chainparams.GetConsensus(), nScriptCheckThreads ? &vChecks : NULL)) From 75b751ec17cc46bad27ab049021a00b03c5434a2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Oct 2016 16:56:27 -0300 Subject: [PATCH 009/101] test --- src/main.cpp | 2 +- src/miner.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 00180caa0..f0f59b21c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2153,7 +2153,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(tx,pindex->pprev->nTime)-tx.GetValueOut(); + nFees += view.GetValueIn(tx,chainActive.Tip()->nTime)-tx.GetValueOut(); 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 faac50bc4..e34e05904 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -275,7 +275,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) if (!view.HaveInputs(tx)) continue; - CAmount nTxFees = view.GetValueIn(tx,pblock->nTime)-tx.GetValueOut(); + CAmount nTxFees = view.GetValueIn(tx,chainActive.Tip()->nTime)-tx.GetValueOut(); nTxSigOps += GetP2SHSigOpCount(tx, view); if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS) From 0f24f24562e22f652f1f416d8d1bb3e9fbec0dbc Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Oct 2016 17:28:28 -0300 Subject: [PATCH 010/101] test --- src/coins.cpp | 8 ++------ src/komodo.h | 18 +++++++++++++++--- src/rpcblockchain.cpp | 2 ++ src/rpcrawtransaction.cpp | 2 ++ src/test/transaction_tests.cpp | 2 +- src/wallet/rpcwallet.cpp | 2 ++ 6 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/coins.cpp b/src/coins.cpp index 82729c952..85bf791f5 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -385,7 +385,7 @@ const CScript &CCoinsViewCache::GetSpendFor(const CTxIn& input) const 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; if ( tx.IsCoinBase() != 0 ) @@ -395,11 +395,7 @@ CAmount CCoinsViewCache::GetValueIn(const CTransaction& tx,uint32_t prevblocktim { value = GetOutputFor(tx.vin[i]).nValue; nResult += value; - if ( (timestamp= komodo_txtime(tx.vin[i].prevout.hash)) != 0 && timestamp < prevblocktime-3600*24*7 && value >= COIN ) - { - minutes = (prevblocktime - timestamp) / 60; - fprintf(stderr,"GetValueIn %lld i.%d time.%u minutes.%d\n",(long long)value,i,timestamp,minutes); - } + nResult += komodo_interest(value,komodo_txtime(tx.vin[i].prevout.hash),tiptime); } nResult += tx.GetJoinSplitValueIn(); diff --git a/src/komodo.h b/src/komodo.h index 90e2527c8..e51a69df8 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -255,7 +255,7 @@ uint32_t komodo_txtime(uint256 hash) //printf("null GetTransaction\n"); return(tx.nLockTime); } - if (!hashBlock.IsNull()) { + /*if (!hashBlock.IsNull()) { BlockMap::iterator mi = mapBlockIndex.find(hashBlock); if (mi != mapBlockIndex.end() && (*mi).second) { @@ -264,9 +264,20 @@ uint32_t komodo_txtime(uint256 hash) return(pindex->GetBlockTime()); } //printf("cant find in iterator\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) @@ -719,4 +730,5 @@ void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height) } } + #endif diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 4c92979b2..803fbd9d0 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -380,6 +380,7 @@ Value gettxoutsetinfo(const Array& params, bool fHelp) return ret; } +int64_t komodo_interest(uint64_t nValue,uint32_t pastlocktime,uint32_t tiptime); Value gettxout(const Array& params, bool fHelp) { if (fHelp || params.size() < 2 || params.size() > 3) @@ -451,6 +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)))); 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 5cca9df9d..864acef4e 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -96,6 +96,7 @@ Array TxJoinSplitToJSON(const CTransaction& tx) { 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) { 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]; 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("n", (int64_t)i)); Object o; ScriptPubKeyToJSON(txout.scriptPubKey, o, true); diff --git a/src/test/transaction_tests.cpp b/src/test/transaction_tests.cpp index c2b0a7017..e9df46152 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; 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: t1.vin[0].scriptSig << OP_11; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 4d6608570..5a30e76ce 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2259,6 +2259,7 @@ Value resendwallettransactions(const Array& params, bool fHelp) return result; } +int64_t komodo_interest(uint64_t nValue,uint32_t pastlocktime,uint32_t tiptime); Value listunspent(const Array& params, bool 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("interest",ValueFromAmount(komodo_interest(nValue,out.tx->nLockTime,activeChain.Tip()->nTime)))); entry.push_back(Pair("confirmations",out.nDepth)); entry.push_back(Pair("spendable", out.fSpendable)); results.push_back(entry); From 0ba361a59a3ca1c797f53089ea65c7dc0d6d096c Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Oct 2016 17:34:42 -0300 Subject: [PATCH 011/101] test --- src/coins.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/coins.h b/src/coins.h index da201a91c..920a17f0c 100644 --- a/src/coins.h +++ b/src/coins.h @@ -85,12 +85,14 @@ public: //! version of the CTransaction; accesses to this value should probably check for nHeight as well, //! as new tx version will probably only be introduced at certain heights int nVersion; + uint32_t nLockTime; void FromTx(const CTransaction &tx, int nHeightIn) { fCoinBase = tx.IsCoinBase(); vout = tx.vout; nHeight = nHeightIn; nVersion = tx.nVersion; + nLockTime = tx.nLockTime; ClearUnspendable(); } From 560c5598bebab043da7b9a2984286bd7beb04ac8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Oct 2016 18:03:15 -0300 Subject: [PATCH 012/101] test --- src/coins.cpp | 1 + src/komodo.h | 9 ++++++--- src/wallet/wallet.cpp | 2 ++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/coins.cpp b/src/coins.cpp index 85bf791f5..6387e13f2 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -384,6 +384,7 @@ const CScript &CCoinsViewCache::GetSpendFor(const CTxIn& input) const } uint32_t komodo_txtime(uint256 hash); +int64_t komodo_interest(uint64_t nValue,uint32_t nLockTime,uint32_t tiptime); CAmount CCoinsViewCache::GetValueIn(const CTransaction& tx,uint32_t tiptime) const { diff --git a/src/komodo.h b/src/komodo.h index e51a69df8..cc3bb60f8 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -271,13 +271,16 @@ uint32_t komodo_txtime(uint256 hash) int64_t komodo_interest(uint64_t nValue,uint32_t nLockTime,uint32_t tiptime) { - int32_t minutes; + int32_t minutes,days; uint64_t interest = 0; 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); + days = minutes / (24 * 60); + if ( days > 0 ) + interest = (nValue * 50000) / (365 * 1000000 / days); + fprintf(stderr,"komodo_interest %lld nLockTime.%u tiptime.%u minutes.%d days.%d interest %lld %.4f%%\n",(long long)nValue,nLockTime,tiptime,minutes,days,(long long)interest,(double)interest/10000.); } - return(0); + return(interest * 0); } void komodo_nutxoadd(int32_t addflag,int32_t height,int32_t notaryid,uint256 txhash,uint64_t voutmask,int32_t numvouts) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 194299472..3c58aca4c 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2333,6 +2333,7 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int return true; } +int64_t komodo_interest(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 { // Output parameter fOnlyCoinbaseCoinsRet is set to true when the only available coins are coinbase utxos. @@ -2374,6 +2375,7 @@ bool CWallet::SelectCoins(const CAmount& nTargetValue, setvout[out.i].nValue; + nValueRet += komodo_interest(out.tx->vout[out.i].nValue,out.tx.nLockTime,activeChain.Tip()->nTime); setCoinsRet.insert(make_pair(out.tx, out.i)); } return (nValueRet >= nTargetValue); From 5c2c4d0edc7416a5cd6eb1cfd4c039763213aa27 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Oct 2016 18:05:09 -0300 Subject: [PATCH 013/101] test --- src/komodo.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index cc3bb60f8..9fc7a65e0 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -277,8 +277,8 @@ int64_t komodo_interest(uint64_t nValue,uint32_t nLockTime,uint32_t tiptime) minutes = (tiptime - nLockTime) / 60; days = minutes / (24 * 60); if ( days > 0 ) - interest = (nValue * 50000) / (365 * 1000000 / days); - fprintf(stderr,"komodo_interest %lld nLockTime.%u tiptime.%u minutes.%d days.%d interest %lld %.4f%%\n",(long long)nValue,nLockTime,tiptime,minutes,days,(long long)interest,(double)interest/10000.); + interest = (nValue * 5000000) / (365 * 1000000 / days); + 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); } From ce8b023c7a7b6f1c13b6dcfcc5d5db617c6b4f51 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Oct 2016 18:14:17 -0300 Subject: [PATCH 014/101] test --- src/komodo.h | 2 ++ src/wallet/rpcwallet.cpp | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index 9fc7a65e0..9ebbf2c21 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -272,6 +272,8 @@ uint32_t komodo_txtime(uint256 hash) int64_t komodo_interest(uint64_t nValue,uint32_t nLockTime,uint32_t tiptime) { int32_t minutes,days; uint64_t interest = 0; + if ( tiptime == 0 ) + tiptime = activeChain.Tip()->nTime; if ( nLockTime >= LOCKTIME_THRESHOLD && tiptime != 0 && nLockTime < tiptime && nValue >= COIN ) { minutes = (tiptime - nLockTime) / 60; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 5a30e76ce..1038854e1 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,activeChain.Tip()->nTime)))); + entry.push_back(Pair("interest",ValueFromAmount(komodo_interest(nValue,out.tx->nLockTime,0)))); entry.push_back(Pair("confirmations",out.nDepth)); entry.push_back(Pair("spendable", out.fSpendable)); results.push_back(entry); From 40cb0c7d41f442c640011bbbd94da57809e0d69b Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Oct 2016 18:15:46 -0300 Subject: [PATCH 015/101] test --- src/komodo.h | 2 +- src/wallet/wallet.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 9ebbf2c21..6382510c3 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -273,7 +273,7 @@ int64_t komodo_interest(uint64_t nValue,uint32_t nLockTime,uint32_t tiptime) { int32_t minutes,days; uint64_t interest = 0; if ( tiptime == 0 ) - tiptime = activeChain.Tip()->nTime; + tiptime = chainActive.Tip()->nTime; if ( nLockTime >= LOCKTIME_THRESHOLD && tiptime != 0 && nLockTime < tiptime && nValue >= COIN ) { minutes = (tiptime - nLockTime) / 60; diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 3c58aca4c..75634c48c 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2375,7 +2375,7 @@ bool CWallet::SelectCoins(const CAmount& nTargetValue, setvout[out.i].nValue; - nValueRet += komodo_interest(out.tx->vout[out.i].nValue,out.tx.nLockTime,activeChain.Tip()->nTime); + nValueRet += komodo_interest(out.tx->vout[out.i].nValue,out.tx.nLockTime,chainActive.Tip()->nTime); setCoinsRet.insert(make_pair(out.tx, out.i)); } return (nValueRet >= nTargetValue); From 2897cc41e0da73cb33256b6c8ef02cec0a77ede7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Oct 2016 18:28:28 -0300 Subject: [PATCH 016/101] test --- src/wallet/wallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 75634c48c..070badbd1 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2375,7 +2375,7 @@ bool CWallet::SelectCoins(const CAmount& nTargetValue, setvout[out.i].nValue; - nValueRet += komodo_interest(out.tx->vout[out.i].nValue,out.tx.nLockTime,chainActive.Tip()->nTime); + nValueRet += komodo_interest(out.tx->vout[out.i].nValue,out.tx->nLockTime,chainActive.Tip()->nTime); setCoinsRet.insert(make_pair(out.tx, out.i)); } return (nValueRet >= nTargetValue); From 8ad9f27fdd719e13494123144453927fc163cdde Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Oct 2016 18:32:52 -0300 Subject: [PATCH 017/101] test --- src/bitcoin-tx.cpp | 5 +++++ src/coins.cpp | 2 +- src/komodo.h | 2 +- src/rpcblockchain.cpp | 2 +- src/rpcrawtransaction.cpp | 2 +- src/wallet/rpcwallet.cpp | 2 +- src/wallet/wallet.cpp | 2 +- 7 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/bitcoin-tx.cpp b/src/bitcoin-tx.cpp index 89a54d846..42e5ebea7 100644 --- a/src/bitcoin-tx.cpp +++ b/src/bitcoin-tx.cpp @@ -327,6 +327,11 @@ 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) { int nHashType = SIGHASH_ALL; diff --git a/src/coins.cpp b/src/coins.cpp index 6387e13f2..2e4f23042 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -384,7 +384,7 @@ const CScript &CCoinsViewCache::GetSpendFor(const CTxIn& input) const } uint32_t komodo_txtime(uint256 hash); -int64_t komodo_interest(uint64_t nValue,uint32_t nLockTime,uint32_t tiptime); +uint64_t komodo_interest(uint64_t nValue,uint32_t nLockTime,uint32_t tiptime); CAmount CCoinsViewCache::GetValueIn(const CTransaction& tx,uint32_t tiptime) const { diff --git a/src/komodo.h b/src/komodo.h index 6382510c3..1cacb95de 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -269,7 +269,7 @@ uint32_t komodo_txtime(uint256 hash) return(0); } -int64_t komodo_interest(uint64_t nValue,uint32_t nLockTime,uint32_t tiptime) +uint64_t komodo_interest(uint64_t nValue,uint32_t nLockTime,uint32_t tiptime) { int32_t minutes,days; uint64_t interest = 0; if ( tiptime == 0 ) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 803fbd9d0..297755e3d 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -380,7 +380,7 @@ Value gettxoutsetinfo(const Array& params, bool fHelp) return ret; } -int64_t komodo_interest(uint64_t nValue,uint32_t pastlocktime,uint32_t tiptime); +uint64_t komodo_interest(uint64_t nValue,uint32_t pastlocktime,uint32_t tiptime); Value gettxout(const Array& params, bool fHelp) { if (fHelp || params.size() < 2 || params.size() > 3) diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index 864acef4e..9d688af1c 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -96,7 +96,7 @@ Array TxJoinSplitToJSON(const CTransaction& tx) { return vjoinsplit; } -int64_t komodo_interest(uint64_t nValue,uint32_t pastlocktime,uint32_t tiptime); +uint64_t komodo_interest(uint64_t nValue,uint32_t pastlocktime,uint32_t tiptime); void TxToJSON(const CTransaction& tx, const uint256 hashBlock, Object& entry) { entry.push_back(Pair("txid", tx.GetHash().GetHex())); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 1038854e1..1568ffb33 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2259,7 +2259,7 @@ Value resendwallettransactions(const Array& params, bool fHelp) return result; } -int64_t komodo_interest(uint64_t nValue,uint32_t pastlocktime,uint32_t tiptime); +uint64_t komodo_interest(uint64_t nValue,uint32_t pastlocktime,uint32_t tiptime); Value listunspent(const Array& params, bool fHelp) { if (!EnsureWalletIsAvailable(fHelp)) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 070badbd1..ad8976c70 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; } -int64_t komodo_interest(uint64_t nValue,uint32_t nLockTime,uint32_t tiptime); +uint64_t komodo_interest(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 { // Output parameter fOnlyCoinbaseCoinsRet is set to true when the only available coins are coinbase utxos. From 355ca56547184d90a0909c9677fa8618553028ae Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Oct 2016 19:09:24 -0300 Subject: [PATCH 018/101] test --- src/coins.cpp | 9 ++++++--- src/coins.h | 2 +- src/komodo.h | 3 +-- src/main.cpp | 11 ++++++----- src/miner.cpp | 3 ++- src/test/transaction_tests.cpp | 4 ++-- 6 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/coins.cpp b/src/coins.cpp index 2e4f23042..505430e87 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -386,9 +386,10 @@ const CScript &CCoinsViewCache::GetSpendFor(const CTxIn& input) const uint32_t komodo_txtime(uint256 hash); uint64_t komodo_interest(uint64_t nValue,uint32_t nLockTime,uint32_t tiptime); -CAmount CCoinsViewCache::GetValueIn(const CTransaction& tx,uint32_t tiptime) const +CAmount CCoinsViewCache::GetValueIn(int64_t *interestp,const CTransaction& tx,uint32_t tiptime) const { - uint32_t timestamp,minutes; + uint32_t timestamp,minutes; int64_t interest; + *interestp = 0; if ( tx.IsCoinBase() != 0 ) return 0; CAmount value,nResult = 0; @@ -396,7 +397,9 @@ CAmount CCoinsViewCache::GetValueIn(const CTransaction& tx,uint32_t tiptime) con { value = GetOutputFor(tx.vin[i]).nValue; nResult += value; - nResult += komodo_interest(value,komodo_txtime(tx.vin[i].prevout.hash),tiptime); + interest = komodo_interest(value,komodo_txtime(tx.vin[i].prevout.hash),tiptime); + nResult += interest; + (*interestp) += interest; } nResult += tx.GetJoinSplitValueIn(); diff --git a/src/coins.h b/src/coins.h index 920a17f0c..bf4bc7af3 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(const CTransaction& tx,uint32_t prevblocktime) const; + CAmount GetValueIn(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 1cacb95de..6c243e6f8 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -278,8 +278,7 @@ uint64_t komodo_interest(uint64_t nValue,uint32_t nLockTime,uint32_t tiptime) { minutes = (tiptime - nLockTime) / 60; days = minutes / (24 * 60); - if ( days > 0 ) - interest = (nValue * 5000000) / (365 * 1000000 / days); + interest = (nValue * 5000000) / ((365 * 1000000 * 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); diff --git a/src/main.cpp b/src/main.cpp index f0f59b21c..fc20e557a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1097,7 +1097,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa { CCoinsView dummy; CCoinsViewCache view(&dummy); - + int64_t interest; CAmount nValueIn = 0; { LOCK(pool.cs); @@ -1132,7 +1132,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa // Bring the best block into scope view.GetBestBlock(); - nValueIn = view.GetValueIn(tx,chainActive.Tip()->nTime); + nValueIn = view.GetValueIn(&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); @@ -2100,6 +2100,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin int64_t nTimeStart = GetTimeMicros(); CAmount nFees = 0; int nInputs = 0; + int64_t interest,sum = 0; unsigned int nSigOps = 0; CDiskTxPos pos(pindex->GetBlockPos(), GetSizeOfCompactSize(block.vtx.size())); std::vector > vPos; @@ -2153,14 +2154,14 @@ 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(tx,chainActive.Tip()->nTime)-tx.GetValueOut(); - + nFees += view.GetValueIn(&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)) return false; control.Add(vChecks); } - + komodo_accrued_interest(pindex->nHeight,sum); CTxUndo undoDummy; if (i > 0) { blockundo.vtxundo.push_back(CTxUndo()); diff --git a/src/miner.cpp b/src/miner.cpp index e34e05904..611facea6 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -228,6 +228,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) // Collect transactions into block uint64_t nBlockSize = 1000; uint64_t nBlockTx = 0; + int64_t interest; int nBlockSigOps = 100; bool fSortedByFee = (nBlockPrioritySize <= 0); @@ -275,7 +276,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) if (!view.HaveInputs(tx)) continue; - CAmount nTxFees = view.GetValueIn(tx,chainActive.Tip()->nTime)-tx.GetValueOut(); + CAmount nTxFees = view.GetValueIn(&interest,tx,chainActive.Tip()->nTime)-tx.GetValueOut(); nTxSigOps += GetP2SHSigOpCount(tx, view); if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS) diff --git a/src/test/transaction_tests.cpp b/src/test/transaction_tests.cpp index e9df46152..3de71ca14 100644 --- a/src/test/transaction_tests.cpp +++ b/src/test/transaction_tests.cpp @@ -520,9 +520,9 @@ BOOST_AUTO_TEST_CASE(test_Get) t1.vout.resize(2); t1.vout[0].nValue = 90*CENT; t1.vout[0].scriptPubKey << OP_1; - + int64_t interest; BOOST_CHECK(AreInputsStandard(t1, coins)); - BOOST_CHECK_EQUAL(coins.GetValueIn(t1,0), (50+21+22)*CENT); + BOOST_CHECK_EQUAL(coins.GetValueIn(&interest,t1,0), (50+21+22)*CENT); // Adding extra junk to the scriptSig should make it non-standard: t1.vin[0].scriptSig << OP_11; From 0016f0db51c2953d3a657b8e22f24a0e6b02611c Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Oct 2016 19:15:43 -0300 Subject: [PATCH 019/101] test --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index 6c243e6f8..23d53941e 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -278,7 +278,7 @@ uint64_t komodo_interest(uint64_t nValue,uint32_t nLockTime,uint32_t tiptime) { minutes = (tiptime - nLockTime) / 60; days = minutes / (24 * 60); - interest = (nValue * 5000000) / ((365 * 1000000 * 24 * 60) / minutes); + interest = (nValue * 5000000) / (((uint64_t)365 * 1000000 * 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); From 97b900d77eb6f0b318e94c9c55438b5da15b9e16 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 22 Oct 2016 10:06:11 -0300 Subject: [PATCH 020/101] test --- src/komodo.h | 2 +- src/main.cpp | 29 ++++++++++++++++++----------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 23d53941e..174a13e1a 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -278,7 +278,7 @@ uint64_t komodo_interest(uint64_t nValue,uint32_t nLockTime,uint32_t tiptime) { minutes = (tiptime - nLockTime) / 60; days = minutes / (24 * 60); - interest = (nValue * 5000000) / (((uint64_t)365 * 1000000 * 24 * 60) / minutes); + 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); diff --git a/src/main.cpp b/src/main.cpp index fc20e557a..254053a90 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3079,19 +3079,26 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta return state.DoS(100, error("%s: forked chain older than last checkpoint (height %d) vs %d", __func__, nHeight,pcheckpoint->nHeight)); else { - int32_t notarized_height; uint256 notarized_hash,notarized_btctxid; + int32_t notarized_height; uint256 notarized_hash,notarized_btctxid; CBlockIndex *notary; notarized_height = komodo_notarizeddata(chainActive.Tip()->nHeight,¬arized_hash,¬arized_btctxid); - //printf("nHeight.%d -> (%d %s)\n",chainActive.Tip()->nHeight,notarized_height,notarized_hash.ToString().c_str()); - if ( nHeight < notarized_height ) + if ( (notary= mapBlockIndex[notarized_hash]) != 0 ) { - fprintf(stderr,"nHeight.%d < NOTARIZED_HEIGHT.%d\n",nHeight,notarized_height); - return state.DoS(100, error("%s: forked chain older than last notarized (height %d) vs %d", __func__,nHeight, notarized_height)); - } - else if ( nHeight == notarized_height && memcmp(&hash,¬arized_hash,sizeof(hash)) != 0 ) - { - fprintf(stderr,"nHeight.%d == NOTARIZED_HEIGHT.%d, diff hash\n",nHeight,notarized_height); - return state.DoS(100, error("%s: forked chain at notarized (height %d) with different hash", __func__, notarized_height)); - } + //printf("nHeight.%d -> (%d %s)\n",chainActive.Tip()->nHeight,notarized_height,notarized_hash.ToString().c_str()); + if ( notary->nHeight == notarized_height ) // if notarized_hash not in chain, reorg + { + if ( nHeight < notarized_height ) + { + fprintf(stderr,"nHeight.%d < NOTARIZED_HEIGHT.%d\n",nHeight,notarized_height); + return state.DoS(100, error("%s: forked chain older than last notarized (height %d) vs %d", __func__,nHeight, notarized_height)); + } + else if ( nHeight == notarized_height && memcmp(&hash,¬arized_hash,sizeof(hash)) != 0 ) + { + fprintf(stderr,"nHeight.%d == NOTARIZED_HEIGHT.%d, diff hash\n",nHeight,notarized_height); + return state.DoS(100, error("%s: forked chain at notarized (height %d) with different hash", __func__, notarized_height)); + } + } else fprintf(stderr,"notary_hash %s ht.%d at ht.%d\n",notarized_hash.ToString().c_str(),notarized_height,notary->nHeight); + } else if ( notarized_height > 0 ) + fprintf(stderr,"couldnt find notary_hash %s ht.%d\n",notarized_hash.ToString().c_str(),notarized_height); } } From 6ef202b24a20d563311ad0ac14d7ba6fcfde0e13 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 22 Oct 2016 10:24:06 -0300 Subject: [PATCH 021/101] 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); From ae02c5b4b6831080e1d2ca592fc14de291052ff1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 22 Oct 2016 10:27:14 -0300 Subject: [PATCH 022/101] test --- src/rpcblockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index f8df14b6d..297755e3d 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,pcoinsTip->nTime)))); + ret.push_back(Pair("interest", ValueFromAmount(komodo_interest(coins.vout[n].nValue,coins.nLockTime,chainActive.Tip()->nTime)))); Object o; ScriptPubKeyToJSON(coins.vout[n].scriptPubKey, o, true); ret.push_back(Pair("scriptPubKey", o)); From 03b093e29f9c8ab78714df2159e4758323365e57 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 22 Oct 2016 10:28:41 -0300 Subject: [PATCH 023/101] test --- src/rpcrawtransaction.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index e6f374f72..9d688af1c 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,pcoinsTip->nTime)))); + out.push_back(Pair("interest", ValueFromAmount(komodo_interest(txout.nValue,tx.nLockTime,chainActive.Tip()->nTime)))); out.push_back(Pair("n", (int64_t)i)); Object o; ScriptPubKeyToJSON(txout.scriptPubKey, o, true); From 09c5c3d3322348bd70a0cfc462504bba35fe6eb3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 22 Oct 2016 10:31:05 -0300 Subject: [PATCH 024/101] test --- src/wallet/wallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index c8b2f4a1f..501860705 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2376,7 +2376,7 @@ bool CWallet::SelectCoins(const CAmount& nTargetValue, setvout[out.i].nValue; - interest = komodo_interest(out.tx->vout[out.i].nValue,out.tx->nLockTime,pcoinsTip->nTime); + interest = komodo_interest(out.tx->vout[out.i].nValue,out.tx->nLockTime,chainActive.Tip()->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)); From b927fb353541d233455356e8bcaca54be1b438c9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 22 Oct 2016 10:37:11 -0300 Subject: [PATCH 025/101] test --- src/komodo.h | 26 ++++++++++++++++++++++++-- src/komodo_interest.h | 27 +++------------------------ 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index c8104efaa..8656d6e6d 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -21,7 +21,6 @@ #include #include "uthash.h" -#define KOMODO_INTEREST ((uint64_t)0.05 * COIN) #include "komodo_interest.h" #define KOMODO_TESTNET_EXPIRATION 60000 @@ -244,11 +243,34 @@ int32_t komodo_threshold(int32_t height,uint64_t signedmask) for (i=0; i (numnotaries >> 1) || (wt > numnotaries/5 && (signedmask & 3) != 0) ) + if ( wt > (numnotaries >> 1) || (wt > 7 && (signedmask & 3) != 0) ) return(1); // N/2+1 || N/3 + devsig 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); +} + 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 index f95540274..83d238b39 100644 --- a/src/komodo_interest.h +++ b/src/komodo_interest.h @@ -1,31 +1,10 @@ -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); -} + + +#define KOMODO_INTEREST ((uint64_t)0.05 * COIN) 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; From a6ce4b84b19f57c55b64016091727d21fb6a7742 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 22 Oct 2016 10:41:02 -0300 Subject: [PATCH 026/101] test --- src/coins.cpp | 3 +-- src/komodo.h | 11 ----------- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/src/coins.cpp b/src/coins.cpp index 505430e87..59228498a 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -383,7 +383,6 @@ const CScript &CCoinsViewCache::GetSpendFor(const CTxIn& input) const return coins->vout[input.prevout.n].scriptPubKey; } -uint32_t komodo_txtime(uint256 hash); uint64_t komodo_interest(uint64_t nValue,uint32_t nLockTime,uint32_t tiptime); CAmount CCoinsViewCache::GetValueIn(int64_t *interestp,const CTransaction& tx,uint32_t tiptime) const @@ -397,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,komodo_txtime(tx.vin[i].prevout.hash),tiptime); + interest = komodo_interest(value,tx.nLockTime,tiptime); nResult += interest; (*interestp) += interest; } diff --git a/src/komodo.h b/src/komodo.h index 8656d6e6d..76c277596 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -257,17 +257,6 @@ uint32_t komodo_txtime(uint256 hash) //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); } From 09335626d357013ade9042b27926913802894953 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 22 Oct 2016 10:52:59 -0300 Subject: [PATCH 027/101] test --- src/komodo_interest.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/komodo_interest.h b/src/komodo_interest.h index 83d238b39..d1811a04e 100644 --- a/src/komodo_interest.h +++ b/src/komodo_interest.h @@ -1,6 +1,7 @@ #define KOMODO_INTEREST ((uint64_t)0.05 * COIN) +#define dstr(x) ((double)(x)/COIN) uint64_t komodo_interest(uint64_t nValue,uint32_t nLockTime,uint32_t tiptime) { @@ -8,8 +9,12 @@ uint64_t komodo_interest(uint64_t nValue,uint32_t nLockTime,uint32_t tiptime) 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); + numerator = (nValue * KOMODO_INTEREST); + denominator = (((uint64_t)365 * 24 * 60) / minutes); + if ( denominator == 0 ) + denominator = 1; // max KOMODO_INTEREST per transfer, do it at least annually! + interest = numerator / denominator; + fprintf(stderr,"komodo_interest %lld %.8f nLockTime.%u tiptime.%u minutes.%d interest %lld %.8f (%llu / %llu)\n",(long long)nValue,dstr(nValue),nLockTime,tiptime,minutes,(long long)interest,dstr(interest),(long long)numerator,(long long)denominator); } return(interest * 0); } From 8bbc6241a5b57b4a0133c3c3a6418a20dd083763 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 22 Oct 2016 10:55:09 -0300 Subject: [PATCH 028/101] test --- src/komodo_interest.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_interest.h b/src/komodo_interest.h index d1811a04e..69f340d13 100644 --- a/src/komodo_interest.h +++ b/src/komodo_interest.h @@ -5,7 +5,7 @@ uint64_t komodo_interest(uint64_t nValue,uint32_t nLockTime,uint32_t tiptime) { - int32_t minutes; uint64_t interest = 0; + int32_t minutes; uint64_t numerator,denominator,interest = 0; if ( nLockTime >= LOCKTIME_THRESHOLD && tiptime != 0 && nLockTime < tiptime && nValue >= COIN ) { minutes = (tiptime - nLockTime) / 60; From 2ffcaf4e1c3dd4cb983fb824a8dc419d771b56cf Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 22 Oct 2016 11:05:02 -0300 Subject: [PATCH 029/101] test --- src/komodo_interest.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_interest.h b/src/komodo_interest.h index 69f340d13..db6f32166 100644 --- a/src/komodo_interest.h +++ b/src/komodo_interest.h @@ -1,6 +1,6 @@ -#define KOMODO_INTEREST ((uint64_t)0.05 * COIN) +#define KOMODO_INTEREST ((uint64_t)(0.05 * COIN)) #define dstr(x) ((double)(x)/COIN) uint64_t komodo_interest(uint64_t nValue,uint32_t nLockTime,uint32_t tiptime) From cad0d1ca628038b1edd73ae39521d7d100232ad4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 22 Oct 2016 11:32:24 -0300 Subject: [PATCH 030/101] test --- src/komodo_interest.h | 2 +- src/miner.cpp | 2 +- src/rpcblockchain.cpp | 5 ++--- src/rpcrawtransaction.cpp | 6 +++++- src/wallet/rpcwallet.cpp | 1 + 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/komodo_interest.h b/src/komodo_interest.h index db6f32166..201489516 100644 --- a/src/komodo_interest.h +++ b/src/komodo_interest.h @@ -13,7 +13,7 @@ uint64_t komodo_interest(uint64_t nValue,uint32_t nLockTime,uint32_t tiptime) denominator = (((uint64_t)365 * 24 * 60) / minutes); if ( denominator == 0 ) denominator = 1; // max KOMODO_INTEREST per transfer, do it at least annually! - interest = numerator / denominator; + interest = (numerator / denominator) / COIN; fprintf(stderr,"komodo_interest %lld %.8f nLockTime.%u tiptime.%u minutes.%d interest %lld %.8f (%llu / %llu)\n",(long long)nValue,dstr(nValue),nLockTime,tiptime,minutes,(long long)interest,dstr(interest),(long long)numerator,(long long)denominator); } return(interest * 0); diff --git a/src/miner.cpp b/src/miner.cpp index 611facea6..5691a225c 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -330,7 +330,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) // Create coinbase tx CMutableTransaction txNew; - txNew.nLockTime = (uint32_t)time(NULL) - 60; + //txNew.nLockTime = (uint32_t)time(NULL) - 60; txNew.vin.resize(1); txNew.vin[0].prevout.SetNull(); txNew.vout.resize(1); diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 297755e3d..995b4464a 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -449,10 +449,9 @@ Value gettxout(const Array& params, bool fHelp) ret.push_back(Pair("bestblock", pindex->GetBlockHash().GetHex())); if ((unsigned int)coins.nHeight == MEMPOOL_HEIGHT) ret.push_back(Pair("confirmations", 0)); - else - ret.push_back(Pair("confirmations", pindex->nHeight - coins.nHeight + 1)); + 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,coins.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..48593afeb 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -97,6 +97,7 @@ Array TxJoinSplitToJSON(const CTransaction& tx) { } uint64_t komodo_interest(uint64_t nValue,uint32_t pastlocktime,uint32_t tiptime); + void TxToJSON(const CTransaction& tx, const uint256 hashBlock, Object& entry) { entry.push_back(Pair("txid", tx.GetHash().GetHex())); @@ -120,11 +121,14 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, Object& entry) } entry.push_back(Pair("vin", vin)); Array vout; + 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))); - out.push_back(Pair("interest", ValueFromAmount(komodo_interest(txout.nValue,tx.nLockTime,chainActive.Tip()->nTime)))); + interest = komodo_interest(txout.nValue,tx.nLockTime,chainActive.Tip()->nTime)); + fprintf(stderr,"TxtoJSON interest %llu %.8f\n",(long long)interest,(double)interest/COIN); + out.push_back(Pair("interest", ValueFromAmount(interest)); 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 914155d66..214593a28 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2364,6 +2364,7 @@ Value listunspent(const Array& params, bool fHelp) } } entry.push_back(Pair("amount",ValueFromAmount(nValue))); + fprintf(stderr,"nLock.%u tip.%u\n",tx->nLockTime,chainActive.Tip()->nTime); 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)); From e42867d124b3c6dbfb9c8560cae06c022d0d581b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 22 Oct 2016 11:38:25 -0300 Subject: [PATCH 031/101] test --- src/rpcblockchain.cpp | 2 +- src/rpcrawtransaction.cpp | 11 ++++++++--- src/wallet/rpcwallet.cpp | 9 +++++++-- src/wallet/wallet.cpp | 1 + 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 995b4464a..ce485a9ec 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -451,7 +451,7 @@ 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))); - ret.push_back(Pair("interest", ValueFromAmount(komodo_interest(coins.vout[n].nValue,coins.nLockTime,coins.nTime)))); + ret.push_back(Pair("interest", ValueFromAmount(komodo_interest(coins.vout[n].nValue,coins.nLockTime,pindex->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 48593afeb..510b3e71a 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -121,14 +121,19 @@ 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; 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))); - interest = komodo_interest(txout.nValue,tx.nLockTime,chainActive.Tip()->nTime)); - fprintf(stderr,"TxtoJSON interest %llu %.8f\n",(long long)interest,(double)interest/COIN); - out.push_back(Pair("interest", ValueFromAmount(interest)); + if ( pindex != 0 ) + { + interest = komodo_interest(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))); + } 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 214593a28..dace1d69e 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2364,8 +2364,13 @@ Value listunspent(const Array& params, bool fHelp) } } entry.push_back(Pair("amount",ValueFromAmount(nValue))); - fprintf(stderr,"nLock.%u tip.%u\n",tx->nLockTime,chainActive.Tip()->nTime); - entry.push_back(Pair("interest",ValueFromAmount(komodo_interest(nValue,out.tx->nLockTime,chainActive.Tip()->nTime)))); + BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock()); + CBlockIndex *pindex = it->second; + if ( pindex != 0 ) + { + fprintf(stderr,"nLock.%u tip.%u\n",tx->nLockTime,chainActive.Tip()->nTime); + entry.push_back(Pair("interest",ValueFromAmount(komodo_interest(nValue,out.tx->nLockTime,pindex->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 501860705..524fcd9ac 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2334,6 +2334,7 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int } uint64_t komodo_interest(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 { // Output parameter fOnlyCoinbaseCoinsRet is set to true when the only available coins are coinbase utxos. From 24eefea8e0e759908344e9e00579eb2a610559f3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 22 Oct 2016 11:41:49 -0300 Subject: [PATCH 032/101] test --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index dace1d69e..00833a64e 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2368,7 +2368,7 @@ Value listunspent(const Array& params, bool fHelp) CBlockIndex *pindex = it->second; if ( pindex != 0 ) { - fprintf(stderr,"nLock.%u tip.%u\n",tx->nLockTime,chainActive.Tip()->nTime); + fprintf(stderr,"nLock.%u tip.%u %u\n",out.tx->nLockTime,chainActive.Tip()->nTime,pindex->nTime); entry.push_back(Pair("interest",ValueFromAmount(komodo_interest(nValue,out.tx->nLockTime,pindex->nTime)))); } entry.push_back(Pair("confirmations",out.nDepth)); From fdbf481faff66c1f7342723fc088f0baac2b54b4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 22 Oct 2016 11:56:19 -0300 Subject: [PATCH 033/101] test --- src/coins.cpp | 2 ++ src/komodo_interest.h | 3 ++- src/rpcrawtransaction.cpp | 2 +- src/wallet/rpcwallet.cpp | 15 ++++++++++----- src/wallet/wallet.cpp | 2 ++ 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/coins.cpp b/src/coins.cpp index 59228498a..858e04b15 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -397,7 +397,9 @@ 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); +#ifdef KOMODO_ENABLE_INTEREST nResult += interest; +#endif (*interestp) += interest; } nResult += tx.GetJoinSplitValueIn(); diff --git a/src/komodo_interest.h b/src/komodo_interest.h index 201489516..9a7670032 100644 --- a/src/komodo_interest.h +++ b/src/komodo_interest.h @@ -1,4 +1,5 @@ +//#define KOMODO_ENABLE_INTEREST #define KOMODO_INTEREST ((uint64_t)(0.05 * COIN)) #define dstr(x) ((double)(x)/COIN) @@ -16,5 +17,5 @@ uint64_t komodo_interest(uint64_t nValue,uint32_t nLockTime,uint32_t tiptime) interest = (numerator / denominator) / COIN; fprintf(stderr,"komodo_interest %lld %.8f nLockTime.%u tiptime.%u minutes.%d interest %lld %.8f (%llu / %llu)\n",(long long)nValue,dstr(nValue),nLockTime,tiptime,minutes,(long long)interest,dstr(interest),(long long)numerator,(long long)denominator); } - return(interest * 0); + return(interest); } diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index 510b3e71a..93d7b0e2d 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -128,7 +128,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))); - if ( pindex != 0 ) + if ( pindex != 0 && tx.nLockTime != 0 ) { interest = komodo_interest(txout.nValue,tx.nLockTime,pindex->nTime); fprintf(stderr,"TxtoJSON interest %llu %.8f\n",(long long)interest,(double)interest/COIN); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 00833a64e..a059fa9a3 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2364,12 +2364,17 @@ Value listunspent(const Array& params, bool fHelp) } } entry.push_back(Pair("amount",ValueFromAmount(nValue))); - BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock()); - CBlockIndex *pindex = it->second; - if ( pindex != 0 ) + if ( out.tx->nLockTime != 0 ) { - fprintf(stderr,"nLock.%u tip.%u %u\n",out.tx->nLockTime,chainActive.Tip()->nTime,pindex->nTime); - entry.push_back(Pair("interest",ValueFromAmount(komodo_interest(nValue,out.tx->nLockTime,pindex->nTime)))); + BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock()); + CBlockIndex *pindex = it->second; + uint64_t interest; + if ( pindex != 0 ) + { + interest = komodo_interest(nValue,out.tx->nLockTime,pindex->nTime); + fprintf(stderr,"nLock.%u tip.%u %u interest.%llu\n",out.tx->nLockTime,chainActive.Tip()->nTime,pindex->nTime,(long long)interest); + entry.push_back(Pair("interest",ValueFromAmount(interest))); + } } entry.push_back(Pair("confirmations",out.nDepth)); entry.push_back(Pair("spendable", out.fSpendable)); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 524fcd9ac..9f1f07536 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2378,7 +2378,9 @@ 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); +#ifdef KOMODO_ENABLE_INTEREST nValueRet += interest; +#endif 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)); } From 6f3a04079828ac83ab97b8001dd336f44b80df4f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 22 Oct 2016 12:09:45 -0300 Subject: [PATCH 034/101] test --- src/rpcblockchain.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index ce485a9ec..396211a8f 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -451,7 +451,15 @@ 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))); - ret.push_back(Pair("interest", ValueFromAmount(komodo_interest(coins.vout[n].nValue,coins.nLockTime,pindex->nTime)))); + + it = mapBlockIndex.find(hash); + if ( (pindex= it->second) != 0 ) + { + uint64_t interest; + interest = komodo_interest(coins.vout[n].nValue,coins.nLockTime,pindex->nTime); + fprintf(stderr,"nValue %llu lock.%u nTime.%u -> %llu\n",(long long)coins.vout[n].nValue,coins.nLockTime,pindex->nTime,(long long)interest); + ret.push_back(Pair("interest", ValueFromAmount(interest))); + } Object o; ScriptPubKeyToJSON(coins.vout[n].scriptPubKey, o, true); ret.push_back(Pair("scriptPubKey", o)); From 47658758e170324bbcdef6abdea65db2d439c12e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 22 Oct 2016 12:27:01 -0300 Subject: [PATCH 035/101] test --- src/rpcblockchain.cpp | 5 +---- src/wallet/rpcwallet.cpp | 8 ++++---- src/wallet/wallet.cpp | 2 +- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 396211a8f..c9c13b7a0 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -452,14 +452,11 @@ 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))); - it = mapBlockIndex.find(hash); - if ( (pindex= it->second) != 0 ) - { uint64_t interest; interest = komodo_interest(coins.vout[n].nValue,coins.nLockTime,pindex->nTime); fprintf(stderr,"nValue %llu lock.%u nTime.%u -> %llu\n",(long long)coins.vout[n].nValue,coins.nLockTime,pindex->nTime,(long long)interest); ret.push_back(Pair("interest", ValueFromAmount(interest))); - } + Object o; ScriptPubKeyToJSON(coins.vout[n].scriptPubKey, o, true); ret.push_back(Pair("scriptPubKey", o)); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index a059fa9a3..0a5d8f579 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -610,7 +610,7 @@ Value getreceivedbyaddress(const Array& params, bool fHelp) BOOST_FOREACH(const CTxOut& txout, wtx.vout) if (txout.scriptPubKey == scriptPubKey) if (wtx.GetDepthInMainChain() >= nMinDepth) - nAmount += txout.nValue; + nAmount += txout.nValue; // komodo_interest? } return ValueFromAmount(nAmount); @@ -666,7 +666,7 @@ Value getreceivedbyaccount(const Array& params, bool fHelp) CTxDestination address; if (ExtractDestination(txout.scriptPubKey, address) && IsMine(*pwalletMain, address) && setAddress.count(address)) if (wtx.GetDepthInMainChain() >= nMinDepth) - nAmount += txout.nValue; + nAmount += txout.nValue; // komodo_interest? } } @@ -1140,7 +1140,7 @@ Value ListReceived(const Array& params, bool fByAccounts) continue; tallyitem& item = mapTally[address]; - item.nAmount += txout.nValue; + item.nAmount += txout.nValue; // komodo_interest? item.nConf = min(item.nConf, nDepth); item.txids.push_back(wtx.GetHash()); if (mine & ISMINE_WATCH_ONLY) @@ -2893,7 +2893,7 @@ CAmount getBalanceTaddr(std::string transparentAddress, int minDepth=1) { } } - CAmount nValue = out.tx->vout[out.i].nValue; + CAmount nValue = out.tx->vout[out.i].nValue; // komodo_interest balance += nValue; } return balance; diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 9f1f07536..dadb566d0 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1312,7 +1312,7 @@ CAmount CWallet::GetDebit(const CTxIn &txin, const isminefilter& filter) const const CWalletTx& prev = (*mi).second; if (txin.prevout.n < prev.vout.size()) if (IsMine(prev.vout[txin.prevout.n]) & filter) - return prev.vout[txin.prevout.n].nValue; + return prev.vout[txin.prevout.n].nValue; // komodo_interest? } } return 0; From 382c22eaa7b7c428570f579ac535575307d8c6b7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 22 Oct 2016 12:31:43 -0300 Subject: [PATCH 036/101] test --- src/rpcblockchain.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index c9c13b7a0..afdcc8607 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -445,18 +445,20 @@ Value gettxout(const Array& params, bool fHelp) return Value::null; BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock()); - CBlockIndex *pindex = it->second; + BlockMap::iterator it2 = mapBlockIndex.find(hash); + CBlockIndex *pindex2,*pindex = it->second; ret.push_back(Pair("bestblock", pindex->GetBlockHash().GetHex())); if ((unsigned int)coins.nHeight == MEMPOOL_HEIGHT) 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))); - + if ( (pindex2= it2->second) != 0 ) + { uint64_t interest; - interest = komodo_interest(coins.vout[n].nValue,coins.nLockTime,pindex->nTime); - fprintf(stderr,"nValue %llu lock.%u nTime.%u -> %llu\n",(long long)coins.vout[n].nValue,coins.nLockTime,pindex->nTime,(long long)interest); + interest = komodo_interest(coins.vout[n].nValue,pindex2->nTime,pindex->nTime); + fprintf(stderr,"nValue %llu lock.%u nTime.%u -> %llu\n",(long long)coins.vout[n].nValue,coins.nLockTime,pindex2->nTime,(long long)interest); ret.push_back(Pair("interest", ValueFromAmount(interest))); - + } Object o; ScriptPubKeyToJSON(coins.vout[n].scriptPubKey, o, true); ret.push_back(Pair("scriptPubKey", o)); From 7a77c4431c4bb810e4b52c1e22988d490b037964 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 22 Oct 2016 12:46:45 -0300 Subject: [PATCH 037/101] test --- src/rpcblockchain.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index afdcc8607..95e7d15fc 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -381,6 +381,8 @@ Value gettxoutsetinfo(const Array& params, bool fHelp) } uint64_t komodo_interest(uint64_t nValue,uint32_t pastlocktime,uint32_t tiptime); +uint32_t komodo_txtime(uint256 hash); + Value gettxout(const Array& params, bool fHelp) { if (fHelp || params.size() < 2 || params.size() > 3) @@ -445,20 +447,18 @@ Value gettxout(const Array& params, bool fHelp) return Value::null; BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock()); - BlockMap::iterator it2 = mapBlockIndex.find(hash); - CBlockIndex *pindex2,*pindex = it->second; + CBlockIndex *pindex = it->second; ret.push_back(Pair("bestblock", pindex->GetBlockHash().GetHex())); if ((unsigned int)coins.nHeight == MEMPOOL_HEIGHT) 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))); - if ( (pindex2= it2->second) != 0 ) - { - uint64_t interest; - interest = komodo_interest(coins.vout[n].nValue,pindex2->nTime,pindex->nTime); - fprintf(stderr,"nValue %llu lock.%u nTime.%u -> %llu\n",(long long)coins.vout[n].nValue,coins.nLockTime,pindex2->nTime,(long long)interest); - ret.push_back(Pair("interest", ValueFromAmount(interest))); - } + + uint64_t interest; uint32_t timestamp = komodo_txtime(hash); + 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); + ret.push_back(Pair("interest", ValueFromAmount(interest))); + Object o; ScriptPubKeyToJSON(coins.vout[n].scriptPubKey, o, true); ret.push_back(Pair("scriptPubKey", o)); From 2860f74793f84a8bf4e6d0e75673080f9e0f434e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 22 Oct 2016 13:03:18 -0300 Subject: [PATCH 038/101] test --- src/rpcblockchain.cpp | 6 +++++- src/wallet/rpcwallet.cpp | 1 - 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 95e7d15fc..07c20cb2f 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -454,7 +454,11 @@ 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))); - uint64_t interest; uint32_t timestamp = komodo_txtime(hash); + 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); ret.push_back(Pair("interest", ValueFromAmount(interest))); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 0a5d8f579..d95dea463 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2372,7 +2372,6 @@ Value listunspent(const Array& params, bool fHelp) if ( pindex != 0 ) { interest = komodo_interest(nValue,out.tx->nLockTime,pindex->nTime); - fprintf(stderr,"nLock.%u tip.%u %u interest.%llu\n",out.tx->nLockTime,chainActive.Tip()->nTime,pindex->nTime,(long long)interest); entry.push_back(Pair("interest",ValueFromAmount(interest))); } } From 17878015bb3b4227127c5ceb1f8637c62ef42f14 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 22 Oct 2016 13:23:25 -0300 Subject: [PATCH 039/101] 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 From 7652ed92bd22789710ef8768528b88411b1a4616 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 22 Oct 2016 13:35:17 -0300 Subject: [PATCH 040/101] test --- src/komodo.h | 7 +++++++ src/miner.cpp | 12 +++++++++++- src/wallet/rpcwallet.cpp | 2 +- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 42a632827..981dc0ddd 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -678,5 +678,12 @@ void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height) } } +int32_t komodo_opreturn(uint8_t *opret,int32_t maxsize) +{ + int32_t i; + for (i=0; i<8; i++) + opret[i] = i; + return(i); +} #endif diff --git a/src/miner.cpp b/src/miner.cpp index c5a4fa3dc..80f974759 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -96,6 +96,8 @@ void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, consensusParams); } +int32_t komodo_opreturn(uint8_t *opret,int32_t maxsize); + CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) { const CChainParams& chainparams = Params(); @@ -333,11 +335,19 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) //txNew.nLockTime = (uint32_t)time(NULL) - 60; txNew.vin.resize(1); txNew.vin[0].prevout.SetNull(); - txNew.vout.resize(1); + int32_t opretlen; uint8_t opret[8192]; + if ( (opretlen= komodo_opreturn(opret,sizeof(opret))) > 0 ) + { + txNew.vout.resize(2); + txNew.vout[1].scriptPubKey.resize(opretlen); + memcpy(txNew.vout[1].scriptPubKey.data(),opret,opretlen); + txNew.vout[1].nValue = 0; + } else txNew.vout.resize(1); txNew.vout[0].scriptPubKey = scriptPubKeyIn; txNew.vout[0].nValue = GetBlockSubsidy(nHeight, chainparams.GetConsensus()); // Add fees txNew.vout[0].nValue += nFees; + txNew.vin[0].scriptSig = CScript() << nHeight << OP_0; pblock->vtx[0] = txNew; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index a609881f6..39b98f0f7 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2372,7 +2372,7 @@ Value listunspent(const Array& params, bool fHelp) uint64_t interest; if ( pindex != 0 ) { - interest = komodo_interest(out.tx->nHeight,nValue,out.tx->nLockTime,pindex->nTime); + interest = komodo_interest(pindex->nHeight,nValue,out.tx->nLockTime,pindex->nTime); entry.push_back(Pair("interest",ValueFromAmount(interest))); } } From 92e15ee3370d365fd1c53ff9977ad597c507fd82 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 22 Oct 2016 13:41:32 -0300 Subject: [PATCH 041/101] test --- src/wallet/wallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 4a6385b9d..9fac07166 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2377,7 +2377,7 @@ bool CWallet::SelectCoins(const CAmount& nTargetValue, setvout[out.i].nValue; - interest = komodo_interest(out.tx->nHeight,out.tx->vout[out.i].nValue,out.tx->nLockTime,chainActive.Tip()->nTime); + interest = komodo_interest(chainActive.Tip()->nHeight,out.tx->vout[out.i].nValue,out.tx->nLockTime,chainActive.Tip()->nTime); #ifdef KOMODO_ENABLE_INTEREST nValueRet += interest; #endif From ee9b44ce666d8b1eea189ff0e303acd808432de4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 22 Oct 2016 13:48:08 -0300 Subject: [PATCH 042/101] test --- src/miner.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/miner.cpp b/src/miner.cpp index 80f974759..776939164 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -342,6 +342,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) txNew.vout[1].scriptPubKey.resize(opretlen); memcpy(txNew.vout[1].scriptPubKey.data(),opret,opretlen); txNew.vout[1].nValue = 0; + fprintf(stderr,"opretlen.%d\n",opretlen); } else txNew.vout.resize(1); txNew.vout[0].scriptPubKey = scriptPubKeyIn; txNew.vout[0].nValue = GetBlockSubsidy(nHeight, chainparams.GetConsensus()); From 00deff02d598158dbec7e29d4d8118525d60a5dd Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 22 Oct 2016 14:19:14 -0300 Subject: [PATCH 043/101] test --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 776939164..7b3fc6f0a 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -342,7 +342,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) txNew.vout[1].scriptPubKey.resize(opretlen); memcpy(txNew.vout[1].scriptPubKey.data(),opret,opretlen); txNew.vout[1].nValue = 0; - fprintf(stderr,"opretlen.%d\n",opretlen); + //fprintf(stderr,"opretlen.%d\n",opretlen); } else txNew.vout.resize(1); txNew.vout[0].scriptPubKey = scriptPubKeyIn; txNew.vout[0].nValue = GetBlockSubsidy(nHeight, chainparams.GetConsensus()); From c0968b8eed98e14609ba72a159e97d461601e06a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 22 Oct 2016 14:21:34 -0300 Subject: [PATCH 044/101] test --- src/komodo.h | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 981dc0ddd..28718f5e6 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -678,12 +678,35 @@ void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height) } } +int32_t komodo_opreturnscript(uint8_t *script,uint8_t *opret,int32_t opretlen) +{ + int32_t offset = 0; + script[offset++] = 0x6a; + if ( opretlen >= 0x4c ) + { + if ( opretlen > 0xff ) + { + script[offset++] = 0x4d; + script[offset++] = opretlen & 0xff; + script[offset++] = (opretlen >> 8) & 0xff; + } + else + { + script[offset++] = 0x4c; + script[offset++] = opretlen; + } + } else script[offset++] = opretlen; + memcpy(&script[offset],opret,opretlen); + return(opretlen + offset); +} + int32_t komodo_opreturn(uint8_t *opret,int32_t maxsize) { - int32_t i; + int32_t i,n; uint8_t data[4096]; for (i=0; i<8; i++) - opret[i] = i; - return(i); + data[i] = i; + n = komodo_opreturnscript(opret,data,i); + return(n); } #endif From 73d79c1d485c940e88c97d134af72add3eacb4c4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 22 Oct 2016 14:37:27 -0300 Subject: [PATCH 045/101] test --- src/komodo.h | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 28718f5e6..a04526428 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -702,10 +702,32 @@ int32_t komodo_opreturnscript(uint8_t *script,uint8_t *opret,int32_t opretlen) int32_t komodo_opreturn(uint8_t *opret,int32_t maxsize) { - int32_t i,n; uint8_t data[4096]; - for (i=0; i<8; i++) - data[i] = i; - n = komodo_opreturnscript(opret,data,i); + FILE *fp; char fname[512]; uint32_t crc32,check; int32_t i,n,retval,fsize; uint8_t data[8192]; +#ifdef WIN32 + sprintf(fname,"%s\\%s",GetDataDir(false).string().c_str(),(char *)"komodofeed"); +#else + sprintf(fname,"%s/%s",GetDataDir(false).string().c_str(),(char *)"komodofeed"); +#endif + if ( (fp= fopen(fname,"rb")) != 0 ) + { + fseek(fp,0,SEEK_END); + fsize = (int32_t)ftell(fp); + rewind(fp); + if ( fsize <= maxsize-4 && fsize <= sizeof(data) && fsize > sizeof(uin32_t) ) + { + if ( (retval= (int32_t)fread(data,1,fsize,fp)) == fsize ) + { + iguana_rwnum(0,data,sizeof(crc32),(void *)&crc32); + check = calc_crc32(0,data+sizeof(crc32),(int32_t)(fsize-sizeof(crc32))); + n = komodo_opreturnscript(opret,data+sizeof(crc32),(int32_t)(fsize-sizeof(crc32))); + for (i=0; i maxsize.%d or data[%d]\n",fsize,maxsize,sizeof(data)); + fclose(fp); + } return(n); } From 2bd54af4a2ed0b7207c0fb6c15844b7cd7056455 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 22 Oct 2016 14:38:28 -0300 Subject: [PATCH 046/101] test --- src/komodo.h | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src/komodo.h b/src/komodo.h index a04526428..b0bc3bce7 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -83,6 +83,64 @@ const char *Notaries[][2] = { "titomane_SH", "035f49d7a308dd9a209e894321f010d21b7793461b0c89d6d9231a3fe5f68d9960" }, }; +static const uint32_t crc32_tab[] = { + 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, + 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, + 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, + 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, + 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, + 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, + 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, + 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, + 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, + 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, + 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106, + 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, + 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, + 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, + 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, + 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, + 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, + 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, + 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, + 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, + 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, + 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, + 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84, + 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, + 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, + 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, + 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e, + 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, + 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, + 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, + 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, + 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, + 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, + 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, + 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, + 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, + 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, + 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, + 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, + 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, + 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, + 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, + 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d +}; + +uint32_t calc_crc32(uint32_t crc,const void *buf,size_t size) +{ + const uint8_t *p; + + p = (const uint8_t *)buf; + crc = crc ^ ~0U; + + while (size--) + crc = crc32_tab[(crc ^ *p++) & 0xFF] ^ (crc >> 8); + + return crc ^ ~0U; +} int32_t iguana_rwnum(int32_t rwflag,uint8_t *serialized,int32_t len,void *endianedp) { From 4087487ba630dc1e44424a023ccb198e787494a3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 22 Oct 2016 14:39:42 -0300 Subject: [PATCH 047/101] test --- src/komodo.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index b0bc3bce7..56bc01cd8 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -771,7 +771,7 @@ int32_t komodo_opreturn(uint8_t *opret,int32_t maxsize) fseek(fp,0,SEEK_END); fsize = (int32_t)ftell(fp); rewind(fp); - if ( fsize <= maxsize-4 && fsize <= sizeof(data) && fsize > sizeof(uin32_t) ) + if ( fsize <= maxsize-4 && fsize <= sizeof(data) && fsize > sizeof(crc32) ) { if ( (retval= (int32_t)fread(data,1,fsize,fp)) == fsize ) { @@ -783,7 +783,7 @@ int32_t komodo_opreturn(uint8_t *opret,int32_t maxsize) printf(" coinbase opret[%d] crc32.%u:%u\n",n,crc32,check); } else printf("fread.%d error != fsize.%d\n",retval,fsize); - } else printf("fsize.%ld > maxsize.%d or data[%d]\n",fsize,maxsize,sizeof(data)); + } else printf("fsize.%ld > maxsize.%d or data[%d]\n",fsize,maxsize,(int32_t)sizeof(data)); fclose(fp); } return(n); From 3ab13bf358479bcb27ce73eb77d7be9b614077d8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 22 Oct 2016 14:41:31 -0300 Subject: [PATCH 048/101] test --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index 56bc01cd8..da9b0b3ea 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -783,7 +783,7 @@ int32_t komodo_opreturn(uint8_t *opret,int32_t maxsize) printf(" coinbase opret[%d] crc32.%u:%u\n",n,crc32,check); } else printf("fread.%d error != fsize.%d\n",retval,fsize); - } else printf("fsize.%ld > maxsize.%d or data[%d]\n",fsize,maxsize,(int32_t)sizeof(data)); + } else printf("fsize.%d > maxsize.%d or data[%d]\n",fsize,maxsize,(int32_t)sizeof(data)); fclose(fp); } return(n); From d81c57cbcaa3ac226c67870a1241fc5e610d3ef1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Oct 2016 09:29:30 -0300 Subject: [PATCH 049/101] test --- src/miner.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 7b3fc6f0a..c05e43056 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -335,12 +335,14 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) //txNew.nLockTime = (uint32_t)time(NULL) - 60; txNew.vin.resize(1); txNew.vin[0].prevout.SetNull(); - int32_t opretlen; uint8_t opret[8192]; + int32_t i,opretlen; uint8_t opret[8192],*ptr; if ( (opretlen= komodo_opreturn(opret,sizeof(opret))) > 0 ) { txNew.vout.resize(2); txNew.vout[1].scriptPubKey.resize(opretlen); - memcpy(txNew.vout[1].scriptPubKey.data(),opret,opretlen); + ptr = (uint8_t *)txNew.vout[1].scriptPubKey.data(); + for (i=0; i Date: Sun, 23 Oct 2016 10:45:47 -0300 Subject: [PATCH 050/101] test --- src/komodo.h | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index da9b0b3ea..7e0399a2d 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -760,7 +760,7 @@ int32_t komodo_opreturnscript(uint8_t *script,uint8_t *opret,int32_t opretlen) int32_t komodo_opreturn(uint8_t *opret,int32_t maxsize) { - FILE *fp; char fname[512]; uint32_t crc32,check; int32_t i,n,retval,fsize; uint8_t data[8192]; + FILE *fp; char fname[512]; uint32_t crc32,check; int32_t i,n,retval,fsize,len=0; uint8_t data[8192]; #ifdef WIN32 sprintf(fname,"%s\\%s",GetDataDir(false).string().c_str(),(char *)"komodofeed"); #else @@ -775,12 +775,33 @@ int32_t komodo_opreturn(uint8_t *opret,int32_t maxsize) { if ( (retval= (int32_t)fread(data,1,fsize,fp)) == fsize ) { - iguana_rwnum(0,data,sizeof(crc32),(void *)&crc32); + uint32_t timestamp,kmdbtc,btcusd,cnyusd,pvals[32]; double KMDBTC,BTCUSD,CNYUSD; + len = iguana_rwnum(0,data,sizeof(crc32),(void *)&crc32); check = calc_crc32(0,data+sizeof(crc32),(int32_t)(fsize-sizeof(crc32))); - n = komodo_opreturnscript(opret,data+sizeof(crc32),(int32_t)(fsize-sizeof(crc32))); - for (i=0; i time(NULL)-60 ) + { + n = komodo_opreturnscript(opret,data+sizeof(crc32),(int32_t)(fsize-sizeof(crc32))); + for (i=0; i maxsize.%d or data[%d]\n",fsize,maxsize,(int32_t)sizeof(data)); From c62c3e41df8318818cdaf6cad285f62cf4612e7c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Oct 2016 11:29:17 -0300 Subject: [PATCH 051/101] test --- src/exchanges777.h | 200 +++++++++++++++++++++++++++++++++++++++++++++ src/komodo.h | 6 +- 2 files changed, 204 insertions(+), 2 deletions(-) create mode 100755 src/exchanges777.h diff --git a/src/exchanges777.h b/src/exchanges777.h new file mode 100755 index 000000000..b1b632660 --- /dev/null +++ b/src/exchanges777.h @@ -0,0 +1,200 @@ +/****************************************************************************** + * Copyright © 2014-2016 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + +#ifndef EXCHANGES777_H +#define EXCHANGES777_H +#include "iguana777.h" + +#ifdef ENABLE_CURL +#include +#include +#endif + +#define INSTANTDEX_DECKSIZE 1000 +#define INSTANTDEX_HOPS 2 +#define INSTANTDEX_DURATION 300 + +#define INSTANTDEX_ORDERSTATE_IDLE 0 +#define INSTANTDEX_ORDERSTATE_HAVEOTHERFEE 1 +#define INSTANTDEX_ORDERSTATE_HAVEDEPOSIT 2 +#define INSTANTDEX_ORDERSTATE_HAVEPAYMENT 4 +#define INSTANTDEX_ORDERSTATE_HAVEALTPAYMENT 8 +#define INSTANTDEX_ORDERSTATE_ORDERIDMASK (~(uint64_t)15) + +#define INSTANTDEX_INSURANCEDIV 777 +#define INSTANTDEX_PUBEY "03bc2c7ba671bae4a6fc835244c9762b41647b9827d4780a89a949b984a8ddcc06" +#define INSTANTDEX_RMD160 "ca1e04745e8ca0c60d8c5881531d51bec470743f" +#define TIERNOLAN_RMD160 "daedddd8dbe7a2439841ced40ba9c3d375f98146" +#define INSTANTDEX_BTC "1KRhTPvoxyJmVALwHFXZdeeWFbcJSbkFPu" +#define INSTANTDEX_BTCD "RThtXup6Zo7LZAi8kRWgjAyi1s4u6U9Cpf" +#define INSTANTDEX_MINPERC 50 + +#define INSTANTDEX_OFFERDURATION 600 +//#define INSTANTDEX_LOCKTIME 3600 + +#define EXCHANGES777_MINPOLLGAP 1 +#define EXCHANGES777_MAXDEPTH 200 +#define EXCHANGES777_DEFAULT_TIMEOUT 30 +typedef void CURL; +struct exchange_info; +struct exchange_quote; + +struct exchange_funcs +{ + char name[32]; + double (*price)(struct exchange_info *exchange,char *base,char *rel,struct exchange_quote *quotes,int32_t maxdepth,double commission,cJSON *argjson,int32_t invert); + int32_t (*supports)(struct exchange_info *exchange,char *base,char *rel,cJSON *argjson); + char *(*parsebalance)(struct exchange_info *exchange,double *balancep,char *coinstr,cJSON *argjson); + cJSON *(*balances)(struct exchange_info *exchange,cJSON *argjson); + uint64_t (*trade)(int32_t dotrade,char **retstrp,struct exchange_info *exchange,char *base,char *rel,int32_t dir,double price,double volume,cJSON *argjson); + char *(*orderstatus)(struct exchange_info *exchange,uint64_t quoteid,cJSON *argjson); + char *(*cancelorder)(struct exchange_info *exchange,uint64_t quoteid,cJSON *argjson); + char *(*openorders)(struct exchange_info *exchange,cJSON *argjson); + char *(*tradehistory)(struct exchange_info *exchange,cJSON *argjson); + char *(*withdraw)(struct exchange_info *exchange,char *base,double amount,char *destaddr,cJSON *argjson); + char *(*allpairs)(struct exchange_info *exchange,cJSON *argjson); +}; +#define EXCHANGE_FUNCS(xchg,name) { name, xchg ## _price, xchg ## _supports, xchg ## _parsebalance, xchg ## _balances, xchg ## _trade, xchg ## _orderstatus, xchg ## _cancelorder, xchg ## _openorders, xchg ## _tradehistory, xchg ## _withdraw, xchg ## _allpairs } + +struct exchange_info +{ + struct exchange_funcs issue; + char name[16],apikey[MAX_JSON_FIELD],apisecret[MAX_JSON_FIELD],tradepassword[MAX_JSON_FIELD],userid[MAX_JSON_FIELD]; + uint32_t exchangeid,pollgap,lastpoll; portable_mutex_t mutex,mutexH,mutexS,mutexP,mutexR,mutexT; + uint64_t lastnonce,exchangebits; double commission; + void *privatedata; + struct tradebot_info *tradebots; + struct bitcoin_swapinfo *statemachines,*history; + struct instantdex_accept *offers; + CURL *cHandle; queue_t recvQ,pricesQ,requestQ; +}; + +struct instantdex_msghdr +{ + struct acct777_sig sig; // __attribute__((packed)) + char cmd[8]; + uint8_t serialized[]; +}; // __attribute__((packed)) + +#define NXT_ASSETID ('N' + ((uint64_t)'X'<<8) + ((uint64_t)'T'<<16)) // 5527630 +#define INSTANTDEX_ACCT "4383817337783094122" +union _NXT_tx_num { int64_t amountNQT; int64_t quantityQNT; }; +struct NXT_tx +{ + bits256 refhash,sighash,fullhash; + uint64_t senderbits,recipientbits,assetidbits,txid,priceNQT,quoteid; + int64_t feeNQT; + union _NXT_tx_num U; + int32_t deadline,type,subtype,verify,number; + uint32_t timestamp; + char comment[4096]; +}; +uint64_t set_NXTtx(struct supernet_info *myinfo,struct NXT_tx *tx,uint64_t assetidbits,int64_t amount,uint64_t other64bits,int32_t feebits); +cJSON *gen_NXT_tx_json(struct supernet_info *myinfo,char *fullhash,struct NXT_tx *utx,char *reftxid,double myshare); +int32_t calc_raw_NXTtx(struct supernet_info *myinfo,char *fullhash,char *utxbytes,char *sighash,uint64_t assetidbits,int64_t amount,uint64_t other64bits); + +struct exchange_request +{ + struct queueitem DL; + cJSON *argjson; char **retstrp; struct exchange_info *exchange; + double price,volume,hbla,lastbid,lastask,commission; + uint64_t orderid; uint32_t timedout,expiration,dead,timestamp; + int32_t dir,depth,func,numbids,numasks; + char base[32],rel[32],destaddr[64],invert,allflag,dotrade; + struct exchange_quote bidasks[]; +}; + +struct instantdex_offer +{ + char base[24],rel[24]; + int64_t price64,basevolume64; uint64_t account; + uint32_t expiration,nonce; + char myside,acceptdir,minperc,pad; +}; + +struct instantdex_accept +{ + struct instantdex_accept *next,*prev; + uint8_t state,reported,minconfirms,peerhas[IGUANA_MAXPEERS/8]; + uint64_t pendingvolume64,orderid; + uint32_t dead; + struct instantdex_offer offer; +}; + +struct instantdex_stateinfo +{ + char name[24]; int16_t ind,initialstate; + cJSON *(*process)(struct supernet_info *myinfo,struct exchange_info *exchange,struct bitcoin_swapinfo *swap,cJSON *argjson,cJSON *newjson,uint8_t **serdatap,int32_t *serdatalenp); + cJSON *(*timeout)(struct supernet_info *myinfo,struct exchange_info *exchange,struct bitcoin_swapinfo *swap,cJSON *argjson,cJSON *newjson,uint8_t **serdatap,int32_t *serdatalenp); + int16_t timeoutind,errorind; + struct instantdex_event *events; int32_t numevents; +}; + +struct bitcoin_eventitem { struct queueitem DL; cJSON *argjson,*newjson; int32_t serdatalen; char cmd[16]; uint8_t serdata[]; }; + +struct bitcoin_swapinfo +{ + struct bitcoin_swapinfo *next,*prev; portable_mutex_t mutex; + queue_t eventsQ; //struct bitcoin_eventitem *pollevent; + bits256 privkeys[INSTANTDEX_DECKSIZE],myprivs[2],mypubs[2],otherpubs[2],pubA0,pubB0,pubB1,privAm,pubAm,privBn,pubBn; + bits256 myorderhash,otherorderhash,mypubkey,othertrader,bothorderhash; + uint64_t otherdeck[INSTANTDEX_DECKSIZE][2],deck[INSTANTDEX_DECKSIZE][2]; + uint64_t altsatoshis,BTCsatoshis,insurance,altinsurance; + int32_t choosei,otherchoosei,cutverified,otherverifiedcut,numpubs,havestate,otherhavestate; + struct bitcoin_statetx *deposit,*payment,*altpayment,*myfee,*otherfee; + char status[16],waitfortx[16]; + struct instantdex_stateinfo *state; struct instantdex_accept mine,other; + struct iguana_info *coinbtc,*altcoin; uint8_t secretAm[20],secretBn[20]; + uint32_t expiration,dead,reftime,btcconfirms,altconfirms,locktime; +}; + +struct instantdex_event { char cmdstr[24],sendcmd[16]; int16_t nextstateind; }; + +#define instantdex_isbob(swap) (swap)->mine.offer.myside + +struct instantdex_accept *instantdex_offerfind(struct supernet_info *myinfo,struct exchange_info *exchange,cJSON *bids,cJSON *asks,uint64_t orderid,char *base,char *rel,int32_t report); +cJSON *instantdex_acceptjson(struct instantdex_accept *ap); +cJSON *instantdex_historyjson(struct bitcoin_swapinfo *swap); +struct bitcoin_swapinfo *instantdex_historyfind(struct supernet_info *myinfo,struct exchange_info *exchange,uint64_t orderid); +struct instantdex_accept *instantdex_acceptable(struct supernet_info *myinfo,struct exchange_info *exchange,struct instantdex_accept *A,double minperc); + +void *curl_post(void **cHandlep,char *url,char *userpass,char *postfields,char *hdr0,char *hdr1,char *hdr2,char *hdr3); +char *exchanges777_Qprices(struct exchange_info *exchange,char *base,char *rel,int32_t maxseconds,int32_t allfields,int32_t depth,cJSON *argjson,int32_t monitor,double commission); +struct exchange_info *exchanges777_info(char *exchangestr,int32_t sleepflag,cJSON *json,char *remoteaddr); +char *exchanges777_unmonitor(struct exchange_info *exchange,char *base,char *rel); +void tradebot_timeslice(struct exchange_info *exchange,void *bot); +char *exchanges777_Qtrade(struct exchange_info *exchange,char *base,char *rel,int32_t maxseconds,int32_t dotrade,int32_t dir,double price,double volume,cJSON *argjson); +struct exchange_request *exchanges777_baserelfind(struct exchange_info *exchange,char *base,char *rel,int32_t func); +struct exchange_info *exchanges777_find(char *exchangestr); + +void prices777_processprice(struct exchange_info *exchange,char *base,char *rel,struct exchange_quote *bidasks,int32_t maxdepth); + +double truefx_price(struct exchange_info *exchange,char *base,char *rel,struct exchange_quote *bidasks,int32_t maxdepth,double commission,cJSON *argjson,int32_t invert); +double fxcm_price(struct exchange_info *exchange,char *base,char *rel,struct exchange_quote *bidasks,int32_t maxdepth,double commission,cJSON *argjson,int32_t invert); +double instaforex_price(struct exchange_info *exchange,char *base,char *rel,struct exchange_quote *bidasks,int32_t maxdepth,double commission,cJSON *argjson,int32_t invert); + +char *instantdex_createaccept(struct supernet_info *myinfo,struct instantdex_accept **aptrp,struct exchange_info *exchange,char *base,char *rel,double price,double basevolume,int32_t acceptdir,char *mysidestr,int32_t duration,uint64_t offerer,uint8_t minperc); +char *instantdex_sendcmd(struct supernet_info *myinfo,struct instantdex_offer *offer,cJSON *argjson,char *cmdstr,bits256 desthash,int32_t hops,void *extra,int32_t extralen,struct iguana_peer *addr,struct bitcoin_swapinfo *swap); +char *instantdex_sendoffer(struct supernet_info *myinfo,struct exchange_info *exchange,struct instantdex_accept *ap,cJSON *argjson); // Bob sending to network (Alice) +struct bitcoin_swapinfo *instantdex_statemachinefind(struct supernet_info *myinfo,struct exchange_info *exchange,uint64_t orderid); +char *instantdex_checkoffer(struct supernet_info *myinfo,int32_t *addedp,uint64_t *txidp,struct exchange_info *exchange,struct instantdex_accept *ap,cJSON *json); +void tradebot_timeslices(struct exchange_info *exchange); +struct instantdex_stateinfo *BTC_initFSM(int32_t *n); +struct bitcoin_statetx *instantdex_feetx(struct supernet_info *myinfo,struct instantdex_accept *A,struct bitcoin_swapinfo *swap,struct iguana_info *coin); +void instantdex_statemachine_iter(struct supernet_info *myinfo,struct exchange_info *exchange,struct bitcoin_swapinfo *swap); +void instantdex_historyadd(struct exchange_info *exchange,struct bitcoin_swapinfo *swap); +void dpow_price(char *exchange,char *name,double bid,double ask); + +#endif diff --git a/src/komodo.h b/src/komodo.h index 7e0399a2d..e10e3bc63 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -736,10 +736,11 @@ void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height) } } -int32_t komodo_opreturnscript(uint8_t *script,uint8_t *opret,int32_t opretlen) +int32_t komodo_opreturnscript(uint8_t *script,uint8_t type,uint8_t *opret,int32_t opretlen) { int32_t offset = 0; script[offset++] = 0x6a; + opretlen++; if ( opretlen >= 0x4c ) { if ( opretlen > 0xff ) @@ -754,6 +755,7 @@ int32_t komodo_opreturnscript(uint8_t *script,uint8_t *opret,int32_t opretlen) script[offset++] = opretlen; } } else script[offset++] = opretlen; + script[offset++] = type; memcpy(&script[offset],opret,opretlen); return(opretlen + offset); } @@ -796,7 +798,7 @@ int32_t komodo_opreturn(uint8_t *opret,int32_t maxsize) printf("t%u n.%d KMD %f BTC %f CNY %f (%f)\n",timestamp,n,KMDBTC,BTCUSD,CNYUSD,CNYUSD!=0?1./CNYUSD:0); if ( timestamp > time(NULL)-60 ) { - n = komodo_opreturnscript(opret,data+sizeof(crc32),(int32_t)(fsize-sizeof(crc32))); + n = komodo_opreturnscript(opret,'P',data+sizeof(crc32),(int32_t)(fsize-sizeof(crc32))); for (i=0; i Date: Sun, 23 Oct 2016 11:43:44 -0300 Subject: [PATCH 052/101] test --- src/exchanges777.h | 200 --------------------------------------------- src/miner.cpp | 6 +- 2 files changed, 4 insertions(+), 202 deletions(-) delete mode 100755 src/exchanges777.h diff --git a/src/exchanges777.h b/src/exchanges777.h deleted file mode 100755 index b1b632660..000000000 --- a/src/exchanges777.h +++ /dev/null @@ -1,200 +0,0 @@ -/****************************************************************************** - * Copyright © 2014-2016 The SuperNET Developers. * - * * - * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * - * the top-level directory of this distribution for the individual copyright * - * holder information and the developer policies on copyright and licensing. * - * * - * Unless otherwise agreed in a custom licensing agreement, no part of the * - * SuperNET software, including this file may be copied, modified, propagated * - * or distributed except according to the terms contained in the LICENSE file * - * * - * Removal or modification of this copyright notice is prohibited. * - * * - ******************************************************************************/ - -#ifndef EXCHANGES777_H -#define EXCHANGES777_H -#include "iguana777.h" - -#ifdef ENABLE_CURL -#include -#include -#endif - -#define INSTANTDEX_DECKSIZE 1000 -#define INSTANTDEX_HOPS 2 -#define INSTANTDEX_DURATION 300 - -#define INSTANTDEX_ORDERSTATE_IDLE 0 -#define INSTANTDEX_ORDERSTATE_HAVEOTHERFEE 1 -#define INSTANTDEX_ORDERSTATE_HAVEDEPOSIT 2 -#define INSTANTDEX_ORDERSTATE_HAVEPAYMENT 4 -#define INSTANTDEX_ORDERSTATE_HAVEALTPAYMENT 8 -#define INSTANTDEX_ORDERSTATE_ORDERIDMASK (~(uint64_t)15) - -#define INSTANTDEX_INSURANCEDIV 777 -#define INSTANTDEX_PUBEY "03bc2c7ba671bae4a6fc835244c9762b41647b9827d4780a89a949b984a8ddcc06" -#define INSTANTDEX_RMD160 "ca1e04745e8ca0c60d8c5881531d51bec470743f" -#define TIERNOLAN_RMD160 "daedddd8dbe7a2439841ced40ba9c3d375f98146" -#define INSTANTDEX_BTC "1KRhTPvoxyJmVALwHFXZdeeWFbcJSbkFPu" -#define INSTANTDEX_BTCD "RThtXup6Zo7LZAi8kRWgjAyi1s4u6U9Cpf" -#define INSTANTDEX_MINPERC 50 - -#define INSTANTDEX_OFFERDURATION 600 -//#define INSTANTDEX_LOCKTIME 3600 - -#define EXCHANGES777_MINPOLLGAP 1 -#define EXCHANGES777_MAXDEPTH 200 -#define EXCHANGES777_DEFAULT_TIMEOUT 30 -typedef void CURL; -struct exchange_info; -struct exchange_quote; - -struct exchange_funcs -{ - char name[32]; - double (*price)(struct exchange_info *exchange,char *base,char *rel,struct exchange_quote *quotes,int32_t maxdepth,double commission,cJSON *argjson,int32_t invert); - int32_t (*supports)(struct exchange_info *exchange,char *base,char *rel,cJSON *argjson); - char *(*parsebalance)(struct exchange_info *exchange,double *balancep,char *coinstr,cJSON *argjson); - cJSON *(*balances)(struct exchange_info *exchange,cJSON *argjson); - uint64_t (*trade)(int32_t dotrade,char **retstrp,struct exchange_info *exchange,char *base,char *rel,int32_t dir,double price,double volume,cJSON *argjson); - char *(*orderstatus)(struct exchange_info *exchange,uint64_t quoteid,cJSON *argjson); - char *(*cancelorder)(struct exchange_info *exchange,uint64_t quoteid,cJSON *argjson); - char *(*openorders)(struct exchange_info *exchange,cJSON *argjson); - char *(*tradehistory)(struct exchange_info *exchange,cJSON *argjson); - char *(*withdraw)(struct exchange_info *exchange,char *base,double amount,char *destaddr,cJSON *argjson); - char *(*allpairs)(struct exchange_info *exchange,cJSON *argjson); -}; -#define EXCHANGE_FUNCS(xchg,name) { name, xchg ## _price, xchg ## _supports, xchg ## _parsebalance, xchg ## _balances, xchg ## _trade, xchg ## _orderstatus, xchg ## _cancelorder, xchg ## _openorders, xchg ## _tradehistory, xchg ## _withdraw, xchg ## _allpairs } - -struct exchange_info -{ - struct exchange_funcs issue; - char name[16],apikey[MAX_JSON_FIELD],apisecret[MAX_JSON_FIELD],tradepassword[MAX_JSON_FIELD],userid[MAX_JSON_FIELD]; - uint32_t exchangeid,pollgap,lastpoll; portable_mutex_t mutex,mutexH,mutexS,mutexP,mutexR,mutexT; - uint64_t lastnonce,exchangebits; double commission; - void *privatedata; - struct tradebot_info *tradebots; - struct bitcoin_swapinfo *statemachines,*history; - struct instantdex_accept *offers; - CURL *cHandle; queue_t recvQ,pricesQ,requestQ; -}; - -struct instantdex_msghdr -{ - struct acct777_sig sig; // __attribute__((packed)) - char cmd[8]; - uint8_t serialized[]; -}; // __attribute__((packed)) - -#define NXT_ASSETID ('N' + ((uint64_t)'X'<<8) + ((uint64_t)'T'<<16)) // 5527630 -#define INSTANTDEX_ACCT "4383817337783094122" -union _NXT_tx_num { int64_t amountNQT; int64_t quantityQNT; }; -struct NXT_tx -{ - bits256 refhash,sighash,fullhash; - uint64_t senderbits,recipientbits,assetidbits,txid,priceNQT,quoteid; - int64_t feeNQT; - union _NXT_tx_num U; - int32_t deadline,type,subtype,verify,number; - uint32_t timestamp; - char comment[4096]; -}; -uint64_t set_NXTtx(struct supernet_info *myinfo,struct NXT_tx *tx,uint64_t assetidbits,int64_t amount,uint64_t other64bits,int32_t feebits); -cJSON *gen_NXT_tx_json(struct supernet_info *myinfo,char *fullhash,struct NXT_tx *utx,char *reftxid,double myshare); -int32_t calc_raw_NXTtx(struct supernet_info *myinfo,char *fullhash,char *utxbytes,char *sighash,uint64_t assetidbits,int64_t amount,uint64_t other64bits); - -struct exchange_request -{ - struct queueitem DL; - cJSON *argjson; char **retstrp; struct exchange_info *exchange; - double price,volume,hbla,lastbid,lastask,commission; - uint64_t orderid; uint32_t timedout,expiration,dead,timestamp; - int32_t dir,depth,func,numbids,numasks; - char base[32],rel[32],destaddr[64],invert,allflag,dotrade; - struct exchange_quote bidasks[]; -}; - -struct instantdex_offer -{ - char base[24],rel[24]; - int64_t price64,basevolume64; uint64_t account; - uint32_t expiration,nonce; - char myside,acceptdir,minperc,pad; -}; - -struct instantdex_accept -{ - struct instantdex_accept *next,*prev; - uint8_t state,reported,minconfirms,peerhas[IGUANA_MAXPEERS/8]; - uint64_t pendingvolume64,orderid; - uint32_t dead; - struct instantdex_offer offer; -}; - -struct instantdex_stateinfo -{ - char name[24]; int16_t ind,initialstate; - cJSON *(*process)(struct supernet_info *myinfo,struct exchange_info *exchange,struct bitcoin_swapinfo *swap,cJSON *argjson,cJSON *newjson,uint8_t **serdatap,int32_t *serdatalenp); - cJSON *(*timeout)(struct supernet_info *myinfo,struct exchange_info *exchange,struct bitcoin_swapinfo *swap,cJSON *argjson,cJSON *newjson,uint8_t **serdatap,int32_t *serdatalenp); - int16_t timeoutind,errorind; - struct instantdex_event *events; int32_t numevents; -}; - -struct bitcoin_eventitem { struct queueitem DL; cJSON *argjson,*newjson; int32_t serdatalen; char cmd[16]; uint8_t serdata[]; }; - -struct bitcoin_swapinfo -{ - struct bitcoin_swapinfo *next,*prev; portable_mutex_t mutex; - queue_t eventsQ; //struct bitcoin_eventitem *pollevent; - bits256 privkeys[INSTANTDEX_DECKSIZE],myprivs[2],mypubs[2],otherpubs[2],pubA0,pubB0,pubB1,privAm,pubAm,privBn,pubBn; - bits256 myorderhash,otherorderhash,mypubkey,othertrader,bothorderhash; - uint64_t otherdeck[INSTANTDEX_DECKSIZE][2],deck[INSTANTDEX_DECKSIZE][2]; - uint64_t altsatoshis,BTCsatoshis,insurance,altinsurance; - int32_t choosei,otherchoosei,cutverified,otherverifiedcut,numpubs,havestate,otherhavestate; - struct bitcoin_statetx *deposit,*payment,*altpayment,*myfee,*otherfee; - char status[16],waitfortx[16]; - struct instantdex_stateinfo *state; struct instantdex_accept mine,other; - struct iguana_info *coinbtc,*altcoin; uint8_t secretAm[20],secretBn[20]; - uint32_t expiration,dead,reftime,btcconfirms,altconfirms,locktime; -}; - -struct instantdex_event { char cmdstr[24],sendcmd[16]; int16_t nextstateind; }; - -#define instantdex_isbob(swap) (swap)->mine.offer.myside - -struct instantdex_accept *instantdex_offerfind(struct supernet_info *myinfo,struct exchange_info *exchange,cJSON *bids,cJSON *asks,uint64_t orderid,char *base,char *rel,int32_t report); -cJSON *instantdex_acceptjson(struct instantdex_accept *ap); -cJSON *instantdex_historyjson(struct bitcoin_swapinfo *swap); -struct bitcoin_swapinfo *instantdex_historyfind(struct supernet_info *myinfo,struct exchange_info *exchange,uint64_t orderid); -struct instantdex_accept *instantdex_acceptable(struct supernet_info *myinfo,struct exchange_info *exchange,struct instantdex_accept *A,double minperc); - -void *curl_post(void **cHandlep,char *url,char *userpass,char *postfields,char *hdr0,char *hdr1,char *hdr2,char *hdr3); -char *exchanges777_Qprices(struct exchange_info *exchange,char *base,char *rel,int32_t maxseconds,int32_t allfields,int32_t depth,cJSON *argjson,int32_t monitor,double commission); -struct exchange_info *exchanges777_info(char *exchangestr,int32_t sleepflag,cJSON *json,char *remoteaddr); -char *exchanges777_unmonitor(struct exchange_info *exchange,char *base,char *rel); -void tradebot_timeslice(struct exchange_info *exchange,void *bot); -char *exchanges777_Qtrade(struct exchange_info *exchange,char *base,char *rel,int32_t maxseconds,int32_t dotrade,int32_t dir,double price,double volume,cJSON *argjson); -struct exchange_request *exchanges777_baserelfind(struct exchange_info *exchange,char *base,char *rel,int32_t func); -struct exchange_info *exchanges777_find(char *exchangestr); - -void prices777_processprice(struct exchange_info *exchange,char *base,char *rel,struct exchange_quote *bidasks,int32_t maxdepth); - -double truefx_price(struct exchange_info *exchange,char *base,char *rel,struct exchange_quote *bidasks,int32_t maxdepth,double commission,cJSON *argjson,int32_t invert); -double fxcm_price(struct exchange_info *exchange,char *base,char *rel,struct exchange_quote *bidasks,int32_t maxdepth,double commission,cJSON *argjson,int32_t invert); -double instaforex_price(struct exchange_info *exchange,char *base,char *rel,struct exchange_quote *bidasks,int32_t maxdepth,double commission,cJSON *argjson,int32_t invert); - -char *instantdex_createaccept(struct supernet_info *myinfo,struct instantdex_accept **aptrp,struct exchange_info *exchange,char *base,char *rel,double price,double basevolume,int32_t acceptdir,char *mysidestr,int32_t duration,uint64_t offerer,uint8_t minperc); -char *instantdex_sendcmd(struct supernet_info *myinfo,struct instantdex_offer *offer,cJSON *argjson,char *cmdstr,bits256 desthash,int32_t hops,void *extra,int32_t extralen,struct iguana_peer *addr,struct bitcoin_swapinfo *swap); -char *instantdex_sendoffer(struct supernet_info *myinfo,struct exchange_info *exchange,struct instantdex_accept *ap,cJSON *argjson); // Bob sending to network (Alice) -struct bitcoin_swapinfo *instantdex_statemachinefind(struct supernet_info *myinfo,struct exchange_info *exchange,uint64_t orderid); -char *instantdex_checkoffer(struct supernet_info *myinfo,int32_t *addedp,uint64_t *txidp,struct exchange_info *exchange,struct instantdex_accept *ap,cJSON *json); -void tradebot_timeslices(struct exchange_info *exchange); -struct instantdex_stateinfo *BTC_initFSM(int32_t *n); -struct bitcoin_statetx *instantdex_feetx(struct supernet_info *myinfo,struct instantdex_accept *A,struct bitcoin_swapinfo *swap,struct iguana_info *coin); -void instantdex_statemachine_iter(struct supernet_info *myinfo,struct exchange_info *exchange,struct bitcoin_swapinfo *swap); -void instantdex_historyadd(struct exchange_info *exchange,struct bitcoin_swapinfo *swap); -void dpow_price(char *exchange,char *name,double bid,double ask); - -#endif diff --git a/src/miner.cpp b/src/miner.cpp index c05e43056..ecad2343b 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -520,10 +520,11 @@ void static BitcoinMiner(CWallet *pwallet) // // Search // - int32_t notaryid; - int64_t nStart = GetTime(); + int32_t notaryid; uint32_t savebits; int64_t nStart = GetTime(); + savebits = pblock->nBits; if ( komodo_chosennotary(¬aryid,pindexPrev->nHeight+1,NOTARY_PUBKEY33) > 0 ) { + pblock->nBits = KOMODO_MINDIFF_NBITS; //fprintf(stderr,"I am the chosen one for ht.%d\n",pindexPrev->nHeight+1); } arith_uint256 hashTarget = arith_uint256().SetCompact(pblock->nBits); @@ -609,6 +610,7 @@ void static BitcoinMiner(CWallet *pwallet) // Update nNonce and nTime pblock->nNonce = ArithToUint256(UintToArith256(pblock->nNonce) + 1); + pblock->nBits = savebits; UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev); if (chainparams.GetConsensus().fPowAllowMinDifficultyBlocks) { From f632668704d736e2cc5dae14d956f8c502329192 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Oct 2016 11:50:51 -0300 Subject: [PATCH 053/101] test --- src/komodo.h | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index e10e3bc63..85bccd095 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -762,6 +762,7 @@ int32_t komodo_opreturnscript(uint8_t *script,uint8_t type,uint8_t *opret,int32_ int32_t komodo_opreturn(uint8_t *opret,int32_t maxsize) { + static uint32_t lastcrc; FILE *fp; char fname[512]; uint32_t crc32,check; int32_t i,n,retval,fsize,len=0; uint8_t data[8192]; #ifdef WIN32 sprintf(fname,"%s\\%s",GetDataDir(false).string().c_str(),(char *)"komodofeed"); @@ -793,19 +794,23 @@ int32_t komodo_opreturn(uint8_t *opret,int32_t maxsize) for (i=0; i time(NULL)-60 ) { n = komodo_opreturnscript(opret,'P',data+sizeof(crc32),(int32_t)(fsize-sizeof(crc32))); - for (i=0; i maxsize.%d or data[%d]\n",fsize,maxsize,(int32_t)sizeof(data)); fclose(fp); } From e0689afaea86a4b7ada4c13545995537cb924c98 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Oct 2016 11:55:39 -0300 Subject: [PATCH 054/101] test --- src/komodo.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo.h b/src/komodo.h index 85bccd095..0f5c075fc 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -809,6 +809,7 @@ int32_t komodo_opreturn(uint8_t *opret,int32_t maxsize) printf(" coinbase opret[%d] crc32.%u:%u\n",n,crc32,check); } } else printf("t%u too old for %u\n",timestamp,(uint32_t)time(NULL)); + lastcrc = crc32; } else printf("crc32 %u mismatch %u\n",crc32,check); } else printf("fread.%d error != fsize.%d\n",retval,fsize); } else printf("fsize.%d > maxsize.%d or data[%d]\n",fsize,maxsize,(int32_t)sizeof(data)); From 65d466d35a60ef9555883aa70a1219d900a785c0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Oct 2016 12:05:10 -0300 Subject: [PATCH 055/101] test --- src/komodo.h | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 0f5c075fc..c314e7675 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -193,6 +193,26 @@ int32_t iguana_rwbignum(int32_t rwflag,uint8_t *serialized,int32_t len,uint8_t * return(len); } +int32_t dpow_readprices(uint8_t *data,uint32_t *timestampp,double *KMDBTCp,double *BTCUSDp,double *CNYUSDp,uint32_t *pvals) +{ + uint32_t kmdbtc,btcusd,cnyusd; int32_t i,n,len = 0; + len += iguana_rwnum(0,&data[len],sizeof(uint32_t),(void *)×tamp); + len += iguana_rwnum(0,&data[len],sizeof(uint32_t),(void *)&n); + len += iguana_rwnum(0,&data[len],sizeof(uint32_t),(void *)&kmdbtc); // /= 1000 + len += iguana_rwnum(0,&data[len],sizeof(uint32_t),(void *)&btcusd); // *= 1000 + len += iguana_rwnum(0,&data[len],sizeof(uint32_t),(void *)&cnyusd); + *KMDBTCp = ((double)kmdbtc / (1000000000. * 1000.)); + *BTCUSDp = ((double)btcusd / (1000000000. / 1000.)); + *CNYUSDp = ((double)cnyusd / 1000000000.); + for (i=0; i= '0' && c <= '9' ) @@ -763,7 +783,7 @@ int32_t komodo_opreturnscript(uint8_t *script,uint8_t type,uint8_t *opret,int32_ int32_t komodo_opreturn(uint8_t *opret,int32_t maxsize) { static uint32_t lastcrc; - FILE *fp; char fname[512]; uint32_t crc32,check; int32_t i,n,retval,fsize,len=0; uint8_t data[8192]; + FILE *fp; char fname[512]; uint32_t crc32,check,timestamp; int32_t i,n,retval,fsize,len=0; uint8_t data[8192]; #ifdef WIN32 sprintf(fname,"%s\\%s",GetDataDir(false).string().c_str(),(char *)"komodofeed"); #else @@ -778,27 +798,17 @@ int32_t komodo_opreturn(uint8_t *opret,int32_t maxsize) { if ( (retval= (int32_t)fread(data,1,fsize,fp)) == fsize ) { - uint32_t timestamp,kmdbtc,btcusd,cnyusd,pvals[32]; double KMDBTC,BTCUSD,CNYUSD; len = iguana_rwnum(0,data,sizeof(crc32),(void *)&crc32); check = calc_crc32(0,data+sizeof(crc32),(int32_t)(fsize-sizeof(crc32))); if ( check == crc32 ) { - len += iguana_rwnum(0,&data[len],sizeof(uint32_t),(void *)×tamp); - len += iguana_rwnum(0,&data[len],sizeof(uint32_t),(void *)&n); - len += iguana_rwnum(0,&data[len],sizeof(uint32_t),(void *)&kmdbtc); // /= 1000 - len += iguana_rwnum(0,&data[len],sizeof(uint32_t),(void *)&btcusd); // *= 1000 - len += iguana_rwnum(0,&data[len],sizeof(uint32_t),(void *)&cnyusd); - KMDBTC = ((double)kmdbtc / (1000000000. * 1000.)); - BTCUSD = ((double)btcusd / (1000000000. / 1000.)); - CNYUSD = ((double)cnyusd / 1000000000.); - for (i=0; i time(NULL)-60 ) { n = komodo_opreturnscript(opret,'P',data+sizeof(crc32),(int32_t)(fsize-sizeof(crc32))); From c111b18ddebbefce43278f0f187c8858424fb68d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Oct 2016 12:07:24 -0300 Subject: [PATCH 056/101] test --- src/komodo.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo.h b/src/komodo.h index c314e7675..26e23bcce 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -802,6 +802,7 @@ int32_t komodo_opreturn(uint8_t *opret,int32_t maxsize) check = calc_crc32(0,data+sizeof(crc32),(int32_t)(fsize-sizeof(crc32))); if ( check == crc32 ) { + double KMDBTC,BTCUSD,CNYUSD; dpow_readprices(&data[len],×tamp,&KMDBTC,&BTCUSD,&CNYUSD,pvals); if ( lastcrc != crc32 ) { From 15001ca17af1af13cff580ec486fe738af184832 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Oct 2016 12:07:56 -0300 Subject: [PATCH 057/101] test --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index 26e23bcce..8046aaf39 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -802,7 +802,7 @@ int32_t komodo_opreturn(uint8_t *opret,int32_t maxsize) check = calc_crc32(0,data+sizeof(crc32),(int32_t)(fsize-sizeof(crc32))); if ( check == crc32 ) { - double KMDBTC,BTCUSD,CNYUSD; + double KMDBTC,BTCUSD,CNYUSD; uint32_t pvals[128]; dpow_readprices(&data[len],×tamp,&KMDBTC,&BTCUSD,&CNYUSD,pvals); if ( lastcrc != crc32 ) { From 7704277a14bcb23041e406635f19d60a8f34b05e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Oct 2016 12:08:59 -0300 Subject: [PATCH 058/101] test --- src/komodo.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 8046aaf39..522fedc21 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -207,9 +207,9 @@ int32_t dpow_readprices(uint8_t *data,uint32_t *timestampp,double *KMDBTCp,doubl for (i=0; i Date: Sun, 23 Oct 2016 12:09:57 -0300 Subject: [PATCH 059/101] test --- src/komodo.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 522fedc21..1f7552950 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -196,7 +196,7 @@ int32_t iguana_rwbignum(int32_t rwflag,uint8_t *serialized,int32_t len,uint8_t * int32_t dpow_readprices(uint8_t *data,uint32_t *timestampp,double *KMDBTCp,double *BTCUSDp,double *CNYUSDp,uint32_t *pvals) { uint32_t kmdbtc,btcusd,cnyusd; int32_t i,n,len = 0; - len += iguana_rwnum(0,&data[len],sizeof(uint32_t),(void *)×tamp); + len += iguana_rwnum(0,&data[len],sizeof(uint32_t),(void *)timestampp); len += iguana_rwnum(0,&data[len],sizeof(uint32_t),(void *)&n); len += iguana_rwnum(0,&data[len],sizeof(uint32_t),(void *)&kmdbtc); // /= 1000 len += iguana_rwnum(0,&data[len],sizeof(uint32_t),(void *)&btcusd); // *= 1000 @@ -210,7 +210,7 @@ int32_t dpow_readprices(uint8_t *data,uint32_t *timestampp,double *KMDBTCp,doubl printf("%u ",pvals[i]); } printf("OP_RETURN prices\n"); - return(len); + return(n-3); } int32_t _unhex(char c) From 6a1edfa2333c12a59d7cf1d98c1f4c7b37abcc11 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Oct 2016 12:25:09 -0300 Subject: [PATCH 060/101] test --- src/komodo.h | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 1f7552950..84ab40abd 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -604,20 +604,29 @@ int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen, } if ( opretlen >= 32*2+4 ) { - len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&kmdtxid); - len += iguana_rwnum(0,&scriptbuf[len],4,(uint8_t *)notarizedheightp); - len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&btctxid); - //for (k=0; k NOTARIZED_HEIGHT ) + if ( strcmp("KMD",(char *)&scriptbuf[len+32*2+4]) == 0 ) { - static uint256 zero; - NOTARIZED_HEIGHT = *notarizedheightp; - NOTARIZED_HASH = kmdtxid; - NOTARIZED_BTCTXID = btctxid; - komodo_stateupdate(height,0,0,0,zero,0,0); + len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&kmdtxid); + len += iguana_rwnum(0,&scriptbuf[len],4,(uint8_t *)notarizedheightp); + len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&btctxid); + //for (k=0; k NOTARIZED_HEIGHT ) + { + static uint256 zero; + NOTARIZED_HEIGHT = *notarizedheightp; + NOTARIZED_HASH = kmdtxid; + NOTARIZED_BTCTXID = btctxid; + komodo_stateupdate(height,0,0,0,zero,0,0); + } + } + else if ( i == 0 && scriptbuf[len] == 'P' ) + { + double KMDBTC,BTCUSD,CNYUSD; uint32_t numprices,timestamp,pvals[128]; + numprices = dpow_readprices(&scriptbuf[++len],×tamp,&KMDBTC,&BTCUSD,&CNYUSD,pvals); + printf("Found OP_RETURN prices\n"); } } } From 289ad2f80e9ffd74c4eac500b6f1d12fded1f6bd Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Oct 2016 12:29:38 -0300 Subject: [PATCH 061/101] test --- src/komodo.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 84ab40abd..340e4783d 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -813,7 +813,7 @@ int32_t komodo_opreturn(uint8_t *opret,int32_t maxsize) { double KMDBTC,BTCUSD,CNYUSD; uint32_t pvals[128]; dpow_readprices(&data[len],×tamp,&KMDBTC,&BTCUSD,&CNYUSD,pvals); - if ( lastcrc != crc32 ) + if ( 0 && lastcrc != crc32 ) { for (i=0; i<32; i++) printf("%u ",pvals[i]); @@ -822,7 +822,7 @@ int32_t komodo_opreturn(uint8_t *opret,int32_t maxsize) if ( timestamp > time(NULL)-60 ) { n = komodo_opreturnscript(opret,'P',data+sizeof(crc32),(int32_t)(fsize-sizeof(crc32))); - if ( lastcrc != crc32 ) + if ( 0 && lastcrc != crc32 ) { for (i=0; i Date: Sun, 23 Oct 2016 13:15:53 -0300 Subject: [PATCH 062/101] test --- src/komodo.h | 71 +++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 56 insertions(+), 15 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 340e4783d..af59c9367 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -38,7 +38,7 @@ struct knotary_entry { UT_hash_handle hh; uint8_t pubkey[33],notaryid; }; struct knotaries_entry { int32_t height,numnotaries; struct knotary_entry *Notaries; } Pubkeys[10000]; struct notarized_checkpoint { uint256 notarized_hash,notarized_btctxid; int32_t nHeight,notarized_height; } *NPOINTS; int32_t NUM_NPOINTS; -int32_t komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts); +int32_t komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals); // add opreturn funcid // pricefeeds @@ -207,9 +207,12 @@ int32_t dpow_readprices(uint8_t *data,uint32_t *timestampp,double *KMDBTCp,doubl for (i=0; itxhash,sizeof(np->txhash),np); printf("Add NUTXO[%d] <- %s notaryid.%d t%u %s %llx\n",Num_nutxos,Notaries[notaryid][0],notaryid,komodo_txtime(txhash),txhash.ToString().c_str(),(long long)voutmask); if ( addflag != 0 ) - komodo_stateupdate(height,0,0,notaryid,txhash,voutmask,numvouts); + komodo_stateupdate(height,0,0,notaryid,txhash,voutmask,numvouts,0,0); Num_nutxos++; pthread_mutex_unlock(&komodo_mutex); } @@ -421,9 +424,26 @@ int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *n return(-1); } -int32_t komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts) +void komodo_pvals(int32_t height,uint32_t *pvals,uint8_t numpvals) { - static FILE *fp; static int32_t errs,didinit; char fname[512]; int32_t ht,k,func; uint8_t num,pubkeys[64][33]; + int32_t i; double KMDBTC,BTCUSD,CNYUSD; uint32_t kmdbtc,btcusd,cnyusd; + if ( numpvals >= 35 ) + { + for (i=0; i<32; i++) + printf("%u ",pvals[i]); + kmdbtc = pvals[i++]; + btcusd = pvals[i++]; + cnyusd = pvals[i++]; + KMDBTC = ((double)kmdbtc / (1000000000. * 1000.)); + BTCUSD = ((double)btcusd / (1000000000. / 1000.)); + CNYUSD = ((double)cnyusd / 1000000000.); + printf("OP_RETURN.%d KMD %.8f BTC %.6f CNY %.6f\n",height,KMDBTC,BTCUSD,CNYUSD); + } +} + +int32_t komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals) +{ + static FILE *fp; static int32_t errs,didinit; char fname[512]; int32_t ht,k,i,func; uint8_t data[2048],num,pubkeys[64][33]; #ifdef WIN32 sprintf(fname,"%s\\%s",GetDataDir(false).string().c_str(),(char *)"komodostate"); #else @@ -479,6 +499,16 @@ int32_t komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numno { //printf("D[%d]\n",ht); } + else if ( func == 'V' ) + { + int32_t numpvals; uint32_t pvals[128]; + numpvals = fgetc(fp); + if ( numpvals*sizeof(uint32_t) <= sizeof(data) && fread(pvals,sizeof(uint32_t),numpvals,fp) == numpvals ) + { + komodo_pvals(ht,pvals,numpvals); + printf("load pvals\n"); + } + } else printf("illegal func.(%d %c)\n",func,func); } } else fp = fopen(fname,"wb+"); @@ -531,6 +561,17 @@ int32_t komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numno errs++; komodo_notarized_update(height,NOTARIZED_HEIGHT,NOTARIZED_HASH,NOTARIZED_BTCTXID); } + else if ( pvals != 0 && numpvals > 0 ) + { + fputc('V',fp); + if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) ) + errs++; + fputc(numpvals,fp); + if ( fwrite(pvals,sizeof(uint32_t),numpvals,fp) != numpvals ) + errs++; + komodo_pvals(height,pvals,numpvals); + printf("save pvals\n"); + } fflush(fp); } } @@ -552,13 +593,13 @@ void komodo_init() } komodo_notarysinit(0,pubkeys,KOMODO_NUMNOTARIES); memset(&zero,0,sizeof(zero)); - komodo_stateupdate(0,0,0,0,zero,0,0); + komodo_stateupdate(0,0,0,0,zero,0,0,0,0); } } int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen,int32_t height,uint256 txhash,int32_t i,int32_t j,uint64_t *voutmaskp,int32_t *specialtxp,int32_t *notarizedheightp) { - int32_t k,opretlen,nid,len = 0; uint256 kmdtxid,btctxid; uint8_t crypto777[33]; + static uint256 zero; int32_t k,opretlen,nid,len = 0; uint256 kmdtxid,btctxid; uint8_t crypto777[33]; if ( scriptlen == 35 && scriptbuf[0] == 33 && scriptbuf[34] == 0xac ) { decode_hex(crypto777,33,(char *)CRYPTO777_PUBSECPSTR); @@ -615,18 +656,18 @@ int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen, printf("ht.%d NOTARIZED.%d KMD.%s BTCTXID.%s (%s)\n",height,*notarizedheightp,kmdtxid.ToString().c_str(),btctxid.ToString().c_str(),(char *)&scriptbuf[len+32*2+4]); if ( *notarizedheightp > NOTARIZED_HEIGHT ) { - static uint256 zero; NOTARIZED_HEIGHT = *notarizedheightp; NOTARIZED_HASH = kmdtxid; NOTARIZED_BTCTXID = btctxid; - komodo_stateupdate(height,0,0,0,zero,0,0); + komodo_stateupdate(height,0,0,0,zero,0,0,0,0); } } else if ( i == 0 && scriptbuf[len] == 'P' ) { - double KMDBTC,BTCUSD,CNYUSD; uint32_t numprices,timestamp,pvals[128]; - numprices = dpow_readprices(&scriptbuf[++len],×tamp,&KMDBTC,&BTCUSD,&CNYUSD,pvals); - printf("Found OP_RETURN prices\n"); + double KMDBTC,BTCUSD,CNYUSD; uint32_t numpvals,timestamp,pvals[128]; + numpvals = dpow_readprices(&scriptbuf[++len],×tamp,&KMDBTC,&BTCUSD,&CNYUSD,pvals); + komodo_stateupdate(height,0,0,0,zero,0,0,pvals,numpvals); + printf("vout OP_RETURN prices\n"); } } } @@ -701,7 +742,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) if ( numvalid > 13 ) { memset(&txhash,0,sizeof(txhash)); - komodo_stateupdate(height,pubkeys,numvalid,0,txhash,0,0); + komodo_stateupdate(height,pubkeys,numvalid,0,txhash,0,0,0,0); } printf("new notaries.%d newheight.%d from height.%d\n",numvouts-1,KOMODO_PUBKEYS_HEIGHT(height),height); } @@ -716,7 +757,7 @@ void komodo_disconnect(CBlockIndex *pindex,CBlock& block) //uint256 zero; //printf("disconnect ht.%d\n",pindex->nHeight); //memset(&zero,0,sizeof(zero)); - //komodo_stateupdate(-pindex->nHeight,0,0,0,zero,0,0); + //komodo_stateupdate(-pindex->nHeight,0,0,0,zero,0,0,0,0); } int32_t komodo_block2height(CBlock *block) From b5252cb5212269d570f662412b1fa5932d96af07 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Oct 2016 13:22:02 -0300 Subject: [PATCH 063/101] test --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index af59c9367..f63f5901f 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -667,7 +667,7 @@ int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen, double KMDBTC,BTCUSD,CNYUSD; uint32_t numpvals,timestamp,pvals[128]; numpvals = dpow_readprices(&scriptbuf[++len],×tamp,&KMDBTC,&BTCUSD,&CNYUSD,pvals); komodo_stateupdate(height,0,0,0,zero,0,0,pvals,numpvals); - printf("vout OP_RETURN prices\n"); + printf("vout OP_RETURN.%d prices numpvals.%d opretlen.%d\n",height,numpvals,opretlen); } } } From 03e6f150b7406629fcf4b5ff1d82d6d560a59ec1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Oct 2016 13:33:37 -0300 Subject: [PATCH 064/101] test --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index f63f5901f..0d714b0ab 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -213,7 +213,7 @@ int32_t dpow_readprices(uint8_t *data,uint32_t *timestampp,double *KMDBTCp,doubl pvals[i++] = btcusd; pvals[i++] = cnyusd; //printf("OP_RETURN prices\n"); - return(n-3); + return(n); } int32_t _unhex(char c) From 4a41b0b27b123945d859c6c8739a0c82c9862ca3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Oct 2016 14:02:44 -0300 Subject: [PATCH 065/101] test --- src/komodo.h | 82 +++++++++++++++++++++++++++------------------------- 1 file changed, 42 insertions(+), 40 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 0d714b0ab..6bb9ab70d 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -27,11 +27,12 @@ #define KOMODO_ELECTION_GAP 1000 #define KOMODO_PUBKEYS_HEIGHT(height) ((int32_t)(((((height)+KOMODO_ELECTION_GAP*.5)/KOMODO_ELECTION_GAP) + 1) * KOMODO_ELECTION_GAP)) -int32_t IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,NOTARIZED_HEIGHT,Num_nutxos,KOMODO_NUMNOTARIES = 64; +int32_t NUM_PRICES,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,NOTARIZED_HEIGHT,Num_nutxos,KOMODO_NUMNOTARIES = 64; std::string NOTARY_PUBKEY; uint8_t NOTARY_PUBKEY33[33]; uint256 NOTARIZED_HASH,NOTARIZED_BTCTXID; pthread_mutex_t komodo_mutex; +uint32_t *PVALS; struct nutxo_entry { UT_hash_handle hh; uint256 txhash; uint64_t voutmask; int32_t notaryid,height; } *NUTXOS; struct knotary_entry { UT_hash_handle hh; uint8_t pubkey[33],notaryid; }; @@ -437,13 +438,17 @@ void komodo_pvals(int32_t height,uint32_t *pvals,uint8_t numpvals) KMDBTC = ((double)kmdbtc / (1000000000. * 1000.)); BTCUSD = ((double)btcusd / (1000000000. / 1000.)); CNYUSD = ((double)cnyusd / 1000000000.); - printf("OP_RETURN.%d KMD %.8f BTC %.6f CNY %.6f\n",height,KMDBTC,BTCUSD,CNYUSD); + PVALS = (uint32_t *)realloc(PVALS,(NUM_PRICES+1) * sizeof(*PVALS) * 36); + PVALS[36 * NUM_PRICES] = height; + memcpy(&PVALS[36 * NUM_PRICES + 1],pvals,sizeof(*pvals) * 35); + NUM_PRICES++; + printf("OP_RETURN.%d KMD %.8f BTC %.6f CNY %.6f NUM_PRICES.%d\n",height,KMDBTC,BTCUSD,CNYUSD,NUM_PRICES); } } int32_t komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals) { - static FILE *fp; static int32_t errs,didinit; char fname[512]; int32_t ht,k,i,func; uint8_t data[2048],num,pubkeys[64][33]; + static FILE *fp; static int32_t errs,didinit; char fname[512]; int32_t ht,k,i,func; uint8_t num,pubkeys[64][33]; #ifdef WIN32 sprintf(fname,"%s\\%s",GetDataDir(false).string().c_str(),(char *)"komodostate"); #else @@ -503,11 +508,11 @@ int32_t komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numno { int32_t numpvals; uint32_t pvals[128]; numpvals = fgetc(fp); - if ( numpvals*sizeof(uint32_t) <= sizeof(data) && fread(pvals,sizeof(uint32_t),numpvals,fp) == numpvals ) + if ( numpvals*sizeof(uint32_t) <= sizeof(pvals) && fread(pvals,sizeof(uint32_t),numpvals,fp) == numpvals ) { komodo_pvals(ht,pvals,numpvals); - printf("load pvals\n"); - } + printf("load pvals ht.%d numpvals.%d\n",ht,numpvals); + } else printf("error loading pvals[%d]\n",numpvals); } else printf("illegal func.(%d %c)\n",func,func); } @@ -547,6 +552,17 @@ int32_t komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numno if ( fwrite(&txhash,1,sizeof(txhash),fp) != sizeof(txhash) ) errs++; } + else if ( pvals != 0 && numpvals > 0 ) + { + fputc('V',fp); + if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) ) + errs++; + fputc(numpvals,fp); + if ( fwrite(pvals,sizeof(uint32_t),numpvals,fp) != numpvals ) + errs++; + komodo_pvals(height,pvals,numpvals); + printf("save pvals height.%d numpvals.%d\n",height,numpvals); + } else if ( height != 0 ) { //printf("func N ht.%d errs.%d\n",NOTARIZED_HEIGHT,errs); @@ -561,17 +577,6 @@ int32_t komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numno errs++; komodo_notarized_update(height,NOTARIZED_HEIGHT,NOTARIZED_HASH,NOTARIZED_BTCTXID); } - else if ( pvals != 0 && numpvals > 0 ) - { - fputc('V',fp); - if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) ) - errs++; - fputc(numpvals,fp); - if ( fwrite(pvals,sizeof(uint32_t),numpvals,fp) != numpvals ) - errs++; - komodo_pvals(height,pvals,numpvals); - printf("save pvals\n"); - } fflush(fp); } } @@ -643,33 +648,30 @@ int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen, opretlen = scriptbuf[len++]; opretlen = (opretlen << 8) + scriptbuf[len++]; } - if ( opretlen >= 32*2+4 ) + if ( opretlen >= 32*2+4 && strcmp("KMD",(char *)&scriptbuf[len+32*2+4]) == 0 ) { - if ( strcmp("KMD",(char *)&scriptbuf[len+32*2+4]) == 0 ) + len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&kmdtxid); + len += iguana_rwnum(0,&scriptbuf[len],4,(uint8_t *)notarizedheightp); + len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&btctxid); + //for (k=0; k NOTARIZED_HEIGHT ) { - len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&kmdtxid); - len += iguana_rwnum(0,&scriptbuf[len],4,(uint8_t *)notarizedheightp); - len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&btctxid); - //for (k=0; k NOTARIZED_HEIGHT ) - { - NOTARIZED_HEIGHT = *notarizedheightp; - NOTARIZED_HASH = kmdtxid; - NOTARIZED_BTCTXID = btctxid; - komodo_stateupdate(height,0,0,0,zero,0,0,0,0); - } - } - else if ( i == 0 && scriptbuf[len] == 'P' ) - { - double KMDBTC,BTCUSD,CNYUSD; uint32_t numpvals,timestamp,pvals[128]; - numpvals = dpow_readprices(&scriptbuf[++len],×tamp,&KMDBTC,&BTCUSD,&CNYUSD,pvals); - komodo_stateupdate(height,0,0,0,zero,0,0,pvals,numpvals); - printf("vout OP_RETURN.%d prices numpvals.%d opretlen.%d\n",height,numpvals,opretlen); + NOTARIZED_HEIGHT = *notarizedheightp; + NOTARIZED_HASH = kmdtxid; + NOTARIZED_BTCTXID = btctxid; + komodo_stateupdate(height,0,0,0,zero,0,0,0,0); } } + else if ( i == 0 && scriptbuf[len] == 'P' ) + { + double KMDBTC,BTCUSD,CNYUSD; uint32_t numpvals,timestamp,pvals[128]; + numpvals = dpow_readprices(&scriptbuf[++len],×tamp,&KMDBTC,&BTCUSD,&CNYUSD,pvals); + komodo_stateupdate(height,0,0,0,zero,0,0,pvals,numpvals); + printf("vout OP_RETURN.%d prices numpvals.%d opretlen.%d\n",height,numpvals,opretlen); + } } return(notaryid); } From a9869d0dd74ddf5b421e992ca86f7a78b365c6d5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Oct 2016 14:40:41 -0300 Subject: [PATCH 066/101] test --- src/komodo.h | 45 +++++++++++++++++++++++++++++++++++++++++++ src/rpcblockchain.cpp | 18 +++++++++++++++++ src/rpcclient.cpp | 3 ++- src/rpcserver.h | 1 + 4 files changed, 66 insertions(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index 6bb9ab70d..4ea9bd6fb 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -45,6 +45,32 @@ int32_t komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numno #define CRYPTO777_PUBSECPSTR "020e46e79a2a8d12b9b5d12c7a91adb4e454edfae43c0a0cb805427d2ac7613fd9" +char CURRENCIES[][8] = { "USD", "EUR", "JPY", "GBP", "AUD", "CAD", "CHF", "NZD", // major currencies + "CNY", "RUB", "MXN", "BRL", "INR", "HKD", "TRY", "ZAR", "PLN", "NOK", "SEK", "DKK", "CZK", "HUF", "ILS", "KRW", "MYR", "PHP", "RON", "SGD", "THB", "BGN", "IDR", "HRK" }; + +uint32_t MINDENOMS[] = { 1000, 1000, 100000, 1000, 1000, 1000, 1000, 1000, // major currencies + 10000, 100000, 10000, 1000, 100000, 10000, 1000, 10000, 1000, 10000, 10000, 10000, 10000, 100000, 1000, 1000000, 1000, 10000, 1000, 1000, 10000, 1000, 10000000, 10000, // end of currencies +}; + +uint32_t PAX_val32(double val) +{ + uint32_t val32 = 0; struct price_resolution price; + if ( (price.Pval= val*1000000000) != 0 ) + { + if ( price.Pval > 0xffffffff ) + printf("Pval overflow error %lld\n",(long long)price.Pval); + else val32 = (uint32_t)price.Pval; + } + return(val32); +} + +double PAX_val(uint32_t pval,int32_t baseid) +{ + if ( baseid >= 0 && baseid < MAX_CURRENCIES ) + return(((double)pval / 1000000000.) / MINDENOMS[baseid]); + return(0.); +} + const char *Notaries[][2] = { { "jl777_testA", "03b7621b44118017a16043f19b30cc8a4cfe068ac4e42417bae16ba460c80f3828" }, @@ -446,6 +472,25 @@ void komodo_pvals(int32_t height,uint32_t *pvals,uint8_t numpvals) } } +uint64_t komodo_paxprice(int32_t height,char *base,char *rel) +{ + int32_t baseid,relid,i,ht; uint32_t pvalb,pvalr,*ptr; + if ( (baseid= komodo_baseid(base)) >= 0 && (relid= komodo_baseid(rel)) >= 0 ) + { + for (i=NUM_PRICES-1; i>=0; i--) + { + ptr = &PVALS[36 * i]; + if ( *ptr <= height ) + { + if ( (pvalb= ptr[baseid]) != 0 && (pvalr= ptr[relid]) != 0 ) + return(SATOSHIDEN * (PAX_val(pvalb,baseid) / PAX_val(pvalr,relid))); + return(0); + } + } + } + return(0); +} + int32_t komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals) { static FILE *fp; static int32_t errs,didinit; char fname[512]; int32_t ht,k,i,func; uint8_t num,pubkeys[64][33]; diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 9664e085b..2d0bd8c38 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -382,6 +382,24 @@ Value gettxoutsetinfo(const Array& params, bool fHelp) 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(int32_t height,char *base,char *rel); + +Value paxprice(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 3) + throw runtime_error("paxprice \"base\" \"rel\" height\n"); + LOCK(cs_main); + Object ret; uint64_t pricetoshis; + std::string base = params[0].get_str(); + std::string rel = params[1].get_str(); + int height = params[2].get_int(); + pricetoshis = komodo_paxprice(height,(char *)base.c_str(),(char *)rel.c_str()); + ret.push_back(Pair("base", base)); + ret.push_back(Pair("rel", rel)); + ret.push_back(Pair("height", height)); + ret.push_back(Pair("price", ValueFromAmount(pricetoshis))); + return ret; +} Value gettxout(const Array& params, bool fHelp) { diff --git a/src/rpcclient.cpp b/src/rpcclient.cpp index 2841a3793..04fc84c9d 100644 --- a/src/rpcclient.cpp +++ b/src/rpcclient.cpp @@ -105,7 +105,8 @@ static const CRPCConvertParam vRPCConvertParams[] = { "z_sendmany", 2}, { "z_getoperationstatus", 0}, { "z_getoperationresult", 0}, - { "z_importkey", 1 } + { "z_importkey", 1 }, + { "paxprice", 3 }, }; class CRPCConvertTable diff --git a/src/rpcserver.h b/src/rpcserver.h index 6402a7a16..a721c6381 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -243,6 +243,7 @@ extern json_spirit::Value getblockhash(const json_spirit::Array& params, bool fH extern json_spirit::Value getblock(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value gettxoutsetinfo(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value gettxout(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value paxprice(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value verifychain(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getchaintips(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value invalidateblock(const json_spirit::Array& params, bool fHelp); From d105332751f52ac173d6e4419c3ac10f8f50fee6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Oct 2016 14:44:15 -0300 Subject: [PATCH 067/101] test --- src/komodo.h | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 4ea9bd6fb..ada094cfa 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -45,6 +45,7 @@ int32_t komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numno #define CRYPTO777_PUBSECPSTR "020e46e79a2a8d12b9b5d12c7a91adb4e454edfae43c0a0cb805427d2ac7613fd9" +#define MAX_CURRENCIES 32 char CURRENCIES[][8] = { "USD", "EUR", "JPY", "GBP", "AUD", "CAD", "CHF", "NZD", // major currencies "CNY", "RUB", "MXN", "BRL", "INR", "HKD", "TRY", "ZAR", "PLN", "NOK", "SEK", "DKK", "CZK", "HUF", "ILS", "KRW", "MYR", "PHP", "RON", "SGD", "THB", "BGN", "IDR", "HRK" }; @@ -52,7 +53,7 @@ uint32_t MINDENOMS[] = { 1000, 1000, 100000, 1000, 1000, 1000, 1000, 1000, // ma 10000, 100000, 10000, 1000, 100000, 10000, 1000, 10000, 1000, 10000, 10000, 10000, 10000, 100000, 1000, 1000000, 1000, 10000, 1000, 1000, 10000, 1000, 10000000, 10000, // end of currencies }; -uint32_t PAX_val32(double val) +/*uint32_t PAX_val32(double val) { uint32_t val32 = 0; struct price_resolution price; if ( (price.Pval= val*1000000000) != 0 ) @@ -62,7 +63,7 @@ uint32_t PAX_val32(double val) else val32 = (uint32_t)price.Pval; } return(val32); -} +}*/ double PAX_val(uint32_t pval,int32_t baseid) { @@ -472,6 +473,15 @@ void komodo_pvals(int32_t height,uint32_t *pvals,uint8_t numpvals) } } +int32_t komodo_baseid(char *base) +{ + int32_t i; + for (i=0; i NOTARIZED_HEIGHT ) { NOTARIZED_HEIGHT = *notarizedheightp; From de5678d8ed8635603c2097990d4ece8828fa4750 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Oct 2016 14:51:43 -0300 Subject: [PATCH 068/101] test --- src/rpcserver.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index a18b9ec72..6becec534 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -300,6 +300,7 @@ static const CRPCCommand vRPCCommands[] = { "blockchain", "verifytxoutproof", &verifytxoutproof, true }, { "blockchain", "gettxoutsetinfo", &gettxoutsetinfo, true }, { "blockchain", "verifychain", &verifychain, true }, + { "blockchain", "paxprice", &paxprice, true }, /* Mining */ { "mining", "getblocktemplate", &getblocktemplate, true }, From f09940d8b4895b27040f8079b37cce2d05c19937 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Oct 2016 15:07:07 -0300 Subject: [PATCH 069/101] test --- src/rpcblockchain.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 2d0bd8c38..81370d0b1 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -386,13 +386,13 @@ uint64_t komodo_paxprice(int32_t height,char *base,char *rel); Value paxprice(const Array& params, bool fHelp) { - if (fHelp || params.size() != 3) + if ( fHelp || params.size() != 3 ) throw runtime_error("paxprice \"base\" \"rel\" height\n"); LOCK(cs_main); Object ret; uint64_t pricetoshis; std::string base = params[0].get_str(); std::string rel = params[1].get_str(); - int height = params[2].get_int(); + int height = atoi(params[2].get_str().c_str()); pricetoshis = komodo_paxprice(height,(char *)base.c_str(),(char *)rel.c_str()); ret.push_back(Pair("base", base)); ret.push_back(Pair("rel", rel)); From a0ae285799a78a3d2719d4c340fd0ac7fd7dd3ff Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Oct 2016 15:36:43 -0300 Subject: [PATCH 070/101] test --- src/komodo.h | 45 ++++++++++++++++++++++++++++--------------- src/rpcblockchain.cpp | 2 +- 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index ada094cfa..09783fe2e 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -67,6 +67,7 @@ uint32_t MINDENOMS[] = { 1000, 1000, 100000, 1000, 1000, 1000, 1000, 1000, // ma double PAX_val(uint32_t pval,int32_t baseid) { + printf("PAX_val baseid.%d pval.%u\n",baseid,pval); if ( baseid >= 0 && baseid < MAX_CURRENCIES ) return(((double)pval / 1000000000.) / MINDENOMS[baseid]); return(0.); @@ -454,22 +455,29 @@ int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *n void komodo_pvals(int32_t height,uint32_t *pvals,uint8_t numpvals) { - int32_t i; double KMDBTC,BTCUSD,CNYUSD; uint32_t kmdbtc,btcusd,cnyusd; + int32_t i,nonz; double KMDBTC,BTCUSD,CNYUSD; uint32_t kmdbtc,btcusd,cnyusd; if ( numpvals >= 35 ) { - for (i=0; i<32; i++) + for (nonz=i=0; i<32; i++) + { + if ( pvals[i] != 0 ) + nonz++; printf("%u ",pvals[i]); - kmdbtc = pvals[i++]; - btcusd = pvals[i++]; - cnyusd = pvals[i++]; - KMDBTC = ((double)kmdbtc / (1000000000. * 1000.)); - BTCUSD = ((double)btcusd / (1000000000. / 1000.)); - CNYUSD = ((double)cnyusd / 1000000000.); - PVALS = (uint32_t *)realloc(PVALS,(NUM_PRICES+1) * sizeof(*PVALS) * 36); - PVALS[36 * NUM_PRICES] = height; - memcpy(&PVALS[36 * NUM_PRICES + 1],pvals,sizeof(*pvals) * 35); - NUM_PRICES++; - printf("OP_RETURN.%d KMD %.8f BTC %.6f CNY %.6f NUM_PRICES.%d\n",height,KMDBTC,BTCUSD,CNYUSD,NUM_PRICES); + } + if ( nonz == 32 ) + { + kmdbtc = pvals[i++]; + btcusd = pvals[i++]; + cnyusd = pvals[i++]; + KMDBTC = ((double)kmdbtc / (1000000000. * 1000.)); + BTCUSD = ((double)btcusd / (1000000000. / 1000.)); + CNYUSD = ((double)cnyusd / 1000000000.); + PVALS = (uint32_t *)realloc(PVALS,(NUM_PRICES+1) * sizeof(*PVALS) * 36); + PVALS[36 * NUM_PRICES] = height; + memcpy(&PVALS[36 * NUM_PRICES + 1],pvals,sizeof(*pvals) * 35); + NUM_PRICES++; + printf("OP_RETURN.%d KMD %.8f BTC %.6f CNY %.6f NUM_PRICES.%d\n",height,KMDBTC,BTCUSD,CNYUSD,NUM_PRICES); + } } } @@ -484,7 +492,7 @@ int32_t komodo_baseid(char *base) uint64_t komodo_paxprice(int32_t height,char *base,char *rel) { - int32_t baseid,relid,i,ht; uint32_t pvalb,pvalr,*ptr; + int32_t baseid,relid,i,ht; uint32_t pvalb,pvalr,*ptr; double baseval,relval; if ( (baseid= komodo_baseid(base)) >= 0 && (relid= komodo_baseid(rel)) >= 0 ) { for (i=NUM_PRICES-1; i>=0; i--) @@ -493,11 +501,16 @@ uint64_t komodo_paxprice(int32_t height,char *base,char *rel) if ( *ptr <= height ) { if ( (pvalb= ptr[baseid]) != 0 && (pvalr= ptr[relid]) != 0 ) - return(COIN * (PAX_val(pvalb,baseid) / PAX_val(pvalr,relid))); + { + baseval = PAX_val(pvalb,baseid); + relval = PAX_val(pvalr,relid); + printf("ht.%d [%d] base.(%u %f) rel.(%u %f) -> %llu\n",height,*ptr,pvalb,baseval,pvalr,relval,(long long)(COIN * (baseval / relval))); + return(COIN * (baseval / relval)); + } return(0); } } - } + } else printf("paxprice invalid base.%s rel.%s\n",base,rel); return(0); } diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 81370d0b1..2e955bfcc 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -392,7 +392,7 @@ Value paxprice(const Array& params, bool fHelp) Object ret; uint64_t pricetoshis; std::string base = params[0].get_str(); std::string rel = params[1].get_str(); - int height = atoi(params[2].get_str().c_str()); + int32_t height = atoi(params[2].get_str().c_str()); pricetoshis = komodo_paxprice(height,(char *)base.c_str(),(char *)rel.c_str()); ret.push_back(Pair("base", base)); ret.push_back(Pair("rel", rel)); From 88f973c27d07f827afcf3ce9162f4a819e18da70 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Oct 2016 15:46:33 -0300 Subject: [PATCH 071/101] test --- src/komodo.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 09783fe2e..857f63efd 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -19,6 +19,7 @@ #include #include #include +#include #include "uthash.h" #include "komodo_interest.h" @@ -481,9 +482,12 @@ void komodo_pvals(int32_t height,uint32_t *pvals,uint8_t numpvals) } } -int32_t komodo_baseid(char *base) +int32_t komodo_baseid(char *origbase) { - int32_t i; + int32_t i; char base[64]; + for (i=0; origbase[i]!=0&&i Date: Sun, 23 Oct 2016 15:53:05 -0300 Subject: [PATCH 072/101] test --- src/komodo.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 857f63efd..9b4d768b0 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -502,9 +502,9 @@ uint64_t komodo_paxprice(int32_t height,char *base,char *rel) for (i=NUM_PRICES-1; i>=0; i--) { ptr = &PVALS[36 * i]; - if ( *ptr <= height ) + if ( *ptr < height ) { - if ( (pvalb= ptr[baseid]) != 0 && (pvalr= ptr[relid]) != 0 ) + if ( (pvalb= ptr[1 + baseid]) != 0 && (pvalr= ptr[1 + relid]) != 0 ) { baseval = PAX_val(pvalb,baseid); relval = PAX_val(pvalr,relid); From 1f34636377e155ddf5707a8b2cd19f1ba5d5e2a7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Oct 2016 16:54:13 -0300 Subject: [PATCH 073/101] test --- src/komodo.h | 33 ++++++++++++++++++++++++++------- src/rpcblockchain.cpp | 17 ++++++++++++----- 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 9b4d768b0..14de88f4d 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -68,7 +68,7 @@ uint32_t MINDENOMS[] = { 1000, 1000, 100000, 1000, 1000, 1000, 1000, 1000, // ma double PAX_val(uint32_t pval,int32_t baseid) { - printf("PAX_val baseid.%d pval.%u\n",baseid,pval); + //printf("PAX_val baseid.%d pval.%u\n",baseid,pval); if ( baseid >= 0 && baseid < MAX_CURRENCIES ) return(((double)pval / 1000000000.) / MINDENOMS[baseid]); return(0.); @@ -488,15 +488,17 @@ int32_t komodo_baseid(char *origbase) for (i=0; origbase[i]!=0&&i= 0 && (relid= komodo_baseid(rel)) >= 0 ) { for (i=NUM_PRICES-1; i>=0; i--) @@ -504,12 +506,29 @@ uint64_t komodo_paxprice(int32_t height,char *base,char *rel) ptr = &PVALS[36 * i]; if ( *ptr < height ) { - if ( (pvalb= ptr[1 + baseid]) != 0 && (pvalr= ptr[1 + relid]) != 0 ) + if ( (pvalb= ptr[1 + baseid]) != 0 ) { baseval = PAX_val(pvalb,baseid); - relval = PAX_val(pvalr,relid); - printf("ht.%d [%d] base.(%u %f) rel.(%u %f) -> %llu\n",height,*ptr,pvalb,baseval,pvalr,relval,(long long)(COIN * (baseval / relval))); - return(COIN * (baseval / relval)); + if ( relid == MAX_CURRENCIES ) + { + kmdbtc = ptr[1 + MAX_CURRENCIES]; + btcusd = ptr[1 + MAX_CURRENCIES + 1]; + if ( ptr[1 + USD] != 0 && kmdbtc != 0 && btcusd != 0 ) + { + usdval = PAX_val(ptr[1 + USD],USD); + KMDBTC = ((double)kmdbtc / (1000000000. * 1000.)); + BTCUSD = ((double)btcusd / (1000000000. / 1000.)); + KMDUSD = (KMDBTC * BTCUSD); + printf("base -> USD %f, BTC %f KMDUSD %f\n",baseval/usdval,BTCUSD,KMDUSD); + return(volume * (baseval / usdval) / KMDUSD); + } + } + else if ( (pvalr= ptr[1 + relid]) != 0 ) + { + relval = PAX_val(pvalr,relid); + printf("ht.%d [%d] base.(%u %f) rel.(%u %f) -> %llu\n",height,*ptr,pvalb,baseval,pvalr,relval,(long long)(COIN * (baseval / relval))); + return(volume * (baseval / relval)); + } } return(0); } diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 2e955bfcc..7dc95eb82 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -382,22 +382,29 @@ Value gettxoutsetinfo(const Array& params, bool fHelp) 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(int32_t height,char *base,char *rel); +uint64_t komodo_paxprice(int32_t height,char *base,char *rel,uint64_t basevolume); Value paxprice(const Array& params, bool fHelp) { - if ( fHelp || params.size() != 3 ) + if ( fHelp || params.size() < 3 || params.size() > 4 ) throw runtime_error("paxprice \"base\" \"rel\" height\n"); LOCK(cs_main); - Object ret; uint64_t pricetoshis; + Object ret; uint64_t pricetoshis,basevolume; std::string base = params[0].get_str(); std::string rel = params[1].get_str(); int32_t height = atoi(params[2].get_str().c_str()); - pricetoshis = komodo_paxprice(height,(char *)base.c_str(),(char *)rel.c_str()); + if ( params.size() == 3 ) + basevolume = COIN; + else basevolume = AmountFromValue(params[3]); + relvolume = komodo_paxprice(height,(char *)base.c_str(),(char *)rel.c_str(),basevolume); ret.push_back(Pair("base", base)); ret.push_back(Pair("rel", rel)); ret.push_back(Pair("height", height)); - ret.push_back(Pair("price", ValueFromAmount(pricetoshis))); + if ( relvolume != 0 ) + { + ret.push_back(Pair("price", ValueFromAmount(basevolume) / ValueFromAmount(relvolume))); + ret.push_back(Pair("relvolume", ValueFromAmount(relvolume))); + } return ret; } From 72d2efb259abaefd03e00dc6d697895b84422f13 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Oct 2016 17:00:48 -0300 Subject: [PATCH 074/101] test --- src/komodo.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 14de88f4d..98d0be264 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -48,7 +48,8 @@ int32_t komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numno #define MAX_CURRENCIES 32 char CURRENCIES[][8] = { "USD", "EUR", "JPY", "GBP", "AUD", "CAD", "CHF", "NZD", // major currencies - "CNY", "RUB", "MXN", "BRL", "INR", "HKD", "TRY", "ZAR", "PLN", "NOK", "SEK", "DKK", "CZK", "HUF", "ILS", "KRW", "MYR", "PHP", "RON", "SGD", "THB", "BGN", "IDR", "HRK" }; + "CNY", "RUB", "MXN", "BRL", "INR", "HKD", "TRY", "ZAR", "PLN", "NOK", "SEK", "DKK", "CZK", "HUF", "ILS", "KRW", "MYR", "PHP", "RON", "SGD", "THB", "BGN", "IDR", "HRK", + "KMD" }; uint32_t MINDENOMS[] = { 1000, 1000, 100000, 1000, 1000, 1000, 1000, 1000, // major currencies 10000, 100000, 10000, 1000, 100000, 10000, 1000, 10000, 1000, 10000, 10000, 10000, 10000, 100000, 1000, 1000000, 1000, 10000, 1000, 1000, 10000, 1000, 10000000, 10000, // end of currencies @@ -488,17 +489,16 @@ int32_t komodo_baseid(char *origbase) for (i=0; origbase[i]!=0&&i= 0 && (relid= komodo_baseid(rel)) >= 0 ) { for (i=NUM_PRICES-1; i>=0; i--) @@ -533,7 +533,7 @@ uint64_t komodo_paxprice(int32_t height,char *base,char *rel,uint64_t volume) return(0); } } - } else printf("paxprice invalid base.%s rel.%s\n",base,rel); + } else printf("paxprice invalid base.%s %d, rel.%s %d\n",base,baseid,rel,relid); return(0); } @@ -953,7 +953,7 @@ int32_t komodo_opreturn(uint8_t *opret,int32_t maxsize) printf("%u ",pvals[i]); printf("t%u n.%d KMD %f BTC %f CNY %f (%f)\n",timestamp,n,KMDBTC,BTCUSD,CNYUSD,CNYUSD!=0?1./CNYUSD:0); } - if ( timestamp > time(NULL)-60 ) + if ( timestamp > time(NULL)-600 ) { n = komodo_opreturnscript(opret,'P',data+sizeof(crc32),(int32_t)(fsize-sizeof(crc32))); if ( 0 && lastcrc != crc32 ) From 744258899f2c9bd922bcea939146296a1de929b2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Oct 2016 17:02:39 -0300 Subject: [PATCH 075/101] test --- src/komodo.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index 98d0be264..4eab0ac5c 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -496,9 +496,10 @@ int32_t komodo_baseid(char *origbase) return(-1); } +#define USD 0 uint64_t komodo_paxprice(int32_t height,char *base,char *rel,uint64_t volume) { - int32_t baseid=-1,relid=-1,i,ht; uint32_t usdval,kmdbtc,btcusd,pvalb,pvalr,*ptr; double usdval,baseval,relval,KMDBTC,BTCUSD; + int32_t baseid=-1,relid=-1,i,ht; uint32_t kmdbtc,btcusd,pvalb,pvalr,*ptr; double usdval,baseval,relval,KMDBTC,BTCUSD,KMDUSD; if ( (baseid= komodo_baseid(base)) >= 0 && (relid= komodo_baseid(rel)) >= 0 ) { for (i=NUM_PRICES-1; i>=0; i--) From 46d5a641f8c1c680fd325c4b4a89533f0f8de0e6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Oct 2016 17:05:22 -0300 Subject: [PATCH 076/101] test --- src/rpcblockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 7dc95eb82..f8c4a68ec 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -389,7 +389,7 @@ Value paxprice(const Array& params, bool fHelp) if ( fHelp || params.size() < 3 || params.size() > 4 ) throw runtime_error("paxprice \"base\" \"rel\" height\n"); LOCK(cs_main); - Object ret; uint64_t pricetoshis,basevolume; + Object ret; uint64_t pricetoshis,basevolume,relvolume; std::string base = params[0].get_str(); std::string rel = params[1].get_str(); int32_t height = atoi(params[2].get_str().c_str()); From 303e9e00c6296465e5bc1be3e907f3921e0cbf81 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Oct 2016 17:06:56 -0300 Subject: [PATCH 077/101] test --- src/rpcblockchain.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index f8c4a68ec..ccb684ecb 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -389,20 +389,21 @@ Value paxprice(const Array& params, bool fHelp) if ( fHelp || params.size() < 3 || params.size() > 4 ) throw runtime_error("paxprice \"base\" \"rel\" height\n"); LOCK(cs_main); - Object ret; uint64_t pricetoshis,basevolume,relvolume; + Object ret; uint64_t pricetoshis,basevolume=0,relvolume; std::string base = params[0].get_str(); std::string rel = params[1].get_str(); int32_t height = atoi(params[2].get_str().c_str()); - if ( params.size() == 3 ) + if ( params.size() == 4 ) + basevolume = AmountFromValue(params[3]); + if ( basevolume == 0 ) basevolume = COIN; - else basevolume = AmountFromValue(params[3]); relvolume = komodo_paxprice(height,(char *)base.c_str(),(char *)rel.c_str(),basevolume); ret.push_back(Pair("base", base)); ret.push_back(Pair("rel", rel)); ret.push_back(Pair("height", height)); if ( relvolume != 0 ) { - ret.push_back(Pair("price", ValueFromAmount(basevolume) / ValueFromAmount(relvolume))); + ret.push_back(Pair("price", ValueFromAmount(((double)basevolume / (double)relvolume)))); ret.push_back(Pair("relvolume", ValueFromAmount(relvolume))); } return ret; From 768f9a1df51dc5f48063924069497b17bd5c9f7f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Oct 2016 17:13:31 -0300 Subject: [PATCH 078/101] test --- src/rpcblockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index ccb684ecb..5afe0630b 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -403,7 +403,7 @@ Value paxprice(const Array& params, bool fHelp) ret.push_back(Pair("height", height)); if ( relvolume != 0 ) { - ret.push_back(Pair("price", ValueFromAmount(((double)basevolume / (double)relvolume)))); + ret.push_back(Pair("price",((double)basevolume / (double)relvolume)); ret.push_back(Pair("relvolume", ValueFromAmount(relvolume))); } return ret; From 536480588ec1955111fe575df42ccb8d3711d756 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Oct 2016 17:18:13 -0300 Subject: [PATCH 079/101] test --- src/miner.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index ecad2343b..cceec7f01 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -521,6 +521,7 @@ void static BitcoinMiner(CWallet *pwallet) // Search // int32_t notaryid; uint32_t savebits; int64_t nStart = GetTime(); + uint32_t starttime = (uint32_t)time(NULL); savebits = pblock->nBits; if ( komodo_chosennotary(¬aryid,pindexPrev->nHeight+1,NOTARY_PUBKEY33) > 0 ) { @@ -568,10 +569,15 @@ void static BitcoinMiner(CWallet *pwallet) // Found a solution SetThreadPriority(THREAD_PRIORITY_NORMAL); LogPrintf("ZcashMiner:\n"); - LogPrintf("proof-of-work found \n hash: %s \ntarget: %s\n", pblock->GetHash().GetHex(), hashTarget.GetHex()); + LogPrintf("proof-of-work found \n hash: %s \ntarget: %s\n", pblock->GetHash().GetHex(), hashTarget.GetHex()); + if ( pblock->nBits == KOMODO_MINDIFF_NBITS ) + { + while ( time(NULL) < starttime+50 ) + fprintf(stderr,"%u: wait until %u\n",(uint32_t)time(NULL),starttime+50); + } if (ProcessBlockFound(pblock, *pwallet, reservekey)) { - // Ignore chain updates caused by us - std::lock_guard lock{m_cs}; + // Ignore chain updates caused by us + std::lock_guard lock{m_cs}; cancelSolver = false; } SetThreadPriority(THREAD_PRIORITY_LOWEST); From ff2d88cc236e714d5eb8935ff09834c5d05bb6e3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Oct 2016 17:31:02 -0300 Subject: [PATCH 080/101] test --- src/main.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 45e617a9c..3cf45b287 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1070,7 +1070,10 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa // is it already in the memory pool? uint256 hash = tx.GetHash(); if (pool.exists(hash)) + { + fprintf(stderr,"already in mempool\n"); return false; + } // Check for conflicts with in-memory transactions { From 800ae0a1a2a485b6b9d23d663fd80816b81a3cb8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Oct 2016 17:33:28 -0300 Subject: [PATCH 081/101] test --- src/main.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 3cf45b287..22c2608dc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1084,6 +1084,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa if (pool.mapNextTx.count(outpoint)) { // Disable replacement feature for now + fprintf(stderr,"Disable replacement feature for now\n"); return false; } } @@ -1091,6 +1092,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa BOOST_FOREACH(const uint256 &nf, joinsplit.nullifiers) { if (pool.mapNullifiers.count(nf)) { + fprintf(stderr,"pool.mapNullifiers.count\n"); return false; } } @@ -1109,7 +1111,10 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa // do we already have it? if (view.HaveCoins(hash)) + { + fprintf(stderr,"view.HaveCoins(hash) error\n"); return false; + } // do all inputs exist? // Note that this does not check for the presence of actual outputs (see the next check for that), @@ -1118,6 +1123,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa if (!view.HaveCoins(txin.prevout.hash)) { if (pfMissingInputs) *pfMissingInputs = true; + fprintf(stderr,"do all inputs exist?\n"); return false; } } From 49559c890a5a1eb578b2c2387728d2c72e69486f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Oct 2016 17:35:19 -0300 Subject: [PATCH 082/101] test --- src/miner.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index cceec7f01..0fa2c7a16 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -572,8 +572,11 @@ void static BitcoinMiner(CWallet *pwallet) LogPrintf("proof-of-work found \n hash: %s \ntarget: %s\n", pblock->GetHash().GetHex(), hashTarget.GetHex()); if ( pblock->nBits == KOMODO_MINDIFF_NBITS ) { - while ( time(NULL) < starttime+50 ) + while ( (uint32_t)time(NULL) < starttime+50 ) + { fprintf(stderr,"%u: wait until %u\n",(uint32_t)time(NULL),starttime+50); + sleep(1); + } } if (ProcessBlockFound(pblock, *pwallet, reservekey)) { // Ignore chain updates caused by us From a6a0d913012a626645c79f8f4a5f65adc2793f7e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Oct 2016 17:38:42 -0300 Subject: [PATCH 083/101] test --- src/miner.cpp | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 0fa2c7a16..3cb96fb4a 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -503,6 +503,7 @@ void static BitcoinMiner(CWallet *pwallet) // // Create new block // + uint32_t starttime = (uint32_t)time(NULL); unsigned int nTransactionsUpdatedLast = mempool.GetTransactionsUpdated(); CBlockIndex* pindexPrev = chainActive.Tip(); @@ -521,7 +522,6 @@ void static BitcoinMiner(CWallet *pwallet) // Search // int32_t notaryid; uint32_t savebits; int64_t nStart = GetTime(); - uint32_t starttime = (uint32_t)time(NULL); savebits = pblock->nBits; if ( komodo_chosennotary(¬aryid,pindexPrev->nHeight+1,NOTARY_PUBKEY33) > 0 ) { @@ -565,22 +565,17 @@ void static BitcoinMiner(CWallet *pwallet) if (UintToArith256(pblock->GetHash()) > hashTarget) { return false; } + if ( time(NULL) < starttime+50 ) + sleep(starttime+50-time(NULL)); // Found a solution SetThreadPriority(THREAD_PRIORITY_NORMAL); LogPrintf("ZcashMiner:\n"); - LogPrintf("proof-of-work found \n hash: %s \ntarget: %s\n", pblock->GetHash().GetHex(), hashTarget.GetHex()); - if ( pblock->nBits == KOMODO_MINDIFF_NBITS ) - { - while ( (uint32_t)time(NULL) < starttime+50 ) - { - fprintf(stderr,"%u: wait until %u\n",(uint32_t)time(NULL),starttime+50); - sleep(1); - } - } + LogPrintf("proof-of-work found \n hash: %s \ntarget: %s\n", pblock->GetHash().GetHex(), hashTarget.GetHex()); + if (ProcessBlockFound(pblock, *pwallet, reservekey)) { - // Ignore chain updates caused by us - std::lock_guard lock{m_cs}; + // Ignore chain updates caused by us + std::lock_guard lock{m_cs}; cancelSolver = false; } SetThreadPriority(THREAD_PRIORITY_LOWEST); From 7726fe88f4fb4f0934e6abacd56d2408d473025d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Oct 2016 17:41:08 -0300 Subject: [PATCH 084/101] test --- src/miner.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 3cb96fb4a..c14a76d53 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -565,8 +565,8 @@ void static BitcoinMiner(CWallet *pwallet) if (UintToArith256(pblock->GetHash()) > hashTarget) { return false; } - if ( time(NULL) < starttime+50 ) - sleep(starttime+50-time(NULL)); + /* if ( pblock->nBits == KOMODO_MINDIFF_NBITS && time(NULL) < starttime+50 ) + sleep(starttime+50-time(NULL));*/ // Found a solution SetThreadPriority(THREAD_PRIORITY_NORMAL); From 0012cfe4a85defd01af5ba7ddeeeb73403e0e9d7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Oct 2016 17:42:46 -0300 Subject: [PATCH 085/101] test --- src/rpcblockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 5afe0630b..de12e3213 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -403,7 +403,7 @@ Value paxprice(const Array& params, bool fHelp) ret.push_back(Pair("height", height)); if ( relvolume != 0 ) { - ret.push_back(Pair("price",((double)basevolume / (double)relvolume)); + ret.push_back(Pair("price",((double)basevolume / (double)relvolume))); ret.push_back(Pair("relvolume", ValueFromAmount(relvolume))); } return ret; From a86b9b7f99808484405904c063be9bcd133e2407 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Oct 2016 17:56:08 -0300 Subject: [PATCH 086/101] test --- src/Makefile.gtest.include | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Makefile.gtest.include b/src/Makefile.gtest.include index 3aa076bb1..3664a94b3 100644 --- a/src/Makefile.gtest.include +++ b/src/Makefile.gtest.include @@ -7,7 +7,7 @@ komodo_gtest_SOURCES = \ gtest/test_checktransaction.cpp \ gtest/json_test_vectors.cpp \ gtest/json_test_vectors.h \ - gtest/test_foundersreward.cpp \ + //gtest/test_foundersreward.cpp \ gtest/test_wallet_zkeys.cpp \ gtest/test_jsonspirit.cpp \ gtest/test_tautology.cpp \ From 8a1a972ad7bbd605cd77fa4a02036b58e6393948 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Oct 2016 18:00:04 -0300 Subject: [PATCH 087/101] test --- src/Makefile.gtest.include | 2 +- src/gtest/test_foundersreward.cpp | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Makefile.gtest.include b/src/Makefile.gtest.include index 3664a94b3..3aa076bb1 100644 --- a/src/Makefile.gtest.include +++ b/src/Makefile.gtest.include @@ -7,7 +7,7 @@ komodo_gtest_SOURCES = \ gtest/test_checktransaction.cpp \ gtest/json_test_vectors.cpp \ gtest/json_test_vectors.h \ - //gtest/test_foundersreward.cpp \ + gtest/test_foundersreward.cpp \ gtest/test_wallet_zkeys.cpp \ gtest/test_jsonspirit.cpp \ gtest/test_tautology.cpp \ diff --git a/src/gtest/test_foundersreward.cpp b/src/gtest/test_foundersreward.cpp index b7515f55d..59f49dce8 100644 --- a/src/gtest/test_foundersreward.cpp +++ b/src/gtest/test_foundersreward.cpp @@ -14,6 +14,7 @@ #include #include "util.h" +#ifndef disable_founders // To run tests: // ./zcash-gtest --gtest_filter="founders_reward_test.*" @@ -178,3 +179,4 @@ TEST(founders_reward_test, per_address_reward_testnet) { SelectParams(CBaseChainParams::TESTNET); verifyNumberOfRewards(); } +#endif From d15f15ae5c9b8dbc19573664c8e6efe50ebbee74 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Oct 2016 18:01:11 -0300 Subject: [PATCH 088/101] test --- src/gtest/test_foundersreward.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gtest/test_foundersreward.cpp b/src/gtest/test_foundersreward.cpp index 59f49dce8..d8b0fb39e 100644 --- a/src/gtest/test_foundersreward.cpp +++ b/src/gtest/test_foundersreward.cpp @@ -14,7 +14,7 @@ #include #include "util.h" -#ifndef disable_founders +//#ifndef disable_founders // To run tests: // ./zcash-gtest --gtest_filter="founders_reward_test.*" @@ -179,4 +179,4 @@ TEST(founders_reward_test, per_address_reward_testnet) { SelectParams(CBaseChainParams::TESTNET); verifyNumberOfRewards(); } -#endif +//#endif From 679496c3468b848de5564fa63838ae93c386389a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Oct 2016 18:06:33 -0300 Subject: [PATCH 089/101] test --- src/Makefile.gtest.include | 2 +- src/gtest/test_foundersreward.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Makefile.gtest.include b/src/Makefile.gtest.include index 3aa076bb1..531cab7a6 100644 --- a/src/Makefile.gtest.include +++ b/src/Makefile.gtest.include @@ -7,7 +7,7 @@ komodo_gtest_SOURCES = \ gtest/test_checktransaction.cpp \ gtest/json_test_vectors.cpp \ gtest/json_test_vectors.h \ - gtest/test_foundersreward.cpp \ + # gtest/test_foundersreward.cpp \ gtest/test_wallet_zkeys.cpp \ gtest/test_jsonspirit.cpp \ gtest/test_tautology.cpp \ diff --git a/src/gtest/test_foundersreward.cpp b/src/gtest/test_foundersreward.cpp index d8b0fb39e..59f49dce8 100644 --- a/src/gtest/test_foundersreward.cpp +++ b/src/gtest/test_foundersreward.cpp @@ -14,7 +14,7 @@ #include #include "util.h" -//#ifndef disable_founders +#ifndef disable_founders // To run tests: // ./zcash-gtest --gtest_filter="founders_reward_test.*" @@ -179,4 +179,4 @@ TEST(founders_reward_test, per_address_reward_testnet) { SelectParams(CBaseChainParams::TESTNET); verifyNumberOfRewards(); } -//#endif +#endif From 3fef7c32785ebb13cbcd136eea28ce34d24654d3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Oct 2016 18:29:08 -0300 Subject: [PATCH 090/101] test --- src/main.cpp | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 22c2608dc..ddbe43380 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1039,13 +1039,12 @@ CAmount GetMinRelayFee(const CTransaction& tx, unsigned int nBytes, bool fAllowF } -bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransaction &tx, bool fLimitFree, - bool* pfMissingInputs, bool fRejectAbsurdFee) +bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransaction &tx, bool fLimitFree,bool* pfMissingInputs, bool fRejectAbsurdFee) { AssertLockHeld(cs_main); if (pfMissingInputs) *pfMissingInputs = false; - +fprintf(stderr,"AcceptToMemoryPool\n"); if (!CheckTransaction(tx, state)) return error("AcceptToMemoryPool: CheckTransaction failed"); @@ -1057,8 +1056,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa // Rather not work on nonstandard transactions (unless -testnet/-regtest) string reason; if (Params().RequireStandard() && !IsStandardTx(tx, reason)) - return state.DoS(0, - error("AcceptToMemoryPool: nonstandard transaction: %s", reason), + return state.DoS(0,error("AcceptToMemoryPool: nonstandard transaction: %s", reason), REJECT_NONSTANDARD, reason); // Only accept nLockTime-using transactions that can be mined in the next @@ -1067,7 +1065,8 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa if (!CheckFinalTx(tx, STANDARD_LOCKTIME_VERIFY_FLAGS)) return state.DoS(0, false, REJECT_NONSTANDARD, "non-final"); - // is it already in the memory pool? +fprintf(stderr,"AcceptToMemoryPool B\n"); + // is it already in the memory pool? uint256 hash = tx.GetHash(); if (pool.exists(hash)) { @@ -1098,6 +1097,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa } } } +fprintf(stderr,"AcceptToMemoryPool C\n"); { CCoinsView dummy; @@ -1127,6 +1127,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa return false; } } +fprintf(stderr,"AcceptToMemoryPool D\n"); // are the actual inputs available? if (!view.HaveInputs(tx)) @@ -1159,8 +1160,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa unsigned int nSigOps = GetLegacySigOpCount(tx); nSigOps += GetP2SHSigOpCount(tx, view); if (nSigOps > MAX_STANDARD_TX_SIGOPS) - return state.DoS(0, - error("AcceptToMemoryPool: too many sigops %s, %d > %d", + return state.DoS(0, error("AcceptToMemoryPool: too many sigops %s, %d > %d", hash.ToString(), nSigOps, MAX_STANDARD_TX_SIGOPS), REJECT_NONSTANDARD, "bad-txns-too-many-sigops"); @@ -1170,6 +1170,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa CTxMemPoolEntry entry(tx, nFees, GetTime(), dPriority, chainActive.Height(), mempool.HasNoInputsOf(tx)); unsigned int nSize = entry.GetTxSize(); +fprintf(stderr,"AcceptToMemoryPool D\n"); // Don't accept it if it can't get into a block CAmount txMinFee = GetMinRelayFee(tx, nSize, true); @@ -1201,16 +1202,15 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa // -limitfreerelay unit is thousand-bytes-per-minute // At default rate it would take over a month to fill 1GB if (dFreeCount >= GetArg("-limitfreerelay", 15)*10*1000) - return state.DoS(0, error("AcceptToMemoryPool: free transaction rejected by rate limiter"), - REJECT_INSUFFICIENTFEE, "rate limited free transaction"); + return state.DoS(0, error("AcceptToMemoryPool: free transaction rejected by rate limiter"), REJECT_INSUFFICIENTFEE, "rate limited free transaction"); LogPrint("mempool", "Rate limit dFreeCount: %g => %g\n", dFreeCount, dFreeCount+nSize); dFreeCount += nSize; } if (fRejectAbsurdFee && nFees > ::minRelayTxFee.GetFee(nSize) * 10000) return error("AcceptToMemoryPool: absurdly high fees %s, %d > %d", - hash.ToString(), - nFees, ::minRelayTxFee.GetFee(nSize) * 10000); + hash.ToString(), nFees, ::minRelayTxFee.GetFee(nSize) * 10000); +fprintf(stderr,"AcceptToMemoryPool E\n"); // Check against previous transactions // This is done last to help prevent CPU exhaustion denial-of-service attacks. @@ -1236,6 +1236,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa // Store transaction in memory pool.addUnchecked(hash, entry, !IsInitialBlockDownload()); } +fprintf(stderr,"AcceptToMemoryPool F\n"); SyncWithWallets(tx, NULL); From 8ce38a37fb2ef075462c1baa85c4ff3129ad31ad Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Oct 2016 18:40:38 -0300 Subject: [PATCH 091/101] test --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index 4eab0ac5c..a4e9127d9 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -452,7 +452,7 @@ int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *n return(np->notarized_height); } memset(notarized_hashp,0,sizeof(*notarized_hashp)); - return(-1); + return(0); } void komodo_pvals(int32_t height,uint32_t *pvals,uint8_t numpvals) From 828ea6ec2491cc6b1798c2fac89d6df800255b13 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Oct 2016 18:42:30 -0300 Subject: [PATCH 092/101] test --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index a4e9127d9..3285c687a 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -450,7 +450,7 @@ int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *n *notarized_hashp = np->notarized_hash; *notarized_btctxidp = np->notarized_btctxid; return(np->notarized_height); - } + } memset(notarized_hashp,0,sizeof(*notarized_hashp)); return(0); } From 9eb44c75a81967464b8bcacdc9c8fe5eb60a21c3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Oct 2016 18:46:46 -0300 Subject: [PATCH 093/101] test --- src/main.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index ddbe43380..16cb93d9d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1046,25 +1046,31 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa *pfMissingInputs = false; fprintf(stderr,"AcceptToMemoryPool\n"); if (!CheckTransaction(tx, state)) + { + fprintf(stderr,"AcceptToMemoryPool CheckTransaction failed\n"); return error("AcceptToMemoryPool: CheckTransaction failed"); - + } // Coinbase is only valid in a block, not as a loose transaction if (tx.IsCoinBase()) - return state.DoS(100, error("AcceptToMemoryPool: coinbase as individual tx"), - REJECT_INVALID, "coinbase"); - + { + fprintf(stderr,"AcceptToMemoryPool coinbase as individual tx\n"); + return state.DoS(100, error("AcceptToMemoryPool: coinbase as individual tx"),REJECT_INVALID, "coinbase"); + } // Rather not work on nonstandard transactions (unless -testnet/-regtest) string reason; if (Params().RequireStandard() && !IsStandardTx(tx, reason)) - return state.DoS(0,error("AcceptToMemoryPool: nonstandard transaction: %s", reason), - REJECT_NONSTANDARD, reason); - + { + fprintf(stderr,"AcceptToMemoryPool nonstandard transaction: %s\n",reason.c_str()); + return state.DoS(0,error("AcceptToMemoryPool: nonstandard transaction: %s", reason),REJECT_NONSTANDARD, reason); + } // Only accept nLockTime-using transactions that can be mined in the next // block; we don't want our mempool filled up with transactions that can't // be mined yet. if (!CheckFinalTx(tx, STANDARD_LOCKTIME_VERIFY_FLAGS)) + { + fprintf(stderr,"AcceptToMemoryPool non-final\n"); return state.DoS(0, false, REJECT_NONSTANDARD, "non-final"); - + } fprintf(stderr,"AcceptToMemoryPool B\n"); // is it already in the memory pool? uint256 hash = tx.GetHash(); From a9980a36f12166220acf2eff4bf4b9e22e84917d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Oct 2016 18:49:14 -0300 Subject: [PATCH 094/101] test --- src/main.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 16cb93d9d..5a5c7df9b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -700,7 +700,10 @@ bool IsFinalTx(const CTransaction &tx, int nBlockHeight, int64_t nBlockTime) if ((int64_t)tx.nLockTime < ((int64_t)tx.nLockTime < LOCKTIME_THRESHOLD ? (int64_t)nBlockHeight : nBlockTime)) return true; if ( (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD && (int64_t)tx.nLockTime < nBlockTime-3600 ) + { + fprintf(stderr,"IsFinalTx reject locktime %u vs nBlockTime %u\n",tx.nLockTime,(uint32_t)nBlockTime); return(false); // need to prevent pastdating tx + } BOOST_FOREACH(const CTxIn& txin, tx.vin) if (!txin.IsFinal()) return false; From c3e43fb182e4787dd1f7c39f01dd76c126fdeaf4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Oct 2016 18:52:10 -0300 Subject: [PATCH 095/101] test --- src/wallet/wallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 9fac07166..3a25d8363 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2445,7 +2445,7 @@ bool CWallet::CreateTransaction(const vector& vecSend, } else { - txNew.nLockTime = (uint32_t)time(NULL) - 60; // set to a time close to now + txNew.nLockTime = (uint32_t)chainActive.Tip()->nTime + 1; // set to a time close to now } { From 14512c9697d065b80ce34cd6e0b2355435d9ef4c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Oct 2016 19:05:44 -0300 Subject: [PATCH 096/101] test --- src/main.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 5a5c7df9b..0f458bb3a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -706,7 +706,10 @@ bool IsFinalTx(const CTransaction &tx, int nBlockHeight, int64_t nBlockTime) } BOOST_FOREACH(const CTxIn& txin, tx.vin) if (!txin.IsFinal()) + { + printf("non-final txin\n"); return false; + } return true; } From d127bdc1319e0794f4b36c4354371a6e1be6ff69 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Oct 2016 19:16:54 -0300 Subject: [PATCH 097/101] test --- src/main.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 0f458bb3a..e9debb463 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -707,7 +707,7 @@ bool IsFinalTx(const CTransaction &tx, int nBlockHeight, int64_t nBlockTime) BOOST_FOREACH(const CTxIn& txin, tx.vin) if (!txin.IsFinal()) { - printf("non-final txin\n"); + printf("non-final txin seq.%x\n",txin.nSequence); return false; } return true; @@ -1050,7 +1050,6 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa AssertLockHeld(cs_main); if (pfMissingInputs) *pfMissingInputs = false; -fprintf(stderr,"AcceptToMemoryPool\n"); if (!CheckTransaction(tx, state)) { fprintf(stderr,"AcceptToMemoryPool CheckTransaction failed\n"); @@ -1077,7 +1076,6 @@ fprintf(stderr,"AcceptToMemoryPool\n"); fprintf(stderr,"AcceptToMemoryPool non-final\n"); return state.DoS(0, false, REJECT_NONSTANDARD, "non-final"); } -fprintf(stderr,"AcceptToMemoryPool B\n"); // is it already in the memory pool? uint256 hash = tx.GetHash(); if (pool.exists(hash)) @@ -1109,7 +1107,6 @@ fprintf(stderr,"AcceptToMemoryPool B\n"); } } } -fprintf(stderr,"AcceptToMemoryPool C\n"); { CCoinsView dummy; @@ -1139,7 +1136,6 @@ fprintf(stderr,"AcceptToMemoryPool C\n"); return false; } } -fprintf(stderr,"AcceptToMemoryPool D\n"); // are the actual inputs available? if (!view.HaveInputs(tx)) @@ -1182,7 +1178,6 @@ fprintf(stderr,"AcceptToMemoryPool D\n"); CTxMemPoolEntry entry(tx, nFees, GetTime(), dPriority, chainActive.Height(), mempool.HasNoInputsOf(tx)); unsigned int nSize = entry.GetTxSize(); -fprintf(stderr,"AcceptToMemoryPool D\n"); // Don't accept it if it can't get into a block CAmount txMinFee = GetMinRelayFee(tx, nSize, true); @@ -1222,7 +1217,6 @@ fprintf(stderr,"AcceptToMemoryPool D\n"); if (fRejectAbsurdFee && nFees > ::minRelayTxFee.GetFee(nSize) * 10000) return error("AcceptToMemoryPool: absurdly high fees %s, %d > %d", hash.ToString(), nFees, ::minRelayTxFee.GetFee(nSize) * 10000); -fprintf(stderr,"AcceptToMemoryPool E\n"); // Check against previous transactions // This is done last to help prevent CPU exhaustion denial-of-service attacks. @@ -1248,7 +1242,6 @@ fprintf(stderr,"AcceptToMemoryPool E\n"); // Store transaction in memory pool.addUnchecked(hash, entry, !IsInitialBlockDownload()); } -fprintf(stderr,"AcceptToMemoryPool F\n"); SyncWithWallets(tx, NULL); From 6998860925fc228de1efe5751972da7f34434a02 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Oct 2016 19:30:00 -0300 Subject: [PATCH 098/101] test --- src/main.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index e9debb463..c10113b4f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -705,11 +705,17 @@ bool IsFinalTx(const CTransaction &tx, int nBlockHeight, int64_t nBlockTime) return(false); // need to prevent pastdating tx } BOOST_FOREACH(const CTxIn& txin, tx.vin) - if (!txin.IsFinal()) + { + if ( txin.nSequence == 0xfffffffe && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD && (int64_t)tx.nLockTime > nBlockTime ) + { + + } + else if (!txin.IsFinal()) { printf("non-final txin seq.%x\n",txin.nSequence); return false; } + } return true; } From 586e33b1723e5232b8114b0404ca74fa12c217e8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Oct 2016 19:38:51 -0300 Subject: [PATCH 099/101] test --- src/komodo_interest.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/komodo_interest.h b/src/komodo_interest.h index e78c65fc5..f86d29267 100644 --- a/src/komodo_interest.h +++ b/src/komodo_interest.h @@ -48,13 +48,15 @@ uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uin int32_t minutes; uint64_t numerator,denominator,interest = 0; if ( komodo_moneysupply(txheight) < MAX_MONEY && nLockTime >= LOCKTIME_THRESHOLD && tiptime != 0 && nLockTime < tiptime && nValue >= COIN ) { - minutes = (tiptime - nLockTime) / 60; - numerator = (nValue * KOMODO_INTEREST); - denominator = (((uint64_t)365 * 24 * 60) / minutes); - if ( denominator == 0 ) - denominator = 1; // max KOMODO_INTEREST per transfer, do it at least annually! - interest = (numerator / denominator) / COIN; - fprintf(stderr,"komodo_interest %lld %.8f nLockTime.%u tiptime.%u minutes.%d interest %lld %.8f (%llu / %llu)\n",(long long)nValue,dstr(nValue),nLockTime,tiptime,minutes,(long long)interest,dstr(interest),(long long)numerator,(long long)denominator); + if ( (minutes= (tiptime - nLockTime) / 60) > 60 ) + { + numerator = (nValue * KOMODO_INTEREST); + denominator = (((uint64_t)365 * 24 * 60) / minutes); + if ( denominator == 0 ) + denominator = 1; // max KOMODO_INTEREST per transfer, do it at least annually! + interest = (numerator / denominator) / COIN; + fprintf(stderr,"komodo_interest %lld %.8f nLockTime.%u tiptime.%u minutes.%d interest %lld %.8f (%llu / %llu)\n",(long long)nValue,dstr(nValue),nLockTime,tiptime,minutes,(long long)interest,dstr(interest),(long long)numerator,(long long)denominator); + } } return(interest); } From bc1d085a7ae2745673103696afdebe299143d2ce Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Oct 2016 19:50:16 -0300 Subject: [PATCH 100/101] test --- src/komodo.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 3285c687a..c983fde35 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -424,6 +424,11 @@ int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33) void komodo_notarized_update(int32_t nHeight,int32_t notarized_height,uint256 notarized_hash,uint256 notarized_btctxid) { struct notarized_checkpoint *np; + if ( notarized_height > nHeight ) + { + printf("komodo_notarized_update REJECT notarized_height %d > %d nHeight\n",notarized_height,nHeight); + return; + } NPOINTS = (struct notarized_checkpoint *)realloc(NPOINTS,(NUM_NPOINTS+1) * sizeof(*NPOINTS)); np = &NPOINTS[NUM_NPOINTS++]; memset(np,0,sizeof(*np)); @@ -748,14 +753,14 @@ int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen, //for (k=0; k NOTARIZED_HEIGHT ) + if ( *notarizedheightp > NOTARIZED_HEIGHT && *notarizedheightp < height ) { + printf("ht.%d NOTARIZED.%d KMD.%s BTCTXID.%s (%s)\n",height,*notarizedheightp,kmdtxid.ToString().c_str(),btctxid.ToString().c_str(),(char *)&scriptbuf[len]); NOTARIZED_HEIGHT = *notarizedheightp; NOTARIZED_HASH = kmdtxid; NOTARIZED_BTCTXID = btctxid; komodo_stateupdate(height,0,0,0,zero,0,0,0,0); - } + } else printf("reject ht.%d NOTARIZED.%d KMD.%s BTCTXID.%s (%s)\n",height,*notarizedheightp,kmdtxid.ToString().c_str(),btctxid.ToString().c_str(),(char *)&scriptbuf[len]); } else if ( i == 0 && scriptbuf[len] == 'P' ) { From 3000de349a2d666e01461d371a18dbf969b6144d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Oct 2016 20:28:00 -0300 Subject: [PATCH 101/101] test --- src/rpcblockchain.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index de12e3213..eed707d58 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -401,9 +401,9 @@ Value paxprice(const Array& params, bool fHelp) ret.push_back(Pair("base", base)); ret.push_back(Pair("rel", rel)); ret.push_back(Pair("height", height)); - if ( relvolume != 0 ) + if ( basevolume != 0 ) { - ret.push_back(Pair("price",((double)basevolume / (double)relvolume))); + ret.push_back(Pair("price",((double)relvolume / (double)basevolume))); ret.push_back(Pair("relvolume", ValueFromAmount(relvolume))); } return ret;