From 7e282415b1b24c51f6bbc5b96b118139ce8b8e99 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 23:57:20 -1100 Subject: [PATCH] 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