diff --git a/src/chain.h b/src/chain.h index 41cf28652..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,zfunds; //! Which # file this block is stored in (blk?????.dat) int nFile; @@ -181,6 +181,7 @@ public: void SetNull() { phashBlock = NULL; + newcoins = zfunds = 0; pprev = NULL; pskip = NULL; nHeight = 0; diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 785cfe6cf..27f0a26a4 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1532,3 +1532,72 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) else return(0); } +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 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= 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 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); +} + +int64_t komodo_coinsupply(int64_t *zfundsp,int32_t height) +{ + 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 ) + { + if ( pindex->newcoins == 0 && pindex->zfunds == 0 ) + { + if ( komodo_blockload(block,pindex) == 0 ) + pindex->newcoins = komodo_newcoins(&pindex->zfunds,pindex->nHeight,&block); + else + { + fprintf(stderr,"error loading block.%d\n",pindex->nHeight); + return(0); + } + } + supply += pindex->newcoins; + zfunds += pindex->zfunds; + //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; + } + } + *zfundsp = zfunds; + return(supply); +} 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..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; @@ -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; diff --git a/src/primitives/transaction.cpp b/src/primitives/transaction.cpp index d6ad31c3a..04222e854 100644 --- a/src/primitives/transaction.cpp +++ b/src/primitives/transaction.cpp @@ -232,11 +232,26 @@ CAmount CTransaction::GetJoinSplitValueIn() const { // NB: vpub_new "gives" money to the value pool just as inputs do nValue += it->vpub_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; diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index 065739a9a..04376f4a5 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(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; @@ -226,6 +227,25 @@ public: }; #endif +UniValue coinsupply(const UniValue& params, bool fHelp) +{ + 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(&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); +} + UniValue jumblr_deposit(const UniValue& params, bool fHelp) { int32_t retval; UniValue result(UniValue::VOBJ); 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 }, 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