From 2e500f5048e51a5d769754fcd225c0c91c9c64f1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 14 Nov 2016 15:00:25 -0300 Subject: [PATCH 01/80] test --- src/init.cpp | 11 ++++++----- src/komodo.h | 2 +- src/miner.cpp | 18 +++++++++--------- src/rpcserver.cpp | 2 +- src/test/rpc_wallet_tests.cpp | 2 +- src/wallet/rpcdump.cpp | 6 +++--- src/wallet/rpcwallet.cpp | 24 ++++++++++++------------ 7 files changed, 33 insertions(+), 32 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index fb2ae6aeb..cfd4f56dc 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -455,7 +455,8 @@ std::string HelpMessage(HelpMessageMode mode) std::string LicenseInfo() { return FormatParagraph(strprintf(_("Copyright (C) 2009-%i The Bitcoin Core Developers"), COPYRIGHT_YEAR)) + "\n" + - FormatParagraph(strprintf(_("Copyright (C) 2015-%i The Zcash Developers"), COPYRIGHT_YEAR)) + "\n" + + FormatParagraph(strprintf(_("Copyright (C) 2015-%i The Zcash Developers"), COPYRIGHT_YEAR)) + "\n" + + FormatParagraph(strprintf(_("Copyright (C) 2015-%i jl777 and SuperNET developers"), COPYRIGHT_YEAR)) + "\n" + "\n" + FormatParagraph(_("This is experimental software.")) + "\n" + "\n" + @@ -929,7 +930,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) // Sanity check if (!InitSanityCheck()) - return InitError(_("Initialization sanity check failed. Zcash is shutting down.")); + return InitError(_("Initialization sanity check failed. Komodo is shutting down.")); std::string strDataDir = GetDataDir().string(); #ifdef ENABLE_WALLET @@ -945,9 +946,9 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) try { static boost::interprocess::file_lock lock(pathLockFile.string().c_str()); if (!lock.try_lock()) - return InitError(strprintf(_("Cannot obtain a lock on data directory %s. Zcash is probably already running."), strDataDir)); + return InitError(strprintf(_("Cannot obtain a lock on data directory %s. Komodo is probably already running."), strDataDir)); } catch(const boost::interprocess::interprocess_exception& e) { - return InitError(strprintf(_("Cannot obtain a lock on data directory %s. Zcash is probably already running.") + " %s.", strDataDir, e.what())); + return InitError(strprintf(_("Cannot obtain a lock on data directory %s. Komodo is probably already running.") + " %s.", strDataDir, e.what())); } #ifndef WIN32 @@ -956,7 +957,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) if (GetBoolArg("-shrinkdebugfile", !fDebug)) ShrinkDebugFile(); LogPrintf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); - LogPrintf("Zcash version %s (%s)\n", FormatFullVersion(), CLIENT_DATE); + LogPrintf("Komodo version %s (%s)\n", FormatFullVersion(), CLIENT_DATE); LogPrintf("Using OpenSSL version %s\n", SSLeay_version(SSLEAY_VERSION)); #ifdef ENABLE_WALLET LogPrintf("Using BerkeleyDB version %s\n", DbEnv::version(0, 0, 0)); diff --git a/src/komodo.h b/src/komodo.h index 34b249f3b..5a6cded90 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -20,7 +20,7 @@ // 0. optimize assetchains RT loop // 1. error check fiat redeem amounts // 2. net balance limiter -// 3. verify: interest payment, ratification, reorgs +// 3. verify: interest payment, reorgs // 4. automate notarization fee payouts // 5. automated distribution of test REVS snapshot diff --git a/src/miner.cpp b/src/miner.cpp index 928bad008..90fd460f6 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -479,7 +479,7 @@ static bool ProcessBlockFound(CBlock* pblock, CWallet& wallet, CReserveKey& rese { LOCK(cs_main); if (pblock->hashPrevBlock != chainActive.Tip()->GetBlockHash()) - return error("ZcashMiner: generated block is stale"); + return error("KomodoMiner: generated block is stale"); } // Remove key from key pool @@ -495,7 +495,7 @@ static bool ProcessBlockFound(CBlock* pblock, CWallet& wallet, CReserveKey& rese // Process this block the same as if we had received it from another node CValidationState state; if (!ProcessNewBlock(chainActive.Tip()->nHeight+1,state, NULL, pblock, true, NULL)) - return error("ZcashMiner: ProcessNewBlock, block not accepted"); + return error("KomodoMiner: ProcessNewBlock, block not accepted"); minedBlocks.increment(); @@ -506,9 +506,9 @@ int32_t komodo_baseid(char *origbase); void static BitcoinMiner(CWallet *pwallet) { - LogPrintf("ZcashMiner started\n"); + LogPrintf("KomodoMiner started\n"); SetThreadPriority(THREAD_PRIORITY_LOWEST); - RenameThread("zcash-miner"); + RenameThread("komodo-miner"); const CChainParams& chainparams = Params(); // Each thread has its own key and counter @@ -583,12 +583,12 @@ void static BitcoinMiner(CWallet *pwallet) unique_ptr pblocktemplate(CreateNewBlockWithKey(reservekey)); if (!pblocktemplate.get()) { - LogPrintf("Error in ZcashMiner: Keypool ran out, please call keypoolrefill before restarting the mining thread\n"); + LogPrintf("Error in KomodoMiner: Keypool ran out, please call keypoolrefill before restarting the mining thread\n"); return; } CBlock *pblock = &pblocktemplate->block; IncrementExtraNonce(pblock, pindexPrev, nExtraNonce); - LogPrintf("Running ZcashMiner.%s with %u transactions in block (%u bytes)\n",solver.c_str(),pblock->vtx.size(),::GetSerializeSize(*pblock,SER_NETWORK,PROTOCOL_VERSION)); + LogPrintf("Running KomodoMiner.%s with %u transactions in block (%u bytes)\n",solver.c_str(),pblock->vtx.size(),::GetSerializeSize(*pblock,SER_NETWORK,PROTOCOL_VERSION)); // // Search // @@ -641,7 +641,7 @@ void static BitcoinMiner(CWallet *pwallet) } // Found a solution SetThreadPriority(THREAD_PRIORITY_NORMAL); - LogPrintf("ZcashMiner:\n"); + LogPrintf("KomodoMiner:\n"); 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 @@ -755,12 +755,12 @@ void static BitcoinMiner(CWallet *pwallet) } catch (const boost::thread_interrupted&) { - LogPrintf("ZcashMiner terminated\n"); + LogPrintf("KomodoMiner terminated\n"); throw; } catch (const std::runtime_error &e) { - LogPrintf("ZcashMiner runtime error: %s\n", e.what()); + LogPrintf("KomodoMiner runtime error: %s\n", e.what()); return; } c.disconnect(); diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index 78a438d03..f1f64b042 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -638,7 +638,7 @@ void StartRPCThreads() "The username and password MUST NOT be the same.\n" "If the file does not exist, create it with owner-readable-only file permissions.\n" "It is also recommended to set alertnotify so you are notified of problems;\n" - "for example: alertnotify=echo %%s | mail -s \"Zcash Alert\" admin@foo.com\n"), + "for example: alertnotify=echo %%s | mail -s \"Komodo Alert\" admin@foo.com\n"), GetConfigFile().string(), EncodeBase58(&rand_pwd[0],&rand_pwd[0]+32)), "", CClientUIInterface::MSG_ERROR | CClientUIInterface::SECURE); diff --git a/src/test/rpc_wallet_tests.cpp b/src/test/rpc_wallet_tests.cpp index 2f674df0f..885dcf5b7 100644 --- a/src/test/rpc_wallet_tests.cpp +++ b/src/test/rpc_wallet_tests.cpp @@ -375,7 +375,7 @@ BOOST_AUTO_TEST_CASE(rpc_wallet_z_importwallet) std::string testKey = CZCSpendingKey(testSpendingKey).ToString(); // create test data using the random key - std::string format_str = "# Wallet dump created by Zcash v0.11.2.0.z8-9155cc6-dirty (2016-08-11 11:37:00 -0700)\n" + std::string format_str = "# Wallet dump created by Komodo v0.11.2.0.z8-9155cc6-dirty (2016-08-11 11:37:00 -0700)\n" "# * Created on 2016-08-12T21:55:36Z\n" "# * Best block at time of backup was 0 (0de0a3851fef2d433b9b4f51d4342bdd24c5ddd793eb8fba57189f07e9235d52),\n" "# mined on 2009-01-03T18:15:05Z\n" diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 789bd4537..9e8fc6e68 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -182,7 +182,7 @@ Value importaddress(const Array& params, bool fHelp) std::vector data(ParseHex(params[0].get_str())); script = CScript(data.begin(), data.end()); } else { - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Zcash address or script"); + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Komodo address or script"); } string strLabel = ""; @@ -408,7 +408,7 @@ Value dumpprivkey(const Array& params, bool fHelp) string strAddress = params[0].get_str(); CBitcoinAddress address; if (!address.SetString(strAddress)) - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Zcash address"); + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Komodo address"); CKeyID keyID; if (!address.GetKeyID(keyID)) throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to a key"); @@ -483,7 +483,7 @@ Value dumpwallet_impl(const Array& params, bool fHelp, bool fDumpZKeys) std::sort(vKeyBirth.begin(), vKeyBirth.end()); // produce output - file << strprintf("# Wallet dump created by Zcash %s (%s)\n", CLIENT_BUILD, CLIENT_DATE); + file << strprintf("# Wallet dump created by Komodo %s (%s)\n", CLIENT_BUILD, CLIENT_DATE); file << strprintf("# * Created on %s\n", EncodeDumpTime(GetTime())); file << strprintf("# * Best block at time of backup was %i (%s),\n", chainActive.Height(), chainActive.Tip()->GetBlockHash().ToString()); file << strprintf("# mined on %s\n", EncodeDumpTime(chainActive.Tip()->GetBlockTime())); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 1e8e6c17d..9b16c0f67 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -114,7 +114,7 @@ Value getnewaddress(const Array& params, bool fHelp) if (fHelp || params.size() > 1) throw runtime_error( "getnewaddress ( \"account\" )\n" - "\nReturns a new Zcash address for receiving payments.\n" + "\nReturns a new Komodo address for receiving payments.\n" "\nArguments:\n" "1. \"account\" (string, optional) DEPRECATED. If provided, it MUST be set to the empty string \"\" to represent the default account. Passing any other string will result in an error.\n" "\nResult:\n" @@ -191,7 +191,7 @@ Value getaccountaddress(const Array& params, bool fHelp) if (fHelp || params.size() != 1) throw runtime_error( "getaccountaddress \"account\"\n" - "\nDEPRECATED. Returns the current Zcash address for receiving payments to this account.\n" + "\nDEPRECATED. Returns the current Komodo address for receiving payments to this account.\n" "\nArguments:\n" "1. \"account\" (string, required) MUST be set to the empty string \"\" to represent the default account. Passing any other string will result in an error.\n" "\nResult:\n" @@ -223,7 +223,7 @@ Value getrawchangeaddress(const Array& params, bool fHelp) if (fHelp || params.size() > 1) throw runtime_error( "getrawchangeaddress\n" - "\nReturns a new Zcash address, for receiving change.\n" + "\nReturns a new Komodo address, for receiving change.\n" "This is for use with raw transactions, NOT normal use.\n" "\nResult:\n" "\"address\" (string) The address\n" @@ -271,7 +271,7 @@ Value setaccount(const Array& params, bool fHelp) CBitcoinAddress address(params[0].get_str()); if (!address.IsValid()) - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Zcash address"); + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Komodo address"); string strAccount; if (params.size() > 1) @@ -318,7 +318,7 @@ Value getaccount(const Array& params, bool fHelp) CBitcoinAddress address(params[0].get_str()); if (!address.IsValid()) - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Zcash address"); + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Komodo address"); string strAccount; map::iterator mi = pwalletMain->mapAddressBook.find(address.Get()); @@ -443,7 +443,7 @@ Value sendtoaddress(const Array& params, bool fHelp) CBitcoinAddress address(params[0].get_str()); if (!address.IsValid()) - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Zcash address"); + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Komodo address"); // Amount CAmount nAmount = AmountFromValue(params[1]); @@ -683,7 +683,7 @@ Value getreceivedbyaddress(const Array& params, bool fHelp) // Bitcoin address CBitcoinAddress address = CBitcoinAddress(params[0].get_str()); if (!address.IsValid()) - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Zcash address"); + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Komodo address"); CScript scriptPubKey = GetScriptForDestination(address.Get()); if (!IsMine(*pwalletMain,scriptPubKey)) return (double)0.0; @@ -995,7 +995,7 @@ Value sendfrom(const Array& params, bool fHelp) string strAccount = AccountFromValue(params[0]); CBitcoinAddress address(params[1].get_str()); if (!address.IsValid()) - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Zcash address"); + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Komodo address"); CAmount nAmount = AmountFromValue(params[2]); int nMinDepth = 1; if (params.size() > 3) @@ -1087,7 +1087,7 @@ Value sendmany(const Array& params, bool fHelp) { CBitcoinAddress address(s.name_); if (!address.IsValid()) - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, string("Invalid Zcash address: ")+s.name_); + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, string("Invalid Komodo address: ")+s.name_); if (setAddress.count(address)) throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, duplicated address: ")+s.name_); @@ -1139,7 +1139,7 @@ Value addmultisigaddress(const Array& params, bool fHelp) { string msg = "addmultisigaddress nrequired [\"key\",...] ( \"account\" )\n" "\nAdd a nrequired-to-sign multisignature address to the wallet.\n" - "Each key is a Zcash address or hex-encoded public key.\n" + "Each key is a Komodo address or hex-encoded public key.\n" "If 'account' is specified (DEPRECATED), assign address to that account.\n" "\nArguments:\n" @@ -2134,7 +2134,7 @@ Value encryptwallet(const Array& params, bool fHelp) // slack space in .dat files; that is bad if the old data is // unencrypted private keys. So: StartShutdown(); - return "wallet encrypted; Zcash server stopping, restart to run with encrypted wallet. The keypool has been flushed, you need to make a new backup."; + return "wallet encrypted; Komodo server stopping, restart to run with encrypted wallet. The keypool has been flushed, you need to make a new backup."; } Value lockunspent(const Array& params, bool fHelp) @@ -2423,7 +2423,7 @@ Value listunspent(const Array& params, bool fHelp) BOOST_FOREACH(Value& input, inputs) { CBitcoinAddress address(input.get_str()); if (!address.IsValid()) - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, string("Invalid Zcash address: ")+input.get_str()); + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, string("Invalid Komodo address: ")+input.get_str()); if (setAddress.count(address)) throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, duplicated address: ")+input.get_str()); setAddress.insert(address); From 073a37a2dcf61f11783032abca58311860417419 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 14 Nov 2016 15:10:42 -0300 Subject: [PATCH 02/80] test --- src/coins.cpp | 2 +- src/wallet/wallet.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coins.cpp b/src/coins.cpp index dc3880a2a..d7208cce8 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -401,7 +401,7 @@ CAmount CCoinsViewCache::GetValueIn(int32_t nHeight,int64_t *interestp,const CTr #ifdef KOMODO_ENABLE_INTEREST if ( ASSETCHAINS_SYMBOL[0] == 0 && nHeight >= 60000 ) { - if ( interest != 0 ) + //if ( interest != 0 ) { printf("nResult %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)nResult/COIN,(double)interest/COIN,nHeight,tx.nLockTime,tiptime); fprintf(stderr,"nResult %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)nResult/COIN,(double)interest/COIN,nHeight,tx.nLockTime,tiptime); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 5c8ce5a9f..5bf6c4ca4 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2403,7 +2403,7 @@ bool CWallet::SelectCoins(const CAmount& nTargetValue, setnHeight+1 >= 60000 ) { - if ( interest != 0 ) + //if ( interest != 0 ) { printf("nValueRet %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)nValueRet/COIN,(double)interest/COIN,chainActive.Tip()->nHeight+1,out.tx->nLockTime,chainActive.Tip()->nTime); fprintf(stderr,"nValueRet %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)nValueRet/COIN,(double)interest/COIN,chainActive.Tip()->nHeight+1,out.tx->nLockTime,chainActive.Tip()->nTime); From a547ea39b63d52de2b815b3d48542b591d772bad Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 14 Nov 2016 15:32:28 -0300 Subject: [PATCH 03/80] 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 5bf6c4ca4..ccba81b4d 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2405,7 +2405,7 @@ bool CWallet::SelectCoins(const CAmount& nTargetValue, setnHeight+1,out.tx->nLockTime,chainActive.Tip()->nTime); + printf("nValueRet %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)out.tx->vout[out.i].nValue/COIN,(double)interest/COIN,chainActive.Tip()->nHeight+1,out.tx->nLockTime,chainActive.Tip()->nTime); fprintf(stderr,"nValueRet %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)nValueRet/COIN,(double)interest/COIN,chainActive.Tip()->nHeight+1,out.tx->nLockTime,chainActive.Tip()->nTime); } nValueRet += interest; From a130c5cb667e867de58659d28e653fa41a3a2f38 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 07:47:14 -0300 Subject: [PATCH 04/80] test --- src/coins.cpp | 2 +- src/coins.h | 4 ++-- src/komodo.h | 1 + src/pow.cpp | 4 ++-- src/rpcblockchain.cpp | 1 + src/rpcrawtransaction.cpp | 17 +++++++++++++++++ 6 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/coins.cpp b/src/coins.cpp index d7208cce8..46e4f55b4 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -408,8 +408,8 @@ CAmount CCoinsViewCache::GetValueIn(int32_t nHeight,int64_t *interestp,const CTr } nResult += interest; } -#endif (*interestp) += interest; +#endif } nResult += tx.GetJoinSplitValueIn(); diff --git a/src/coins.h b/src/coins.h index 7d5bc8168..34e3a89d7 100644 --- a/src/coins.h +++ b/src/coins.h @@ -87,14 +87,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; + //uint32_t nLockTime; void FromTx(const CTransaction &tx, int nHeightIn) { fCoinBase = tx.IsCoinBase(); vout = tx.vout; nHeight = nHeightIn; nVersion = tx.nVersion; - nLockTime = tx.nLockTime; + //nLockTime = tx.nLockTime; ClearUnspendable(); } diff --git a/src/komodo.h b/src/komodo.h index 5a6cded90..ccc94bb36 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -17,6 +17,7 @@ #define H_KOMODO_H // Todo: +// 00. standardize interests // 0. optimize assetchains RT loop // 1. error check fiat redeem amounts // 2. net balance limiter diff --git a/src/pow.cpp b/src/pow.cpp index befb665bd..69789f5fa 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -155,8 +155,8 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned in } if (fNegative || bnTarget == 0 || fOverflow || bnTarget > UintToArith256(params.powLimit)) return error("CheckProofOfWork(): nBits below minimum work"); - if ( height > 70000 ) - bnTarget /= 64; + //if ( height > 70000 ) + // bnTarget /= 64; // Check proof of work matches claimed amount if ( UintToArith256(hash) > bnTarget ) { diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 7373d51c9..a08866fa5 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -577,6 +577,7 @@ Value gettxout(const Array& params, bool fHelp) CBlockIndex *pblockindex = chainActive[coins.nHeight]; uint64_t interest; uint32_t timestamp=0; + if ( pblockindex != 0 ) timestamp = pblockindex->nTime; // this is approx, but cant figure out how to get tx here interest = komodo_interest(coins.nHeight,coins.vout[n].nValue,timestamp,pindex->nTime); diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index c27f8213c..72887d0f4 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -251,6 +251,23 @@ Value getrawtransaction(const Array& params, bool fHelp) return result; } +uint32_t komodo_interest_args(int32_t *prevblockheightp,int32_t *prevblocktimep,uint64_t *valuep,uint256 hash,int32_t n) +{ + //interest = komodo_interest(pindex->nHeight,txout.nValue,tx.nLockTime,pindex->nTime); + LOCK(cs_main); + CTransaction tx; + uint256 hashBlock; + if ( !GetTransaction(hash,tx,hashBlock,true) ) + return(0); + uint32_t locktime = 0; + if ( n < tx.vout.size() ) + { + locktime = tx.nLockTime; + //TxToJSON(tx,hashBlock,result); + } + return(locktime); +} + Value gettxoutproof(const Array& params, bool fHelp) { if (fHelp || (params.size() != 1 && params.size() != 2)) From 0fec0cc4b39e474a1c4dcd2cd7229a8fa20eeb7b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 10:38:38 -0300 Subject: [PATCH 05/80] test --- src/coins.cpp | 10 +++++----- src/komodo_interest.h | 8 ++++---- src/rpcblockchain.cpp | 25 +++++++++++++++---------- src/rpcrawtransaction.cpp | 24 ++++++++++++++---------- src/wallet/rpcwallet.cpp | 6 +++--- src/wallet/wallet.cpp | 6 +++--- 6 files changed, 44 insertions(+), 35 deletions(-) diff --git a/src/coins.cpp b/src/coins.cpp index 46e4f55b4..d572990b5 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -388,7 +388,6 @@ extern char ASSETCHAINS_SYMBOL[16]; CAmount CCoinsViewCache::GetValueIn(int32_t nHeight,int64_t *interestp,const CTransaction& tx,uint32_t tiptime) const { - uint32_t timestamp,minutes; int64_t interest; *interestp = 0; if ( tx.IsCoinBase() != 0 ) return 0; @@ -397,18 +396,19 @@ CAmount CCoinsViewCache::GetValueIn(int32_t nHeight,int64_t *interestp,const CTr { value = GetOutputFor(tx.vin[i]).nValue; nResult += value; - interest = komodo_interest(nHeight,value,tx.nLockTime,tiptime); #ifdef KOMODO_ENABLE_INTEREST - if ( ASSETCHAINS_SYMBOL[0] == 0 && nHeight >= 60000 ) + if ( strcmp(ASSETCHAINS_SYMBOL,"REVS") == 0 )//&& nHeight >= 60000 ) { - //if ( interest != 0 ) + int64_t interest; + interest = komodo_interest(nHeight,value,tx.nLockTime,tiptime); + if ( interest != 0 || value >= COIN*100 ) { printf("nResult %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)nResult/COIN,(double)interest/COIN,nHeight,tx.nLockTime,tiptime); fprintf(stderr,"nResult %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)nResult/COIN,(double)interest/COIN,nHeight,tx.nLockTime,tiptime); } nResult += interest; + (*interestp) += interest; } - (*interestp) += interest; #endif } nResult += tx.GetJoinSplitValueIn(); diff --git a/src/komodo_interest.h b/src/komodo_interest.h index 68ab2e2f3..9d66b3344 100644 --- a/src/komodo_interest.h +++ b/src/komodo_interest.h @@ -15,7 +15,7 @@ #define KOMODO_INTEREST ((uint64_t)(0.05 * COIN)) // 5% -uint64_t komodo_accrued_interest(int32_t height,int64_t paidinterest) +uint64_t komodo_earned_interest(int32_t height,int64_t paidinterest) { static uint64_t *interests; static int32_t maxheight; uint64_t total; int32_t ind,incr = 100000; @@ -50,15 +50,15 @@ uint64_t komodo_accrued_interest(int32_t height,int64_t paidinterest) uint64_t komodo_moneysupply(int32_t height) { - if ( height <= 1 ) + if ( height <= 1 || ASSETCHAINS_SYMBOL[0] == 0 ) return(0); - else return(COIN * 100000000 + (height-1) * 3 + komodo_accrued_interest(height,-1)); + else return(COIN * 100000000 + (height-1) * 3 + komodo_earned_interest(height,-1)); } uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime) { int32_t minutes; uint64_t numerator,denominator,interest = 0; - if ( komodo_moneysupply(txheight) < MAX_MONEY && nLockTime >= LOCKTIME_THRESHOLD && tiptime != 0 && nLockTime < tiptime && nValue >= COIN ) + if ( komodo_moneysupply(txheight) < MAX_MONEY && nLockTime >= LOCKTIME_THRESHOLD && tiptime != 0 && nLockTime < tiptime && nValue >= 100*COIN ) { if ( (minutes= (tiptime - nLockTime) / 60) > 60 ) { diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index a08866fa5..fcc8cc099 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -380,6 +380,7 @@ Value gettxoutsetinfo(const Array& params, bool fHelp) return ret; } +uint32_t komodo_interest_args(int32_t *prevblockheightp,int32_t *prevblocktimep,uint64_t *valuep,uint256 hash,int32_t n); uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime); uint32_t komodo_txtime(uint256 hash); uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uint64_t basevolume); @@ -504,6 +505,18 @@ Value paxprices(const Array& params, bool fHelp) return ret; } +uint64_t komodo_accrued_interest(uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue) +{ + uint64_t value; int32_t txheight; uint32_t locktime,prevblocktime; + if ( (locktime= komodo_interest_args(&txheight,&prevblocktime,&value,hash,n)) != 0 ) + { + if ( (checkvalue == 0 || value == checkvalue) && (checkheight == 0 || txheight == checkheight) ) + return(komodo_interest(txheight,value,locktime,prevblocktime)); + //fprintf(stderr,"nValue %llu lock.%u:%u nTime.%u -> %llu\n",(long long)coins.vout[n].nValue,coins.nLockTime,timestamp,pindex->nTime,(long long)interest); + } else fprintf(stderr,"komodo_accrued_interest value mismatch %llu vs %llu or height mismatch %d vs %d\n",(long long)value,(long long)checkvalue,txheight,checkheight); + return(0); +} + Value gettxout(const Array& params, bool fHelp) { if (fHelp || params.size() < 2 || params.size() > 3) @@ -574,16 +587,8 @@ Value gettxout(const Array& params, bool fHelp) ret.push_back(Pair("confirmations", 0)); else ret.push_back(Pair("confirmations", pindex->nHeight - coins.nHeight + 1)); ret.push_back(Pair("value", ValueFromAmount(coins.vout[n].nValue))); - - CBlockIndex *pblockindex = chainActive[coins.nHeight]; - uint64_t interest; uint32_t timestamp=0; - - if ( pblockindex != 0 ) - timestamp = pblockindex->nTime; // this is approx, but cant figure out how to get tx here - interest = komodo_interest(coins.nHeight,coins.vout[n].nValue,timestamp,pindex->nTime); - //fprintf(stderr,"nValue %llu lock.%u:%u nTime.%u -> %llu\n",(long long)coins.vout[n].nValue,coins.nLockTime,timestamp,pindex->nTime,(long long)interest); - ret.push_back(Pair("interest", ValueFromAmount(interest))); - + if ( (interest= komodo_accrued_interest(hash,n,coins.nHeight,coins.vout[n].nValue)) != 0 ) + ret.push_back(Pair("interest", ValueFromAmount(interest))); Object o; ScriptPubKeyToJSON(coins.vout[n].scriptPubKey, o, true); ret.push_back(Pair("scriptPubKey", o)); diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index 72887d0f4..32e9a3341 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -122,16 +122,17 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, Object& entry) entry.push_back(Pair("vin", vin)); Array vout; BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock()); - CBlockIndex *pindex = it->second; + CBlockIndex *tipindex,*pindex = it->second; uint64_t interest; for (unsigned int i = 0; i < tx.vout.size(); i++) { const CTxOut& txout = tx.vout[i]; Object out; out.push_back(Pair("value", ValueFromAmount(txout.nValue))); - if ( pindex != 0 && tx.nLockTime != 0 ) + if ( pindex != 0 && tx.nLockTime != 0 && (tipindex= chainActive.Tip()) != 0 ) { - interest = komodo_interest(pindex->nHeight,txout.nValue,tx.nLockTime,pindex->nTime); - //fprintf(stderr,"TxtoJSON interest %llu %.8f\n",(long long)interest,(double)interest/COIN); + interest = komodo_interest(pindex->nHeight,txout.nValue,tx.nLockTime,tipindex->nTime); + if ( strcmp("REVS",ASSETCHAINS_SYMBOL) == 0 ) + fprintf(stderr,"TxtoJSON interest %llu %.8f (%d %llu %u %u)\n",(long long)interest,(double)interest/COIN,(int32_t)pindex->nHeight,(long long)txout.nValue,(uint32_t)tx.nLockTime,(int32_t)pcoinsTip->nTime); out.push_back(Pair("interest", ValueFromAmount(interest))); } out.push_back(Pair("n", (int64_t)i)); @@ -251,19 +252,22 @@ Value getrawtransaction(const Array& params, bool fHelp) return result; } -uint32_t komodo_interest_args(int32_t *prevblockheightp,int32_t *prevblocktimep,uint64_t *valuep,uint256 hash,int32_t n) +uint32_t komodo_interest_args(int32_t *txheightp,int32_t *tiptimep,uint64_t *valuep,uint256 hash,int32_t n) { - //interest = komodo_interest(pindex->nHeight,txout.nValue,tx.nLockTime,pindex->nTime); LOCK(cs_main); - CTransaction tx; - uint256 hashBlock; + CTransaction tx; uint256 hashBlock; CBlockIndex *pindex,*tipindex; if ( !GetTransaction(hash,tx,hashBlock,true) ) return(0); uint32_t locktime = 0; if ( n < tx.vout.size() ) { - locktime = tx.nLockTime; - //TxToJSON(tx,hashBlock,result); + if ( (pindex= map[hashBlock]) != 0 && (tipindex= chainActive.Tip()) != 0 ) + { + *valuep = tx.vout[n].nValue; + *txheightp = pindex->nHeight; + *tiptimep = tipindex->nTime; + locktime = tx.nLockTime; + } } return(locktime); } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 9b16c0f67..12350db81 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2473,11 +2473,11 @@ Value listunspent(const Array& params, bool fHelp) if ( out.tx->nLockTime != 0 ) { BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock()); - CBlockIndex *pindex = it->second; + CBlockIndex *tipindex,*pindex = it->second; uint64_t interest; - if ( pindex != 0 ) + if ( pindex != 0 && (tipindex= chainActive.Tip()) != 0 ) { - interest = komodo_interest(pindex->nHeight,nValue,out.tx->nLockTime,pindex->nTime); + interest = komodo_interest(pindex->nHeight,nValue,out.tx->nLockTime,tipindex->nTime); entry.push_back(Pair("interest",ValueFromAmount(interest))); } } diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index ccba81b4d..0ce980304 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2399,11 +2399,11 @@ bool CWallet::SelectCoins(const CAmount& nTargetValue, setvout[out.i].nValue; - interest = komodo_interest(chainActive.Tip()->nHeight+1,out.tx->vout[out.i].nValue,out.tx->nLockTime,chainActive.Tip()->nTime); #ifdef KOMODO_ENABLE_INTEREST - if ( ASSETCHAINS_SYMBOL[0] == 0 && chainActive.Tip()->nHeight+1 >= 60000 ) + if ( strcmp(ASSETCHAINS_SYMBOL,"REVS") == 0 )//&& chainActive.Tip()->nHeight+1 >= 60000 ) { - //if ( interest != 0 ) + interest = komodo_interest(chainActive.Tip()->nHeight+1,out.tx->vout[out.i].nValue,out.tx->nLockTime,chainActive.Tip()->nTime); + if ( interest != 0 || value >= COIN*100 ) { printf("nValueRet %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)out.tx->vout[out.i].nValue/COIN,(double)interest/COIN,chainActive.Tip()->nHeight+1,out.tx->nLockTime,chainActive.Tip()->nTime); fprintf(stderr,"nValueRet %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)nValueRet/COIN,(double)interest/COIN,chainActive.Tip()->nHeight+1,out.tx->nLockTime,chainActive.Tip()->nTime); From 1565e3c31efa59c6f96e5fed6645a868854ea7fd Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 10:39:47 -0300 Subject: [PATCH 06/80] test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index dd1d52a92..11c1ad0b5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2230,7 +2230,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin return false; control.Add(vChecks); } - komodo_accrued_interest(pindex->nHeight,sum); + komodo_earned_interest(pindex->nHeight,sum); CTxUndo undoDummy; if (i > 0) { blockundo.vtxundo.push_back(CTxUndo()); From cd94227f89047ef0a125f6aa44b135e20e9794ac Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 10:43:10 -0300 Subject: [PATCH 07/80] test --- src/rpcblockchain.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index fcc8cc099..7c942d0e9 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -380,7 +380,7 @@ Value gettxoutsetinfo(const Array& params, bool fHelp) return ret; } -uint32_t komodo_interest_args(int32_t *prevblockheightp,int32_t *prevblocktimep,uint64_t *valuep,uint256 hash,int32_t n); +uint32_t komodo_interest_args(int32_t *txheightp,uint32_t *tiptimep,uint64_t *valuep,uint256 hash,int32_t n); uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime); uint32_t komodo_txtime(uint256 hash); uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uint64_t basevolume); @@ -507,11 +507,11 @@ Value paxprices(const Array& params, bool fHelp) uint64_t komodo_accrued_interest(uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue) { - uint64_t value; int32_t txheight; uint32_t locktime,prevblocktime; - if ( (locktime= komodo_interest_args(&txheight,&prevblocktime,&value,hash,n)) != 0 ) + uint64_t value; int32_t txheight; uint32_t locktime,tiptime; + if ( (locktime= komodo_interest_args(&txheight,&tiptime,&value,hash,n)) != 0 ) { if ( (checkvalue == 0 || value == checkvalue) && (checkheight == 0 || txheight == checkheight) ) - return(komodo_interest(txheight,value,locktime,prevblocktime)); + return(komodo_interest(txheight,value,locktime,tiptime)); //fprintf(stderr,"nValue %llu lock.%u:%u nTime.%u -> %llu\n",(long long)coins.vout[n].nValue,coins.nLockTime,timestamp,pindex->nTime,(long long)interest); } else fprintf(stderr,"komodo_accrued_interest value mismatch %llu vs %llu or height mismatch %d vs %d\n",(long long)value,(long long)checkvalue,txheight,checkheight); return(0); @@ -587,6 +587,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))); + uint64_t interest; if ( (interest= komodo_accrued_interest(hash,n,coins.nHeight,coins.vout[n].nValue)) != 0 ) ret.push_back(Pair("interest", ValueFromAmount(interest))); Object o; From f2176cec5335c92690c5b45c6349331d14864561 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 10:51:04 -0300 Subject: [PATCH 08/80] test --- src/rpcrawtransaction.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index 32e9a3341..aff59f850 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -130,9 +130,10 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, Object& entry) out.push_back(Pair("value", ValueFromAmount(txout.nValue))); if ( pindex != 0 && tx.nLockTime != 0 && (tipindex= chainActive.Tip()) != 0 ) { + extern char ASSETCHAINS_SYMBOL[16]; interest = komodo_interest(pindex->nHeight,txout.nValue,tx.nLockTime,tipindex->nTime); if ( strcmp("REVS",ASSETCHAINS_SYMBOL) == 0 ) - fprintf(stderr,"TxtoJSON interest %llu %.8f (%d %llu %u %u)\n",(long long)interest,(double)interest/COIN,(int32_t)pindex->nHeight,(long long)txout.nValue,(uint32_t)tx.nLockTime,(int32_t)pcoinsTip->nTime); + fprintf(stderr,"TxtoJSON interest %llu %.8f (%d %llu %u %u)\n",(long long)interest,(double)interest/COIN,(int32_t)pindex->nHeight,(long long)txout.nValue,(uint32_t)tx.nLockTime,(int32_t)tipindex->nTime); out.push_back(Pair("interest", ValueFromAmount(interest))); } out.push_back(Pair("n", (int64_t)i)); @@ -261,7 +262,7 @@ uint32_t komodo_interest_args(int32_t *txheightp,int32_t *tiptimep,uint64_t *val uint32_t locktime = 0; if ( n < tx.vout.size() ) { - if ( (pindex= map[hashBlock]) != 0 && (tipindex= chainActive.Tip()) != 0 ) + if ( (pindex= mapBlockIndex[hashBlock]) != 0 && (tipindex= chainActive.Tip()) != 0 ) { *valuep = tx.vout[n].nValue; *txheightp = pindex->nHeight; From 7c29073fa4dcca96b1de52343815a98597ec911f Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 10:54:01 -0300 Subject: [PATCH 09/80] test --- src/wallet/wallet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 0ce980304..1a9e477d8 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2393,7 +2393,6 @@ bool CWallet::SelectCoins(const CAmount& nTargetValue, setHasSelected()) { extern char ASSETCHAINS_SYMBOL[16]; - uint64_t interest; BOOST_FOREACH(const COutput& out, vCoins) { if(!out.fSpendable) @@ -2402,8 +2401,9 @@ bool CWallet::SelectCoins(const CAmount& nTargetValue, setnHeight+1 >= 60000 ) { + uint64_t interest; interest = komodo_interest(chainActive.Tip()->nHeight+1,out.tx->vout[out.i].nValue,out.tx->nLockTime,chainActive.Tip()->nTime); - if ( interest != 0 || value >= COIN*100 ) + if ( interest != 0 || out.tx->vout[out.i].nValue >= COIN*100 ) { printf("nValueRet %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)out.tx->vout[out.i].nValue/COIN,(double)interest/COIN,chainActive.Tip()->nHeight+1,out.tx->nLockTime,chainActive.Tip()->nTime); fprintf(stderr,"nValueRet %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)nValueRet/COIN,(double)interest/COIN,chainActive.Tip()->nHeight+1,out.tx->nLockTime,chainActive.Tip()->nTime); From e596e202ca609518a5050e59746a029ed59fe51a Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 10:56:34 -0300 Subject: [PATCH 10/80] test --- src/rpcblockchain.cpp | 21 ++++++++++++++++++++- src/rpcrawtransaction.cpp | 20 +------------------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 7c942d0e9..c0bf6fc5f 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -380,7 +380,6 @@ Value gettxoutsetinfo(const Array& params, bool fHelp) return ret; } -uint32_t komodo_interest_args(int32_t *txheightp,uint32_t *tiptimep,uint64_t *valuep,uint256 hash,int32_t n); uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime); uint32_t komodo_txtime(uint256 hash); uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uint64_t basevolume); @@ -388,6 +387,26 @@ int32_t komodo_paxprices(int32_t *heights,uint64_t *prices,int32_t max,char *bas int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height); char *bitcoin_address(char *coinaddr,uint8_t addrtype,uint8_t *pubkey_or_rmd160,int32_t len); +uint32_t komodo_interest_args(int32_t *txheightp,int32_t *tiptimep,uint64_t *valuep,uint256 hash,int32_t n) +{ + LOCK(cs_main); + CTransaction tx; uint256 hashBlock; CBlockIndex *pindex,*tipindex; + if ( !GetTransaction(hash,tx,hashBlock,true) ) + return(0); + uint32_t locktime = 0; + if ( n < tx.vout.size() ) + { + if ( (pindex= mapBlockIndex[hashBlock]) != 0 && (tipindex= chainActive.Tip()) != 0 ) + { + *valuep = tx.vout[n].nValue; + *txheightp = pindex->nHeight; + *tiptimep = tipindex->nTime; + locktime = tx.nLockTime; + } + } + return(locktime); +} + Value notaries(const Array& params, bool fHelp) { Array a; Object ret; int32_t i,j,n,m; char *hexstr; uint8_t pubkeys[64][33]; char btcaddr[64],kmdaddr[64],*ptr; diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index aff59f850..04a6238c5 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -253,25 +253,7 @@ Value getrawtransaction(const Array& params, bool fHelp) return result; } -uint32_t komodo_interest_args(int32_t *txheightp,int32_t *tiptimep,uint64_t *valuep,uint256 hash,int32_t n) -{ - LOCK(cs_main); - CTransaction tx; uint256 hashBlock; CBlockIndex *pindex,*tipindex; - if ( !GetTransaction(hash,tx,hashBlock,true) ) - return(0); - uint32_t locktime = 0; - if ( n < tx.vout.size() ) - { - if ( (pindex= mapBlockIndex[hashBlock]) != 0 && (tipindex= chainActive.Tip()) != 0 ) - { - *valuep = tx.vout[n].nValue; - *txheightp = pindex->nHeight; - *tiptimep = tipindex->nTime; - locktime = tx.nLockTime; - } - } - return(locktime); -} +uint32_t komodo_interest_args(int32_t *txheightp,int32_t *tiptimep,uint64_t *valuep,uint256 hash,int32_t n); Value gettxoutproof(const Array& params, bool fHelp) { From 919b3cff7589d7cdf341532e871234c85b358faf Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 10:57:44 -0300 Subject: [PATCH 11/80] test --- src/rpcblockchain.cpp | 2 +- src/rpcrawtransaction.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index c0bf6fc5f..44e3f29d1 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -387,7 +387,7 @@ int32_t komodo_paxprices(int32_t *heights,uint64_t *prices,int32_t max,char *bas int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height); char *bitcoin_address(char *coinaddr,uint8_t addrtype,uint8_t *pubkey_or_rmd160,int32_t len); -uint32_t komodo_interest_args(int32_t *txheightp,int32_t *tiptimep,uint64_t *valuep,uint256 hash,int32_t n) +uint32_t komodo_interest_args(int32_t *txheightp,uint32_t *tiptimep,uint64_t *valuep,uint256 hash,int32_t n) { LOCK(cs_main); CTransaction tx; uint256 hashBlock; CBlockIndex *pindex,*tipindex; diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index 04a6238c5..a65f42836 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -253,7 +253,7 @@ Value getrawtransaction(const Array& params, bool fHelp) return result; } -uint32_t komodo_interest_args(int32_t *txheightp,int32_t *tiptimep,uint64_t *valuep,uint256 hash,int32_t n); +uint32_t komodo_interest_args(int32_t *txheightp,uint32_t *tiptimep,uint64_t *valuep,uint256 hash,int32_t n); Value gettxoutproof(const Array& params, bool fHelp) { From ce906ce7572343ab226adaba190f0e4aa2848f5e Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 11:17:55 -0300 Subject: [PATCH 12/80] test --- src/bitcoind.cpp | 3 ++- src/rpcrawtransaction.cpp | 2 -- src/rpcserver.cpp | 5 +++-- src/wallet/wallet.cpp | 10 +++++----- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index 5f47ba352..1f7267701 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -144,7 +144,8 @@ bool AppInit(int argc, char* argv[]) fDaemon = GetBoolArg("-daemon", false); if (fDaemon) { - fprintf(stdout, "Komodo server starting\n"); + extern char ASSETCHAINS_SYMBOL[16]; + fprintf(stdout, "Komodo %s server starting\n",ASSETCHAINS_SYMBOL); // Daemonize pid_t pid = fork(); diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index a65f42836..4b5cdae35 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -253,8 +253,6 @@ Value getrawtransaction(const Array& params, bool fHelp) return result; } -uint32_t komodo_interest_args(int32_t *txheightp,uint32_t *tiptimep,uint64_t *valuep,uint256 hash,int32_t n); - Value gettxoutproof(const Array& params, bool fHelp) { if (fHelp || (params.size() != 1 && params.size() != 2)) diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index f1f64b042..adb6b36bc 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -253,11 +253,12 @@ Value help(const Array& params, bool fHelp) Value stop(const Array& params, bool fHelp) { - // Accept the deprecated and ignored 'detach' boolean argument + extern char ASSETCHAINS_SYMBOL[16]; + // Accept the deprecated and ignored 'detach' boolean argument if (fHelp || params.size() > 1) throw runtime_error( "stop\n" - "\nStop Komodo server."); + "\nStop Komodo %s server.",ASSETCHAINS_SYMBOL); // Shutdown will take long enough that the response should get back StartShutdown(); return "Komodo server stopping"; diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 1a9e477d8..01832e173 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2354,7 +2354,7 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int return true; } -uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime); +uint64_t komodo_accrued_interest(uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue); bool CWallet::SelectCoins(const CAmount& nTargetValue, set >& setCoinsRet, CAmount& nValueRet, bool& fOnlyCoinbaseCoinsRet, bool& fNeedCoinbaseCoinsRet, const CCoinControl* coinControl) const { @@ -2400,13 +2400,13 @@ bool CWallet::SelectCoins(const CAmount& nTargetValue, setvout[out.i].nValue; #ifdef KOMODO_ENABLE_INTEREST if ( strcmp(ASSETCHAINS_SYMBOL,"REVS") == 0 )//&& chainActive.Tip()->nHeight+1 >= 60000 ) - { + {sss uint64_t interest; interest = komodo_interest(chainActive.Tip()->nHeight+1,out.tx->vout[out.i].nValue,out.tx->nLockTime,chainActive.Tip()->nTime); - if ( interest != 0 || out.tx->vout[out.i].nValue >= COIN*100 ) + //if ( interest != 0 || out.tx->vout[out.i].nValue >= COIN*100 ) { - printf("nValueRet %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)out.tx->vout[out.i].nValue/COIN,(double)interest/COIN,chainActive.Tip()->nHeight+1,out.tx->nLockTime,chainActive.Tip()->nTime); - fprintf(stderr,"nValueRet %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)nValueRet/COIN,(double)interest/COIN,chainActive.Tip()->nHeight+1,out.tx->nLockTime,chainActive.Tip()->nTime); + printf("wallet nValueRet %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)out.tx->vout[out.i].nValue/COIN,(double)interest/COIN,chainActive.Tip()->nHeight+1,out.tx->nLockTime,chainActive.Tip()->nTime); + fprintf(stderr,"wallet nValueRet %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)nValueRet/COIN,(double)interest/COIN,chainActive.Tip()->nHeight+1,out.tx->nLockTime,chainActive.Tip()->nTime); } nValueRet += interest; } From e80de3b274882ef797b264f4563c71159573b0e3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 11:20:45 -0300 Subject: [PATCH 13/80] test --- src/rpcserver.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index adb6b36bc..e8a9958ce 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -253,12 +253,11 @@ Value help(const Array& params, bool fHelp) Value stop(const Array& params, bool fHelp) { - extern char ASSETCHAINS_SYMBOL[16]; // Accept the deprecated and ignored 'detach' boolean argument if (fHelp || params.size() > 1) throw runtime_error( "stop\n" - "\nStop Komodo %s server.",ASSETCHAINS_SYMBOL); + "\nStop Komodo server."); // Shutdown will take long enough that the response should get back StartShutdown(); return "Komodo server stopping"; From ff3fb0f16128a115a2691a61dc75d8930a0323b9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 11:23:06 -0300 Subject: [PATCH 14/80] test --- src/wallet/wallet.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 01832e173..112c52aba 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2354,7 +2354,8 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int return true; } -uint64_t komodo_accrued_interest(uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue); +//uint64_t komodo_accrued_interest(uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue); +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 { @@ -2400,7 +2401,7 @@ bool CWallet::SelectCoins(const CAmount& nTargetValue, setvout[out.i].nValue; #ifdef KOMODO_ENABLE_INTEREST if ( strcmp(ASSETCHAINS_SYMBOL,"REVS") == 0 )//&& chainActive.Tip()->nHeight+1 >= 60000 ) - {sss + { uint64_t interest; interest = komodo_interest(chainActive.Tip()->nHeight+1,out.tx->vout[out.i].nValue,out.tx->nLockTime,chainActive.Tip()->nTime); //if ( interest != 0 || out.tx->vout[out.i].nValue >= COIN*100 ) From 98d166cfc9682bd92eb832b120604b1e2863a77b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 11:33:45 -0300 Subject: [PATCH 15/80] test --- src/coins.cpp | 8 +++++--- src/rpcmisc.cpp | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/coins.cpp b/src/coins.cpp index d572990b5..ba9bd51e9 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -383,7 +383,8 @@ const CScript &CCoinsViewCache::GetSpendFor(const CTxIn& input) const return coins->vout[input.prevout.n].scriptPubKey; } -uint64_t komodo_interest(int32_t txheight,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); +uint64_t komodo_accrued_interest(uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue); extern char ASSETCHAINS_SYMBOL[16]; CAmount CCoinsViewCache::GetValueIn(int32_t nHeight,int64_t *interestp,const CTransaction& tx,uint32_t tiptime) const @@ -400,8 +401,9 @@ CAmount CCoinsViewCache::GetValueIn(int32_t nHeight,int64_t *interestp,const CTr if ( strcmp(ASSETCHAINS_SYMBOL,"REVS") == 0 )//&& nHeight >= 60000 ) { int64_t interest; - interest = komodo_interest(nHeight,value,tx.nLockTime,tiptime); - if ( interest != 0 || value >= COIN*100 ) + interest = komodo_accrued_interest(tx.vin[i].hash,tx.vin[i].n,nHeight,value); + //interest = komodo_interest(nHeight,value,tx.nLockTime,tiptime); + //if ( interest != 0 || value >= COIN*100 ) { printf("nResult %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)nResult/COIN,(double)interest/COIN,nHeight,tx.nLockTime,tiptime); fprintf(stderr,"nResult %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)nResult/COIN,(double)interest/COIN,nHeight,tx.nLockTime,tiptime); diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index 4642a52db..66e3c54f7 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -94,6 +94,8 @@ Value getinfo(const Array& params, bool fHelp) #endif obj.push_back(Pair("blocks", (int)chainActive.Height())); obj.push_back(Pair("timeoffset", GetTimeOffset())); + if ( chainActive.Tip() != 0 ) + obj.push_back(Pair("tiptime", chainActive.Tip()->nTime)); obj.push_back(Pair("connections", (int)vNodes.size())); obj.push_back(Pair("proxy", (proxy.IsValid() ? proxy.proxy.ToStringIPPort() : string()))); obj.push_back(Pair("difficulty", (double)GetDifficulty())); From 49c9db6a51189df40a6ff30c110bbbe1a54c28f7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 11:36:29 -0300 Subject: [PATCH 16/80] test --- src/rpcmisc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index 66e3c54f7..122ee0a90 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -95,7 +95,7 @@ Value getinfo(const Array& params, bool fHelp) obj.push_back(Pair("blocks", (int)chainActive.Height())); obj.push_back(Pair("timeoffset", GetTimeOffset())); if ( chainActive.Tip() != 0 ) - obj.push_back(Pair("tiptime", chainActive.Tip()->nTime)); + obj.push_back(Pair("tiptime", (int)chainActive.Tip()->nTime)); obj.push_back(Pair("connections", (int)vNodes.size())); obj.push_back(Pair("proxy", (proxy.IsValid() ? proxy.proxy.ToStringIPPort() : string()))); obj.push_back(Pair("difficulty", (double)GetDifficulty())); From b25d6fd16048c24352cef927ba967eaf8bc059ce Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 11:38:03 -0300 Subject: [PATCH 17/80] test --- src/coins.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coins.cpp b/src/coins.cpp index ba9bd51e9..2b73f3ebf 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -401,7 +401,7 @@ CAmount CCoinsViewCache::GetValueIn(int32_t nHeight,int64_t *interestp,const CTr if ( strcmp(ASSETCHAINS_SYMBOL,"REVS") == 0 )//&& nHeight >= 60000 ) { int64_t interest; - interest = komodo_accrued_interest(tx.vin[i].hash,tx.vin[i].n,nHeight,value); + interest = komodo_accrued_interest(GetOutputFor(tx.vin[i]).hash,GetOutputFor(tx.vin[i]).n,nHeight,value); //interest = komodo_interest(nHeight,value,tx.nLockTime,tiptime); //if ( interest != 0 || value >= COIN*100 ) { From 3b97ccc9a7c4c8f8a0462d11890287bea9456ca1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 11:39:36 -0300 Subject: [PATCH 18/80] test --- src/coins.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/coins.cpp b/src/coins.cpp index 2b73f3ebf..6343e2374 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -400,16 +400,16 @@ CAmount CCoinsViewCache::GetValueIn(int32_t nHeight,int64_t *interestp,const CTr #ifdef KOMODO_ENABLE_INTEREST if ( strcmp(ASSETCHAINS_SYMBOL,"REVS") == 0 )//&& nHeight >= 60000 ) { - int64_t interest; - interest = komodo_accrued_interest(GetOutputFor(tx.vin[i]).hash,GetOutputFor(tx.vin[i]).n,nHeight,value); - //interest = komodo_interest(nHeight,value,tx.nLockTime,tiptime); - //if ( interest != 0 || value >= COIN*100 ) + //if ( value >= COIN*100 ) { + int64_t interest; + interest = komodo_accrued_interest(tx.vin[i].prevout.hash,tx.vin[i].prevout.n,nHeight,value); + //interest = komodo_interest(nHeight,value,tx.nLockTime,tiptime); printf("nResult %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)nResult/COIN,(double)interest/COIN,nHeight,tx.nLockTime,tiptime); fprintf(stderr,"nResult %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)nResult/COIN,(double)interest/COIN,nHeight,tx.nLockTime,tiptime); + nResult += interest; + (*interestp) += interest; } - nResult += interest; - (*interestp) += interest; } #endif } From 485e48cabd2889b391d8fab36efc07248514b46d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 11:42:05 -0300 Subject: [PATCH 19/80] test --- src/komodo_bitcoind.h | 12 ++++++++++++ src/rpcblockchain.cpp | 12 +----------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index af86faa76..1bb2ddf91 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -547,3 +547,15 @@ int32_t komodo_checkpoint(int32_t *notarized_heightp,int32_t nHeight,uint256 has fprintf(stderr,"couldnt find notary_hash %s ht.%d\n",notarized_hash.ToString().c_str(),notarized_height); return(0); } + +uint64_t komodo_accrued_interest(uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue) +{ + uint64_t value; int32_t txheight; uint32_t locktime,tiptime; + if ( (locktime= komodo_interest_args(&txheight,&tiptime,&value,hash,n)) != 0 ) + { + if ( (checkvalue == 0 || value == checkvalue) && (checkheight == 0 || txheight == checkheight) ) + return(komodo_interest(txheight,value,locktime,tiptime)); + //fprintf(stderr,"nValue %llu lock.%u:%u nTime.%u -> %llu\n",(long long)coins.vout[n].nValue,coins.nLockTime,timestamp,pindex->nTime,(long long)interest); + } else fprintf(stderr,"komodo_accrued_interest value mismatch %llu vs %llu or height mismatch %d vs %d\n",(long long)value,(long long)checkvalue,txheight,checkheight); + return(0); +} diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 44e3f29d1..4c1f06dea 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -524,17 +524,7 @@ Value paxprices(const Array& params, bool fHelp) return ret; } -uint64_t komodo_accrued_interest(uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue) -{ - uint64_t value; int32_t txheight; uint32_t locktime,tiptime; - if ( (locktime= komodo_interest_args(&txheight,&tiptime,&value,hash,n)) != 0 ) - { - if ( (checkvalue == 0 || value == checkvalue) && (checkheight == 0 || txheight == checkheight) ) - return(komodo_interest(txheight,value,locktime,tiptime)); - //fprintf(stderr,"nValue %llu lock.%u:%u nTime.%u -> %llu\n",(long long)coins.vout[n].nValue,coins.nLockTime,timestamp,pindex->nTime,(long long)interest); - } else fprintf(stderr,"komodo_accrued_interest value mismatch %llu vs %llu or height mismatch %d vs %d\n",(long long)value,(long long)checkvalue,txheight,checkheight); - return(0); -} +uint64_t komodo_accrued_interest(uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue); Value gettxout(const Array& params, bool fHelp) { From 50760585735d7df3d8bad3d47b641edb1126bb4e Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 11:47:21 -0300 Subject: [PATCH 20/80] test --- src/coins.cpp | 4 ++-- src/komodo_bitcoind.h | 11 ----------- src/komodo_interest.h | 32 ++++++++++++++++++++++++++++++++ src/rpcblockchain.cpp | 21 +-------------------- 4 files changed, 35 insertions(+), 33 deletions(-) diff --git a/src/coins.cpp b/src/coins.cpp index 6343e2374..4b89e8a69 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -405,8 +405,8 @@ CAmount CCoinsViewCache::GetValueIn(int32_t nHeight,int64_t *interestp,const CTr int64_t interest; interest = komodo_accrued_interest(tx.vin[i].prevout.hash,tx.vin[i].prevout.n,nHeight,value); //interest = komodo_interest(nHeight,value,tx.nLockTime,tiptime); - printf("nResult %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)nResult/COIN,(double)interest/COIN,nHeight,tx.nLockTime,tiptime); - fprintf(stderr,"nResult %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)nResult/COIN,(double)interest/COIN,nHeight,tx.nLockTime,tiptime); + printf("nResult %.8f += val %.8f interest %.8f ht.%d lock.%u tip.%u\n",(double)nResult/COIN,(double)value/COIN,(double)interest/COIN,nHeight,tx.nLockTime,tiptime); + fprintf(stderr,"nResult %.8f += val %.8f interest %.8f ht.%d lock.%u tip.%u\n",(double)nResult/COIN,(double)value/COIN,(double)interest/COIN,nHeight,tx.nLockTime,tiptime); nResult += interest; (*interestp) += interest; } diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 1bb2ddf91..602174257 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -548,14 +548,3 @@ int32_t komodo_checkpoint(int32_t *notarized_heightp,int32_t nHeight,uint256 has return(0); } -uint64_t komodo_accrued_interest(uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue) -{ - uint64_t value; int32_t txheight; uint32_t locktime,tiptime; - if ( (locktime= komodo_interest_args(&txheight,&tiptime,&value,hash,n)) != 0 ) - { - if ( (checkvalue == 0 || value == checkvalue) && (checkheight == 0 || txheight == checkheight) ) - return(komodo_interest(txheight,value,locktime,tiptime)); - //fprintf(stderr,"nValue %llu lock.%u:%u nTime.%u -> %llu\n",(long long)coins.vout[n].nValue,coins.nLockTime,timestamp,pindex->nTime,(long long)interest); - } else fprintf(stderr,"komodo_accrued_interest value mismatch %llu vs %llu or height mismatch %d vs %d\n",(long long)value,(long long)checkvalue,txheight,checkheight); - return(0); -} diff --git a/src/komodo_interest.h b/src/komodo_interest.h index 9d66b3344..d0b8f014c 100644 --- a/src/komodo_interest.h +++ b/src/komodo_interest.h @@ -72,3 +72,35 @@ uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uin } return(interest); } + +uint32_t komodo_interest_args(int32_t *txheightp,uint32_t *tiptimep,uint64_t *valuep,uint256 hash,int32_t n) +{ + LOCK(cs_main); + CTransaction tx; uint256 hashBlock; CBlockIndex *pindex,*tipindex; + if ( !GetTransaction(hash,tx,hashBlock,true) ) + return(0); + uint32_t locktime = 0; + if ( n < tx.vout.size() ) + { + if ( (pindex= mapBlockIndex[hashBlock]) != 0 && (tipindex= chainActive.Tip()) != 0 ) + { + *valuep = tx.vout[n].nValue; + *txheightp = pindex->nHeight; + *tiptimep = tipindex->nTime; + locktime = tx.nLockTime; + } + } + return(locktime); +} + +uint64_t komodo_accrued_interest(uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue) +{ + uint64_t value; int32_t txheight; uint32_t locktime,tiptime; + if ( (locktime= komodo_interest_args(&txheight,&tiptime,&value,hash,n)) != 0 ) + { + if ( (checkvalue == 0 || value == checkvalue) && (checkheight == 0 || txheight == checkheight) ) + return(komodo_interest(txheight,value,locktime,tiptime)); + //fprintf(stderr,"nValue %llu lock.%u:%u nTime.%u -> %llu\n",(long long)coins.vout[n].nValue,coins.nLockTime,timestamp,pindex->nTime,(long long)interest); + } else fprintf(stderr,"komodo_accrued_interest value mismatch %llu vs %llu or height mismatch %d vs %d\n",(long long)value,(long long)checkvalue,txheight,checkheight); + return(0); +} diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 4c1f06dea..37079088a 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -386,26 +386,7 @@ uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uin int32_t komodo_paxprices(int32_t *heights,uint64_t *prices,int32_t max,char *base,char *rel); int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height); char *bitcoin_address(char *coinaddr,uint8_t addrtype,uint8_t *pubkey_or_rmd160,int32_t len); - -uint32_t komodo_interest_args(int32_t *txheightp,uint32_t *tiptimep,uint64_t *valuep,uint256 hash,int32_t n) -{ - LOCK(cs_main); - CTransaction tx; uint256 hashBlock; CBlockIndex *pindex,*tipindex; - if ( !GetTransaction(hash,tx,hashBlock,true) ) - return(0); - uint32_t locktime = 0; - if ( n < tx.vout.size() ) - { - if ( (pindex= mapBlockIndex[hashBlock]) != 0 && (tipindex= chainActive.Tip()) != 0 ) - { - *valuep = tx.vout[n].nValue; - *txheightp = pindex->nHeight; - *tiptimep = tipindex->nTime; - locktime = tx.nLockTime; - } - } - return(locktime); -} +uint32_t komodo_interest_args(int32_t *txheightp,uint32_t *tiptimep,uint64_t *valuep,uint256 hash,int32_t n); Value notaries(const Array& params, bool fHelp) { From b33ca600cc1a7e2179aeb9c837c7f69a6f0cdcf0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 11:51:35 -0300 Subject: [PATCH 21/80] test --- src/komodo_bitcoind.h | 32 ++++++++++++++++++++++++++++++++ src/komodo_interest.h | 31 ------------------------------- 2 files changed, 32 insertions(+), 31 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 602174257..2701749a1 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -548,3 +548,35 @@ int32_t komodo_checkpoint(int32_t *notarized_heightp,int32_t nHeight,uint256 has return(0); } +uint32_t komodo_interest_args(int32_t *txheightp,uint32_t *tiptimep,uint64_t *valuep,uint256 hash,int32_t n) +{ + LOCK(cs_main); + CTransaction tx; uint256 hashBlock; CBlockIndex *pindex,*tipindex; + if ( !GetTransaction(hash,tx,hashBlock,true) ) + return(0); + uint32_t locktime = 0; + if ( n < tx.vout.size() ) + { + if ( (pindex= mapBlockIndex[hashBlock]) != 0 && (tipindex= chainActive.Tip()) != 0 ) + { + *valuep = tx.vout[n].nValue; + *txheightp = pindex->nHeight; + *tiptimep = tipindex->nTime; + locktime = tx.nLockTime; + } + } + return(locktime); +} + +uint64_t komodo_accrued_interest(uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue) +{ + uint64_t value; int32_t txheight; uint32_t locktime,tiptime; + if ( (locktime= komodo_interest_args(&txheight,&tiptime,&value,hash,n)) != 0 ) + { + if ( (checkvalue == 0 || value == checkvalue) && (checkheight == 0 || txheight == checkheight) ) + return(komodo_interest(txheight,value,locktime,tiptime)); + //fprintf(stderr,"nValue %llu lock.%u:%u nTime.%u -> %llu\n",(long long)coins.vout[n].nValue,coins.nLockTime,timestamp,pindex->nTime,(long long)interest); + } else fprintf(stderr,"komodo_accrued_interest value mismatch %llu vs %llu or height mismatch %d vs %d\n",(long long)value,(long long)checkvalue,txheight,checkheight); + return(0); +} + diff --git a/src/komodo_interest.h b/src/komodo_interest.h index d0b8f014c..5933c406f 100644 --- a/src/komodo_interest.h +++ b/src/komodo_interest.h @@ -73,34 +73,3 @@ uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uin return(interest); } -uint32_t komodo_interest_args(int32_t *txheightp,uint32_t *tiptimep,uint64_t *valuep,uint256 hash,int32_t n) -{ - LOCK(cs_main); - CTransaction tx; uint256 hashBlock; CBlockIndex *pindex,*tipindex; - if ( !GetTransaction(hash,tx,hashBlock,true) ) - return(0); - uint32_t locktime = 0; - if ( n < tx.vout.size() ) - { - if ( (pindex= mapBlockIndex[hashBlock]) != 0 && (tipindex= chainActive.Tip()) != 0 ) - { - *valuep = tx.vout[n].nValue; - *txheightp = pindex->nHeight; - *tiptimep = tipindex->nTime; - locktime = tx.nLockTime; - } - } - return(locktime); -} - -uint64_t komodo_accrued_interest(uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue) -{ - uint64_t value; int32_t txheight; uint32_t locktime,tiptime; - if ( (locktime= komodo_interest_args(&txheight,&tiptime,&value,hash,n)) != 0 ) - { - if ( (checkvalue == 0 || value == checkvalue) && (checkheight == 0 || txheight == checkheight) ) - return(komodo_interest(txheight,value,locktime,tiptime)); - //fprintf(stderr,"nValue %llu lock.%u:%u nTime.%u -> %llu\n",(long long)coins.vout[n].nValue,coins.nLockTime,timestamp,pindex->nTime,(long long)interest); - } else fprintf(stderr,"komodo_accrued_interest value mismatch %llu vs %llu or height mismatch %d vs %d\n",(long long)value,(long long)checkvalue,txheight,checkheight); - return(0); -} From 30f036eeccd3b49ea5248667c8d17ac5b609274e Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 11:52:59 -0300 Subject: [PATCH 22/80] test --- src/komodo_bitcoind.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 2701749a1..764631284 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -568,6 +568,7 @@ uint32_t komodo_interest_args(int32_t *txheightp,uint32_t *tiptimep,uint64_t *va return(locktime); } +uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime); uint64_t komodo_accrued_interest(uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue) { uint64_t value; int32_t txheight; uint32_t locktime,tiptime; From d0e75beb8503b9d0d918394ec99d3be9997cb2e7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 11:56:43 -0300 Subject: [PATCH 23/80] test --- src/coins.cpp | 35 +++++++++++++++++++++++++++++++++-- src/komodo_bitcoind.h | 33 --------------------------------- 2 files changed, 33 insertions(+), 35 deletions(-) diff --git a/src/coins.cpp b/src/coins.cpp index 4b89e8a69..07de3901f 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -383,10 +383,41 @@ const CScript &CCoinsViewCache::GetSpendFor(const CTxIn& input) const return coins->vout[input.prevout.n].scriptPubKey; } -//uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime); -uint64_t komodo_accrued_interest(uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue); +uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime); extern char ASSETCHAINS_SYMBOL[16]; +uint32_t komodo_interest_args(int32_t *txheightp,uint32_t *tiptimep,uint64_t *valuep,uint256 hash,int32_t n) +{ + LOCK(cs_main); + CTransaction tx; uint256 hashBlock; CBlockIndex *pindex,*tipindex; + if ( !GetTransaction(hash,tx,hashBlock,true) ) + return(0); + uint32_t locktime = 0; + if ( n < tx.vout.size() ) + { + if ( (pindex= mapBlockIndex[hashBlock]) != 0 && (tipindex= chainActive.Tip()) != 0 ) + { + *valuep = tx.vout[n].nValue; + *txheightp = pindex->nHeight; + *tiptimep = tipindex->nTime; + locktime = tx.nLockTime; + } + } + return(locktime); +} + +uint64_t komodo_accrued_interest(uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue) +{ + uint64_t value; int32_t txheight; uint32_t locktime,tiptime; + if ( (locktime= komodo_interest_args(&txheight,&tiptime,&value,hash,n)) != 0 ) + { + if ( (checkvalue == 0 || value == checkvalue) && (checkheight == 0 || txheight == checkheight) ) + return(komodo_interest(txheight,value,locktime,tiptime)); + //fprintf(stderr,"nValue %llu lock.%u:%u nTime.%u -> %llu\n",(long long)coins.vout[n].nValue,coins.nLockTime,timestamp,pindex->nTime,(long long)interest); + } else fprintf(stderr,"komodo_accrued_interest value mismatch %llu vs %llu or height mismatch %d vs %d\n",(long long)value,(long long)checkvalue,txheight,checkheight); + return(0); +} + CAmount CCoinsViewCache::GetValueIn(int32_t nHeight,int64_t *interestp,const CTransaction& tx,uint32_t tiptime) const { *interestp = 0; diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 764631284..602174257 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -548,36 +548,3 @@ int32_t komodo_checkpoint(int32_t *notarized_heightp,int32_t nHeight,uint256 has return(0); } -uint32_t komodo_interest_args(int32_t *txheightp,uint32_t *tiptimep,uint64_t *valuep,uint256 hash,int32_t n) -{ - LOCK(cs_main); - CTransaction tx; uint256 hashBlock; CBlockIndex *pindex,*tipindex; - if ( !GetTransaction(hash,tx,hashBlock,true) ) - return(0); - uint32_t locktime = 0; - if ( n < tx.vout.size() ) - { - if ( (pindex= mapBlockIndex[hashBlock]) != 0 && (tipindex= chainActive.Tip()) != 0 ) - { - *valuep = tx.vout[n].nValue; - *txheightp = pindex->nHeight; - *tiptimep = tipindex->nTime; - locktime = tx.nLockTime; - } - } - return(locktime); -} - -uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime); -uint64_t komodo_accrued_interest(uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue) -{ - uint64_t value; int32_t txheight; uint32_t locktime,tiptime; - if ( (locktime= komodo_interest_args(&txheight,&tiptime,&value,hash,n)) != 0 ) - { - if ( (checkvalue == 0 || value == checkvalue) && (checkheight == 0 || txheight == checkheight) ) - return(komodo_interest(txheight,value,locktime,tiptime)); - //fprintf(stderr,"nValue %llu lock.%u:%u nTime.%u -> %llu\n",(long long)coins.vout[n].nValue,coins.nLockTime,timestamp,pindex->nTime,(long long)interest); - } else fprintf(stderr,"komodo_accrued_interest value mismatch %llu vs %llu or height mismatch %d vs %d\n",(long long)value,(long long)checkvalue,txheight,checkheight); - return(0); -} - From c1c95e3627a83116a63c8eff64402ec575b927a7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 11:57:56 -0300 Subject: [PATCH 24/80] test --- src/coins.cpp | 35 ++--------------------------------- src/komodo_bitcoind.h | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 33 deletions(-) diff --git a/src/coins.cpp b/src/coins.cpp index 07de3901f..4b89e8a69 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -383,41 +383,10 @@ const CScript &CCoinsViewCache::GetSpendFor(const CTxIn& input) const return coins->vout[input.prevout.n].scriptPubKey; } -uint64_t komodo_interest(int32_t txheight,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); +uint64_t komodo_accrued_interest(uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue); extern char ASSETCHAINS_SYMBOL[16]; -uint32_t komodo_interest_args(int32_t *txheightp,uint32_t *tiptimep,uint64_t *valuep,uint256 hash,int32_t n) -{ - LOCK(cs_main); - CTransaction tx; uint256 hashBlock; CBlockIndex *pindex,*tipindex; - if ( !GetTransaction(hash,tx,hashBlock,true) ) - return(0); - uint32_t locktime = 0; - if ( n < tx.vout.size() ) - { - if ( (pindex= mapBlockIndex[hashBlock]) != 0 && (tipindex= chainActive.Tip()) != 0 ) - { - *valuep = tx.vout[n].nValue; - *txheightp = pindex->nHeight; - *tiptimep = tipindex->nTime; - locktime = tx.nLockTime; - } - } - return(locktime); -} - -uint64_t komodo_accrued_interest(uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue) -{ - uint64_t value; int32_t txheight; uint32_t locktime,tiptime; - if ( (locktime= komodo_interest_args(&txheight,&tiptime,&value,hash,n)) != 0 ) - { - if ( (checkvalue == 0 || value == checkvalue) && (checkheight == 0 || txheight == checkheight) ) - return(komodo_interest(txheight,value,locktime,tiptime)); - //fprintf(stderr,"nValue %llu lock.%u:%u nTime.%u -> %llu\n",(long long)coins.vout[n].nValue,coins.nLockTime,timestamp,pindex->nTime,(long long)interest); - } else fprintf(stderr,"komodo_accrued_interest value mismatch %llu vs %llu or height mismatch %d vs %d\n",(long long)value,(long long)checkvalue,txheight,checkheight); - return(0); -} - CAmount CCoinsViewCache::GetValueIn(int32_t nHeight,int64_t *interestp,const CTransaction& tx,uint32_t tiptime) const { *interestp = 0; diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 602174257..764631284 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -548,3 +548,36 @@ int32_t komodo_checkpoint(int32_t *notarized_heightp,int32_t nHeight,uint256 has return(0); } +uint32_t komodo_interest_args(int32_t *txheightp,uint32_t *tiptimep,uint64_t *valuep,uint256 hash,int32_t n) +{ + LOCK(cs_main); + CTransaction tx; uint256 hashBlock; CBlockIndex *pindex,*tipindex; + if ( !GetTransaction(hash,tx,hashBlock,true) ) + return(0); + uint32_t locktime = 0; + if ( n < tx.vout.size() ) + { + if ( (pindex= mapBlockIndex[hashBlock]) != 0 && (tipindex= chainActive.Tip()) != 0 ) + { + *valuep = tx.vout[n].nValue; + *txheightp = pindex->nHeight; + *tiptimep = tipindex->nTime; + locktime = tx.nLockTime; + } + } + return(locktime); +} + +uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime); +uint64_t komodo_accrued_interest(uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue) +{ + uint64_t value; int32_t txheight; uint32_t locktime,tiptime; + if ( (locktime= komodo_interest_args(&txheight,&tiptime,&value,hash,n)) != 0 ) + { + if ( (checkvalue == 0 || value == checkvalue) && (checkheight == 0 || txheight == checkheight) ) + return(komodo_interest(txheight,value,locktime,tiptime)); + //fprintf(stderr,"nValue %llu lock.%u:%u nTime.%u -> %llu\n",(long long)coins.vout[n].nValue,coins.nLockTime,timestamp,pindex->nTime,(long long)interest); + } else fprintf(stderr,"komodo_accrued_interest value mismatch %llu vs %llu or height mismatch %d vs %d\n",(long long)value,(long long)checkvalue,txheight,checkheight); + return(0); +} + From a933451cc149e658ec4bcb1bd13c1f7ed610803d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 11:58:58 -0300 Subject: [PATCH 25/80] test --- src/komodo-tx.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/komodo-tx.cpp b/src/komodo-tx.cpp index 32d504b18..2fecea09a 100644 --- a/src/komodo-tx.cpp +++ b/src/komodo-tx.cpp @@ -29,6 +29,11 @@ using namespace std; #include "komodo_interest.h" +uint64_t komodo_accrued_interest(uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue) +{ + return(0); +} + static bool fCreateBlank; static map registers; From 72712d696f9a4cb59c84ee8f00a3497fd70d288a Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 12:07:27 -0300 Subject: [PATCH 26/80] test --- src/komodo_bitcoind.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 764631284..f1a0ec684 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -563,6 +563,7 @@ uint32_t komodo_interest_args(int32_t *txheightp,uint32_t *tiptimep,uint64_t *va *txheightp = pindex->nHeight; *tiptimep = tipindex->nTime; locktime = tx.nLockTime; + fprintf(stderr,"tx locktime.%u %.8f height.%d | tiptime.%u\n",locktime,(double)*valuep/COIN,*txheightp,*timetimep); } } return(locktime); From 03ad49c4d33d947a0ee31aa18decc13a127fee54 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 12:09:11 -0300 Subject: [PATCH 27/80] test --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index f1a0ec684..22c924166 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -563,7 +563,7 @@ uint32_t komodo_interest_args(int32_t *txheightp,uint32_t *tiptimep,uint64_t *va *txheightp = pindex->nHeight; *tiptimep = tipindex->nTime; locktime = tx.nLockTime; - fprintf(stderr,"tx locktime.%u %.8f height.%d | tiptime.%u\n",locktime,(double)*valuep/COIN,*txheightp,*timetimep); + fprintf(stderr,"tx locktime.%u %.8f height.%d | tiptime.%u\n",locktime,(double)*valuep/COIN,*txheightp,*tiptimep); } } return(locktime); From 798f28c7d3c4f00681ac93bf7d1037378d2a2ab3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 12:27:14 -0300 Subject: [PATCH 28/80] test --- src/coins.cpp | 10 +++++----- src/komodo-tx.cpp | 2 +- src/komodo_bitcoind.h | 12 ++++++------ src/rpcblockchain.cpp | 6 +++--- src/wallet/wallet.cpp | 1 - 5 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/coins.cpp b/src/coins.cpp index 4b89e8a69..70eccebbb 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -384,7 +384,7 @@ const CScript &CCoinsViewCache::GetSpendFor(const CTxIn& input) const } //uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime); -uint64_t komodo_accrued_interest(uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue); +uint64_t komodo_accrued_interest(int32_t *txheightp,uint32_t *locktimep,uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue); extern char ASSETCHAINS_SYMBOL[16]; CAmount CCoinsViewCache::GetValueIn(int32_t nHeight,int64_t *interestp,const CTransaction& tx,uint32_t tiptime) const @@ -402,11 +402,11 @@ CAmount CCoinsViewCache::GetValueIn(int32_t nHeight,int64_t *interestp,const CTr { //if ( value >= COIN*100 ) { - int64_t interest; - interest = komodo_accrued_interest(tx.vin[i].prevout.hash,tx.vin[i].prevout.n,nHeight,value); + int64_t interest; int32_t txheight; uint32_t locktime; + interest = komodo_accrued_interest(&txheight,&locktime,tx.vin[i].prevout.hash,tx.vin[i].prevout.n,0,value); //interest = komodo_interest(nHeight,value,tx.nLockTime,tiptime); - printf("nResult %.8f += val %.8f interest %.8f ht.%d lock.%u tip.%u\n",(double)nResult/COIN,(double)value/COIN,(double)interest/COIN,nHeight,tx.nLockTime,tiptime); - fprintf(stderr,"nResult %.8f += val %.8f interest %.8f ht.%d lock.%u tip.%u\n",(double)nResult/COIN,(double)value/COIN,(double)interest/COIN,nHeight,tx.nLockTime,tiptime); + printf("nResult %.8f += val %.8f interest %.8f ht.%d lock.%u tip.%u\n",(double)nResult/COIN,(double)value/COIN,(double)interest/COIN,txheight,locktime,tiptime); + fprintf(stderr,"nResult %.8f += val %.8f interest %.8f ht.%d lock.%u tip.%u\n",(double)nResult/COIN,(double)value/COIN,(double)interest/COIN,txheight,locktime,tiptime); nResult += interest; (*interestp) += interest; } diff --git a/src/komodo-tx.cpp b/src/komodo-tx.cpp index 2fecea09a..d5e333093 100644 --- a/src/komodo-tx.cpp +++ b/src/komodo-tx.cpp @@ -29,7 +29,7 @@ using namespace std; #include "komodo_interest.h" -uint64_t komodo_accrued_interest(uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue) +uint64_t komodo_accrued_interest(int32_t *txheightp,uint32_t *locktimep,uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue) { return(0); } diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 22c924166..ae0b3a3f1 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -570,15 +570,15 @@ uint32_t komodo_interest_args(int32_t *txheightp,uint32_t *tiptimep,uint64_t *va } uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime); -uint64_t komodo_accrued_interest(uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue) +uint64_t komodo_accrued_interest(int32_t *txheightp,uint32_t *locktimep,uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue) { - uint64_t value; int32_t txheight; uint32_t locktime,tiptime; - if ( (locktime= komodo_interest_args(&txheight,&tiptime,&value,hash,n)) != 0 ) + uint64_t value; uint32_t tiptime; + if ( (*locktimep= komodo_interest_args(txheightp,&tiptime,&value,hash,n)) != 0 ) { - if ( (checkvalue == 0 || value == checkvalue) && (checkheight == 0 || txheight == checkheight) ) - return(komodo_interest(txheight,value,locktime,tiptime)); + if ( (checkvalue == 0 || value == checkvalue) && (checkheight == 0 || *txheightp == checkheight) ) + return(komodo_interest(*txheightp,value,*locktimep,tiptime)); //fprintf(stderr,"nValue %llu lock.%u:%u nTime.%u -> %llu\n",(long long)coins.vout[n].nValue,coins.nLockTime,timestamp,pindex->nTime,(long long)interest); - } else fprintf(stderr,"komodo_accrued_interest value mismatch %llu vs %llu or height mismatch %d vs %d\n",(long long)value,(long long)checkvalue,txheight,checkheight); + } else fprintf(stderr,"komodo_accrued_interest value mismatch %llu vs %llu or height mismatch %d vs %d\n",(long long)value,(long long)checkvalue,*txheightp,checkheight); return(0); } diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 37079088a..ae9f41540 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -505,7 +505,7 @@ Value paxprices(const Array& params, bool fHelp) return ret; } -uint64_t komodo_accrued_interest(uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue); +uint64_t komodo_accrued_interest(int32_t *txheightp,uint32_t *locktimep,uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue); Value gettxout(const Array& params, bool fHelp) { @@ -577,8 +577,8 @@ Value gettxout(const Array& params, bool fHelp) ret.push_back(Pair("confirmations", 0)); else ret.push_back(Pair("confirmations", pindex->nHeight - coins.nHeight + 1)); ret.push_back(Pair("value", ValueFromAmount(coins.vout[n].nValue))); - uint64_t interest; - if ( (interest= komodo_accrued_interest(hash,n,coins.nHeight,coins.vout[n].nValue)) != 0 ) + uint64_t interest; int32_t txheight; uint32_t locktime; + if ( (interest= komodo_accrued_interest(&txheight,&locktime,hash,n,coins.nHeight,coins.vout[n].nValue)) != 0 ) ret.push_back(Pair("interest", ValueFromAmount(interest))); Object o; ScriptPubKeyToJSON(coins.vout[n].scriptPubKey, o, true); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 112c52aba..08fd483ad 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2354,7 +2354,6 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int return true; } -//uint64_t komodo_accrued_interest(uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue); 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 From 1c2f0c49cf25fc5f9bdc4359ae992f69422265df Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 12:32:01 -0300 Subject: [PATCH 29/80] test --- src/komodo_bitcoind.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index ae0b3a3f1..0c4748275 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -578,7 +578,8 @@ uint64_t komodo_accrued_interest(int32_t *txheightp,uint32_t *locktimep,uint256 if ( (checkvalue == 0 || value == checkvalue) && (checkheight == 0 || *txheightp == checkheight) ) return(komodo_interest(*txheightp,value,*locktimep,tiptime)); //fprintf(stderr,"nValue %llu lock.%u:%u nTime.%u -> %llu\n",(long long)coins.vout[n].nValue,coins.nLockTime,timestamp,pindex->nTime,(long long)interest); - } else fprintf(stderr,"komodo_accrued_interest value mismatch %llu vs %llu or height mismatch %d vs %d\n",(long long)value,(long long)checkvalue,*txheightp,checkheight); + else fprintf(stderr,"komodo_accrued_interest value mismatch %llu vs %llu or height mismatch %d vs %d\n",(long long)value,(long long)checkvalue,*txheightp,checkheight); + } return(0); } From 687aa6ce8c5b30aab0078e4e3fb0a351be452129 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 12:35:35 -0300 Subject: [PATCH 30/80] test --- src/komodo_interest.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_interest.h b/src/komodo_interest.h index 5933c406f..68b03ed65 100644 --- a/src/komodo_interest.h +++ b/src/komodo_interest.h @@ -58,9 +58,9 @@ uint64_t komodo_moneysupply(int32_t height) uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime) { int32_t minutes; uint64_t numerator,denominator,interest = 0; - if ( komodo_moneysupply(txheight) < MAX_MONEY && nLockTime >= LOCKTIME_THRESHOLD && tiptime != 0 && nLockTime < tiptime && nValue >= 100*COIN ) + if ( komodo_moneysupply(txheight) < MAX_MONEY && nLockTime >= LOCKTIME_THRESHOLD && tiptime != 0 && nLockTime < tiptime && nValue >= COIN ) { - if ( (minutes= (tiptime - nLockTime) / 60) > 60 ) + if ( (minutes= (tiptime - nLockTime) / 60) > 1 ) { numerator = (nValue * KOMODO_INTEREST); denominator = (((uint64_t)365 * 24 * 60) / minutes); From 0ad6a463688c1703bf9828af1d2673a9dc567f0a Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 13:18:43 -0300 Subject: [PATCH 31/80] test --- src/wallet/wallet.cpp | 42 ++++++++++++++++++++++-------------------- src/wallet/wallet.h | 2 +- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 08fd483ad..32f8d25a5 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2169,6 +2169,8 @@ CAmount CWallet::GetImmatureWatchOnlyBalance() const /** * populate vCoins with vector of available COutputs. */ +uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime); + void CWallet::AvailableCoins(vector& vCoins, bool fOnlyConfirmed, const CCoinControl *coinControl, bool fIncludeZeroValue, bool fIncludeCoinBase) const { vCoins.clear(); @@ -2196,19 +2198,35 @@ void CWallet::AvailableCoins(vector& vCoins, bool fOnlyConfirmed, const if (nDepth < 0) continue; - for (unsigned int i = 0; i < pcoin->vout.size(); i++) { + for (unsigned int i = 0; i < pcoin->vout.size(); i++) + { isminetype mine = IsMine(pcoin->vout[i]); if (!(IsSpent(wtxid, i)) && mine != ISMINE_NO && !IsLockedCoin((*it).first, i) && (pcoin->vout[i].nValue > 0 || fIncludeZeroValue) && (!coinControl || !coinControl->HasSelected() || coinControl->IsSelected((*it).first, i))) - vCoins.push_back(COutput(pcoin, i, nDepth, (mine & ISMINE_SPENDABLE) != ISMINE_NO)); + { +#ifdef KOMODO_ENABLE_INTEREST + extern char ASSETCHAINS_SYMBOL[16]; + if ( strcmp(ASSETCHAINS_SYMBOL,"REVS") == 0 && chainActive.Tip() != 0 ) + { + uint64_t interest; + interest = komodo_interest(chainActive.Tip()->nHeight+1,pcoin->vout[i].nValue,pcoin->nLockTime,chainActive.Tip()->nTime); + if ( pcoin->vout[i].nValue >= COIN ) + { + printf("wallet nValueRet %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)pcoin->vout[i].nValue/COIN,(double)interest/COIN,chainActive.Tip()->nHeight+1,pcoin->nLockTime,chainActive.Tip()->nTime); + fprintf(stderr,"wallet nValueRet %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)pcoin->vout[i].nValue/COIN,(double)interest/COIN,chainActive.Tip()->nHeight+1,pcoin->nLockTime,chainActive.Tip()->nTime); + pcoin->vout[i].nValue += interest; + } + } +#endif + vCoins.push_back(COutput(pcoin, i, nDepth, (mine & ISMINE_SPENDABLE) != ISMINE_NO)); + } } } } } -static void ApproximateBestSubset(vector > >vValue, const CAmount& nTotalLower, const CAmount& nTargetValue, - vector& vfBest, CAmount& nBest, int iterations = 1000) +static void ApproximateBestSubset(vector > >vValue, const CAmount& nTotalLower, const CAmount& nTargetValue,vector& vfBest, CAmount& nBest, int iterations = 1000) { vector vfIncluded; @@ -2354,8 +2372,6 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int return true; } -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 { // Output parameter fOnlyCoinbaseCoinsRet is set to true when the only available coins are coinbase utxos. @@ -2392,25 +2408,11 @@ 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()) { - extern char ASSETCHAINS_SYMBOL[16]; BOOST_FOREACH(const COutput& out, vCoins) { if(!out.fSpendable) continue; nValueRet += out.tx->vout[out.i].nValue; -#ifdef KOMODO_ENABLE_INTEREST - if ( strcmp(ASSETCHAINS_SYMBOL,"REVS") == 0 )//&& chainActive.Tip()->nHeight+1 >= 60000 ) - { - uint64_t interest; - interest = komodo_interest(chainActive.Tip()->nHeight+1,out.tx->vout[out.i].nValue,out.tx->nLockTime,chainActive.Tip()->nTime); - //if ( interest != 0 || out.tx->vout[out.i].nValue >= COIN*100 ) - { - printf("wallet nValueRet %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)out.tx->vout[out.i].nValue/COIN,(double)interest/COIN,chainActive.Tip()->nHeight+1,out.tx->nLockTime,chainActive.Tip()->nTime); - fprintf(stderr,"wallet nValueRet %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)nValueRet/COIN,(double)interest/COIN,chainActive.Tip()->nHeight+1,out.tx->nLockTime,chainActive.Tip()->nTime); - } - nValueRet += interest; - } -#endif setCoinsRet.insert(make_pair(out.tx, out.i)); } return (nValueRet >= nTargetValue); diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 404edf4b7..960992f16 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -279,7 +279,7 @@ public: uint256 hashBlock; std::vector vMerkleBranch; int nIndex; - + // memory only mutable bool fMerkleVerified; From 0a72b10ad512817374554b96411e158eb1ab8f2b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 13:28:43 -0300 Subject: [PATCH 32/80] test --- src/wallet/wallet.cpp | 2 +- src/wallet/wallet.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 32f8d25a5..7b7bf1cc4 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2171,7 +2171,7 @@ CAmount CWallet::GetImmatureWatchOnlyBalance() const */ uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime); -void CWallet::AvailableCoins(vector& vCoins, bool fOnlyConfirmed, const CCoinControl *coinControl, bool fIncludeZeroValue, bool fIncludeCoinBase) const +void CWallet::AvailableCoins(vector& vCoins, bool fOnlyConfirmed, const CCoinControl *coinControl, bool fIncludeZeroValue, bool fIncludeCoinBase) { vCoins.clear(); diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 960992f16..7d5e19250 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -790,7 +790,7 @@ public: //! check whether we are allowed to upgrade (or already support) to the named feature bool CanSupportFeature(enum WalletFeature wf) { AssertLockHeld(cs_wallet); return nWalletMaxVersion >= wf; } - void AvailableCoins(std::vector& vCoins, bool fOnlyConfirmed=true, const CCoinControl *coinControl = NULL, bool fIncludeZeroValue=false, bool fIncludeCoinBase=true) const; + void AvailableCoins(std::vector& vCoins, bool fOnlyConfirmed=true, const CCoinControl *coinControl = NULL, bool fIncludeZeroValue=false, bool fIncludeCoinBase=true); bool SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int nConfTheirs, std::vector vCoins, std::set >& setCoinsRet, CAmount& nValueRet) const; bool IsSpent(const uint256& hash, unsigned int n) const; From 779d962f3302211fa6ece2fce51263eeb86637e3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 13:37:51 -0300 Subject: [PATCH 33/80] test --- src/wallet/wallet.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 7b7bf1cc4..4ac98bf1b 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2209,13 +2209,15 @@ void CWallet::AvailableCoins(vector& vCoins, bool fOnlyConfirmed, const extern char ASSETCHAINS_SYMBOL[16]; if ( strcmp(ASSETCHAINS_SYMBOL,"REVS") == 0 && chainActive.Tip() != 0 ) { - uint64_t interest; + uint64_t interest,*ptr; interest = komodo_interest(chainActive.Tip()->nHeight+1,pcoin->vout[i].nValue,pcoin->nLockTime,chainActive.Tip()->nTime); if ( pcoin->vout[i].nValue >= COIN ) { printf("wallet nValueRet %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)pcoin->vout[i].nValue/COIN,(double)interest/COIN,chainActive.Tip()->nHeight+1,pcoin->nLockTime,chainActive.Tip()->nTime); fprintf(stderr,"wallet nValueRet %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)pcoin->vout[i].nValue/COIN,(double)interest/COIN,chainActive.Tip()->nHeight+1,pcoin->nLockTime,chainActive.Tip()->nTime); - pcoin->vout[i].nValue += interest; + ptr = (uint64_t *)&pcoin->vout[i].nValue; + (*ptr) += interest; + //pcoin->vout[i].nValue += interest; } } #endif From be4f847b2e6b07f5c05c82f1e4e5d7ef0c050ded Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 13:38:56 -0300 Subject: [PATCH 34/80] test --- src/wallet/wallet.cpp | 2 +- src/wallet/wallet.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 4ac98bf1b..45d152f8b 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2171,7 +2171,7 @@ CAmount CWallet::GetImmatureWatchOnlyBalance() const */ uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime); -void CWallet::AvailableCoins(vector& vCoins, bool fOnlyConfirmed, const CCoinControl *coinControl, bool fIncludeZeroValue, bool fIncludeCoinBase) +void CWallet::AvailableCoins(vector& vCoins, bool fOnlyConfirmed, const CCoinControl *coinControl, bool fIncludeZeroValue, bool fIncludeCoinBase) const { vCoins.clear(); diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 7d5e19250..960992f16 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -790,7 +790,7 @@ public: //! check whether we are allowed to upgrade (or already support) to the named feature bool CanSupportFeature(enum WalletFeature wf) { AssertLockHeld(cs_wallet); return nWalletMaxVersion >= wf; } - void AvailableCoins(std::vector& vCoins, bool fOnlyConfirmed=true, const CCoinControl *coinControl = NULL, bool fIncludeZeroValue=false, bool fIncludeCoinBase=true); + void AvailableCoins(std::vector& vCoins, bool fOnlyConfirmed=true, const CCoinControl *coinControl = NULL, bool fIncludeZeroValue=false, bool fIncludeCoinBase=true) const; bool SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int nConfTheirs, std::vector vCoins, std::set >& setCoinsRet, CAmount& nValueRet) const; bool IsSpent(const uint256& hash, unsigned int n) const; From 782120ca469202c8f67c86d9cccdcffed8793c95 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 13:57:07 -0300 Subject: [PATCH 35/80] test --- src/main.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 11c1ad0b5..583f4ad1a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1718,6 +1718,19 @@ bool NonContextualCheckInputs(const CTransaction& tx, CValidationState &state, c // Check for negative or overflow input values nValueIn += coins->vout[prevout.n].nValue; +#ifdef KOMODO_ENABLE_INTEREST + if ( strcmp(ASSETCHAINS_SYMBOL,"REVS") == 0 )//&& nHeight >= 60000 ) + { + //if ( value >= COIN*100 ) + { + int64_t interest; int32_t txheight; uint32_t locktime; + interest = komodo_accrued_interest(&txheight,&locktime,prevout.hash,prevout.n,0,coins->vout[prevout.n].nValue); + printf("checkResult %.8f += val %.8f interest %.8f ht.%d lock.%u tip.%u\n",(double)nResult/COIN,(double)coins->vout[prevout.n].nValue/COIN,(double)interest/COIN,txheight,locktime,tiptime); + fprintf(stderr,"checkResult %.8f += val %.8f interest %.8f ht.%d lock.%u tip.%u\n",(double)nResult/COIN,(double)coins->vout[prevout.n].nValue/COIN,(double)interest/COIN,txheight,locktime,tiptime); + nValueIn += interest; + } + } +#endif if (!MoneyRange(coins->vout[prevout.n].nValue) || !MoneyRange(nValueIn)) return state.DoS(100, error("CheckInputs(): txin values out of range"), REJECT_INVALID, "bad-txns-inputvalues-outofrange"); From 430d6f71b05996852aaf876528250a0607d04901 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 13:58:41 -0300 Subject: [PATCH 36/80] test --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 583f4ad1a..bbe4a7cd2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1725,8 +1725,8 @@ bool NonContextualCheckInputs(const CTransaction& tx, CValidationState &state, c { int64_t interest; int32_t txheight; uint32_t locktime; interest = komodo_accrued_interest(&txheight,&locktime,prevout.hash,prevout.n,0,coins->vout[prevout.n].nValue); - printf("checkResult %.8f += val %.8f interest %.8f ht.%d lock.%u tip.%u\n",(double)nResult/COIN,(double)coins->vout[prevout.n].nValue/COIN,(double)interest/COIN,txheight,locktime,tiptime); - fprintf(stderr,"checkResult %.8f += val %.8f interest %.8f ht.%d lock.%u tip.%u\n",(double)nResult/COIN,(double)coins->vout[prevout.n].nValue/COIN,(double)interest/COIN,txheight,locktime,tiptime); + printf("checkResult %.8f += val %.8f interest %.8f ht.%d lock.%u tip.%u\n",(double)nResult/COIN,(double)coins->vout[prevout.n].nValue/COIN,(double)interest/COIN,txheight,locktime,chainActive->Tip()->nTime); + fprintf(stderr,"checkResult %.8f += val %.8f interest %.8f ht.%d lock.%u tip.%u\n",(double)nResult/COIN,(double)coins->vout[prevout.n].nValue/COIN,(double)interest/COIN,txheight,locktime,chainActive->Tip()->nTime); nValueIn += interest; } } From 53a3e8a06deb95a924364f50182c189827175f74 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 13:59:35 -0300 Subject: [PATCH 37/80] test --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index bbe4a7cd2..f55974553 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1725,8 +1725,8 @@ bool NonContextualCheckInputs(const CTransaction& tx, CValidationState &state, c { int64_t interest; int32_t txheight; uint32_t locktime; interest = komodo_accrued_interest(&txheight,&locktime,prevout.hash,prevout.n,0,coins->vout[prevout.n].nValue); - printf("checkResult %.8f += val %.8f interest %.8f ht.%d lock.%u tip.%u\n",(double)nResult/COIN,(double)coins->vout[prevout.n].nValue/COIN,(double)interest/COIN,txheight,locktime,chainActive->Tip()->nTime); - fprintf(stderr,"checkResult %.8f += val %.8f interest %.8f ht.%d lock.%u tip.%u\n",(double)nResult/COIN,(double)coins->vout[prevout.n].nValue/COIN,(double)interest/COIN,txheight,locktime,chainActive->Tip()->nTime); + printf("checkResult %.8f += val %.8f interest %.8f ht.%d lock.%u tip.%u\n",(double)nResult/COIN,(double)coins->vout[prevout.n].nValue/COIN,(double)interest/COIN,txheight,locktime,chainActive.Tip()->nTime); + fprintf(stderr,"checkResult %.8f += val %.8f interest %.8f ht.%d lock.%u tip.%u\n",(double)nResult/COIN,(double)coins->vout[prevout.n].nValue/COIN,(double)interest/COIN,txheight,locktime,chainActive.Tip()->nTime); nValueIn += interest; } } From ad1796dfc96071d39bb877abcbe535a4bcb23e56 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 14:00:43 -0300 Subject: [PATCH 38/80] test --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index f55974553..c374ad34a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1725,8 +1725,8 @@ bool NonContextualCheckInputs(const CTransaction& tx, CValidationState &state, c { int64_t interest; int32_t txheight; uint32_t locktime; interest = komodo_accrued_interest(&txheight,&locktime,prevout.hash,prevout.n,0,coins->vout[prevout.n].nValue); - printf("checkResult %.8f += val %.8f interest %.8f ht.%d lock.%u tip.%u\n",(double)nResult/COIN,(double)coins->vout[prevout.n].nValue/COIN,(double)interest/COIN,txheight,locktime,chainActive.Tip()->nTime); - fprintf(stderr,"checkResult %.8f += val %.8f interest %.8f ht.%d lock.%u tip.%u\n",(double)nResult/COIN,(double)coins->vout[prevout.n].nValue/COIN,(double)interest/COIN,txheight,locktime,chainActive.Tip()->nTime); + printf("checkResult %.8f += val %.8f interest %.8f ht.%d lock.%u tip.%u\n",(double)nValueIn/COIN,(double)coins->vout[prevout.n].nValue/COIN,(double)interest/COIN,txheight,locktime,chainActive.Tip()->nTime); + fprintf(stderr,"checkResult %.8f += val %.8f interest %.8f ht.%d lock.%u tip.%u\n",(double)nValueIn/COIN,(double)coins->vout[prevout.n].nValue/COIN,(double)interest/COIN,txheight,locktime,chainActive.Tip()->nTime); nValueIn += interest; } } From 407de87c12729f103c3d3ff2d314a289c2badbe3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 14:22:39 -0300 Subject: [PATCH 39/80] test --- src/main.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index c374ad34a..040794c7e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1721,13 +1721,15 @@ bool NonContextualCheckInputs(const CTransaction& tx, CValidationState &state, c #ifdef KOMODO_ENABLE_INTEREST if ( strcmp(ASSETCHAINS_SYMBOL,"REVS") == 0 )//&& nHeight >= 60000 ) { - //if ( value >= COIN*100 ) + if ( value >= COIN ) { int64_t interest; int32_t txheight; uint32_t locktime; - interest = komodo_accrued_interest(&txheight,&locktime,prevout.hash,prevout.n,0,coins->vout[prevout.n].nValue); - printf("checkResult %.8f += val %.8f interest %.8f ht.%d lock.%u tip.%u\n",(double)nValueIn/COIN,(double)coins->vout[prevout.n].nValue/COIN,(double)interest/COIN,txheight,locktime,chainActive.Tip()->nTime); - fprintf(stderr,"checkResult %.8f += val %.8f interest %.8f ht.%d lock.%u tip.%u\n",(double)nValueIn/COIN,(double)coins->vout[prevout.n].nValue/COIN,(double)interest/COIN,txheight,locktime,chainActive.Tip()->nTime); - nValueIn += interest; + if ( (interest= komodo_accrued_interest(&txheight,&locktime,prevout.hash,prevout.n,0,coins->vout[prevout.n].nValue)) != 0 ) + { + printf("checkResult %.8f += val %.8f interest %.8f ht.%d lock.%u tip.%u\n",(double)nValueIn/COIN,(double)coins->vout[prevout.n].nValue/COIN,(double)interest/COIN,txheight,locktime,chainActive.Tip()->nTime); + fprintf(stderr,"checkResult %.8f += val %.8f interest %.8f ht.%d lock.%u tip.%u\n",(double)nValueIn/COIN,(double)coins->vout[prevout.n].nValue/COIN,(double)interest/COIN,txheight,locktime,chainActive.Tip()->nTime); + nValueIn += interest; + } } } #endif @@ -1743,9 +1745,8 @@ bool NonContextualCheckInputs(const CTransaction& tx, CValidationState &state, c REJECT_INVALID, "bad-txns-inputvalues-outofrange"); if (nValueIn < tx.GetValueOut()) - return state.DoS(100, error("CheckInputs(): %s value in (%s) < value out (%s)", - tx.GetHash().ToString(), FormatMoney(nValueIn), FormatMoney(tx.GetValueOut())), - REJECT_INVALID, "bad-txns-in-belowout"); + return state.DoS(100, error("CheckInputs(): %s value in (%s) < value out (%s) diff %.8f", + tx.GetHash().ToString(), FormatMoney(nValueIn), FormatMoney(tx.GetValueOut()),((double)nValueIn - tx.GetValueOut())/COIN),REJECT_INVALID, "bad-txns-in-belowout"); // Tally transaction fees CAmount nTxFee = nValueIn - tx.GetValueOut(); From 804b9e4aa1e1d32f0c7b9e148f6e8d76df363eb6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 14:23:56 -0300 Subject: [PATCH 40/80] test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 040794c7e..be90c6e08 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1721,7 +1721,7 @@ bool NonContextualCheckInputs(const CTransaction& tx, CValidationState &state, c #ifdef KOMODO_ENABLE_INTEREST if ( strcmp(ASSETCHAINS_SYMBOL,"REVS") == 0 )//&& nHeight >= 60000 ) { - if ( value >= COIN ) + if ( coins->vout[prevout.n].nValue >= COIN ) { int64_t interest; int32_t txheight; uint32_t locktime; if ( (interest= komodo_accrued_interest(&txheight,&locktime,prevout.hash,prevout.n,0,coins->vout[prevout.n].nValue)) != 0 ) From cdf56203465409ffbb40fc25f5d4980ef3a13633 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 14:37:21 -0300 Subject: [PATCH 41/80] test --- src/wallet/wallet.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 45d152f8b..2de11e7d8 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2415,6 +2415,7 @@ bool CWallet::SelectCoins(const CAmount& nTargetValue, setvout[out.i].nValue; + fprintf(stderr,"[%.8f] ",(double)out.tx->vout[out.i].nValue/COIN); setCoinsRet.insert(make_pair(out.tx, out.i)); } return (nValueRet >= nTargetValue); @@ -2557,8 +2558,8 @@ bool CWallet::CreateTransaction(const vector& vecSend, age += 1; dPriority += (double)nCredit * age; } - CAmount nChange = nValueIn - nValue; +fprintf(stderr,"wallet sum %.8f (%.8f - %.8f)\n",(double)nChange/COIN,(double)nValueIn/COIN,(double)nValue/COIN); if (nSubtractFeeFromAmount == 0) nChange -= nFeeRet; From e9e8044e662881ced226a8b71f308b1a34be7215 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 14:45:45 -0300 Subject: [PATCH 42/80] test --- src/wallet/wallet.cpp | 17 ++++++++++------- src/wallet/wallet.h | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 2de11e7d8..18a89e151 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2210,14 +2210,18 @@ void CWallet::AvailableCoins(vector& vCoins, bool fOnlyConfirmed, const if ( strcmp(ASSETCHAINS_SYMBOL,"REVS") == 0 && chainActive.Tip() != 0 ) { uint64_t interest,*ptr; - interest = komodo_interest(chainActive.Tip()->nHeight+1,pcoin->vout[i].nValue,pcoin->nLockTime,chainActive.Tip()->nTime); if ( pcoin->vout[i].nValue >= COIN ) { - printf("wallet nValueRet %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)pcoin->vout[i].nValue/COIN,(double)interest/COIN,chainActive.Tip()->nHeight+1,pcoin->nLockTime,chainActive.Tip()->nTime); - fprintf(stderr,"wallet nValueRet %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)pcoin->vout[i].nValue/COIN,(double)interest/COIN,chainActive.Tip()->nHeight+1,pcoin->nLockTime,chainActive.Tip()->nTime); - ptr = (uint64_t *)&pcoin->vout[i].nValue; - (*ptr) += interest; - //pcoin->vout[i].nValue += interest; + interest = komodo_interest(chainActive.Tip()->nHeight+1,pcoin->vout[i].nValue,pcoin->nLockTime,chainActive.Tip()->nTime); + if ( interest != 0 && pcoin->vout[i].addedinterest == 0 ) + { + printf("wallet nValueRet %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)pcoin->vout[i].nValue/COIN,(double)interest/COIN,chainActive.Tip()->nHeight+1,pcoin->nLockTime,chainActive.Tip()->nTime); + fprintf(stderr,"wallet nValueRet %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)pcoin->vout[i].nValue/COIN,(double)interest/COIN,chainActive.Tip()->nHeight+1,pcoin->nLockTime,chainActive.Tip()->nTime); + ptr = (uint64_t *)&pcoin->vout[i].nValue; + (*ptr) += interest; + pcoin->vout[i].interest = interest; + //pcoin->vout[i].nValue += interest; + } } } #endif @@ -2415,7 +2419,6 @@ bool CWallet::SelectCoins(const CAmount& nTargetValue, setvout[out.i].nValue; - fprintf(stderr,"[%.8f] ",(double)out.tx->vout[out.i].nValue/COIN); setCoinsRet.insert(make_pair(out.tx, out.i)); } return (nValueRet >= nTargetValue); diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 960992f16..4e7161147 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -347,7 +347,7 @@ public: char fFromMe; std::string strFromAccount; int64_t nOrderPos; //! position in ordered transaction list - + uint64_t interest; // memory only mutable bool fDebitCached; mutable bool fCreditCached; From 2f0645568b7c844f09efbcae18dd80d30b4628d9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 14:54:20 -0300 Subject: [PATCH 43/80] test --- src/wallet/wallet.cpp | 2 +- src/wallet/wallet.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 18a89e151..ccfda8aee 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2213,7 +2213,7 @@ void CWallet::AvailableCoins(vector& vCoins, bool fOnlyConfirmed, const if ( pcoin->vout[i].nValue >= COIN ) { interest = komodo_interest(chainActive.Tip()->nHeight+1,pcoin->vout[i].nValue,pcoin->nLockTime,chainActive.Tip()->nTime); - if ( interest != 0 && pcoin->vout[i].addedinterest == 0 ) + if ( interest != 0 && pcoin->vout[i].interest == 0 ) { printf("wallet nValueRet %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)pcoin->vout[i].nValue/COIN,(double)interest/COIN,chainActive.Tip()->nHeight+1,pcoin->nLockTime,chainActive.Tip()->nTime); fprintf(stderr,"wallet nValueRet %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)pcoin->vout[i].nValue/COIN,(double)interest/COIN,chainActive.Tip()->nHeight+1,pcoin->nLockTime,chainActive.Tip()->nTime); diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 4e7161147..930242adc 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -151,6 +151,7 @@ struct COutputEntry CTxDestination destination; CAmount amount; int vout; + uint64_t interest; }; /** An note outpoint */ From 897d3273d5da7394e58f667e130025b059132ef1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 14:57:53 -0300 Subject: [PATCH 44/80] test --- src/primitives/transaction.h | 2 +- src/wallet/wallet.h | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index 035f9af9e..3c02f2134 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -239,7 +239,7 @@ class CTxOut public: CAmount nValue; CScript scriptPubKey; - + uint64_t interest; CTxOut() { SetNull(); diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 930242adc..960992f16 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -151,7 +151,6 @@ struct COutputEntry CTxDestination destination; CAmount amount; int vout; - uint64_t interest; }; /** An note outpoint */ @@ -348,7 +347,7 @@ public: char fFromMe; std::string strFromAccount; int64_t nOrderPos; //! position in ordered transaction list - uint64_t interest; + // memory only mutable bool fDebitCached; mutable bool fCreditCached; From 68713b786ff0d1033b727bbd8d72286c90d38e66 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 15:16:15 -0300 Subject: [PATCH 45/80] test --- src/wallet/wallet.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index ccfda8aee..b38b2736c 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2219,7 +2219,8 @@ void CWallet::AvailableCoins(vector& vCoins, bool fOnlyConfirmed, const fprintf(stderr,"wallet nValueRet %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)pcoin->vout[i].nValue/COIN,(double)interest/COIN,chainActive.Tip()->nHeight+1,pcoin->nLockTime,chainActive.Tip()->nTime); ptr = (uint64_t *)&pcoin->vout[i].nValue; (*ptr) += interest; - pcoin->vout[i].interest = interest; + ptr = (uint64_t *)&pcoin->vout[i].interest; + (*ptr) = interest; //pcoin->vout[i].nValue += interest; } } From f6356642b09d6219570819b6294adff313467a38 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 15:36:44 -0300 Subject: [PATCH 46/80] test --- src/coins.cpp | 9 ++++----- src/main.cpp | 6 +++--- src/wallet/wallet.cpp | 6 +++--- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/coins.cpp b/src/coins.cpp index 70eccebbb..7a17534d1 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -398,15 +398,14 @@ CAmount CCoinsViewCache::GetValueIn(int32_t nHeight,int64_t *interestp,const CTr value = GetOutputFor(tx.vin[i]).nValue; nResult += value; #ifdef KOMODO_ENABLE_INTEREST - if ( strcmp(ASSETCHAINS_SYMBOL,"REVS") == 0 )//&& nHeight >= 60000 ) + if ( value >= COIN ) { - //if ( value >= COIN*100 ) + if ( strcmp(ASSETCHAINS_SYMBOL,"REVS") == 0 )//&& nHeight >= 60000 ) { int64_t interest; int32_t txheight; uint32_t locktime; interest = komodo_accrued_interest(&txheight,&locktime,tx.vin[i].prevout.hash,tx.vin[i].prevout.n,0,value); - //interest = komodo_interest(nHeight,value,tx.nLockTime,tiptime); - printf("nResult %.8f += val %.8f interest %.8f ht.%d lock.%u tip.%u\n",(double)nResult/COIN,(double)value/COIN,(double)interest/COIN,txheight,locktime,tiptime); - fprintf(stderr,"nResult %.8f += val %.8f interest %.8f ht.%d lock.%u tip.%u\n",(double)nResult/COIN,(double)value/COIN,(double)interest/COIN,txheight,locktime,tiptime); + //printf("nResult %.8f += val %.8f interest %.8f ht.%d lock.%u tip.%u\n",(double)nResult/COIN,(double)value/COIN,(double)interest/COIN,txheight,locktime,tiptime); + //fprintf(stderr,"nResult %.8f += val %.8f interest %.8f ht.%d lock.%u tip.%u\n",(double)nResult/COIN,(double)value/COIN,(double)interest/COIN,txheight,locktime,tiptime); nResult += interest; (*interestp) += interest; } diff --git a/src/main.cpp b/src/main.cpp index be90c6e08..5d97e7d05 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1726,8 +1726,8 @@ bool NonContextualCheckInputs(const CTransaction& tx, CValidationState &state, c int64_t interest; int32_t txheight; uint32_t locktime; if ( (interest= komodo_accrued_interest(&txheight,&locktime,prevout.hash,prevout.n,0,coins->vout[prevout.n].nValue)) != 0 ) { - printf("checkResult %.8f += val %.8f interest %.8f ht.%d lock.%u tip.%u\n",(double)nValueIn/COIN,(double)coins->vout[prevout.n].nValue/COIN,(double)interest/COIN,txheight,locktime,chainActive.Tip()->nTime); - fprintf(stderr,"checkResult %.8f += val %.8f interest %.8f ht.%d lock.%u tip.%u\n",(double)nValueIn/COIN,(double)coins->vout[prevout.n].nValue/COIN,(double)interest/COIN,txheight,locktime,chainActive.Tip()->nTime); + //printf("checkResult %.8f += val %.8f interest %.8f ht.%d lock.%u tip.%u\n",(double)nValueIn/COIN,(double)coins->vout[prevout.n].nValue/COIN,(double)interest/COIN,txheight,locktime,chainActive.Tip()->nTime); + //fprintf(stderr,"checkResult %.8f += val %.8f interest %.8f ht.%d lock.%u tip.%u\n",(double)nValueIn/COIN,(double)coins->vout[prevout.n].nValue/COIN,(double)interest/COIN,txheight,locktime,chainActive.Tip()->nTime); nValueIn += interest; } } @@ -1757,7 +1757,7 @@ bool NonContextualCheckInputs(const CTransaction& tx, CValidationState &state, c if (!MoneyRange(nFees)) return state.DoS(100, error("CheckInputs(): nFees out of range"), REJECT_INVALID, "bad-txns-fee-outofrange"); - +fprintf(stderr,"nFees %.8f\n",(double)nFees/COIN); // The first loop above does all the inexpensive checks. // Only if ALL inputs pass do we perform expensive ECDSA signature checks. // Helps prevent CPU exhaustion attacks. diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index b38b2736c..a641c398c 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2215,8 +2215,8 @@ void CWallet::AvailableCoins(vector& vCoins, bool fOnlyConfirmed, const interest = komodo_interest(chainActive.Tip()->nHeight+1,pcoin->vout[i].nValue,pcoin->nLockTime,chainActive.Tip()->nTime); if ( interest != 0 && pcoin->vout[i].interest == 0 ) { - printf("wallet nValueRet %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)pcoin->vout[i].nValue/COIN,(double)interest/COIN,chainActive.Tip()->nHeight+1,pcoin->nLockTime,chainActive.Tip()->nTime); - fprintf(stderr,"wallet nValueRet %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)pcoin->vout[i].nValue/COIN,(double)interest/COIN,chainActive.Tip()->nHeight+1,pcoin->nLockTime,chainActive.Tip()->nTime); + //printf("wallet nValueRet %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)pcoin->vout[i].nValue/COIN,(double)interest/COIN,chainActive.Tip()->nHeight+1,pcoin->nLockTime,chainActive.Tip()->nTime); + //fprintf(stderr,"wallet nValueRet %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)pcoin->vout[i].nValue/COIN,(double)interest/COIN,chainActive.Tip()->nHeight+1,pcoin->nLockTime,chainActive.Tip()->nTime); ptr = (uint64_t *)&pcoin->vout[i].nValue; (*ptr) += interest; ptr = (uint64_t *)&pcoin->vout[i].interest; @@ -2563,7 +2563,7 @@ bool CWallet::CreateTransaction(const vector& vecSend, dPriority += (double)nCredit * age; } CAmount nChange = nValueIn - nValue; -fprintf(stderr,"wallet sum %.8f (%.8f - %.8f)\n",(double)nChange/COIN,(double)nValueIn/COIN,(double)nValue/COIN); +fprintf(stderr,"wallet change %.8f (%.8f - %.8f)\n",(double)nChange/COIN,(double)nValueIn/COIN,(double)nValue/COIN); if (nSubtractFeeFromAmount == 0) nChange -= nFeeRet; From bd99d1f236af9b52e8f6b34cb13df785e00ed742 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 15:45:04 -0300 Subject: [PATCH 47/80] test --- src/wallet/wallet.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index a641c398c..12bf922a4 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2433,8 +2433,7 @@ bool CWallet::SelectCoins(const CAmount& nTargetValue, set& vecSend, CWalletTx& wtxNew, CReserveKey& reservekey, CAmount& nFeeRet, int& nChangePosRet, std::string& strFailReason, const CCoinControl* coinControl) { - CAmount nValue = 0; - unsigned int nSubtractFeeFromAmount = 0; + uint64_t interest = 0; CAmount nValue = 0; unsigned int nSubtractFeeFromAmount = 0; BOOST_FOREACH (const CRecipient& recipient, vecSend) { if (nValue < 0 || recipient.nAmount < 0) @@ -2553,6 +2552,7 @@ bool CWallet::CreateTransaction(const vector& vecSend, BOOST_FOREACH(PAIRTYPE(const CWalletTx*, unsigned int) pcoin, setCoins) { CAmount nCredit = pcoin.first->vout[pcoin.second].nValue; + interest += pcoin.first->vout[pcoin.second].interest; //The coin age after the next block (depth+1) is used instead of the current, //reflecting an assumption the user would accept a bit more delay for //a chance at a free transaction. @@ -2562,8 +2562,8 @@ bool CWallet::CreateTransaction(const vector& vecSend, age += 1; dPriority += (double)nCredit * age; } - CAmount nChange = nValueIn - nValue; -fprintf(stderr,"wallet change %.8f (%.8f - %.8f)\n",(double)nChange/COIN,(double)nValueIn/COIN,(double)nValue/COIN); + CAmount nChange = nValueIn - nValue + interest; +fprintf(stderr,"wallet change %.8f (%.8f - %.8f) interest %.8f\n",(double)nChange/COIN,(double)nValueIn/COIN,(double)nValue/COIN,(double)interest/COIN); if (nSubtractFeeFromAmount == 0) nChange -= nFeeRet; From 03ee4b8f892261a37bb1d9b53bc6de4a2a0935f7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 16:07:46 -0300 Subject: [PATCH 48/80] test --- src/wallet/wallet.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 12bf922a4..75f98d28b 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2278,8 +2278,7 @@ static void ApproximateBestSubset(vector vCoins, - set >& setCoinsRet, CAmount& nValueRet) const +bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int nConfTheirs, vector vCoins,set >& setCoinsRet, CAmount& nValueRet) const { setCoinsRet.clear(); nValueRet = 0; @@ -2549,9 +2548,11 @@ bool CWallet::CreateTransaction(const vector& vecSend, } return false; } + interest = 0; BOOST_FOREACH(PAIRTYPE(const CWalletTx*, unsigned int) pcoin, setCoins) { CAmount nCredit = pcoin.first->vout[pcoin.second].nValue; + fprintf(stderr,"val %.8f interest %.8f\n",(double)nCredit/COIN,(double)pcoin.first->vout[pcoin.second].interest); interest += pcoin.first->vout[pcoin.second].interest; //The coin age after the next block (depth+1) is used instead of the current, //reflecting an assumption the user would accept a bit more delay for @@ -2562,7 +2563,7 @@ bool CWallet::CreateTransaction(const vector& vecSend, age += 1; dPriority += (double)nCredit * age; } - CAmount nChange = nValueIn - nValue + interest; + CAmount nChange = (nValueIn - nValue + interest); fprintf(stderr,"wallet change %.8f (%.8f - %.8f) interest %.8f\n",(double)nChange/COIN,(double)nValueIn/COIN,(double)nValue/COIN,(double)interest/COIN); if (nSubtractFeeFromAmount == 0) nChange -= nFeeRet; From 41d80d3bc73826d040ab141986a98b600ce1cb5d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 16:15:14 -0300 Subject: [PATCH 49/80] test --- src/wallet/wallet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 75f98d28b..e15067686 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2552,8 +2552,8 @@ bool CWallet::CreateTransaction(const vector& vecSend, BOOST_FOREACH(PAIRTYPE(const CWalletTx*, unsigned int) pcoin, setCoins) { CAmount nCredit = pcoin.first->vout[pcoin.second].nValue; - fprintf(stderr,"val %.8f interest %.8f\n",(double)nCredit/COIN,(double)pcoin.first->vout[pcoin.second].interest); - interest += pcoin.first->vout[pcoin.second].interest; + fprintf(stderr,"val %.8f interest %.8f\n",(double)nCredit/COIN,(double)pcoin.vout[pcoin.second].interest); + interest += pcoin.vout[pcoin.second].interest; //The coin age after the next block (depth+1) is used instead of the current, //reflecting an assumption the user would accept a bit more delay for //a chance at a free transaction. From 15649f727dab5e89fb94977ad9e5d35dccdd476e Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 16:28:56 -0300 Subject: [PATCH 50/80] test --- src/wallet/wallet.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index e15067686..88ae03540 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2278,11 +2278,11 @@ static void ApproximateBestSubset(vector vCoins,set >& setCoinsRet, CAmount& nValueRet) const +bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int nConfTheirs, vector vCoins,set >& setCoinsRet, CAmount& nValueRet, uint64_t *interestp) const { setCoinsRet.clear(); nValueRet = 0; - + *interestp = 0; // List of values less than target pair > coinLowestLarger; coinLowestLarger.first = std::numeric_limits::max(); @@ -2311,6 +2311,7 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int { setCoinsRet.insert(coin.second); nValueRet += coin.first; + *interestp += pcoin->vout[i].interest; return true; } else if (n < nTargetValue + CENT) @@ -2321,6 +2322,7 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int else if (n < coinLowestLarger.first) { coinLowestLarger = coin; + coinLowestLarger.second.first->interest = pcoin->vout[i].interest; } } @@ -2330,6 +2332,7 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int { setCoinsRet.insert(vValue[i].second); nValueRet += vValue[i].first; + *interestp += pcoin->vout[i].interest; } return true; } @@ -2340,6 +2343,7 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int return false; setCoinsRet.insert(coinLowestLarger.second); nValueRet += coinLowestLarger.first; + *interestp += pcoin->vout[i].interest; return true; } @@ -2359,6 +2363,7 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int { setCoinsRet.insert(coinLowestLarger.second); nValueRet += coinLowestLarger.first; + *interestp += coinLowestLarger.second.first->interest; } else { for (unsigned int i = 0; i < vValue.size(); i++) @@ -2366,6 +2371,7 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int { setCoinsRet.insert(vValue[i].second); nValueRet += vValue[i].first; + *interestp += vValue[i].second.first->interest; } LogPrint("selectcoins", "SelectCoins() best subset: "); @@ -2412,6 +2418,7 @@ bool CWallet::SelectCoins(const CAmount& nTargetValue, set return all selected outputs (we want all selected to go into the transaction for sure) + *interestp = 0; if (coinControl && coinControl->HasSelected()) { BOOST_FOREACH(const COutput& out, vCoins) @@ -2419,14 +2426,15 @@ bool CWallet::SelectCoins(const CAmount& nTargetValue, setvout[out.i].nValue; + *interestp += out.tx->vout[out.i].interest; setCoinsRet.insert(make_pair(out.tx, out.i)); } return (nValueRet >= nTargetValue); } - return (SelectCoinsMinConf(nTargetValue, 1, 6, vCoins, setCoinsRet, nValueRet) || - SelectCoinsMinConf(nTargetValue, 1, 1, vCoins, setCoinsRet, nValueRet) || - (bSpendZeroConfChange && SelectCoinsMinConf(nTargetValue, 0, 1, vCoins, setCoinsRet, nValueRet))); + return (SelectCoinsMinConf(nTargetValue, 1, 6, vCoins, setCoinsRet, nValueRet,interestp) || + SelectCoinsMinConf(nTargetValue, 1, 1, vCoins, setCoinsRet, nValueRet,interestp) || + (bSpendZeroConfChange && SelectCoinsMinConf(nTargetValue, 0, 1, vCoins, setCoinsRet, nValueRet,interestp))); } bool CWallet::CreateTransaction(const vector& vecSend, From 29c91a290bd462e0d8fec5e0f2a1f3bea2a04d6e Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 16:31:44 -0300 Subject: [PATCH 51/80] test --- src/wallet/wallet.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 88ae03540..b8e9ad311 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2384,7 +2384,7 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int return true; } -bool CWallet::SelectCoins(const CAmount& nTargetValue, set >& setCoinsRet, CAmount& nValueRet, bool& fOnlyCoinbaseCoinsRet, bool& fNeedCoinbaseCoinsRet, const CCoinControl* coinControl) const +bool CWallet::SelectCoins(const CAmount& nTargetValue, set >& setCoinsRet, CAmount& nValueRet, bool& fOnlyCoinbaseCoinsRet, bool& fNeedCoinbaseCoinsRet, const CCoinControl* coinControl,uint64_t *interestp) const { // Output parameter fOnlyCoinbaseCoinsRet is set to true when the only available coins are coinbase utxos. vector vCoinsNoCoinbase, vCoinsWithCoinbase; @@ -2545,7 +2545,8 @@ bool CWallet::CreateTransaction(const vector& vecSend, CAmount nValueIn = 0; bool fOnlyCoinbaseCoins = false; bool fNeedCoinbaseCoins = false; - if (!SelectCoins(nTotalValue, setCoins, nValueIn, fOnlyCoinbaseCoins, fNeedCoinbaseCoins, coinControl)) + interest = 0; + if (!SelectCoins(nTotalValue, setCoins, nValueIn, fOnlyCoinbaseCoins, fNeedCoinbaseCoins, coinControl,&interest)) { if (fOnlyCoinbaseCoins && Params().GetConsensus().fCoinbaseMustBeProtected) { strFailReason = _("Coinbase funds can only be sent to a zaddr"); @@ -2556,12 +2557,10 @@ bool CWallet::CreateTransaction(const vector& vecSend, } return false; } - interest = 0; + fprintf(stderr,"interest sum %.8f\n",(double)interest/COIN); BOOST_FOREACH(PAIRTYPE(const CWalletTx*, unsigned int) pcoin, setCoins) { CAmount nCredit = pcoin.first->vout[pcoin.second].nValue; - fprintf(stderr,"val %.8f interest %.8f\n",(double)nCredit/COIN,(double)pcoin.vout[pcoin.second].interest); - interest += pcoin.vout[pcoin.second].interest; //The coin age after the next block (depth+1) is used instead of the current, //reflecting an assumption the user would accept a bit more delay for //a chance at a free transaction. From 758197cea0d0841e126adb3f5b1140e43d376f87 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 16:33:19 -0300 Subject: [PATCH 52/80] test --- src/wallet/wallet.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 960992f16..2163c246a 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -575,7 +575,7 @@ public: class CWallet : public CCryptoKeyStore, public CValidationInterface { private: - bool SelectCoins(const CAmount& nTargetValue, std::set >& setCoinsRet, CAmount& nValueRet, bool& fOnlyCoinbaseCoinsRet, bool& fNeedCoinbaseCoinsRet, const CCoinControl *coinControl = NULL) const; + bool SelectCoins(const CAmount& nTargetValue, std::set >& setCoinsRet, CAmount& nValueRet, bool& fOnlyCoinbaseCoinsRet, bool& fNeedCoinbaseCoinsRet, const CCoinControl *coinControl = NULL,uint64_t *interestp) const; CWalletDB *pwalletdbEncryption; @@ -791,7 +791,7 @@ public: bool CanSupportFeature(enum WalletFeature wf) { AssertLockHeld(cs_wallet); return nWalletMaxVersion >= wf; } void AvailableCoins(std::vector& vCoins, bool fOnlyConfirmed=true, const CCoinControl *coinControl = NULL, bool fIncludeZeroValue=false, bool fIncludeCoinBase=true) const; - bool SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int nConfTheirs, std::vector vCoins, std::set >& setCoinsRet, CAmount& nValueRet) const; + bool SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int nConfTheirs, std::vector vCoins, std::set >& setCoinsRet, CAmount& nValueRet,uint64_t *interestp) const; bool IsSpent(const uint256& hash, unsigned int n) const; bool IsSpent(const uint256& nullifier) const; From b82f1051b5173f27f3c27e85a08c155f002200fd Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 16:36:00 -0300 Subject: [PATCH 53/80] test --- src/wallet/wallet.cpp | 4 ++++ src/wallet/wallet.h | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index b8e9ad311..05b7c9c55 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2387,6 +2387,10 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int bool CWallet::SelectCoins(const CAmount& nTargetValue, set >& setCoinsRet, CAmount& nValueRet, bool& fOnlyCoinbaseCoinsRet, bool& fNeedCoinbaseCoinsRet, const CCoinControl* coinControl,uint64_t *interestp) const { // Output parameter fOnlyCoinbaseCoinsRet is set to true when the only available coins are coinbase utxos. + uint64_t tmp; + if ( interestp == 0 ) + interestp = &tmp; + *interestp = 0; vector vCoinsNoCoinbase, vCoinsWithCoinbase; AvailableCoins(vCoinsNoCoinbase, true, coinControl, false, false); AvailableCoins(vCoinsWithCoinbase, true, coinControl, false, true); diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 2163c246a..8dee91cf7 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -575,7 +575,7 @@ public: class CWallet : public CCryptoKeyStore, public CValidationInterface { private: - bool SelectCoins(const CAmount& nTargetValue, std::set >& setCoinsRet, CAmount& nValueRet, bool& fOnlyCoinbaseCoinsRet, bool& fNeedCoinbaseCoinsRet, const CCoinControl *coinControl = NULL,uint64_t *interestp) const; + bool SelectCoins(const CAmount& nTargetValue, std::set >& setCoinsRet, CAmount& nValueRet, bool& fOnlyCoinbaseCoinsRet, bool& fNeedCoinbaseCoinsRet, const CCoinControl *coinControl = NULL,uint64_t *interestp = NULL) const; CWalletDB *pwalletdbEncryption; From 0f485755195be3e48fdb4f6ccb8ef790ea816fcf Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 16:48:18 -0300 Subject: [PATCH 54/80] test --- src/wallet/wallet.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 05b7c9c55..6adb0ebd3 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2280,7 +2280,9 @@ static void ApproximateBestSubset(vector vCoins,set >& setCoinsRet, CAmount& nValueRet, uint64_t *interestp) const { + uint64_t interests[512],lowest_interest = 0; int32_t count = 0; setCoinsRet.clear(); + memset(interests,0,sizeof(interests)); nValueRet = 0; *interestp = 0; // List of values less than target @@ -2318,11 +2320,13 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int { vValue.push_back(coin); nTotalLower += n; + if ( count < sizeof(interests)/sizeof(*interests) ) + interests[count++] = pcoin->vout[i].interest; } else if (n < coinLowestLarger.first) { coinLowestLarger = coin; - coinLowestLarger.second.first->interest = pcoin->vout[i].interest; + lowest_interest = pcoin->vout[i].interest; } } @@ -2332,7 +2336,8 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int { setCoinsRet.insert(vValue[i].second); nValueRet += vValue[i].first; - *interestp += pcoin->vout[i].interest; + if ( i < count ) + *interestp += interests[i]; } return true; } @@ -2343,7 +2348,7 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int return false; setCoinsRet.insert(coinLowestLarger.second); nValueRet += coinLowestLarger.first; - *interestp += pcoin->vout[i].interest; + *interestp += lowest_interest; return true; } @@ -2363,7 +2368,7 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int { setCoinsRet.insert(coinLowestLarger.second); nValueRet += coinLowestLarger.first; - *interestp += coinLowestLarger.second.first->interest; + *interestp += lowest_interest; } else { for (unsigned int i = 0; i < vValue.size(); i++) @@ -2371,7 +2376,8 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int { setCoinsRet.insert(vValue[i].second); nValueRet += vValue[i].first; - *interestp += vValue[i].second.first->interest; + if ( i < count ) + *interestp += interests[i]; } LogPrint("selectcoins", "SelectCoins() best subset: "); From 5f9b45ad2a4abb3b326fa73eac60af438c6bc110 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 16:51:39 -0300 Subject: [PATCH 55/80] 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 68b03ed65..4ae2e7a0b 100644 --- a/src/komodo_interest.h +++ b/src/komodo_interest.h @@ -67,7 +67,7 @@ uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uin 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); + 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 ebd70eb5dea0fd09d68ad30a7bd6598caf2037f8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 16:53:46 -0300 Subject: [PATCH 56/80] test --- src/komodo_interest.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_interest.h b/src/komodo_interest.h index 4ae2e7a0b..4f0b47621 100644 --- a/src/komodo_interest.h +++ b/src/komodo_interest.h @@ -67,8 +67,8 @@ uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uin 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); - } + 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,(double)interest/COIN,(long long)numerator,(long long)denominator); + } return(interest); } From b7c4066d4ed0d8aedf206d6d7427a8f22d12c5d2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 16:54:49 -0300 Subject: [PATCH 57/80] 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 4f0b47621..226b78896 100644 --- a/src/komodo_interest.h +++ b/src/komodo_interest.h @@ -67,7 +67,7 @@ uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uin 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,(double)interest/COIN,(long long)numerator,(long long)denominator); + fprintf(stderr,"komodo_interest %lld %.8f nLockTime.%u tiptime.%u minutes.%d interest %lld %.8f (%llu / %llu)\n",(long long)nValue,(double)nValue/COIN,nLockTime,tiptime,minutes,(long long)interest,(double)interest/COIN,(long long)numerator,(long long)denominator); } return(interest); From 8fa5e1fff16c70e82402e86606df232a35184ec7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 16:55:44 -0300 Subject: [PATCH 58/80] 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 226b78896..afbc9fcf8 100644 --- a/src/komodo_interest.h +++ b/src/komodo_interest.h @@ -68,7 +68,7 @@ uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uin 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,(double)nValue/COIN,nLockTime,tiptime,minutes,(long long)interest,(double)interest/COIN,(long long)numerator,(long long)denominator); - + } } return(interest); } From d8a120e3ac717436a10957310774347593f54164 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 17:04:57 -0300 Subject: [PATCH 59/80] test --- src/wallet/wallet.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 6adb0ebd3..9a9fc7594 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2321,7 +2321,10 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int vValue.push_back(coin); nTotalLower += n; if ( count < sizeof(interests)/sizeof(*interests) ) + { + fprintf(stderr,"count.%d %.8f\n",count,(double)pcoin->vout[i].interest/COIN); interests[count++] = pcoin->vout[i].interest; + } } else if (n < coinLowestLarger.first) { From 258748f59160422bee0f05a0cc5121f267050216 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 17:10:24 -0300 Subject: [PATCH 60/80] test --- src/wallet/wallet.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 9a9fc7594..d186fce72 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2213,17 +2213,32 @@ void CWallet::AvailableCoins(vector& vCoins, bool fOnlyConfirmed, const if ( pcoin->vout[i].nValue >= COIN ) { interest = komodo_interest(chainActive.Tip()->nHeight+1,pcoin->vout[i].nValue,pcoin->nLockTime,chainActive.Tip()->nTime); - if ( interest != 0 && pcoin->vout[i].interest == 0 ) + if ( interest != 0 ) { //printf("wallet nValueRet %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)pcoin->vout[i].nValue/COIN,(double)interest/COIN,chainActive.Tip()->nHeight+1,pcoin->nLockTime,chainActive.Tip()->nTime); - //fprintf(stderr,"wallet nValueRet %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)pcoin->vout[i].nValue/COIN,(double)interest/COIN,chainActive.Tip()->nHeight+1,pcoin->nLockTime,chainActive.Tip()->nTime); + fprintf(stderr,"wallet nValueRet %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)pcoin->vout[i].nValue/COIN,(double)interest/COIN,chainActive.Tip()->nHeight+1,pcoin->nLockTime,chainActive.Tip()->nTime); ptr = (uint64_t *)&pcoin->vout[i].nValue; (*ptr) += interest; ptr = (uint64_t *)&pcoin->vout[i].interest; (*ptr) = interest; //pcoin->vout[i].nValue += interest; } + else + { + ptr = (uint64_t *)&pcoin->vout[i].interest; + (*ptr) = 0; + } } + else + { + ptr = (uint64_t *)&pcoin->vout[i].interest; + (*ptr) = 0; + } + } + else + { + ptr = (uint64_t *)&pcoin->vout[i].interest; + (*ptr) = 0; } #endif vCoins.push_back(COutput(pcoin, i, nDepth, (mine & ISMINE_SPENDABLE) != ISMINE_NO)); From 5c439232ddb8e36872bd04e479e68303a3017963 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 17:11:40 -0300 Subject: [PATCH 61/80] 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 d186fce72..a5fe817c1 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2173,6 +2173,7 @@ uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uin void CWallet::AvailableCoins(vector& vCoins, bool fOnlyConfirmed, const CCoinControl *coinControl, bool fIncludeZeroValue, bool fIncludeCoinBase) const { + uint64_t interest,*ptr; vCoins.clear(); { @@ -2209,7 +2210,6 @@ void CWallet::AvailableCoins(vector& vCoins, bool fOnlyConfirmed, const extern char ASSETCHAINS_SYMBOL[16]; if ( strcmp(ASSETCHAINS_SYMBOL,"REVS") == 0 && chainActive.Tip() != 0 ) { - uint64_t interest,*ptr; if ( pcoin->vout[i].nValue >= COIN ) { interest = komodo_interest(chainActive.Tip()->nHeight+1,pcoin->vout[i].nValue,pcoin->nLockTime,chainActive.Tip()->nTime); From 9067057a50acc65f2c747cef726da42285de735a Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 17:19:11 -0300 Subject: [PATCH 62/80] test --- src/komodo_interest.h | 2 +- src/wallet/wallet.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo_interest.h b/src/komodo_interest.h index afbc9fcf8..e9a179e08 100644 --- a/src/komodo_interest.h +++ b/src/komodo_interest.h @@ -67,7 +67,7 @@ uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uin 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,(double)nValue/COIN,nLockTime,tiptime,minutes,(long long)interest,(double)interest/COIN,(long long)numerator,(long long)denominator); + //fprintf(stderr,"komodo_interest %lld %.8f nLockTime.%u tiptime.%u minutes.%d interest %lld %.8f (%llu / %llu)\n",(long long)nValue,(double)nValue/COIN,nLockTime,tiptime,minutes,(long long)interest,(double)interest/COIN,(long long)numerator,(long long)denominator); } } return(interest); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index a5fe817c1..a44be4740 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2337,7 +2337,7 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int nTotalLower += n; if ( count < sizeof(interests)/sizeof(*interests) ) { - fprintf(stderr,"count.%d %.8f\n",count,(double)pcoin->vout[i].interest/COIN); + //fprintf(stderr,"count.%d %.8f\n",count,(double)pcoin->vout[i].interest/COIN); interests[count++] = pcoin->vout[i].interest; } } @@ -2593,6 +2593,7 @@ bool CWallet::CreateTransaction(const vector& vecSend, //reflecting an assumption the user would accept a bit more delay for //a chance at a free transaction. //But mempool inputs might still be in the mempool, so their age stays 0 + fprintf(stderr,"nCredit %.8f interest %.8f\n",(double)nCredit/COIN,(double)pcoin.first->vout[pcoin.second].interest/COIN); int age = pcoin.first->GetDepthInMainChain(); if (age != 0) age += 1; From b8adc56428afab23a3447475392be8d12ca6a17f Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 17:29:05 -0300 Subject: [PATCH 63/80] test --- src/wallet/wallet.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index a44be4740..8091dea7b 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2468,7 +2468,7 @@ bool CWallet::SelectCoins(const CAmount& nTargetValue, set& vecSend, CWalletTx& wtxNew, CReserveKey& reservekey, CAmount& nFeeRet, int& nChangePosRet, std::string& strFailReason, const CCoinControl* coinControl) { - uint64_t interest = 0; CAmount nValue = 0; unsigned int nSubtractFeeFromAmount = 0; + uint64_t interest2,interest = 0; CAmount nValue = 0; unsigned int nSubtractFeeFromAmount = 0; BOOST_FOREACH (const CRecipient& recipient, vecSend) { if (nValue < 0 || recipient.nAmount < 0) @@ -2573,7 +2573,7 @@ bool CWallet::CreateTransaction(const vector& vecSend, CAmount nValueIn = 0; bool fOnlyCoinbaseCoins = false; bool fNeedCoinbaseCoins = false; - interest = 0; + interest = interest2 = 0; if (!SelectCoins(nTotalValue, setCoins, nValueIn, fOnlyCoinbaseCoins, fNeedCoinbaseCoins, coinControl,&interest)) { if (fOnlyCoinbaseCoins && Params().GetConsensus().fCoinbaseMustBeProtected) { @@ -2585,7 +2585,6 @@ bool CWallet::CreateTransaction(const vector& vecSend, } return false; } - fprintf(stderr,"interest sum %.8f\n",(double)interest/COIN); BOOST_FOREACH(PAIRTYPE(const CWalletTx*, unsigned int) pcoin, setCoins) { CAmount nCredit = pcoin.first->vout[pcoin.second].nValue; @@ -2593,13 +2592,15 @@ bool CWallet::CreateTransaction(const vector& vecSend, //reflecting an assumption the user would accept a bit more delay for //a chance at a free transaction. //But mempool inputs might still be in the mempool, so their age stays 0 - fprintf(stderr,"nCredit %.8f interest %.8f\n",(double)nCredit/COIN,(double)pcoin.first->vout[pcoin.second].interest/COIN); + //fprintf(stderr,"nCredit %.8f interest %.8f\n",(double)nCredit/COIN,(double)pcoin.first->vout[pcoin.second].interest/COIN); + interest2 += pcoin.first->vout[pcoin.second].interest; int age = pcoin.first->GetDepthInMainChain(); if (age != 0) age += 1; dPriority += (double)nCredit * age; } - CAmount nChange = (nValueIn - nValue + interest); + fprintf(stderr,"interest sum %.8f, interest2 %.8f\n",(double)interest/COIN,(double)interest2/COIN); + CAmount nChange = (nValueIn - nValue); fprintf(stderr,"wallet change %.8f (%.8f - %.8f) interest %.8f\n",(double)nChange/COIN,(double)nValueIn/COIN,(double)nValue/COIN,(double)interest/COIN); if (nSubtractFeeFromAmount == 0) nChange -= nFeeRet; From 9f87f0dcc596a6e77a8ddc18a25311b76e7d51e2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 17:41:40 -0300 Subject: [PATCH 64/80] test --- src/wallet/wallet.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 8091dea7b..b63104456 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2216,7 +2216,7 @@ void CWallet::AvailableCoins(vector& vCoins, bool fOnlyConfirmed, const if ( interest != 0 ) { //printf("wallet nValueRet %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)pcoin->vout[i].nValue/COIN,(double)interest/COIN,chainActive.Tip()->nHeight+1,pcoin->nLockTime,chainActive.Tip()->nTime); - fprintf(stderr,"wallet nValueRet %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)pcoin->vout[i].nValue/COIN,(double)interest/COIN,chainActive.Tip()->nHeight+1,pcoin->nLockTime,chainActive.Tip()->nTime); + //fprintf(stderr,"wallet nValueRet %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)pcoin->vout[i].nValue/COIN,(double)interest/COIN,chainActive.Tip()->nHeight+1,pcoin->nLockTime,chainActive.Tip()->nTime); ptr = (uint64_t *)&pcoin->vout[i].nValue; (*ptr) += interest; ptr = (uint64_t *)&pcoin->vout[i].interest; @@ -2459,7 +2459,7 @@ bool CWallet::SelectCoins(const CAmount& nTargetValue, set= nTargetValue); } - +fprintf(stderr,"nValueRet %8f vs target %.8f\n",(double)nValueRet/COIN,(double)nTargetValue/COIN); return (SelectCoinsMinConf(nTargetValue, 1, 6, vCoins, setCoinsRet, nValueRet,interestp) || SelectCoinsMinConf(nTargetValue, 1, 1, vCoins, setCoinsRet, nValueRet,interestp) || (bSpendZeroConfChange && SelectCoinsMinConf(nTargetValue, 0, 1, vCoins, setCoinsRet, nValueRet,interestp))); @@ -2592,7 +2592,7 @@ bool CWallet::CreateTransaction(const vector& vecSend, //reflecting an assumption the user would accept a bit more delay for //a chance at a free transaction. //But mempool inputs might still be in the mempool, so their age stays 0 - //fprintf(stderr,"nCredit %.8f interest %.8f\n",(double)nCredit/COIN,(double)pcoin.first->vout[pcoin.second].interest/COIN); + fprintf(stderr,"nCredit %.8f interest %.8f\n",(double)nCredit/COIN,(double)pcoin.first->vout[pcoin.second].interest/COIN); interest2 += pcoin.first->vout[pcoin.second].interest; int age = pcoin.first->GetDepthInMainChain(); if (age != 0) @@ -2601,7 +2601,7 @@ bool CWallet::CreateTransaction(const vector& vecSend, } fprintf(stderr,"interest sum %.8f, interest2 %.8f\n",(double)interest/COIN,(double)interest2/COIN); CAmount nChange = (nValueIn - nValue); -fprintf(stderr,"wallet change %.8f (%.8f - %.8f) interest %.8f\n",(double)nChange/COIN,(double)nValueIn/COIN,(double)nValue/COIN,(double)interest/COIN); +fprintf(stderr,"wallet change %.8f (%.8f - %.8f) interest %.8f total %.8f\n",(double)nChange/COIN,(double)nValueIn/COIN,(double)nValue/COIN,(double)interest/COIN,(double)nTotalValue/COIN); if (nSubtractFeeFromAmount == 0) nChange -= nFeeRet; From 8726269f8e2a52740a6b7d525e3fa2c5020566e0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 17:48:54 -0300 Subject: [PATCH 65/80] test --- src/wallet/wallet.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index b63104456..a6d5f46c1 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2217,8 +2217,8 @@ void CWallet::AvailableCoins(vector& vCoins, bool fOnlyConfirmed, const { //printf("wallet nValueRet %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)pcoin->vout[i].nValue/COIN,(double)interest/COIN,chainActive.Tip()->nHeight+1,pcoin->nLockTime,chainActive.Tip()->nTime); //fprintf(stderr,"wallet nValueRet %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)pcoin->vout[i].nValue/COIN,(double)interest/COIN,chainActive.Tip()->nHeight+1,pcoin->nLockTime,chainActive.Tip()->nTime); - ptr = (uint64_t *)&pcoin->vout[i].nValue; - (*ptr) += interest; + //ptr = (uint64_t *)&pcoin->vout[i].nValue; + //(*ptr) += interest; ptr = (uint64_t *)&pcoin->vout[i].interest; (*ptr) = interest; //pcoin->vout[i].nValue += interest; @@ -2444,8 +2444,7 @@ bool CWallet::SelectCoins(const CAmount& nTargetValue, set= nTargetValue); } } - - // coin control -> return all selected outputs (we want all selected to go into the transaction for sure) + // coin control -> return all selected outputs (we want all to go into the transaction for sure) *interestp = 0; if (coinControl && coinControl->HasSelected()) { @@ -2600,7 +2599,7 @@ bool CWallet::CreateTransaction(const vector& vecSend, dPriority += (double)nCredit * age; } fprintf(stderr,"interest sum %.8f, interest2 %.8f\n",(double)interest/COIN,(double)interest2/COIN); - CAmount nChange = (nValueIn - nValue); + CAmount nChange = (nValueIn - nValue + interest); fprintf(stderr,"wallet change %.8f (%.8f - %.8f) interest %.8f total %.8f\n",(double)nChange/COIN,(double)nValueIn/COIN,(double)nValue/COIN,(double)interest/COIN,(double)nTotalValue/COIN); if (nSubtractFeeFromAmount == 0) nChange -= nFeeRet; From 38dfbe150a6b0e24dc5c5c01fe390c2d404b45f7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 17:57:55 -0300 Subject: [PATCH 66/80] test --- src/coins.cpp | 2 +- src/main.cpp | 4 ++-- src/wallet/wallet.cpp | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/coins.cpp b/src/coins.cpp index 7a17534d1..7c3555f13 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -400,7 +400,7 @@ CAmount CCoinsViewCache::GetValueIn(int32_t nHeight,int64_t *interestp,const CTr #ifdef KOMODO_ENABLE_INTEREST if ( value >= COIN ) { - if ( strcmp(ASSETCHAINS_SYMBOL,"REVS") == 0 )//&& nHeight >= 60000 ) + if ( ASSETCHAINS_SYMBOL[0] == 0 && nHeight >= 60000 ) { int64_t interest; int32_t txheight; uint32_t locktime; interest = komodo_accrued_interest(&txheight,&locktime,tx.vin[i].prevout.hash,tx.vin[i].prevout.n,0,value); diff --git a/src/main.cpp b/src/main.cpp index 5d97e7d05..c34044672 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1719,7 +1719,7 @@ bool NonContextualCheckInputs(const CTransaction& tx, CValidationState &state, c // Check for negative or overflow input values nValueIn += coins->vout[prevout.n].nValue; #ifdef KOMODO_ENABLE_INTEREST - if ( strcmp(ASSETCHAINS_SYMBOL,"REVS") == 0 )//&& nHeight >= 60000 ) + if ( ASSETCHAINS_SYMBOL[0] == 0 && nHeight >= 60000 ) { if ( coins->vout[prevout.n].nValue >= COIN ) { @@ -1757,7 +1757,7 @@ bool NonContextualCheckInputs(const CTransaction& tx, CValidationState &state, c if (!MoneyRange(nFees)) return state.DoS(100, error("CheckInputs(): nFees out of range"), REJECT_INVALID, "bad-txns-fee-outofrange"); -fprintf(stderr,"nFees %.8f\n",(double)nFees/COIN); +//fprintf(stderr,"nFees %.8f\n",(double)nFees/COIN); // The first loop above does all the inexpensive checks. // Only if ALL inputs pass do we perform expensive ECDSA signature checks. // Helps prevent CPU exhaustion attacks. diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index a6d5f46c1..80c2581dc 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2208,7 +2208,7 @@ void CWallet::AvailableCoins(vector& vCoins, bool fOnlyConfirmed, const { #ifdef KOMODO_ENABLE_INTEREST extern char ASSETCHAINS_SYMBOL[16]; - if ( strcmp(ASSETCHAINS_SYMBOL,"REVS") == 0 && chainActive.Tip() != 0 ) + if ( ASSETCHAINS_SYMBOL[0] == 0 && nHeight >= 60000 && chainActive.Tip() != 0 ) { if ( pcoin->vout[i].nValue >= COIN ) { @@ -2458,7 +2458,7 @@ bool CWallet::SelectCoins(const CAmount& nTargetValue, set= nTargetValue); } -fprintf(stderr,"nValueRet %8f vs target %.8f\n",(double)nValueRet/COIN,(double)nTargetValue/COIN); +//fprintf(stderr,"nValueRet %8f vs target %.8f\n",(double)nValueRet/COIN,(double)nTargetValue/COIN); return (SelectCoinsMinConf(nTargetValue, 1, 6, vCoins, setCoinsRet, nValueRet,interestp) || SelectCoinsMinConf(nTargetValue, 1, 1, vCoins, setCoinsRet, nValueRet,interestp) || (bSpendZeroConfChange && SelectCoinsMinConf(nTargetValue, 0, 1, vCoins, setCoinsRet, nValueRet,interestp))); @@ -2591,16 +2591,16 @@ bool CWallet::CreateTransaction(const vector& vecSend, //reflecting an assumption the user would accept a bit more delay for //a chance at a free transaction. //But mempool inputs might still be in the mempool, so their age stays 0 - fprintf(stderr,"nCredit %.8f interest %.8f\n",(double)nCredit/COIN,(double)pcoin.first->vout[pcoin.second].interest/COIN); + //fprintf(stderr,"nCredit %.8f interest %.8f\n",(double)nCredit/COIN,(double)pcoin.first->vout[pcoin.second].interest/COIN); interest2 += pcoin.first->vout[pcoin.second].interest; int age = pcoin.first->GetDepthInMainChain(); if (age != 0) age += 1; dPriority += (double)nCredit * age; } - fprintf(stderr,"interest sum %.8f, interest2 %.8f\n",(double)interest/COIN,(double)interest2/COIN); + //fprintf(stderr,"interest sum %.8f, interest2 %.8f\n",(double)interest/COIN,(double)interest2/COIN); CAmount nChange = (nValueIn - nValue + interest); -fprintf(stderr,"wallet change %.8f (%.8f - %.8f) interest %.8f total %.8f\n",(double)nChange/COIN,(double)nValueIn/COIN,(double)nValue/COIN,(double)interest/COIN,(double)nTotalValue/COIN); +//fprintf(stderr,"wallet change %.8f (%.8f - %.8f) interest %.8f total %.8f\n",(double)nChange/COIN,(double)nValueIn/COIN,(double)nValue/COIN,(double)interest/COIN,(double)nTotalValue/COIN); if (nSubtractFeeFromAmount == 0) nChange -= nFeeRet; From 98f682257aad19151b0b6b9f0890e2dbc29173ad Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 17:59:15 -0300 Subject: [PATCH 67/80] test --- src/coins.cpp | 4 ++-- src/komodo_interest.h | 2 +- src/main.cpp | 2 +- src/wallet/wallet.cpp | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/coins.cpp b/src/coins.cpp index 7c3555f13..ca8bf3b46 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -398,9 +398,9 @@ CAmount CCoinsViewCache::GetValueIn(int32_t nHeight,int64_t *interestp,const CTr value = GetOutputFor(tx.vin[i]).nValue; nResult += value; #ifdef KOMODO_ENABLE_INTEREST - if ( value >= COIN ) + if ( ASSETCHAINS_SYMBOL[0] == 0 && nHeight >= 60000 ) { - if ( ASSETCHAINS_SYMBOL[0] == 0 && nHeight >= 60000 ) + if ( value >= 10*COIN ) { int64_t interest; int32_t txheight; uint32_t locktime; interest = komodo_accrued_interest(&txheight,&locktime,tx.vin[i].prevout.hash,tx.vin[i].prevout.n,0,value); diff --git a/src/komodo_interest.h b/src/komodo_interest.h index e9a179e08..b58e45a90 100644 --- a/src/komodo_interest.h +++ b/src/komodo_interest.h @@ -58,7 +58,7 @@ uint64_t komodo_moneysupply(int32_t height) uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime) { int32_t minutes; uint64_t numerator,denominator,interest = 0; - if ( komodo_moneysupply(txheight) < MAX_MONEY && nLockTime >= LOCKTIME_THRESHOLD && tiptime != 0 && nLockTime < tiptime && nValue >= COIN ) + if ( komodo_moneysupply(txheight) < MAX_MONEY && nLockTime >= LOCKTIME_THRESHOLD && tiptime != 0 && nLockTime < tiptime && nValue >= 10*COIN ) { if ( (minutes= (tiptime - nLockTime) / 60) > 1 ) { diff --git a/src/main.cpp b/src/main.cpp index c34044672..79d3fde9d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1721,7 +1721,7 @@ bool NonContextualCheckInputs(const CTransaction& tx, CValidationState &state, c #ifdef KOMODO_ENABLE_INTEREST if ( ASSETCHAINS_SYMBOL[0] == 0 && nHeight >= 60000 ) { - if ( coins->vout[prevout.n].nValue >= COIN ) + if ( coins->vout[prevout.n].nValue >= 10*COIN ) { int64_t interest; int32_t txheight; uint32_t locktime; if ( (interest= komodo_accrued_interest(&txheight,&locktime,prevout.hash,prevout.n,0,coins->vout[prevout.n].nValue)) != 0 ) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 80c2581dc..60ee75694 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2210,7 +2210,7 @@ void CWallet::AvailableCoins(vector& vCoins, bool fOnlyConfirmed, const extern char ASSETCHAINS_SYMBOL[16]; if ( ASSETCHAINS_SYMBOL[0] == 0 && nHeight >= 60000 && chainActive.Tip() != 0 ) { - if ( pcoin->vout[i].nValue >= COIN ) + if ( pcoin->vout[i].nValue >= 10*COIN ) { interest = komodo_interest(chainActive.Tip()->nHeight+1,pcoin->vout[i].nValue,pcoin->nLockTime,chainActive.Tip()->nTime); if ( interest != 0 ) From 9fdf59749b8cbaf5c489efbd0a14d025adb9a1ff Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 18:01:26 -0300 Subject: [PATCH 68/80] test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 79d3fde9d..be9d34e40 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1719,7 +1719,7 @@ bool NonContextualCheckInputs(const CTransaction& tx, CValidationState &state, c // Check for negative or overflow input values nValueIn += coins->vout[prevout.n].nValue; #ifdef KOMODO_ENABLE_INTEREST - if ( ASSETCHAINS_SYMBOL[0] == 0 && nHeight >= 60000 ) + if ( ASSETCHAINS_SYMBOL[0] == 0 && chainActive.Tip() != 0 && chainActive.Tip()->nHeight >= 60000 ) { if ( coins->vout[prevout.n].nValue >= 10*COIN ) { From 55d97e1a6e1bc1f6f5aefa2662579d9f05807582 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 18:03:57 -0300 Subject: [PATCH 69/80] 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 60ee75694..d37b2793f 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2208,7 +2208,7 @@ void CWallet::AvailableCoins(vector& vCoins, bool fOnlyConfirmed, const { #ifdef KOMODO_ENABLE_INTEREST extern char ASSETCHAINS_SYMBOL[16]; - if ( ASSETCHAINS_SYMBOL[0] == 0 && nHeight >= 60000 && chainActive.Tip() != 0 ) + if ( ASSETCHAINS_SYMBOL[0] == 0 && chainActive.Tip() != 0 && chainActive.Tip()->nHeight >= 60000 ) { if ( pcoin->vout[i].nValue >= 10*COIN ) { From 075d0c069666bc871c81932e6c6a3ddb939f9942 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 18:15:15 -0300 Subject: [PATCH 70/80] 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 b58e45a90..b3b1e21f7 100644 --- a/src/komodo_interest.h +++ b/src/komodo_interest.h @@ -60,7 +60,7 @@ 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 >= 10*COIN ) { - if ( (minutes= (tiptime - nLockTime) / 60) > 1 ) + if ( (minutes= (tiptime - nLockTime) / 60) >= 60 ) { numerator = (nValue * KOMODO_INTEREST); denominator = (((uint64_t)365 * 24 * 60) / minutes); From 5590655121085a9e94e514450d69f3750854e9a6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 18:21:48 -0300 Subject: [PATCH 71/80] test --- src/pow.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 69789f5fa..e9d092bb2 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -127,7 +127,7 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned in } if ( nonz == 0 ) return(true); // will come back via different path with pubkey set - if ( height > 60000 ) + //if ( height > 60000 ) { if ( notaryid >= 0 ) { @@ -142,7 +142,7 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned in } } } - else + /*else { if ( special > 0 ) // special notary id == (height % numnotaries) { @@ -151,12 +151,10 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned in bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); flag = 1; } - } + }*/ } if (fNegative || bnTarget == 0 || fOverflow || bnTarget > UintToArith256(params.powLimit)) return error("CheckProofOfWork(): nBits below minimum work"); - //if ( height > 70000 ) - // bnTarget /= 64; // Check proof of work matches claimed amount if ( UintToArith256(hash) > bnTarget ) { From 4b36674267785be4f7fe418573ef40e053fd9dca Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 18:28:07 -0300 Subject: [PATCH 72/80] test --- src/wallet/test/wallet_tests.cpp | 70 ++++++++++++++++---------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/src/wallet/test/wallet_tests.cpp b/src/wallet/test/wallet_tests.cpp index a5bc52b8d..01482e08e 100644 --- a/src/wallet/test/wallet_tests.cpp +++ b/src/wallet/test/wallet_tests.cpp @@ -78,24 +78,24 @@ BOOST_AUTO_TEST_CASE(coin_selection_tests) empty_wallet(); // with an empty wallet we can't even pay one cent - BOOST_CHECK(!wallet.SelectCoinsMinConf( 1 * CENT, 1, 6, vCoins, setCoinsRet, nValueRet)); + BOOST_CHECK(!wallet.SelectCoinsMinConf( 1 * CENT, 1, 6, vCoins, setCoinsRet, nValueRet,0)); add_coin(1*CENT, 4); // add a new 1 cent coin // with a new 1 cent coin, we still can't find a mature 1 cent - BOOST_CHECK(!wallet.SelectCoinsMinConf( 1 * CENT, 1, 6, vCoins, setCoinsRet, nValueRet)); + BOOST_CHECK(!wallet.SelectCoinsMinConf( 1 * CENT, 1, 6, vCoins, setCoinsRet, nValueRet,0)); // but we can find a new 1 cent - BOOST_CHECK( wallet.SelectCoinsMinConf( 1 * CENT, 1, 1, vCoins, setCoinsRet, nValueRet)); + BOOST_CHECK( wallet.SelectCoinsMinConf( 1 * CENT, 1, 1, vCoins, setCoinsRet, nValueRet,0)); BOOST_CHECK_EQUAL(nValueRet, 1 * CENT); add_coin(2*CENT); // add a mature 2 cent coin // we can't make 3 cents of mature coins - BOOST_CHECK(!wallet.SelectCoinsMinConf( 3 * CENT, 1, 6, vCoins, setCoinsRet, nValueRet)); + BOOST_CHECK(!wallet.SelectCoinsMinConf( 3 * CENT, 1, 6, vCoins, setCoinsRet, nValueRet,0)); // we can make 3 cents of new coins - BOOST_CHECK( wallet.SelectCoinsMinConf( 3 * CENT, 1, 1, vCoins, setCoinsRet, nValueRet)); + BOOST_CHECK( wallet.SelectCoinsMinConf( 3 * CENT, 1, 1, vCoins, setCoinsRet, nValueRet,0)); BOOST_CHECK_EQUAL(nValueRet, 3 * CENT); add_coin(5*CENT); // add a mature 5 cent coin, @@ -105,33 +105,33 @@ BOOST_AUTO_TEST_CASE(coin_selection_tests) // now we have new: 1+10=11 (of which 10 was self-sent), and mature: 2+5+20=27. total = 38 // we can't make 38 cents only if we disallow new coins: - BOOST_CHECK(!wallet.SelectCoinsMinConf(38 * CENT, 1, 6, vCoins, setCoinsRet, nValueRet)); + BOOST_CHECK(!wallet.SelectCoinsMinConf(38 * CENT, 1, 6, vCoins, setCoinsRet, nValueRet,0)); // we can't even make 37 cents if we don't allow new coins even if they're from us - BOOST_CHECK(!wallet.SelectCoinsMinConf(38 * CENT, 6, 6, vCoins, setCoinsRet, nValueRet)); + BOOST_CHECK(!wallet.SelectCoinsMinConf(38 * CENT, 6, 6, vCoins, setCoinsRet, nValueRet,0)); // but we can make 37 cents if we accept new coins from ourself - BOOST_CHECK( wallet.SelectCoinsMinConf(37 * CENT, 1, 6, vCoins, setCoinsRet, nValueRet)); + BOOST_CHECK( wallet.SelectCoinsMinConf(37 * CENT, 1, 6, vCoins, setCoinsRet, nValueRet,0)); BOOST_CHECK_EQUAL(nValueRet, 37 * CENT); // and we can make 38 cents if we accept all new coins - BOOST_CHECK( wallet.SelectCoinsMinConf(38 * CENT, 1, 1, vCoins, setCoinsRet, nValueRet)); + BOOST_CHECK( wallet.SelectCoinsMinConf(38 * CENT, 1, 1, vCoins, setCoinsRet, nValueRet,0)); BOOST_CHECK_EQUAL(nValueRet, 38 * CENT); // try making 34 cents from 1,2,5,10,20 - we can't do it exactly - BOOST_CHECK( wallet.SelectCoinsMinConf(34 * CENT, 1, 1, vCoins, setCoinsRet, nValueRet)); + BOOST_CHECK( wallet.SelectCoinsMinConf(34 * CENT, 1, 1, vCoins, setCoinsRet, nValueRet,0)); BOOST_CHECK_GT(nValueRet, 34 * CENT); // but should get more than 34 cents BOOST_CHECK_EQUAL(setCoinsRet.size(), 3U); // the best should be 20+10+5. it's incredibly unlikely the 1 or 2 got included (but possible) // when we try making 7 cents, the smaller coins (1,2,5) are enough. We should see just 2+5 - BOOST_CHECK( wallet.SelectCoinsMinConf( 7 * CENT, 1, 1, vCoins, setCoinsRet, nValueRet)); + BOOST_CHECK( wallet.SelectCoinsMinConf( 7 * CENT, 1, 1, vCoins, setCoinsRet, nValueRet,0)); BOOST_CHECK_EQUAL(nValueRet, 7 * CENT); BOOST_CHECK_EQUAL(setCoinsRet.size(), 2U); // when we try making 8 cents, the smaller coins (1,2,5) are exactly enough. - BOOST_CHECK( wallet.SelectCoinsMinConf( 8 * CENT, 1, 1, vCoins, setCoinsRet, nValueRet)); + BOOST_CHECK( wallet.SelectCoinsMinConf( 8 * CENT, 1, 1, vCoins, setCoinsRet, nValueRet,0)); BOOST_CHECK(nValueRet == 8 * CENT); BOOST_CHECK_EQUAL(setCoinsRet.size(), 3U); // when we try making 9 cents, no subset of smaller coins is enough, and we get the next bigger coin (10) - BOOST_CHECK( wallet.SelectCoinsMinConf( 9 * CENT, 1, 1, vCoins, setCoinsRet, nValueRet)); + BOOST_CHECK( wallet.SelectCoinsMinConf( 9 * CENT, 1, 1, vCoins, setCoinsRet, nValueRet,0)); BOOST_CHECK_EQUAL(nValueRet, 10 * CENT); BOOST_CHECK_EQUAL(setCoinsRet.size(), 1U); @@ -145,30 +145,30 @@ BOOST_AUTO_TEST_CASE(coin_selection_tests) add_coin(30*CENT); // now we have 6+7+8+20+30 = 71 cents total // check that we have 71 and not 72 - BOOST_CHECK( wallet.SelectCoinsMinConf(71 * CENT, 1, 1, vCoins, setCoinsRet, nValueRet)); - BOOST_CHECK(!wallet.SelectCoinsMinConf(72 * CENT, 1, 1, vCoins, setCoinsRet, nValueRet)); + BOOST_CHECK( wallet.SelectCoinsMinConf(71 * CENT, 1, 1, vCoins, setCoinsRet, nValueRet,0)); + BOOST_CHECK(!wallet.SelectCoinsMinConf(72 * CENT, 1, 1, vCoins, setCoinsRet, nValueRet,0)); // now try making 16 cents. the best smaller coins can do is 6+7+8 = 21; not as good at the next biggest coin, 20 - BOOST_CHECK( wallet.SelectCoinsMinConf(16 * CENT, 1, 1, vCoins, setCoinsRet, nValueRet)); + BOOST_CHECK( wallet.SelectCoinsMinConf(16 * CENT, 1, 1, vCoins, setCoinsRet, nValueRet,0)); BOOST_CHECK_EQUAL(nValueRet, 20 * CENT); // we should get 20 in one coin BOOST_CHECK_EQUAL(setCoinsRet.size(), 1U); add_coin( 5*CENT); // now we have 5+6+7+8+20+30 = 75 cents total // now if we try making 16 cents again, the smaller coins can make 5+6+7 = 18 cents, better than the next biggest coin, 20 - BOOST_CHECK( wallet.SelectCoinsMinConf(16 * CENT, 1, 1, vCoins, setCoinsRet, nValueRet)); + BOOST_CHECK( wallet.SelectCoinsMinConf(16 * CENT, 1, 1, vCoins, setCoinsRet, nValueRet,0)); BOOST_CHECK_EQUAL(nValueRet, 18 * CENT); // we should get 18 in 3 coins BOOST_CHECK_EQUAL(setCoinsRet.size(), 3U); add_coin( 18*CENT); // now we have 5+6+7+8+18+20+30 // and now if we try making 16 cents again, the smaller coins can make 5+6+7 = 18 cents, the same as the next biggest coin, 18 - BOOST_CHECK( wallet.SelectCoinsMinConf(16 * CENT, 1, 1, vCoins, setCoinsRet, nValueRet)); + BOOST_CHECK( wallet.SelectCoinsMinConf(16 * CENT, 1, 1, vCoins, setCoinsRet, nValueRet,0)); BOOST_CHECK_EQUAL(nValueRet, 18 * CENT); // we should get 18 in 1 coin BOOST_CHECK_EQUAL(setCoinsRet.size(), 1U); // because in the event of a tie, the biggest coin wins // now try making 11 cents. we should get 5+6 - BOOST_CHECK( wallet.SelectCoinsMinConf(11 * CENT, 1, 1, vCoins, setCoinsRet, nValueRet)); + BOOST_CHECK( wallet.SelectCoinsMinConf(11 * CENT, 1, 1, vCoins, setCoinsRet, nValueRet,0)); BOOST_CHECK_EQUAL(nValueRet, 11 * CENT); BOOST_CHECK_EQUAL(setCoinsRet.size(), 2U); @@ -177,11 +177,11 @@ BOOST_AUTO_TEST_CASE(coin_selection_tests) add_coin( 2*COIN); add_coin( 3*COIN); add_coin( 4*COIN); // now we have 5+6+7+8+18+20+30+100+200+300+400 = 1094 cents - BOOST_CHECK( wallet.SelectCoinsMinConf(95 * CENT, 1, 1, vCoins, setCoinsRet, nValueRet)); + BOOST_CHECK( wallet.SelectCoinsMinConf(95 * CENT, 1, 1, vCoins, setCoinsRet, nValueRet,0)); BOOST_CHECK_EQUAL(nValueRet, 1 * COIN); // we should get 1 BTC in 1 coin BOOST_CHECK_EQUAL(setCoinsRet.size(), 1U); - BOOST_CHECK( wallet.SelectCoinsMinConf(195 * CENT, 1, 1, vCoins, setCoinsRet, nValueRet)); + BOOST_CHECK( wallet.SelectCoinsMinConf(195 * CENT, 1, 1, vCoins, setCoinsRet, nValueRet,0)); BOOST_CHECK_EQUAL(nValueRet, 2 * COIN); // we should get 2 BTC in 1 coin BOOST_CHECK_EQUAL(setCoinsRet.size(), 1U); @@ -195,14 +195,14 @@ BOOST_AUTO_TEST_CASE(coin_selection_tests) // try making 1 cent from 0.1 + 0.2 + 0.3 + 0.4 + 0.5 = 1.5 cents // we'll get sub-cent change whatever happens, so can expect 1.0 exactly - BOOST_CHECK( wallet.SelectCoinsMinConf(1 * CENT, 1, 1, vCoins, setCoinsRet, nValueRet)); + BOOST_CHECK( wallet.SelectCoinsMinConf(1 * CENT, 1, 1, vCoins, setCoinsRet, nValueRet,0)); BOOST_CHECK_EQUAL(nValueRet, 1 * CENT); // but if we add a bigger coin, making it possible to avoid sub-cent change, things change: add_coin(1111*CENT); // try making 1 cent from 0.1 + 0.2 + 0.3 + 0.4 + 0.5 + 1111 = 1112.5 cents - BOOST_CHECK( wallet.SelectCoinsMinConf(1 * CENT, 1, 1, vCoins, setCoinsRet, nValueRet)); + BOOST_CHECK( wallet.SelectCoinsMinConf(1 * CENT, 1, 1, vCoins, setCoinsRet, nValueRet,0)); BOOST_CHECK_EQUAL(nValueRet, 1 * CENT); // we should get the exact amount // if we add more sub-cent coins: @@ -210,7 +210,7 @@ BOOST_AUTO_TEST_CASE(coin_selection_tests) add_coin(0.7*CENT); // and try again to make 1.0 cents, we can still make 1.0 cents - BOOST_CHECK( wallet.SelectCoinsMinConf(1 * CENT, 1, 1, vCoins, setCoinsRet, nValueRet)); + BOOST_CHECK( wallet.SelectCoinsMinConf(1 * CENT, 1, 1, vCoins, setCoinsRet, nValueRet,0)); BOOST_CHECK_EQUAL(nValueRet, 1 * CENT); // we should get the exact amount // run the 'mtgox' test (see http://blockexplorer.com/tx/29a3efd3ef04f9153d47a990bd7b048a4b2d213daaa5fb8ed670fb85f13bdbcf) @@ -219,7 +219,7 @@ BOOST_AUTO_TEST_CASE(coin_selection_tests) for (int i = 0; i < 20; i++) add_coin(50000 * COIN); - BOOST_CHECK( wallet.SelectCoinsMinConf(500000 * COIN, 1, 1, vCoins, setCoinsRet, nValueRet)); + BOOST_CHECK( wallet.SelectCoinsMinConf(500000 * COIN, 1, 1, vCoins, setCoinsRet, nValueRet,0)); BOOST_CHECK_EQUAL(nValueRet, 500000 * COIN); // we should get the exact amount BOOST_CHECK_EQUAL(setCoinsRet.size(), 10U); // in ten coins @@ -232,7 +232,7 @@ BOOST_AUTO_TEST_CASE(coin_selection_tests) add_coin(0.6 * CENT); add_coin(0.7 * CENT); add_coin(1111 * CENT); - BOOST_CHECK( wallet.SelectCoinsMinConf(1 * CENT, 1, 1, vCoins, setCoinsRet, nValueRet)); + BOOST_CHECK( wallet.SelectCoinsMinConf(1 * CENT, 1, 1, vCoins, setCoinsRet, nValueRet,0)); BOOST_CHECK_EQUAL(nValueRet, 1111 * CENT); // we get the bigger coin BOOST_CHECK_EQUAL(setCoinsRet.size(), 1U); @@ -242,7 +242,7 @@ BOOST_AUTO_TEST_CASE(coin_selection_tests) add_coin(0.6 * CENT); add_coin(0.8 * CENT); add_coin(1111 * CENT); - BOOST_CHECK( wallet.SelectCoinsMinConf(1 * CENT, 1, 1, vCoins, setCoinsRet, nValueRet)); + BOOST_CHECK( wallet.SelectCoinsMinConf(1 * CENT, 1, 1, vCoins, setCoinsRet, nValueRet,0)); BOOST_CHECK_EQUAL(nValueRet, 1 * CENT); // we should get the exact amount BOOST_CHECK_EQUAL(setCoinsRet.size(), 2U); // in two coins 0.4+0.6 @@ -253,12 +253,12 @@ BOOST_AUTO_TEST_CASE(coin_selection_tests) add_coin(1 * COIN); // trying to make 1.0001 from these three coins - BOOST_CHECK( wallet.SelectCoinsMinConf(1.0001 * COIN, 1, 1, vCoins, setCoinsRet, nValueRet)); + BOOST_CHECK( wallet.SelectCoinsMinConf(1.0001 * COIN, 1, 1, vCoins, setCoinsRet, nValueRet,0)); BOOST_CHECK_EQUAL(nValueRet, 1.0105 * COIN); // we should get all coins BOOST_CHECK_EQUAL(setCoinsRet.size(), 3U); // but if we try to make 0.999, we should take the bigger of the two small coins to avoid sub-cent change - BOOST_CHECK( wallet.SelectCoinsMinConf(0.999 * COIN, 1, 1, vCoins, setCoinsRet, nValueRet)); + BOOST_CHECK( wallet.SelectCoinsMinConf(0.999 * COIN, 1, 1, vCoins, setCoinsRet, nValueRet,0)); BOOST_CHECK_EQUAL(nValueRet, 1.01 * COIN); // we should get 1 + 0.01 BOOST_CHECK_EQUAL(setCoinsRet.size(), 2U); @@ -270,8 +270,8 @@ BOOST_AUTO_TEST_CASE(coin_selection_tests) // picking 50 from 100 coins doesn't depend on the shuffle, // but does depend on randomness in the stochastic approximation code - BOOST_CHECK(wallet.SelectCoinsMinConf(50 * COIN, 1, 6, vCoins, setCoinsRet , nValueRet)); - BOOST_CHECK(wallet.SelectCoinsMinConf(50 * COIN, 1, 6, vCoins, setCoinsRet2, nValueRet)); + BOOST_CHECK(wallet.SelectCoinsMinConf(50 * COIN, 1, 6, vCoins, setCoinsRet , nValueRet,0)); + BOOST_CHECK(wallet.SelectCoinsMinConf(50 * COIN, 1, 6, vCoins, setCoinsRet2, nValueRet,0)); BOOST_CHECK(!equal_sets(setCoinsRet, setCoinsRet2)); int fails = 0; @@ -279,8 +279,8 @@ BOOST_AUTO_TEST_CASE(coin_selection_tests) { // selecting 1 from 100 identical coins depends on the shuffle; this test will fail 1% of the time // run the test RANDOM_REPEATS times and only complain if all of them fail - BOOST_CHECK(wallet.SelectCoinsMinConf(COIN, 1, 6, vCoins, setCoinsRet , nValueRet)); - BOOST_CHECK(wallet.SelectCoinsMinConf(COIN, 1, 6, vCoins, setCoinsRet2, nValueRet)); + BOOST_CHECK(wallet.SelectCoinsMinConf(COIN, 1, 6, vCoins, setCoinsRet , nValueRet,0)); + BOOST_CHECK(wallet.SelectCoinsMinConf(COIN, 1, 6, vCoins, setCoinsRet2, nValueRet,0)); if (equal_sets(setCoinsRet, setCoinsRet2)) fails++; } @@ -296,8 +296,8 @@ BOOST_AUTO_TEST_CASE(coin_selection_tests) { // selecting 1 from 100 identical coins depends on the shuffle; this test will fail 1% of the time // run the test RANDOM_REPEATS times and only complain if all of them fail - BOOST_CHECK(wallet.SelectCoinsMinConf(90*CENT, 1, 6, vCoins, setCoinsRet , nValueRet)); - BOOST_CHECK(wallet.SelectCoinsMinConf(90*CENT, 1, 6, vCoins, setCoinsRet2, nValueRet)); + BOOST_CHECK(wallet.SelectCoinsMinConf(90*CENT, 1, 6, vCoins, setCoinsRet , nValueRet,0)); + BOOST_CHECK(wallet.SelectCoinsMinConf(90*CENT, 1, 6, vCoins, setCoinsRet2, nValueRet,0)); if (equal_sets(setCoinsRet, setCoinsRet2)) fails++; } From 09e3cf94a43180076e45a0ce8c36aa128c98eaff Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 19:07:45 -0300 Subject: [PATCH 73/80] test --- src/komodo.h | 3 +-- src/komodo_bitcoind.h | 1 - src/rpcmisc.cpp | 3 +++ src/wallet/rpcwallet.cpp | 26 ++++++++++++++++++++++++++ 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index ccc94bb36..f308c893b 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -17,11 +17,10 @@ #define H_KOMODO_H // Todo: -// 00. standardize interests // 0. optimize assetchains RT loop // 1. error check fiat redeem amounts // 2. net balance limiter -// 3. verify: interest payment, reorgs +// 3. verify: reorgs // 4. automate notarization fee payouts // 5. automated distribution of test REVS snapshot diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 0c4748275..017703dbf 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -582,4 +582,3 @@ uint64_t komodo_accrued_interest(int32_t *txheightp,uint32_t *locktimep,uint256 } return(0); } - diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index 122ee0a90..dc4f82074 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -39,6 +39,8 @@ using namespace std; * * Or alternatively, create a specific query method for the information. **/ +uint64_t komod_interestsum(); + Value getinfo(const Array& params, bool fHelp) { extern uint256 NOTARIZED_HASH,NOTARIZED_DESTTXID; @@ -90,6 +92,7 @@ Value getinfo(const Array& params, bool fHelp) if (pwalletMain) { obj.push_back(Pair("walletversion", pwalletMain->GetVersion())); obj.push_back(Pair("balance", ValueFromAmount(pwalletMain->GetBalance()))); + obj.push_back(Pair("interest", ValueFromAmount(komod_interestsum()))); } #endif obj.push_back(Pair("blocks", (int)chainActive.Height())); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 12350db81..e51863dba 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2489,6 +2489,32 @@ Value listunspent(const Array& params, bool fHelp) return results; } +uint64_t komod_interestsum() +{ + uint64_t interest,sum = 0; + vector vecOutputs; + assert(pwalletMain != NULL); + LOCK2(cs_main, pwalletMain->cs_wallet); + pwalletMain->AvailableCoins(vecOutputs, false, NULL, true); + BOOST_FOREACH(const COutput& out,vecOutputs) + { + if (out.nDepth < nMinDepth || out.nDepth > nMaxDepth) + continue; + CAmount nValue = out.tx->vout[out.i].nValue; + if ( out.tx->nLockTime != 0 ) + { + BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock()); + CBlockIndex *tipindex,*pindex = it->second; + if ( pindex != 0 && (tipindex= chainActive.Tip()) != 0 ) + { + interest = komodo_interest(pindex->nHeight,nValue,out.tx->nLockTime,tipindex->nTime); + sum += interest; + } + } + } + return(sum); +} + Value zc_sample_joinsplit(const json_spirit::Array& params, bool fHelp) { if (fHelp) { From f207306e04f621ecae3d9641b57b0030c4317a39 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 19:09:39 -0300 Subject: [PATCH 74/80] test --- src/wallet/rpcwallet.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index e51863dba..8777c3b7e 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2498,8 +2498,6 @@ uint64_t komod_interestsum() pwalletMain->AvailableCoins(vecOutputs, false, NULL, true); BOOST_FOREACH(const COutput& out,vecOutputs) { - if (out.nDepth < nMinDepth || out.nDepth > nMaxDepth) - continue; CAmount nValue = out.tx->vout[out.i].nValue; if ( out.tx->nLockTime != 0 ) { From 7098e8b929adf9d53f7787855882729d720afd30 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 19:26:24 -0300 Subject: [PATCH 75/80] test --- src/wallet/rpcwallet.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 8777c3b7e..4854a4807 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -74,7 +74,7 @@ void EnsureWalletIsUnlocked() void WalletTxToJSON(const CWalletTx& wtx, Object& entry) { - int confirms = wtx.GetDepthInMainChain(); + int32_t i,n,txheight; uint32_t locktime; uint64_t interest = 0; int confirms = wtx.GetDepthInMainChain(); entry.push_back(Pair("confirmations", confirms)); if (wtx.IsCoinBase()) entry.push_back(Pair("generated", true)); @@ -86,6 +86,11 @@ void WalletTxToJSON(const CWalletTx& wtx, Object& entry) } uint256 hash = wtx.GetHash(); entry.push_back(Pair("txid", hash.GetHex())); + n = wtx.vout.size(); + for (i=0; i Date: Tue, 15 Nov 2016 19:30:14 -0300 Subject: [PATCH 76/80] test --- src/rpcmisc.cpp | 4 ++-- src/wallet/rpcwallet.cpp | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index dc4f82074..b2f8aa0b2 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -39,7 +39,7 @@ using namespace std; * * Or alternatively, create a specific query method for the information. **/ -uint64_t komod_interestsum(); +uint64_t komodo_interestsum(); Value getinfo(const Array& params, bool fHelp) { @@ -92,7 +92,7 @@ Value getinfo(const Array& params, bool fHelp) if (pwalletMain) { obj.push_back(Pair("walletversion", pwalletMain->GetVersion())); obj.push_back(Pair("balance", ValueFromAmount(pwalletMain->GetBalance()))); - obj.push_back(Pair("interest", ValueFromAmount(komod_interestsum()))); + obj.push_back(Pair("interest", ValueFromAmount(komodo_interestsum()))); } #endif obj.push_back(Pair("blocks", (int)chainActive.Height())); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 4854a4807..91638174d 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2494,7 +2494,7 @@ Value listunspent(const Array& params, bool fHelp) return results; } -uint64_t komod_interestsum() +uint64_t komodo_interestsum() { uint64_t interest,sum = 0; vector vecOutputs; @@ -3210,9 +3210,11 @@ Value z_gettotalbalance(const Array& params, bool fHelp) // so we use our own method to get balance of utxos. CAmount nBalance = getBalanceTaddr("", nMinDepth); CAmount nPrivateBalance = getBalanceZaddr("", nMinDepth); - CAmount nTotalBalance = nBalance + nPrivateBalance; + uint64_t interest = komodo_interestsum(); + CAmount nTotalBalance = nBalance + nPrivateBalance + interest; Object result; result.push_back(Pair("transparent", FormatMoney(nBalance, false))); + result.push_back(Pair("interest", FormatMoney(interest, false))); result.push_back(Pair("private", FormatMoney(nPrivateBalance, false))); result.push_back(Pair("total", FormatMoney(nTotalBalance, false))); return result; From 15bcd69e99f4377ec4751a4bce79cc132bea7358 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 19:30:46 -0300 Subject: [PATCH 77/80] test --- src/wallet/rpcwallet.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 91638174d..5c54b6f06 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -72,6 +72,8 @@ void EnsureWalletIsUnlocked() throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the wallet passphrase with walletpassphrase first."); } +uint64_t komodo_accrued_interest(int32_t *txheightp,uint32_t *locktimep,uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue); + void WalletTxToJSON(const CWalletTx& wtx, Object& entry) { int32_t i,n,txheight; uint32_t locktime; uint64_t interest = 0; int confirms = wtx.GetDepthInMainChain(); From 1f52f9467f79943fcc5352d0b2dee677dd973e3a Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 19:41:30 -0300 Subject: [PATCH 78/80] test --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 017703dbf..8979bae06 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -563,7 +563,7 @@ uint32_t komodo_interest_args(int32_t *txheightp,uint32_t *tiptimep,uint64_t *va *txheightp = pindex->nHeight; *tiptimep = tipindex->nTime; locktime = tx.nLockTime; - fprintf(stderr,"tx locktime.%u %.8f height.%d | tiptime.%u\n",locktime,(double)*valuep/COIN,*txheightp,*tiptimep); + //fprintf(stderr,"tx locktime.%u %.8f height.%d | tiptime.%u\n",locktime,(double)*valuep/COIN,*txheightp,*tiptimep); } } return(locktime); From 9be8be588fa7620324f791ce9afbd009a83b3bd1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 20:02:18 -0300 Subject: [PATCH 79/80] test --- src/wallet/rpcwallet.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 5c54b6f06..a6a8392a4 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -73,6 +73,7 @@ void EnsureWalletIsUnlocked() } uint64_t komodo_accrued_interest(int32_t *txheightp,uint32_t *locktimep,uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue); +uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime); void WalletTxToJSON(const CWalletTx& wtx, Object& entry) { @@ -90,7 +91,7 @@ void WalletTxToJSON(const CWalletTx& wtx, Object& entry) entry.push_back(Pair("txid", hash.GetHex())); n = wtx.vout.size(); for (i=0; inHeight,wtx.vout[i].nValue,wtx.nLockTime,mapBlockIndex[wtx.hashBlock]->nTime); entry.push_back(Pair("interest", interest)); Array conflicts; From cbe3042f73131b9f7161492f074c050ef7c14074 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 Nov 2016 21:26:50 -0300 Subject: [PATCH 80/80] test --- src/wallet/rpcwallet.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index a6a8392a4..1f2cb706b 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -77,7 +77,8 @@ uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uin void WalletTxToJSON(const CWalletTx& wtx, Object& entry) { - int32_t i,n,txheight; uint32_t locktime; uint64_t interest = 0; int confirms = wtx.GetDepthInMainChain(); + //int32_t i,n,txheight; uint32_t locktime; uint64_t interest = 0; + int confirms = wtx.GetDepthInMainChain(); entry.push_back(Pair("confirmations", confirms)); if (wtx.IsCoinBase()) entry.push_back(Pair("generated", true)); @@ -89,10 +90,10 @@ void WalletTxToJSON(const CWalletTx& wtx, Object& entry) } uint256 hash = wtx.GetHash(); entry.push_back(Pair("txid", hash.GetHex())); - n = wtx.vout.size(); - for (i=0; inHeight,wtx.vout[i].nValue,wtx.nLockTime,mapBlockIndex[wtx.hashBlock]->nTime); - entry.push_back(Pair("interest", interest)); + //n = wtx.vout.size(); + //for (i=0; inHeight,wtx.vout[i].nValue,wtx.nLockTime,mapBlockIndex[wtx.hashBlock]->nTime); + //entry.push_back(Pair("interest", interest)); Array conflicts; BOOST_FOREACH(const uint256& conflict, wtx.GetConflicts())