]> Git Repo - VerusCoin.git/blobdiff - src/komodo.h
Test
[VerusCoin.git] / src / komodo.h
index 3bb6339992b0f35a910c8f9ca29011eec784e531..52daaae0e696bf9e2c91f63c84b5f81100283b80 100644 (file)
@@ -357,6 +357,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar
     if ( didinit == 0 )
     {
         portable_mutex_init(&KOMODO_KV_mutex);
+        portable_mutex_init(&KOMODO_CC_mutex);
         didinit = 1;
     }
     if ( (sp= komodo_stateptr(symbol,dest)) == 0 )
@@ -556,7 +557,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr
     }
     if ( scriptbuf[len++] == 0x6a )
     {
-        int32_t nameoffset;
+        int32_t nameoffset,opoffset = 0;
         if ( (opretlen= scriptbuf[len++]) == 0x4c )
             opretlen = scriptbuf[len++];
         else if ( opretlen == 0x4d )
@@ -564,38 +565,40 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr
             opretlen = scriptbuf[len++];
             opretlen += (scriptbuf[len++] << 8);
         }
+        opoffset = len;
         matched = 0;
         if ( ASSETCHAINS_SYMBOL[0] == 0 )
         {
-            nameoffset = (int32_t)strlen("KMD") + 1;
-            if ( strcmp("KMD",(char *)&scriptbuf[len+offset]) == 0 )
+            if ( strcmp("KMD",(char *)&scriptbuf[len+32 * 2 + 4]) == 0 )
                 matched = 1;
         }
         else
         {
-            nameoffset = (int32_t)strlen(ASSETCHAINS_SYMBOL) + 1;
             if ( strcmp(ASSETCHAINS_SYMBOL,(char *)&scriptbuf[len+offset]) == 0 )
                 matched = 1;
         }
         offset = 32 * (1 + matched) + 4;
-        if ( j == 1 && opretlen >= len+offset )
-        {
-            struct komodo_ccdata ccdata;
+        nameoffset = (int32_t)strlen((char *)&scriptbuf[len+offset]);
+        if ( nameoffset == 2 )
+            nameoffset += 2;
+        else nameoffset++;
+        if ( j == 1 && opretlen >= len+offset-opoffset )
+        {
+            static int32_t last_rewind; int32_t rewindtarget,validated = 0; CBlockIndex *pindex;//
+            struct komodo_ccdata ccdata; struct komodo_ccdataMoMoM MoMoMdata;
             memset(&ccdata,0,sizeof(ccdata));
+            memset(&MoMoMdata,0,sizeof(MoMoMdata));
             strncpy(ccdata.symbol,(char *)&scriptbuf[len+offset],sizeof(ccdata.symbol));
             if ( matched == 0 && bitweight(signedmask) >= KOMODO_MINRATIFY )
                 notarized = 1;
-            if ( strcmp("PIZZA",(char *)&scriptbuf[len+offset]) == 0 && opretlen >= 110 )
+            if ( strcmp("PIZZA",ccdata.symbol) == 0 )
                 notarized = 1;
-            if ( opretlen != 149 )
-                printf("[%s] (%s) matched.%d i.%d j.%d notarized.%d %llx opretlen.%d (%c %c %c)\n",ASSETCHAINS_SYMBOL,ccdata.symbol,matched,i,j,notarized,(long long)signedmask,opretlen,scriptbuf[len+offset],scriptbuf[len+offset+1],scriptbuf[len+offset+2]);
+            if ( 0 && opretlen != 149 )
+                printf("[%s].%d (%s) matched.%d i.%d j.%d notarized.%d %llx opretlen.%d len.%d offset.%d opoffset.%d\n",ASSETCHAINS_SYMBOL,height,ccdata.symbol,matched,i,j,notarized,(long long)signedmask,opretlen,len,offset,opoffset);
             len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&srchash);
             len += iguana_rwnum(0,&scriptbuf[len],sizeof(*notarizedheightp),(uint8_t *)notarizedheightp);
             if ( matched != 0 )
                 len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&desttxid);
-            static int32_t last_rewind;
-            int32_t rewindtarget,validated = 0;
-            CBlockIndex *pindex;//
             if ( matched != 0 && IsInitialBlockDownload() == 0 && ((pindex= mapBlockIndex[srchash]) == 0 || pindex->nHeight != *notarizedheightp) )
             {
                 if ( sp->NOTARIZED_HEIGHT > 0 && sp->NOTARIZED_HEIGHT < *notarizedheightp )
@@ -613,7 +616,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr
                     last_rewind = rewindtarget;
                 }
             } else validated = 1;
-            if ( notarized != 0 && (matched == 0 || (validated != 0 && *notarizedheightp > sp->NOTARIZED_HEIGHT && *notarizedheightp < height))  )
+            if ( notarized != 0 && validated != 0 )
             {
                 //sp->NOTARIZED_HEIGHT = *notarizedheightp;
                 //sp->NOTARIZED_HASH = srchash;
@@ -621,16 +624,16 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr
                 memset(&MoM,0,sizeof(MoM));
                 MoMdepth = 0;
                 len += nameoffset;
-                ccdata.notarized_height = *notarizedheightp;
-                ccdata.height = height;
-                ccdata.txi = i;
-                printf("len.%d + 36 %d vs opretlen.%d\n",len,len+36,opretlen);
-                if ( len+36 <= opretlen )
+                ccdata.MoMdata.notarized_height = *notarizedheightp;
+                ccdata.MoMdata.height = height;
+                ccdata.MoMdata.txi = i;
+                //printf("nameoffset.%d len.%d + 36 %d vs opretlen.%d\n",nameoffset,len,len+36,opretlen);
+                if ( len+36-opoffset <= opretlen )
                 {
                     len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&MoM);
                     len += iguana_rwnum(0,&scriptbuf[len],sizeof(MoMdepth),(uint8_t *)&MoMdepth);
-                    ccdata.MoM = MoM;
-                    ccdata.MoMdepth = MoMdepth;
+                    ccdata.MoMdata.MoM = MoM;
+                    ccdata.MoMdata.MoMdepth = MoMdepth;
                     if ( len+sizeof(ccdata.CCid) <= opretlen )
                     {
                         len += iguana_rwnum(0,&scriptbuf[len],sizeof(ccdata.CCid),(uint8_t *)&ccdata.CCid);
@@ -638,25 +641,25 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr
                         if ( ASSETCHAINS_SYMBOL[0] != 0 )
                         {
                             // MoMoM, depth, numpairs, (notarization ht, MoMoM offset)
-                            if ( len+48 <= opretlen && strcmp(ccdata.symbol,ASSETCHAINS_SYMBOL) == 0 )
+                            if ( len+48-opoffset <= opretlen && strcmp(ccdata.symbol,ASSETCHAINS_SYMBOL) == 0 )
                             {
-                                len += iguana_rwnum(0,&scriptbuf[len],sizeof(uint32_t),(uint8_t *)&ccdata.MoMoMstart);
-                                len += iguana_rwnum(0,&scriptbuf[len],sizeof(uint32_t),(uint8_t *)&ccdata.MoMoMend);
-                                len += iguana_rwbignum(0,&scriptbuf[len],sizeof(ccdata.MoMoM),(uint8_t *)&ccdata.MoMoM);
-                                len += iguana_rwnum(0,&scriptbuf[len],sizeof(uint32_t),(uint8_t *)&ccdata.MoMoMdepth);
-                                len += iguana_rwnum(0,&scriptbuf[len],sizeof(uint32_t),(uint8_t *)&ccdata.numpairs);
-                                ccdata.len += sizeof(ccdata.MoMoM) + sizeof(uint32_t)*4;
-                                if ( len+ccdata.numpairs*8 == opretlen )
+                                len += iguana_rwnum(0,&scriptbuf[len],sizeof(uint32_t),(uint8_t *)&MoMoMdata.kmdstarti);
+                                len += iguana_rwnum(0,&scriptbuf[len],sizeof(uint32_t),(uint8_t *)&MoMoMdata.kmdendi);
+                                len += iguana_rwbignum(0,&scriptbuf[len],sizeof(MoMoMdata.MoMoM),(uint8_t *)&MoMoMdata.MoMoM);
+                                len += iguana_rwnum(0,&scriptbuf[len],sizeof(uint32_t),(uint8_t *)&MoMoMdata.MoMoMdepth);
+                                len += iguana_rwnum(0,&scriptbuf[len],sizeof(uint32_t),(uint8_t *)&MoMoMdata.numpairs);
+                                MoMoMdata.len += sizeof(MoMoMdata.MoMoM) + sizeof(uint32_t)*4;
+                                if ( len+MoMoMdata.numpairs*8-opoffset == opretlen )
                                 {
-                                    ccdata.pairs = (struct komodo_ccdatapair *)calloc(ccdata.numpairs,sizeof(*ccdata.pairs));
-                                    for (k=0; k<ccdata.numpairs; k++)
+                                    MoMoMdata.pairs = (struct komodo_ccdatapair *)calloc(MoMoMdata.numpairs,sizeof(*MoMoMdata.pairs));
+                                    for (k=0; k<MoMoMdata.numpairs; k++)
                                     {
-                                        len += iguana_rwnum(0,&scriptbuf[len],sizeof(int32_t),(uint8_t *)&ccdata.pairs[k].notarization_height);
-                                        len += iguana_rwnum(0,&scriptbuf[len],sizeof(uint32_t),(uint8_t *)&ccdata.pairs[k].MoMoMoffset);
-                                        ccdata.len += sizeof(uint32_t) * 2;
+                                        len += iguana_rwnum(0,&scriptbuf[len],sizeof(int32_t),(uint8_t *)&MoMoMdata.pairs[k].notarization_height);
+                                        len += iguana_rwnum(0,&scriptbuf[len],sizeof(uint32_t),(uint8_t *)&MoMoMdata.pairs[k].MoMoMoffset);
+                                        MoMoMdata.len += sizeof(uint32_t) * 2;
                                     }
-                                } else ccdata.len = 0;
-                            } else ccdata.len = 0;
+                                } else ccdata.len = MoMoMdata.len = 0;
+                            } else ccdata.len = MoMoMdata.len = 0;
                         }
                     }
                     if ( MoM == zero || MoMdepth > 1440 || MoMdepth < 0 )
@@ -666,14 +669,17 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr
                     }
                     else
                     {
-                        komodo_rwccdata(1,&ccdata);
-                        printf("[%s] matched.%d VALID (%s) MoM.%s [%d]\n",ASSETCHAINS_SYMBOL,matched,ccdata.symbol,MoM.ToString().c_str(),MoMdepth);
+                        komodo_rwccdata(ASSETCHAINS_SYMBOL,1,&ccdata,&MoMoMdata);
+                        //printf("[%s] matched.%d VALID (%s) MoM.%s [%d]\n",ASSETCHAINS_SYMBOL,matched,ccdata.symbol,MoM.ToString().c_str(),MoMdepth);
                     }
-                    if ( ccdata.pairs != 0 )
-                        free(ccdata.pairs);
+                    if ( MoMoMdata.pairs != 0 )
+                        free(MoMoMdata.pairs);
                     memset(&ccdata,0,sizeof(ccdata));
+                    memset(&MoMoMdata,0,sizeof(MoMoMdata));
                 }
-                if ( matched != 0 )
+                else if ( ASSETCHAINS_SYMBOL[0] == 0 && matched != 0 && notarized != 0 && validated != 0 )
+                    komodo_rwccdata((char *)"KMD",1,&ccdata,0);
+                if ( matched != 0 && *notarizedheightp > sp->NOTARIZED_HEIGHT && *notarizedheightp < height )
                 {
                     sp->NOTARIZED_HEIGHT = *notarizedheightp;
                     sp->NOTARIZED_HASH = srchash;
@@ -681,7 +687,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr
                     sp->MoM = MoM;
                     sp->MoMdepth = MoMdepth;
                     komodo_stateupdate(height,0,0,0,zero,0,0,0,0,0,0,0,0,0,0,sp->MoM,sp->MoMdepth);
-                    //if ( ASSETCHAINS_SYMBOL[0] != 0 )
+                    if ( ASSETCHAINS_SYMBOL[0] != 0 )
                         printf("[%s] ht.%d NOTARIZED.%d %s.%s %sTXID.%s lens.(%d %d) MoM.%s %d\n",ASSETCHAINS_SYMBOL,height,*notarizedheightp,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,srchash.ToString().c_str(),ASSETCHAINS_SYMBOL[0]==0?"BTC":"KMD",desttxid.ToString().c_str(),opretlen,len,sp->MoM.ToString().c_str(),sp->MoMdepth);
                     if ( ASSETCHAINS_SYMBOL[0] == 0 )
                     {
@@ -708,7 +714,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr
                         }
                     }
                 }
-            } else if ( matched != 0 && *notarizedheightp != sp->NOTARIZED_HEIGHT )
+            } else //if ( matched != 0 && *notarizedheightp != sp->NOTARIZED_HEIGHT )
                 printf("validated.%d notarized.%d %llx reject ht.%d NOTARIZED.%d prev.%d %s.%s DESTTXID.%s len.%d opretlen.%d\n",validated,notarized,(long long)signedmask,height,*notarizedheightp,sp->NOTARIZED_HEIGHT,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,srchash.ToString().c_str(),desttxid.ToString().c_str(),len,opretlen);
         }
         else if ( matched != 0 && i == 0 && j == 1 && opretlen == 149 )
This page took 0.03319 seconds and 4 git commands to generate.