calc_MoM
This commit is contained in:
@@ -42,6 +42,25 @@ bits256 iguana_merkle(bits256 *tree,int32_t txn_count)
|
|||||||
return(tree[n]);
|
return(tree[n]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint256 komodo_calcMoM(int32_t height,int32_t MoMdepth)
|
||||||
|
{
|
||||||
|
static uint256 zero; bits256 MoM,*tree; CBlockIndex *pindex;
|
||||||
|
tree = (bits256 *)calloc(MoMdepth,sizeof(*tree));
|
||||||
|
for (i=0; i<MoMdepth; i++)
|
||||||
|
{
|
||||||
|
if ( (pindex= komodo_chainactive(height - i)) != 0 )
|
||||||
|
memcpy(&tree[i],&pindex->hashMerkleRoot,sizeof(bits256));
|
||||||
|
else
|
||||||
|
{
|
||||||
|
free(tree);
|
||||||
|
return(zero);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MoM = iguana_merkle(tree,MoMdepth);
|
||||||
|
free(tree);
|
||||||
|
return(*(uint256 *)&MoM);
|
||||||
|
}
|
||||||
|
|
||||||
struct komodo_ccdata_entry *komodo_allMoMs(int32_t *nump,uint256 *MoMoMp,int32_t kmdstarti,int32_t kmdendi)
|
struct komodo_ccdata_entry *komodo_allMoMs(int32_t *nump,uint256 *MoMoMp,int32_t kmdstarti,int32_t kmdendi)
|
||||||
{
|
{
|
||||||
struct komodo_ccdata_entry *allMoMs=0; bits256 *tree,tmp; struct komodo_ccdata *ccdata,*tmpptr; int32_t i,num,max;
|
struct komodo_ccdata_entry *allMoMs=0; bits256 *tree,tmp; struct komodo_ccdata *ccdata,*tmpptr; int32_t i,num,max;
|
||||||
@@ -73,7 +92,7 @@ struct komodo_ccdata_entry *komodo_allMoMs(int32_t *nump,uint256 *MoMoMp,int32_t
|
|||||||
for (i=0; i<num; i++)
|
for (i=0; i<num; i++)
|
||||||
memcpy(&tree[i],&allMoMs[i].MoM,sizeof(tree[i]));
|
memcpy(&tree[i],&allMoMs[i].MoM,sizeof(tree[i]));
|
||||||
tmp = iguana_merkle(tree,num);
|
tmp = iguana_merkle(tree,num);
|
||||||
memcpy(MoMoMp,&tree,sizeof(*MoMoMp));
|
memcpy(MoMoMp,&tmp,sizeof(*MoMoMp));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -763,6 +763,7 @@ int32_t komodo_kvsearch(uint256 *refpubkeyp,int32_t current_height,uint32_t *fla
|
|||||||
int32_t komodo_MoM(int32_t *notarized_htp,uint256 *MoMp,uint256 *kmdtxidp,int32_t nHeight,uint256 *MoMoMp,int32_t *MoMoMoffsetp,int32_t *MoMoMdepthp,int32_t *kmdstartip,int32_t *kmdendip);
|
int32_t komodo_MoM(int32_t *notarized_htp,uint256 *MoMp,uint256 *kmdtxidp,int32_t nHeight,uint256 *MoMoMp,int32_t *MoMoMoffsetp,int32_t *MoMoMdepthp,int32_t *kmdstartip,int32_t *kmdendip);
|
||||||
int32_t komodo_MoMoMdata(char *hexstr,int32_t hexsize,struct komodo_ccdataMoMoM *mdata,char *symbol,int32_t kmdheight,int32_t notarized_height);
|
int32_t komodo_MoMoMdata(char *hexstr,int32_t hexsize,struct komodo_ccdataMoMoM *mdata,char *symbol,int32_t kmdheight,int32_t notarized_height);
|
||||||
struct komodo_ccdata_entry *komodo_allMoMs(int32_t *nump,uint256 *MoMoMp,int32_t kmdstarti,int32_t kmdendi);
|
struct komodo_ccdata_entry *komodo_allMoMs(int32_t *nump,uint256 *MoMoMp,int32_t kmdstarti,int32_t kmdendi);
|
||||||
|
uint256 komodo_calcMoM(int32_t height,int32_t MoMdepth);
|
||||||
|
|
||||||
UniValue kvsearch(const UniValue& params, bool fHelp)
|
UniValue kvsearch(const UniValue& params, bool fHelp)
|
||||||
{
|
{
|
||||||
@@ -867,6 +868,25 @@ UniValue MoMoMdata(const UniValue& params, bool fHelp)
|
|||||||
return(ret);
|
return(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UniValue calc_MoM(const UniValue& params, bool fHelp)
|
||||||
|
{
|
||||||
|
int32_t height,MoMdepth; uint256 MoM; UniValue ret(UniValue::VOBJ); UniValue a(UniValue::VARR);
|
||||||
|
if ( fHelp || params.size() != 2 )
|
||||||
|
throw runtime_error("calc_MoM height MoMdepth\n");
|
||||||
|
LOCK(cs_main);
|
||||||
|
height = atoi(params[0].get_str().c_str());
|
||||||
|
MoMdepth = atoi(params[1].get_str().c_str());
|
||||||
|
if ( height <= 0 || MoMdepth <= 0 )
|
||||||
|
throw runtime_error("calc_MoM illegal height or MoMdepth\n");
|
||||||
|
//fprintf(stderr,"height_MoM height.%d\n",height);
|
||||||
|
MoM = komodo_calcMoM(height,MoMdepth);
|
||||||
|
ret.push_back(Pair("coin",(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL)));
|
||||||
|
ret.push_back(Pair("height",height));
|
||||||
|
ret.push_back(Pair("MoMdepth",MoMdepth));
|
||||||
|
ret.push_back(Pair("MoM",MoM.GetHex()));
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
UniValue height_MoM(const UniValue& params, bool fHelp)
|
UniValue height_MoM(const UniValue& params, bool fHelp)
|
||||||
{
|
{
|
||||||
int32_t height,depth,notarized_height,MoMoMdepth,MoMoMoffset,kmdstarti,kmdendi; uint256 MoM,MoMoM,kmdtxid; uint32_t timestamp = 0; UniValue ret(UniValue::VOBJ); UniValue a(UniValue::VARR);
|
int32_t height,depth,notarized_height,MoMoMdepth,MoMoMoffset,kmdstarti,kmdendi; uint256 MoM,MoMoM,kmdtxid; uint32_t timestamp = 0; UniValue ret(UniValue::VOBJ); UniValue a(UniValue::VARR);
|
||||||
|
|||||||
@@ -304,6 +304,7 @@ static const CRPCCommand vRPCCommands[] =
|
|||||||
{ "blockchain", "notaries", ¬aries, true },
|
{ "blockchain", "notaries", ¬aries, true },
|
||||||
{ "blockchain", "allMoMs", &allMoMs, true },
|
{ "blockchain", "allMoMs", &allMoMs, true },
|
||||||
{ "blockchain", "MoMoMdata", &MoMoMdata, true },
|
{ "blockchain", "MoMoMdata", &MoMoMdata, true },
|
||||||
|
{ "blockchain", "calc_MoM", &calc_MoM, true },
|
||||||
{ "blockchain", "height_MoM", &height_MoM, true },
|
{ "blockchain", "height_MoM", &height_MoM, true },
|
||||||
{ "blockchain", "txMoMproof", &txMoMproof, true },
|
{ "blockchain", "txMoMproof", &txMoMproof, true },
|
||||||
{ "blockchain", "minerids", &minerids, true },
|
{ "blockchain", "minerids", &minerids, true },
|
||||||
|
|||||||
@@ -314,6 +314,7 @@ extern UniValue z_validatepaymentdisclosure(const UniValue ¶ms, bool fHelp);
|
|||||||
|
|
||||||
extern UniValue allMoMs(const UniValue& params, bool fHelp);
|
extern UniValue allMoMs(const UniValue& params, bool fHelp);
|
||||||
extern UniValue MoMoMdata(const UniValue& params, bool fHelp);
|
extern UniValue MoMoMdata(const UniValue& params, bool fHelp);
|
||||||
|
extern UniValue calc_MoM(const UniValue& params, bool fHelp);
|
||||||
extern UniValue height_MoM(const UniValue& params, bool fHelp);
|
extern UniValue height_MoM(const UniValue& params, bool fHelp);
|
||||||
extern UniValue txMoMproof(const UniValue& params, bool fHelp);
|
extern UniValue txMoMproof(const UniValue& params, bool fHelp);
|
||||||
extern UniValue notaries(const UniValue& params, bool fHelp);
|
extern UniValue notaries(const UniValue& params, bool fHelp);
|
||||||
|
|||||||
Reference in New Issue
Block a user