Browse Source

Test

pull/4/head
jl777 6 years ago
parent
commit
2618950955
  1. 4
      src/chain.h
  2. 17
      src/komodo_bitcoind.h
  3. 8
      src/rpcmisc.cpp

4
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;

17
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; i<n; i++)
{
CTransaction vintx,&tx = pblock->vtx[i];
zfunds += (tx.GetJoinSplitValueOut() - tx.GetJoinSplitValueIn());
if ( (m= tx.vin.size()) > 0 )
{
for (j=0; j<m; j++)
@ -1564,15 +1565,17 @@ int64_t komodo_newcoins(int32_t nHeight,CBlock *pblock)
voutsum += tx.vout[j].nValue;
}
}
*zfundsp = zfunds;
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));
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);
}

8
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 <height>\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);
}

Loading…
Cancel
Save