Coin supply api
This commit is contained in:
@@ -121,7 +121,7 @@ public:
|
|||||||
|
|
||||||
//! height of the entry in the chain. The genesis block has height 0
|
//! height of the entry in the chain. The genesis block has height 0
|
||||||
int nHeight;
|
int nHeight;
|
||||||
|
int64_t newcoins;
|
||||||
//! Which # file this block is stored in (blk?????.dat)
|
//! Which # file this block is stored in (blk?????.dat)
|
||||||
int nFile;
|
int nFile;
|
||||||
|
|
||||||
|
|||||||
@@ -1532,3 +1532,50 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height)
|
|||||||
else return(0);
|
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; i<n; i++)
|
||||||
|
{
|
||||||
|
const CTransaction vintx,&tx = pblock->vtx[i];
|
||||||
|
if ( (m= tx.vin.size()) > 0 )
|
||||||
|
{
|
||||||
|
for (j=0; j<m; j++)
|
||||||
|
{
|
||||||
|
if ( i == 0 )
|
||||||
|
continue;
|
||||||
|
txid = tx.vin[j].prevout.hash;
|
||||||
|
vout = tx.vin[j].prevout.n;
|
||||||
|
if ( !GetTransaction(txid,vintx,hashBlock, false) || vout >= 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<m-1; j++)
|
||||||
|
voutsum += tx.vout[j].nValue;
|
||||||
|
script = tx.vout[j].scriptPubKey.data();
|
||||||
|
if ( script == 0 || script[0] != 0x6a )
|
||||||
|
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));
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ extern uint64_t KOMODO_INTERESTSUM,KOMODO_WALLETBALANCE;
|
|||||||
extern int32_t KOMODO_LASTMINED,JUMBLR_PAUSE,KOMODO_LONGESTCHAIN;
|
extern int32_t KOMODO_LASTMINED,JUMBLR_PAUSE,KOMODO_LONGESTCHAIN;
|
||||||
extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN];
|
extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN];
|
||||||
uint32_t komodo_segid32(char *coinaddr);
|
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);
|
int32_t notarizedtxid_height(char *dest,char *txidstr,int32_t *kmdnotarized_heightp);
|
||||||
#define KOMODO_VERSION "0.1.1"
|
#define KOMODO_VERSION "0.1.1"
|
||||||
extern uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT;
|
extern uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT;
|
||||||
@@ -226,6 +227,23 @@ public:
|
|||||||
};
|
};
|
||||||
#endif
|
#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 <height>\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)
|
UniValue jumblr_deposit(const UniValue& params, bool fHelp)
|
||||||
{
|
{
|
||||||
int32_t retval; UniValue result(UniValue::VOBJ);
|
int32_t retval; UniValue result(UniValue::VOBJ);
|
||||||
|
|||||||
@@ -207,6 +207,7 @@ extern UniValue getblocktemplate(const UniValue& params, bool fHelp);
|
|||||||
extern UniValue submitblock(const UniValue& params, bool fHelp);
|
extern UniValue submitblock(const UniValue& params, bool fHelp);
|
||||||
extern UniValue estimatefee(const UniValue& params, bool fHelp);
|
extern UniValue estimatefee(const UniValue& params, bool fHelp);
|
||||||
extern UniValue estimatepriority(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 getnewaddress(const UniValue& params, bool fHelp); // in rpcwallet.cpp
|
||||||
//extern UniValue getnewaddress64(const UniValue& params, bool fHelp); // in rpcwallet.cpp
|
//extern UniValue getnewaddress64(const UniValue& params, bool fHelp); // in rpcwallet.cpp
|
||||||
|
|||||||
Reference in New Issue
Block a user