From 261895095501daf0acd7134471628456c50e8bc6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 00:52:36 -1100 Subject: [PATCH] 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); } -- 2.42.0