From 6d2fc2903ee81ecbec27b83490a0044e13064c95 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 23:19:45 -1100 Subject: [PATCH 01/17] -stopat= --- src/komodo_globals.h | 2 +- src/komodo_utils.h | 1 + src/main.cpp | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/komodo_globals.h b/src/komodo_globals.h index c46486430..8dfc7108c 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -52,7 +52,7 @@ uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_PUBLIC char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN],ASSETCHAINS_USERPASS[4096]; uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT; -uint32_t ASSETCHAIN_INIT,ASSETCHAINS_CC; +uint32_t ASSETCHAIN_INIT,ASSETCHAINS_CC,KOMODO_STOPAT; uint32_t ASSETCHAINS_MAGIC = 2387029918; uint64_t KOMODO_INTERESTSUM,KOMODO_WALLETBALANCE; uint64_t ASSETCHAINS_ENDSUBSIDY,ASSETCHAINS_REWARD,ASSETCHAINS_HALVING,ASSETCHAINS_DECAY,ASSETCHAINS_COMMISSION,ASSETCHAINS_STAKED,ASSETCHAINS_SUPPLY = 10; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index f61fd05ea..8188a6154 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1539,6 +1539,7 @@ void komodo_args(char *argv0) } } } + KOMODO_STOPAT = GetArg("-stopat",0); ASSETCHAINS_CC = GetArg("-ac_cc",0); ASSETCHAINS_PUBLIC = GetArg("-ac_public",0); ASSETCHAINS_PRIVATE = GetArg("-ac_private",0); diff --git a/src/main.cpp b/src/main.cpp index 5f51a47c4..cfc97db81 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2691,7 +2691,8 @@ static int64_t nTimeTotal = 0; bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& view, bool fJustCheck,bool fCheckPOW) { const CChainParams& chainparams = Params(); - + if ( KOMODO_STOPAT != 0 && pindex->nHeight > KOMODO_STOPAT ) + return(false); //fprintf(stderr,"connectblock ht.%d\n",(int32_t)pindex->nHeight); AssertLockHeld(cs_main); bool fExpensiveChecks = true; From 7e282415b1b24c51f6bbc5b96b118139ce8b8e99 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 23:57:20 -1100 Subject: [PATCH 02/17] Coin supply api --- src/chain.h | 2 +- src/komodo_bitcoind.h | 47 +++++++++++++++++++++++++++++++++++++++++++ src/rpcmisc.cpp | 18 +++++++++++++++++ src/rpcserver.h | 1 + 4 files changed, 67 insertions(+), 1 deletion(-) diff --git a/src/chain.h b/src/chain.h index 41cf28652..8c86a7ede 100644 --- a/src/chain.h +++ b/src/chain.h @@ -121,7 +121,7 @@ public: //! height of the entry in the chain. The genesis block has height 0 int nHeight; - + int64_t newcoins; //! Which # file this block is stored in (blk?????.dat) int nFile; diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 785cfe6cf..7230757e5 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1532,3 +1532,50 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) else return(0); } +int64_t komodo_newcoins(CBlockIndex *pindex) +{ + int32_t i,j,m,n,vout; uint256 txid,hashBlock; int64_t vinsum=0,voutsum=0; + n = pblock->vtx.size(); + for (i=0; ivtx[i]; + if ( (m= tx.vin.size()) > 0 ) + { + for (j=0; j= vintx.vout.size() ) + { + fprintf(stderr,"ERROR: %s/v%d cant find\n",txid.ToString().c_str(),vout); + return(0); + } + vinsum += vintx.vout[vout].nValue; + } + } + if ( (m= tx.vout.size()) > 0 ) + { + for (j=0; j %.8f\n",pindex->nHeight,dstr(vinsum),dstr(voutsum),dstr(voutsum)-dstr(vinsum)); + return(voutsum - vinsum); +} + +int64_t komodo_coinsupply(int32_t height) +{ + CBlockIndex *pindex; int64_t supply = 0; + if ( (pindex= komodo_chainactive(height)) != 0 ) + { + if ( pindex->newcoins == 0 ) + pindex->newcoins = komodo_newcoins(pindex); + supply += pindex->newcoins; + } + return(supply); +} diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index 065739a9a..b055e591a 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -53,6 +53,7 @@ extern uint64_t KOMODO_INTERESTSUM,KOMODO_WALLETBALANCE; extern int32_t KOMODO_LASTMINED,JUMBLR_PAUSE,KOMODO_LONGESTCHAIN; extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; uint32_t komodo_segid32(char *coinaddr); +int64_t komodo_coinsupply(int32_t height); int32_t notarizedtxid_height(char *dest,char *txidstr,int32_t *kmdnotarized_heightp); #define KOMODO_VERSION "0.1.1" extern uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT; @@ -226,6 +227,23 @@ public: }; #endif +UniValue coinsupply(const UniValue& params, bool fHelp) +{ + int32_t height = 0; int64_t supply = 0; UniValue result(UniValue::VOBJ); + if (fHelp || params.size() > 1) + throw runtime_error("coinsupply \n"); + if ( params.size() == 0 ) + height = chainActive.Height(); + else height = atoi(params[0].get_str()); + if ( (supply= komodo_coinsupply(height)) > 0 ) + { + result.push_back(Pair("result", "success")); + result.push_back(Pair("height", (int)height)); + result.push_back(Pair("supply", ValueFromAmount(supply))); + } else result.push_back(Pair("error", "couldnt calculate supply")); + return(result); +} + UniValue jumblr_deposit(const UniValue& params, bool fHelp) { int32_t retval; UniValue result(UniValue::VOBJ); diff --git a/src/rpcserver.h b/src/rpcserver.h index 5bb949299..586d79a88 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -207,6 +207,7 @@ extern UniValue getblocktemplate(const UniValue& params, bool fHelp); extern UniValue submitblock(const UniValue& params, bool fHelp); extern UniValue estimatefee(const UniValue& params, bool fHelp); extern UniValue estimatepriority(const UniValue& params, bool fHelp); +extern UniValue coinsupply(const UniValue& params, bool fHelp); extern UniValue getnewaddress(const UniValue& params, bool fHelp); // in rpcwallet.cpp //extern UniValue getnewaddress64(const UniValue& params, bool fHelp); // in rpcwallet.cpp From ab98eb8e6ab5ea2005dae06145a9998e40fa5a68 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 23:59:32 -1100 Subject: [PATCH 03/17] 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 7230757e5..9005d8c04 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1534,7 +1534,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) int64_t komodo_newcoins(CBlockIndex *pindex) { - int32_t i,j,m,n,vout; uint256 txid,hashBlock; int64_t vinsum=0,voutsum=0; + int32_t i,j,m,n,vout; uint8_t *script; uint256 txid,hashBlock; int64_t vinsum=0,voutsum=0; n = pblock->vtx.size(); for (i=0; i Date: Thu, 12 Jul 2018 00:01:02 -1100 Subject: [PATCH 04/17] Test --- src/komodo_bitcoind.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 9005d8c04..b50273c79 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1538,7 +1538,7 @@ int64_t komodo_newcoins(CBlockIndex *pindex) n = pblock->vtx.size(); for (i=0; ivtx[i]; + const CTransaction vintx,&tx = pindex->vtx[i]; if ( (m= tx.vin.size()) > 0 ) { for (j=0; j Date: Thu, 12 Jul 2018 00:01:42 -1100 Subject: [PATCH 05/17] 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 b50273c79..cb2a4af53 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1538,7 +1538,7 @@ int64_t komodo_newcoins(CBlockIndex *pindex) n = pblock->vtx.size(); for (i=0; ivtx[i]; + CTransaction vintx,&tx = pindex->vtx[i]; if ( (m= tx.vin.size()) > 0 ) { for (j=0; j Date: Thu, 12 Jul 2018 00:04:45 -1100 Subject: [PATCH 06/17] Test --- src/komodo_bitcoind.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index cb2a4af53..7d9fd5c3a 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1532,13 +1532,13 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) else return(0); } -int64_t komodo_newcoins(CBlockIndex *pindex) +int64_t komodo_newcoins(CBlock *pblock) { int32_t i,j,m,n,vout; uint8_t *script; uint256 txid,hashBlock; int64_t vinsum=0,voutsum=0; n = pblock->vtx.size(); for (i=0; ivtx[i]; + CTransaction vintx,&tx = pblock->vtx[i]; if ( (m= tx.vin.size()) > 0 ) { for (j=0; jnewcoins == 0 ) - pindex->newcoins = komodo_newcoins(pindex); + { + if ( komodo_blockload(block,pindex) == 0 ) + pindex->newcoins = komodo_newcoins(&block); + else return(0); + } supply += pindex->newcoins; } return(supply); From 97a4e9238a097ae986508b7ee5b88d9c4b6675d9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 00:06:47 -1100 Subject: [PATCH 07/17] Test --- src/komodo_bitcoind.h | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 7d9fd5c3a..e24883c08 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1532,7 +1532,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) else return(0); } -int64_t komodo_newcoins(CBlock *pblock) +int64_t komodo_newcoins(int32_t nHeight,CBlock *pblock) { int32_t i,j,m,n,vout; uint8_t *script; uint256 txid,hashBlock; int64_t vinsum=0,voutsum=0; n = pblock->vtx.size(); @@ -1564,7 +1564,7 @@ int64_t komodo_newcoins(CBlock *pblock) voutsum += tx.vout[j].nValue; } } - fprintf(stderr,"ht.%d vins %.8f, vouts %.8f -> %.8f\n",pindex->nHeight,dstr(vinsum),dstr(voutsum),dstr(voutsum)-dstr(vinsum)); + fprintf(stderr,"ht.%d vins %.8f, vouts %.8f -> %.8f\n",nHeight,dstr(vinsum),dstr(voutsum),dstr(voutsum)-dstr(vinsum)); return(voutsum - vinsum); } @@ -1573,13 +1573,17 @@ int64_t komodo_coinsupply(int32_t height) CBlockIndex *pindex; CBlock block; int64_t supply = 0; if ( (pindex= komodo_chainactive(height)) != 0 ) { - if ( pindex->newcoins == 0 ) + while ( pindex != 0 && pindex->nHeight > 0 ) { - if ( komodo_blockload(block,pindex) == 0 ) - pindex->newcoins = komodo_newcoins(&block); - else return(0); + if ( pindex->newcoins == 0 ) + { + if ( komodo_blockload(block,pindex) == 0 ) + pindex->newcoins = komodo_newcoins(pindex->nHeight,&block); + else return(0); + } + supply += pindex->newcoins; + pindex = pindex->pprev; } - supply += pindex->newcoins; } return(supply); } From 26204e59df5d16a22ac2b3b35b1a6ef516432f2c Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 00:18:58 -1100 Subject: [PATCH 08/17] Add coinsupply rpc --- src/rpcserver.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index ed5110114..f37124d0c 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -280,6 +280,7 @@ static const CRPCCommand vRPCCommands[] = { "network", "clearbanned", &clearbanned, true }, /* Block chain and UTXO */ + { "blockchain", "coinsupply", &coinsupply, true }, { "blockchain", "getblockchaininfo", &getblockchaininfo, true }, { "blockchain", "getbestblockhash", &getbestblockhash, true }, { "blockchain", "getblockcount", &getblockcount, true }, From df74ee5fa0c5e28abccff98e19c9c89d980c31be Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 00:23:50 -1100 Subject: [PATCH 09/17] Test --- src/komodo_bitcoind.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index e24883c08..1fd179ae9 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1571,15 +1571,21 @@ int64_t komodo_newcoins(int32_t nHeight,CBlock *pblock) int64_t komodo_coinsupply(int32_t height) { CBlockIndex *pindex; CBlock block; int64_t supply = 0; + fprintf(stderr,"coinsupply %d\n",height); if ( (pindex= komodo_chainactive(height)) != 0 ) { while ( pindex != 0 && pindex->nHeight > 0 ) { + printf("start ht.%d\n",pindex->nHeight); if ( pindex->newcoins == 0 ) { if ( komodo_blockload(block,pindex) == 0 ) pindex->newcoins = komodo_newcoins(pindex->nHeight,&block); - else return(0); + else + { + fprintf(stderr,"error loading block.%d\n",pindex->nHeight); + return(0); + } } supply += pindex->newcoins; pindex = pindex->pprev; From a46d6afb2b2670c2b7973db24787cb06a82ef53f Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 00:28:15 -1100 Subject: [PATCH 10/17] Test --- src/chain.h | 1 + src/komodo_bitcoind.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/chain.h b/src/chain.h index 8c86a7ede..5400abb00 100644 --- a/src/chain.h +++ b/src/chain.h @@ -181,6 +181,7 @@ public: void SetNull() { phashBlock = NULL; + newcoins = 0; pprev = NULL; pskip = NULL; nHeight = 0; diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 1fd179ae9..6c5f615f3 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1576,7 +1576,6 @@ int64_t komodo_coinsupply(int32_t height) { while ( pindex != 0 && pindex->nHeight > 0 ) { - printf("start ht.%d\n",pindex->nHeight); if ( pindex->newcoins == 0 ) { if ( komodo_blockload(block,pindex) == 0 ) @@ -1588,6 +1587,7 @@ int64_t komodo_coinsupply(int32_t height) } } supply += pindex->newcoins; + printf("start ht.%d new %.8f -> supply %.8f\n",pindex->nHeight,dstr(pindex->newcoins),dstr(supply)); pindex = pindex->pprev; } } From 67459d80b4680504c80a9dec77556c770c398714 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 00:39:04 -1100 Subject: [PATCH 11/17] Test --- src/komodo_bitcoind.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 6c5f615f3..5140c0d27 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1564,6 +1564,7 @@ int64_t komodo_newcoins(int32_t nHeight,CBlock *pblock) voutsum += tx.vout[j].nValue; } } + if ( voutsum-vinsum > 100000*SATOSHIDEN || voutsum-vinsum < 0 ) fprintf(stderr,"ht.%d vins %.8f, vouts %.8f -> %.8f\n",nHeight,dstr(vinsum),dstr(voutsum),dstr(voutsum)-dstr(vinsum)); return(voutsum - vinsum); } @@ -1571,7 +1572,7 @@ int64_t komodo_newcoins(int32_t nHeight,CBlock *pblock) int64_t komodo_coinsupply(int32_t height) { CBlockIndex *pindex; CBlock block; int64_t supply = 0; - fprintf(stderr,"coinsupply %d\n",height); + //fprintf(stderr,"coinsupply %d\n",height); if ( (pindex= komodo_chainactive(height)) != 0 ) { while ( pindex != 0 && pindex->nHeight > 0 ) @@ -1587,7 +1588,7 @@ int64_t komodo_coinsupply(int32_t height) } } supply += pindex->newcoins; - printf("start ht.%d new %.8f -> supply %.8f\n",pindex->nHeight,dstr(pindex->newcoins),dstr(supply)); + //printf("start ht.%d new %.8f -> supply %.8f\n",pindex->nHeight,dstr(pindex->newcoins),dstr(supply)); pindex = pindex->pprev; } } From 261895095501daf0acd7134471628456c50e8bc6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 00:52:36 -1100 Subject: [PATCH 12/17] Test --- src/chain.h | 4 ++-- src/komodo_bitcoind.h | 17 +++++++++++------ src/rpcmisc.cpp | 8 +++++--- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/chain.h b/src/chain.h index 5400abb00..71d788531 100644 --- a/src/chain.h +++ b/src/chain.h @@ -121,7 +121,7 @@ public: //! height of the entry in the chain. The genesis block has height 0 int nHeight; - int64_t newcoins; + int64_t newcoins,zfunds; //! Which # file this block is stored in (blk?????.dat) int nFile; @@ -181,7 +181,7 @@ public: void SetNull() { phashBlock = NULL; - newcoins = 0; + newcoins = zfunds = 0; pprev = NULL; pskip = NULL; nHeight = 0; diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 5140c0d27..e9bde8595 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1532,13 +1532,14 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) else return(0); } -int64_t komodo_newcoins(int32_t nHeight,CBlock *pblock) +int64_t komodo_newcoins(int64_t *zfundsp,int32_t nHeight,CBlock *pblock) { - int32_t i,j,m,n,vout; uint8_t *script; uint256 txid,hashBlock; int64_t vinsum=0,voutsum=0; + int32_t i,j,m,n,vout; uint8_t *script; uint256 txid,hashBlock; int64_t zfunds=0,vinsum=0,voutsum=0; n = pblock->vtx.size(); for (i=0; ivtx[i]; + zfunds += (tx.GetJoinSplitValueOut() - tx.GetJoinSplitValueIn()); if ( (m= tx.vin.size()) > 0 ) { for (j=0; j 100000*SATOSHIDEN || voutsum-vinsum < 0 ) - fprintf(stderr,"ht.%d vins %.8f, vouts %.8f -> %.8f\n",nHeight,dstr(vinsum),dstr(voutsum),dstr(voutsum)-dstr(vinsum)); + fprintf(stderr,"ht.%d vins %.8f, vouts %.8f -> %.8f zfunds %.8f\n",nHeight,dstr(vinsum),dstr(voutsum),dstr(voutsum)-dstr(vinsum),dstr(zfunds)); return(voutsum - vinsum); } -int64_t komodo_coinsupply(int32_t height) +int64_t komodo_coinsupply(int64_t *zfundsp,int32_t height) { - CBlockIndex *pindex; CBlock block; int64_t supply = 0; + CBlockIndex *pindex; CBlock block; int64_t zfunds=0,supply = 0; //fprintf(stderr,"coinsupply %d\n",height); + *zfundsp = 0; if ( (pindex= komodo_chainactive(height)) != 0 ) { while ( pindex != 0 && pindex->nHeight > 0 ) @@ -1580,7 +1583,7 @@ int64_t komodo_coinsupply(int32_t height) if ( pindex->newcoins == 0 ) { if ( komodo_blockload(block,pindex) == 0 ) - pindex->newcoins = komodo_newcoins(pindex->nHeight,&block); + pindex->newcoins = komodo_newcoins(&pindex->zfunds,pindex->nHeight,&block); else { fprintf(stderr,"error loading block.%d\n",pindex->nHeight); @@ -1588,9 +1591,11 @@ int64_t komodo_coinsupply(int32_t height) } } supply += pindex->newcoins; + zfunds += pindex->zfunds; //printf("start ht.%d new %.8f -> supply %.8f\n",pindex->nHeight,dstr(pindex->newcoins),dstr(supply)); pindex = pindex->pprev; } } + *zfundsp = zfunds; return(supply); } diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index b055e591a..04376f4a5 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -53,7 +53,7 @@ extern uint64_t KOMODO_INTERESTSUM,KOMODO_WALLETBALANCE; extern int32_t KOMODO_LASTMINED,JUMBLR_PAUSE,KOMODO_LONGESTCHAIN; extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; uint32_t komodo_segid32(char *coinaddr); -int64_t komodo_coinsupply(int32_t height); +int64_t komodo_coinsupply(int64_t *zfundsp,int32_t height); int32_t notarizedtxid_height(char *dest,char *txidstr,int32_t *kmdnotarized_heightp); #define KOMODO_VERSION "0.1.1" extern uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT; @@ -229,17 +229,19 @@ public: UniValue coinsupply(const UniValue& params, bool fHelp) { - int32_t height = 0; int64_t supply = 0; UniValue result(UniValue::VOBJ); + int32_t height = 0; int64_t zfunds,supply = 0; UniValue result(UniValue::VOBJ); if (fHelp || params.size() > 1) throw runtime_error("coinsupply \n"); if ( params.size() == 0 ) height = chainActive.Height(); else height = atoi(params[0].get_str()); - if ( (supply= komodo_coinsupply(height)) > 0 ) + if ( (supply= komodo_coinsupply(&zfunds,height)) > 0 ) { result.push_back(Pair("result", "success")); result.push_back(Pair("height", (int)height)); result.push_back(Pair("supply", ValueFromAmount(supply))); + result.push_back(Pair("zfunds", ValueFromAmount(zfunds))); + result.push_back(Pair("total", ValueFromAmount(zfunds + supply))); } else result.push_back(Pair("error", "couldnt calculate supply")); return(result); } From ae4dbe22bbe32f6a8d1f71db7ac2efa47badec67 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 00:58:25 -1100 Subject: [PATCH 13/17] tx.GetJoinSplitValueOut() --- src/komodo_bitcoind.h | 2 +- src/primitives/transaction.cpp | 17 ++++++++++++++++- src/primitives/transaction.h | 2 ++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index e9bde8595..0293c0dd5 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1539,7 +1539,7 @@ int64_t komodo_newcoins(int64_t *zfundsp,int32_t nHeight,CBlock *pblock) for (i=0; ivtx[i]; - zfunds += (tx.GetJoinSplitValueOut() - tx.GetJoinSplitValueIn()); + zfunds += (tx.GetJoinSplitValueIn() - tx.GetJoinSplitValueOut()); if ( (m= tx.vin.size()) > 0 ) { for (j=0; jvpub_new; - + if (!MoneyRange(it->vpub_new) || !MoneyRange(nValue)) throw std::runtime_error("CTransaction::GetJoinSplitValueIn(): value out of range"); } + + return nValue; +} +CAmount CTransaction::GetJoinSplitValueOut() const +{ + CAmount nValue = 0; + for (std::vector::const_iterator it(vjoinsplit.begin()); it != vjoinsplit.end(); ++it) + { + // NB: vpub_new "gives" money to the value pool just as inputs do + nValue += it->vpub_old; + + if (!MoneyRange(it->vpub_old) || !MoneyRange(nValue)) + throw std::runtime_error("CTransaction::GetJoinSplitValueOut(): value out of range"); + } + return nValue; } diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index 88ee9a312..e3615c120 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -445,6 +445,8 @@ public: // Return sum of JoinSplit vpub_new CAmount GetJoinSplitValueIn() const; + // Return sum of JoinSplit vpub_old + CAmount GetJoinSplitValueOut() const; // Compute priority, given priority of inputs and (optionally) tx size double ComputePriority(double dPriorityInputs, unsigned int nTxSize=0) const; From 1ec2a42ff317ab4cbc81dafb49d6108a6ea6cc16 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 01:01:45 -1100 Subject: [PATCH 14/17] Test --- src/komodo_bitcoind.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 0293c0dd5..1ceeebd38 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1566,7 +1566,12 @@ int64_t komodo_newcoins(int64_t *zfundsp,int32_t nHeight,CBlock *pblock) } } *zfundsp = zfunds; - if ( voutsum-vinsum > 100000*SATOSHIDEN || voutsum-vinsum < 0 ) + if ( ASSETCHAINS_SYMBOL[0] == 0 && (voutsum-vinsum) == 100003*SATOSHIDEN ) + { + fprintf(stderr,"ht.%d special case return 3\n",nHeight); + return(3 * SATOSHIDEN); + } + if ( voutsum-vinsum+zfunds > 100000*SATOSHIDEN || voutsum-vinsum+zfunds < 0 ) fprintf(stderr,"ht.%d vins %.8f, vouts %.8f -> %.8f zfunds %.8f\n",nHeight,dstr(vinsum),dstr(voutsum),dstr(voutsum)-dstr(vinsum),dstr(zfunds)); return(voutsum - vinsum); } From 3118a070000f4267ded1e5c70e3253f3a54c0551 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 01:16:41 -1100 Subject: [PATCH 15/17] Test --- src/komodo_bitcoind.h | 4 ++-- src/main.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 1ceeebd38..1c0264a3a 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1539,7 +1539,7 @@ int64_t komodo_newcoins(int64_t *zfundsp,int32_t nHeight,CBlock *pblock) for (i=0; ivtx[i]; - zfunds += (tx.GetJoinSplitValueIn() - tx.GetJoinSplitValueOut()); + zfunds += (tx.GetJoinSplitValueOut() - tx.GetJoinSplitValueIn()); if ( (m= tx.vin.size()) > 0 ) { for (j=0; jnewcoins; zfunds += pindex->zfunds; - //printf("start ht.%d new %.8f -> supply %.8f\n",pindex->nHeight,dstr(pindex->newcoins),dstr(supply)); + //printf("start ht.%d new %.8f -> supply %.8f zfunds %.8f -> %.8f\n",pindex->nHeight,dstr(pindex->newcoins),dstr(supply),dstr(pindex->zfunds),dstr(zfunds)); pindex = pindex->pprev; } } diff --git a/src/main.cpp b/src/main.cpp index cfc97db81..b08d2e522 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1104,7 +1104,7 @@ bool CheckTransactionWithoutProofVerification(const CTransaction& tx, CValidatio if ( ASSETCHAINS_PRIVATE != 0 ) { fprintf(stderr,"private chain nValue %.8f iscoinbase.%d\n",(double)txout.nValue/COIN,iscoinbase); - if ( txout.nValue > 0 && iscoinbase == 0 ) + if ( (txout.nValue > 0 && iscoinbase == 0) || tx.GetJoinSplitValueOut() > 0 ) return state.DoS(100, error("CheckTransaction(): this is a private chain, no public allowed"),REJECT_INVALID, "bad-txns-acprivacy-chain"); } nValueOut += txout.nValue; From 7130a7cdc8572f8376bb147fb8f4ffbdfc8ff4fe Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 01:21:32 -1100 Subject: [PATCH 16/17] Test --- src/komodo_bitcoind.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 1c0264a3a..f33fc2c01 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1566,11 +1566,8 @@ int64_t komodo_newcoins(int64_t *zfundsp,int32_t nHeight,CBlock *pblock) } } *zfundsp = zfunds; - if ( ASSETCHAINS_SYMBOL[0] == 0 && (voutsum-vinsum) == 100003*SATOSHIDEN ) - { - fprintf(stderr,"ht.%d special case return 3\n",nHeight); + if ( ASSETCHAINS_SYMBOL[0] == 0 && (voutsum-vinsum) == 100003*SATOSHIDEN ) // 15 times return(3 * SATOSHIDEN); - } if ( voutsum-vinsum+zfunds > 100000*SATOSHIDEN || voutsum-vinsum+zfunds < 0 ) fprintf(stderr,"ht.%d vins %.8f, vouts %.8f -> %.8f zfunds %.8f\n",nHeight,dstr(vinsum),dstr(voutsum),dstr(voutsum)-dstr(vinsum),dstr(zfunds)); return(voutsum - vinsum); @@ -1585,7 +1582,7 @@ int64_t komodo_coinsupply(int64_t *zfundsp,int32_t height) { while ( pindex != 0 && pindex->nHeight > 0 ) { - if ( pindex->newcoins == 0 ) + if ( pindex->newcoins == 0 && pindex->zfunds == 0 ) { if ( komodo_blockload(block,pindex) == 0 ) pindex->newcoins = komodo_newcoins(&pindex->zfunds,pindex->nHeight,&block); From aa51eef61991942a6e7eed944d08b673e7c646d0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 01:37:55 -1100 Subject: [PATCH 17/17] coinsupply rpc call --- src/komodo_bitcoind.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index f33fc2c01..27f0a26a4 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1568,8 +1568,8 @@ int64_t komodo_newcoins(int64_t *zfundsp,int32_t nHeight,CBlock *pblock) *zfundsp = zfunds; if ( ASSETCHAINS_SYMBOL[0] == 0 && (voutsum-vinsum) == 100003*SATOSHIDEN ) // 15 times return(3 * SATOSHIDEN); - if ( voutsum-vinsum+zfunds > 100000*SATOSHIDEN || voutsum-vinsum+zfunds < 0 ) - fprintf(stderr,"ht.%d vins %.8f, vouts %.8f -> %.8f zfunds %.8f\n",nHeight,dstr(vinsum),dstr(voutsum),dstr(voutsum)-dstr(vinsum),dstr(zfunds)); + //if ( voutsum-vinsum+zfunds > 100000*SATOSHIDEN || voutsum-vinsum+zfunds < 0 ) + //. fprintf(stderr,"ht.%d vins %.8f, vouts %.8f -> %.8f zfunds %.8f\n",nHeight,dstr(vinsum),dstr(voutsum),dstr(voutsum)-dstr(vinsum),dstr(zfunds)); return(voutsum - vinsum); }