diff --git a/src/komodo_ccdata.h b/src/komodo_ccdata.h index 68a45e3d8..f08a13a71 100644 --- a/src/komodo_ccdata.h +++ b/src/komodo_ccdata.h @@ -42,6 +42,44 @@ bits256 iguana_merkle(bits256 *tree,int32_t txn_count) return(tree[n]); } +struct komodo_ccdata_entry *komodo_allMoMs(int32_t *nump,uint256 *MoMoMp,int32_t *MoMoMdepthp,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; + num = max = 0; + portable_mutex_lock(&KOMODO_CC_mutex); + DL_FOREACH_SAFE(CC_data,ccdata,tmpptr) + { + if ( ccdata->MoMdata.height <= kmdendi && ccdata->MoMdata.height >= kmdstarti ) + { + if ( num >= max ) + { + max += 100; + allMoMs = (struct komodo_ccdata_entry *)realloc(allMoMs,max * sizeof(*allMoMs)); + } + allMoMs[num].MoM = ccdata->MoMdata.MoM; + allMoMs[num].notarized_height = ccdata->MoMdata.notarized_height; + allMoMs[num].height = ccdata->MoMdata.height; + allMoMs[num].txi = ccdata->MoMdata.txi; + strcpy(allMoMs[num].symbol,ccdata->symbol); + num++; + } + } + if ( (*nump= num) > 0 ) + { + tree = (bits256 *)calloc(sizeof(bits256),num*3); + for (i=0; inumpairs == 1 && notarized_height == 0) || ccdata->MoMdata.notarized_height <= notarized_height ) { starti = ccdata->MoMdata.height + 1; + if ( notarized_height == 0 ) + notarized_height = ccdata->MoMdata.notarized_height; break; } if ( mdata->numpairs >= maxpairs ) { maxpairs += 100; mdata->pairs = (struct komodo_ccdatapair *)realloc(mdata->pairs,sizeof(*mdata->pairs)*maxpairs); - fprintf(stderr,"pairs reallocated to %p num.%d\n",mdata->pairs,mdata->numpairs); + //fprintf(stderr,"pairs reallocated to %p num.%d\n",mdata->pairs,mdata->numpairs); } mdata->pairs[mdata->numpairs].notarized_height = ccdata->MoMdata.notarized_height; mdata->pairs[mdata->numpairs].MoMoMoffset = offset; @@ -85,7 +125,7 @@ int32_t komodo_MoMoMdata(char *hexstr,int32_t hexsize,struct komodo_ccdataMoMoM { max += 100; tree = (bits256 *)realloc(tree,sizeof(*tree)*max); - fprintf(stderr,"tree reallocated to %p max.%d\n",tree,max); + //fprintf(stderr,"tree reallocated to %p max.%d\n",tree,max); } memcpy(&tree[offset],&ccdata->MoMdata.MoM,sizeof(bits256)); offset++; @@ -124,7 +164,7 @@ int32_t komodo_MoMoMdata(char *hexstr,int32_t hexsize,struct komodo_ccdataMoMoM if ( i == mdata->numpairs && len*2+1 < hexsize ) { init_hexbytes_noT(hexstr,hexdata,len); - fprintf(stderr,"hexstr.(%s)\n",hexstr); + //fprintf(stderr,"hexstr.(%s)\n",hexstr); retval = 0; } else fprintf(stderr,"%s %d %d too much hexdata[%d] for hexstr[%d]\n",symbol,kmdheight,notarized_height,len,hexsize); } @@ -132,7 +172,7 @@ int32_t komodo_MoMoMdata(char *hexstr,int32_t hexsize,struct komodo_ccdataMoMoM } if ( tree != 0 ) { - fprintf(stderr,"free tree.%p\n",tree); + //fprintf(stderr,"free tree.%p\n",tree); free(tree); } return(retval); diff --git a/src/komodo_structs.h b/src/komodo_structs.h index df9cd2154..634edf74c 100644 --- a/src/komodo_structs.h +++ b/src/komodo_structs.h @@ -95,7 +95,8 @@ struct komodo_ccdataMoM int32_t MoMdepth,notarized_height,height,txi; }; -struct komodo_ccdatapair { int32_t notarized_height; uint32_t MoMoMoffset; }; +struct komodo_ccdata_entry { uint256 MoM; int32_t notarized_height,height,txi; char symbol[65]; }; +struct komodo_ccdatapair { int32_t notarized_height,MoMoMoffset; }; struct komodo_ccdataMoMoM { diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 8b296a66b..770feb4e7 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -555,6 +555,7 @@ int32_t komodo_minerids(uint8_t *minerids,int32_t height,int32_t width); int32_t komodo_kvsearch(uint256 *refpubkeyp,int32_t current_height,uint32_t *flagsp,int32_t *heightp,uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen); 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); +struct komodo_ccdata_entry *komodo_allMoMs(int32_t *nump,int32_t kmdstarti,int32_t kmdendi); UniValue kvsearch(const UniValue& params, bool fHelp) { @@ -591,6 +592,36 @@ UniValue kvsearch(const UniValue& params, bool fHelp) return ret; } +struct komodo_ccdata_entry { uint256 MoM; int32_t notarized_height,height,txi; char symbol[65]; }; + +UniValue allMoMs(const UniValue& params, bool fHelp) +{ + struct komodo_ccdata_entry *allMoMs; uint256 MoMoM; int32_t num,i,kmdstarti,kmdendi; UniValue ret(UniValue::VOBJ); UniValue a(UniValue::VARR); + if ( fHelp || params.size() != 2 ) + throw runtime_error("allMoMs kmdstarti kmdendi\n"); + LOCK(cs_main); + kmdstarti = atoi(params[0].get_str().c_str()); + kmdendi = atoi(params[1].get_str().c_str()); + ret.push_back(Pair("kmdstarti",kmdstarti)); + ret.push_back(Pair("kmdendi",kmdendi)); + if ( (allMoMs= komodo_allMoMs(&num,&MoMoM,&MoMoMdepth,kmdstarti,kmdendi)) != 0 ) + { + for (i=0; i