|
|
@ -230,121 +230,7 @@ int32_t dpow_opreturn_parsesrc(bits256 *blockhashp,int32_t *heightp,bits256 *txi |
|
|
|
return(-1); |
|
|
|
} |
|
|
|
|
|
|
|
int32_t dpow_txhasnotarization(uint64_t *signedmaskp,int32_t *nothtp,struct supernet_info *myinfo,struct iguana_info *coin,bits256 txid,int32_t height,struct komodo_ccdataMoMoM *mdata) |
|
|
|
{ |
|
|
|
cJSON *txobj,*vins,*vin,*vouts,*vout,*spentobj,*sobj; char *hexstr; uint8_t script[256]; bits256 spenttxid; uint64_t notarymask=0; int32_t i,j,numnotaries,len,spentvout,numvins,numvouts,hasnotarization = 0; |
|
|
|
if ( (txobj= dpow_gettransaction(myinfo,coin,txid)) != 0 ) |
|
|
|
{ |
|
|
|
if ( (vins= jarray(&numvins,txobj,"vin")) != 0 ) |
|
|
|
{ |
|
|
|
if ( numvins >= DPOW_MIN_ASSETCHAIN_SIGS ) |
|
|
|
{ |
|
|
|
notarymask = numnotaries = 0; |
|
|
|
for (i=0; i<numvins; i++) |
|
|
|
{ |
|
|
|
vin = jitem(vins,i); |
|
|
|
spenttxid = jbits256(vin,"txid"); |
|
|
|
spentvout = jint(vin,"vout"); |
|
|
|
if ( (spentobj= dpow_gettransaction(myinfo,coin,spenttxid)) != 0 ) |
|
|
|
{ |
|
|
|
if ( (vouts= jarray(&numvouts,spentobj,"vout")) != 0 ) |
|
|
|
{ |
|
|
|
if ( spentvout < numvouts ) |
|
|
|
{ |
|
|
|
vout = jitem(vouts,spentvout); |
|
|
|
if ( (sobj= jobj(vout,"scriptPubKey")) != 0 && (hexstr= jstr(sobj,"hex")) != 0 && (len= is_hexstr(hexstr,0)) == 35*2 ) |
|
|
|
{ |
|
|
|
len >>= 1; |
|
|
|
decode_hex(script,len,hexstr); |
|
|
|
if ( script[0] == 33 && script[34] == 0xac ) |
|
|
|
{ |
|
|
|
for (j=0; j<Notaries_num; j++) |
|
|
|
{ |
|
|
|
if ( strncmp(Notaries_elected[j][1],hexstr+2,66) == 0 ) |
|
|
|
{ |
|
|
|
if ( ((1LL << j) & notarymask) == 0 ) |
|
|
|
{ |
|
|
|
//printf("n%d ",j);
|
|
|
|
numnotaries++; |
|
|
|
notarymask |= (1LL << j); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
free_json(spentobj); |
|
|
|
} |
|
|
|
} |
|
|
|
if ( numnotaries > 0 ) |
|
|
|
{ |
|
|
|
if ( numnotaries >= DPOW_MIN_ASSETCHAIN_SIGS ) |
|
|
|
{ |
|
|
|
hasnotarization = 1; |
|
|
|
*nothtp = 0; |
|
|
|
if ( (vouts= jarray(&numvouts,txobj,"vout")) != 0 ) |
|
|
|
{ |
|
|
|
bits256 blockhash,txid,MoM; uint32_t MoMdepth; char symbol[65];//,str[65],str2[65],str3[65];
|
|
|
|
vout = jitem(vouts,numvouts-1); |
|
|
|
if ( (sobj= jobj(vout,"scriptPubKey")) != 0 && (hexstr= jstr(sobj,"hex")) != 0 && (len= is_hexstr(hexstr,0)) > 36*2 && len < sizeof(script)*2 ) |
|
|
|
{ |
|
|
|
len >>= 1; |
|
|
|
decode_hex(script,len,hexstr); |
|
|
|
if ( dpow_opreturn_parsesrc(&blockhash,nothtp,&txid,symbol,&MoM,&MoMdepth,script,len,mdata) > 0 && strcmp(symbol,coin->symbol) == 0 ) |
|
|
|
{ |
|
|
|
// if ( Notaries_port != DPOW_SOCKPORT ) // keep going till valid MoM found, useful for new chains without any MoM
|
|
|
|
{ |
|
|
|
if ( bits256_nonz(MoM) == 0 || MoMdepth == 0 || *nothtp >= height || *nothtp < 0 ) |
|
|
|
{ |
|
|
|
*nothtp = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
if ( mdata->pairs != 0 && mdata->numpairs > 0 ) |
|
|
|
{ |
|
|
|
for (j=0; j<mdata->numpairs; j++) |
|
|
|
{ |
|
|
|
if ( mdata->pairs[j].notarization_height > coin->MoMoMheight ) |
|
|
|
{ |
|
|
|
coin->MoMoMheight = mdata->pairs[j].notarization_height; |
|
|
|
printf("set %s MoMoMheight <- %d\n",coin->symbol,coin->MoMoMheight); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
//printf("%s.%d notarizationht.%d %s -> %s MoM.%s [%d]\n",symbol,height,*nothtp,bits256_str(str,blockhash),bits256_str(str2,txid),bits256_str(str3,MoM),MoMdepth);
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
free_json(txobj); |
|
|
|
} |
|
|
|
if ( hasnotarization != 0 ) |
|
|
|
(*signedmaskp) = notarymask; |
|
|
|
return(hasnotarization); |
|
|
|
} |
|
|
|
|
|
|
|
int32_t dpow_hasnotarization(uint64_t *signedmaskp,int32_t *nothtp,struct supernet_info *myinfo,struct iguana_info *coin,cJSON *blockjson,int32_t ht,struct komodo_ccdataMoMoM *mdata) |
|
|
|
{ |
|
|
|
int32_t i,n,hasnotarization = 0; bits256 txid; cJSON *txarray; |
|
|
|
*nothtp = 0; |
|
|
|
*signedmaskp = 0; |
|
|
|
memset(mdata,0,sizeof(*mdata)); |
|
|
|
if ( (txarray= jarray(&n,blockjson,"tx")) != 0 ) |
|
|
|
{ |
|
|
|
for (i=0; i<n; i++) |
|
|
|
{ |
|
|
|
txid = jbits256i(txarray,i); |
|
|
|
hasnotarization += dpow_txhasnotarization(signedmaskp,nothtp,myinfo,coin,txid,ht,mdata); |
|
|
|
} |
|
|
|
} |
|
|
|
return(hasnotarization); |
|
|
|
} |
|
|
|
|
|
|
|
bits256 dpow_calcMoM(uint32_t *MoMdepthp,struct supernet_info *myinfo,struct iguana_info *coin,int32_t height) |
|
|
|
/*bits256 dpow_calcMoM(uint32_t *MoMdepthp,struct supernet_info *myinfo,struct iguana_info *coin,int32_t height)
|
|
|
|
{ |
|
|
|
struct komodo_ccdataMoMoM mdata; bits256 MoM,blockhash,merkle,*merkles; cJSON *blockjson; uint64_t signedmask; int32_t breakht=0,notht=0,ht,maxdepth = DPOW_MAXMOMDEPTH,MoMdepth = 0; |
|
|
|
memset(MoM.bytes,0,sizeof(MoM)); |
|
|
@ -410,6 +296,36 @@ bits256 dpow_calcMoM(uint32_t *MoMdepthp,struct supernet_info *myinfo,struct igu |
|
|
|
*MoMdepthp = MoMdepth; |
|
|
|
//printf("done MoM calc %s height.%d MoMdepth.%d\n",coin->symbol,height,MoMdepth);
|
|
|
|
return(MoM); |
|
|
|
}*/ |
|
|
|
|
|
|
|
/*{
|
|
|
|
"coin": "PIZZA", |
|
|
|
"height": 30623, |
|
|
|
"MoMdepth": 10000, |
|
|
|
"MoM": "797239cfd3611d359ec515fa493062cc2838172a99fd86de1d0305d009abde40" |
|
|
|
}*/ |
|
|
|
|
|
|
|
bits256 dpow_calcMoM(uint32_t *MoMdepthp,struct supernet_info *myinfo,struct iguana_info *coin,int32_t height) |
|
|
|
{ |
|
|
|
bits256 MoM; cJSON *MoMjson,*infojson; int32_t prevMoMheight; |
|
|
|
*MoMdepthp = 0; |
|
|
|
memset(MoM.bytes,0,sizeof(MoM)); |
|
|
|
if ( (infojson= dpow_getinfo(myinfo,coin)) != 0 ) |
|
|
|
{ |
|
|
|
if ( (prevMoMheight= jint(infojson,"prevMoMheight")) != 0 ) |
|
|
|
{ |
|
|
|
*MoMdepthp = (height - prevMoMheight); |
|
|
|
if ( *MoMdepthp > 0 && (MoMjson= issue_calcMoM(coin,height,*MoMdepthp)) != 0 ) |
|
|
|
{ |
|
|
|
MoM = jbits256(MoMjson,"MoM"); |
|
|
|
free_json(MoMjson); |
|
|
|
} |
|
|
|
} |
|
|
|
free_json(infojson); |
|
|
|
} |
|
|
|
if ( bits256_nonz(MoM) == 0 ) |
|
|
|
*MoMdepthp = 0; |
|
|
|
return(MoM); |
|
|
|
} |
|
|
|
|
|
|
|
void dpow_statemachinestart(void *ptr) |
|
|
@ -439,16 +355,14 @@ void dpow_statemachinestart(void *ptr) |
|
|
|
return; |
|
|
|
} |
|
|
|
MoMdepth = 0; |
|
|
|
if ( 0 && strcmp(dp->dest,"KMD") == 0 ) |
|
|
|
{ |
|
|
|
portable_mutex_lock(&src->MoM_mutex); |
|
|
|
MoM = dpow_calcMoM(&MoMdepth,myinfo,src,checkpoint.blockhash.height); |
|
|
|
portable_mutex_unlock(&src->MoM_mutex); |
|
|
|
} else memset(&MoM,0,sizeof(MoM)); |
|
|
|
memset(&MoM,0,sizeof(MoM)); |
|
|
|
if ( strcmp(src->symbol,"KMD") == 0 ) |
|
|
|
kmdheight = checkpoint.blockhash.height; |
|
|
|
else if ( strcmp(dest->symbol,"KMD") == 0 ) |
|
|
|
{ |
|
|
|
MoM = dpow_calcMoM(&MoMdepth,myinfo,src,checkpoint.blockhash.height); |
|
|
|
kmdheight = dest->longestchain; |
|
|
|
} |
|
|
|
if ( (bp= dp->blocks[checkpoint.blockhash.height]) == 0 ) |
|
|
|
{ |
|
|
|
bp = calloc(1,sizeof(*bp)); |
|
|
|