]> Git Repo - VerusCoin.git/blobdiff - src/komodo_bitcoind.h
Test
[VerusCoin.git] / src / komodo_bitcoind.h
index 2cab956c398fa4f7e5a887adb58b598bc25f1a60..86989799de179e91f6be8491efdcd3666e34a6c4 100644 (file)
@@ -1,5 +1,5 @@
 /******************************************************************************
 /******************************************************************************
- * Copyright © 2014-2017 The SuperNET Developers.                             *
+ * Copyright © 2014-2018 The SuperNET Developers.                             *
  *                                                                            *
  * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at                  *
  * the top-level directory of this distribution for the individual copyright  *
  *                                                                            *
  * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at                  *
  * the top-level directory of this distribution for the individual copyright  *
@@ -557,10 +557,9 @@ uint64_t komodo_seed(int32_t height)
     return(seed);
 }
 
     return(seed);
 }
 
-uint32_t komodo_txtime(uint64_t *valuep,uint256 hash,int32_t n)
+uint32_t komodo_txtime(uint64_t *valuep,uint256 hash,int32_t n,char *destaddr)
 {
 {
-    CTransaction tx;
-    uint256 hashBlock;
+    CTxDestination address; CTransaction tx; uint256 hashBlock;
     *valuep = 0;
     if (!GetTransaction(hash, tx,
 #ifndef KOMODO_ZCASH
     *valuep = 0;
     if (!GetTransaction(hash, tx,
 #ifndef KOMODO_ZCASH
@@ -568,12 +567,16 @@ uint32_t komodo_txtime(uint64_t *valuep,uint256 hash,int32_t n)
 #endif
                         hashBlock, true))
     {
 #endif
                         hashBlock, true))
     {
-        fprintf(stderr,"%s/v%d null GetTransaction locktime.%u\n",hash.ToString().c_str(),n,(uint32_t)tx.nLockTime);
+        fprintf(stderr,"ERROR: %s/v%d locktime.%u\n",hash.ToString().c_str(),n,(uint32_t)tx.nLockTime);
         return(0);
     }
         return(0);
     }
-    fprintf(stderr,"%s/v%d locktime.%u\n",hash.ToString().c_str(),n,(uint32_t)tx.nLockTime);
+    //fprintf(stderr,"%s/v%d locktime.%u\n",hash.ToString().c_str(),n,(uint32_t)tx.nLockTime);
     if ( n < tx.vout.size() )
     if ( n < tx.vout.size() )
+    {
         *valuep = tx.vout[n].nValue;
         *valuep = tx.vout[n].nValue;
+        if (ExtractDestination(tx.vout[n].scriptPubKey, address))
+            strcpy(destaddr,CBitcoinAddress(address).ToString().c_str());
+    }
     return(tx.nLockTime);
 }
 
     return(tx.nLockTime);
 }
 
@@ -656,19 +659,21 @@ int32_t komodo_block2height(CBlock *block)
     return(height);
 }
 
     return(height);
 }
 
-void komodo_block2pubkey33(uint8_t *pubkey33,CBlockblock)
+void komodo_block2pubkey33(uint8_t *pubkey33,CBlock *block)
 {
     int32_t n;
 {
     int32_t n;
-    memset(pubkey33,0,33);
-    if ( block.vtx[0].vout.size() > 0 )
+    if ( KOMODO_LOADINGBLOCKS == 0 )
+        memset(pubkey33,0xff,33);
+    else memset(pubkey33,0,33);
+    if ( block->vtx[0].vout.size() > 0 )
     {
 #ifdef KOMODO_ZCASH
     {
 #ifdef KOMODO_ZCASH
-        uint8_t *ptr = (uint8_t *)block.vtx[0].vout[0].scriptPubKey.data();
+        uint8_t *ptr = (uint8_t *)block->vtx[0].vout[0].scriptPubKey.data();
 #else
 #else
-        uint8_t *ptr = (uint8_t *)&block.vtx[0].vout[0].scriptPubKey[0];
+        uint8_t *ptr = (uint8_t *)&block->vtx[0].vout[0].scriptPubKey[0];
 #endif
         //komodo_init(0);
 #endif
         //komodo_init(0);
-        n = block.vtx[0].vout[0].scriptPubKey.size();
+        n = block->vtx[0].vout[0].scriptPubKey.size();
         if ( n == 35 )
             memcpy(pubkey33,ptr+1,33);
     }
         if ( n == 35 )
             memcpy(pubkey33,ptr+1,33);
     }
@@ -719,60 +724,74 @@ uint32_t komodo_heightstamp(int32_t height)
     return(0);
 }
 
     return(0);
 }
 
+void komodo_pindex_init(CBlockIndex *pindex,int32_t height)
+{
+    int32_t i,num; uint8_t pubkeys[64][33]; CBlock block;
+    if ( pindex->didinit != 0 )
+        return;
+    //printf("pindex.%d komodo_pindex_init notary.%d from height.%d\n",pindex->nHeight,pindex->notaryid,height);
+    if ( pindex->didinit == 0 )
+    {
+        pindex->notaryid = -1;
+        if ( KOMODO_LOADINGBLOCKS == 0 )
+            memset(pindex->pubkey33,0xff,33);
+        else memset(pindex->pubkey33,0,33);
+        if ( komodo_blockload(block,pindex) == 0 )
+        {
+            komodo_block2pubkey33(pindex->pubkey33,&block);
+            //for (i=0; i<33; i++)
+            //    fprintf(stderr,"%02x",pindex->pubkey33[i]);
+            //fprintf(stderr," set pubkey at height %d/%d\n",pindex->nHeight,height);
+            //if ( pindex->pubkey33[0] == 2 || pindex->pubkey33[0] == 3 )
+            //    pindex->didinit = (KOMODO_LOADINGBLOCKS == 0);
+        } // else fprintf(stderr,"error loading block at %d/%d",pindex->nHeight,height);
+    }
+    if ( pindex->didinit != 0 && pindex->nHeight >= 0 && (num= komodo_notaries(pubkeys,(int32_t)pindex->nHeight,(uint32_t)pindex->nTime)) > 0 )
+    {
+        for (i=0; i<num; i++)
+        {
+            if ( memcmp(pubkeys[i],pindex->pubkey33,33) == 0 )
+            {
+                pindex->notaryid = i;
+                break;
+            }
+        }
+        if ( 0 && i == num )
+        {
+            for (i=0; i<33; i++)
+                fprintf(stderr,"%02x",pindex->pubkey33[i]);
+            fprintf(stderr," unmatched pubkey at height %d/%d\n",pindex->nHeight,height);
+        }
+    }
+}
+
 void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height)
 {
 void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height)
 {
-    CBlock block; int32_t num,i; uint8_t pubkeys[64][33];
-    //komodo_init(height);
+    CBlock block; int32_t num,i;
     memset(pubkey33,0,33);
     if ( pindex != 0 )
     {
     memset(pubkey33,0,33);
     if ( pindex != 0 )
     {
-        if ( pindex->pubkey33[0] == 2 || pindex->pubkey33[0] == 3 )
+        if ( komodo_blockload(block,pindex) == 0 )
         {
         {
-            memcpy(pubkey33,pindex->pubkey33,33);
+            komodo_block2pubkey33(pindex->pubkey33,&block);
             return;
         }
             return;
         }
-        if ( komodo_blockload(block,pindex) == 0 )
+        if ( pindex->didinit != 0 )
         {
         {
-            komodo_block2pubkey33(pubkey33,block);
-            if ( (pubkey33[0] == 2 || pubkey33[0] == 3) )
-            {
-                memcpy(pindex->pubkey33,pubkey33,33);
-                if ( (num= komodo_notaries(pubkeys,(int32_t)pindex->nHeight,(uint32_t)pindex->nTime)) > 0 )
-                {
-                    pindex->notaryid = -1;
-                    for (i=0; i<num; i++)
-                    {
-                        if ( memcmp(pubkeys[i],pubkey33,33) == 0 )
-                        {
-                            pindex->notaryid = i;
-                            break;
-                        }
-                    }
-                }
-            } else pindex->notaryid = -1;
-       }
-    }
-    else
-    {
-        // height -> pubkey33
-        //printf("extending chaintip komodo_index2pubkey33 height.%d need to get pubkey33\n",height);
+            memcpy(pubkey33,pindex->pubkey33,33);
+            return;
+        }
+        komodo_pindex_init(pindex,height);
+        memcpy(pubkey33,pindex->pubkey33,33);
     }
 }
 
     }
 }
 
-/*void komodo_connectpindex(CBlockIndex *pindex)
-{
-    CBlock block;
-    if ( komodo_blockload(block,pindex) == 0 )
-        komodo_connectblock(pindex,block);
-}*/
-
-
 int8_t komodo_minerid(int32_t height,uint8_t *pubkey33)
 {
     int32_t num,i,numnotaries; CBlockIndex *pindex; uint32_t timestamp=0; uint8_t _pubkey33[33],pubkeys[64][33];
     if ( (pindex= chainActive[height]) != 0 )
     {
 int8_t komodo_minerid(int32_t height,uint8_t *pubkey33)
 {
     int32_t num,i,numnotaries; CBlockIndex *pindex; uint32_t timestamp=0; uint8_t _pubkey33[33],pubkeys[64][33];
     if ( (pindex= chainActive[height]) != 0 )
     {
-        if ( (pindex->pubkey33[0] == 2 || pindex->pubkey33[0] == 3) )
+        if ( pindex->didinit != 0 )
         {
             if ( pubkey33 != 0 )
                 memcpy(pubkey33,pindex->pubkey33,33);
         {
             if ( pubkey33 != 0 )
                 memcpy(pubkey33,pindex->pubkey33,33);
@@ -793,13 +812,22 @@ int8_t komodo_minerid(int32_t height,uint8_t *pubkey33)
 
 int32_t komodo_eligiblenotary(uint8_t pubkeys[66][33],int32_t *mids,int32_t *nonzpkeysp,int32_t height)
 {
 
 int32_t komodo_eligiblenotary(uint8_t pubkeys[66][33],int32_t *mids,int32_t *nonzpkeysp,int32_t height)
 {
-    int32_t i,j,duplicate; CBlockIndex *pindex; uint8_t pubkey33[33];
+    int32_t i,j,duplicate; CBlock block; CBlockIndex *pindex; uint8_t pubkey33[33];
     memset(mids,-1,sizeof(*mids)*66);
     for (i=duplicate=0; i<66; i++)
     {
         if ( (pindex= komodo_chainactive(height-i)) != 0 )
         {
     memset(mids,-1,sizeof(*mids)*66);
     for (i=duplicate=0; i<66; i++)
     {
         if ( (pindex= komodo_chainactive(height-i)) != 0 )
         {
-            if ( pindex->notaryid >= 0 && (pindex->pubkey33[0] == 2 || pindex->pubkey33[0] == 3) )
+            if ( pindex->didinit != 0 && (pindex->notaryid >= 64 || pindex->notaryid < -1) )
+            {
+                //fprintf(stderr,"unexpected notaryid.%d at ht.%d\n",pindex->notaryid,height-i);
+                pindex->notaryid = -1;
+                memset(pindex->pubkey33,0,33);
+                pindex->didinit = 0;
+                if ( komodo_blockload(block,pindex) == 0 )
+                    komodo_block2pubkey33(pindex->pubkey33,&block);
+            }
+            if ( pindex->notaryid >= 0 && pindex->didinit != 0 )
             {
                 memcpy(pubkeys[i],pindex->pubkey33,33);
                 mids[i] = pindex->notaryid;
             {
                 memcpy(pubkeys[i],pindex->pubkey33,33);
                 mids[i] = pindex->notaryid;
@@ -807,9 +835,10 @@ int32_t komodo_eligiblenotary(uint8_t pubkeys[66][33],int32_t *mids,int32_t *non
             }
             else
             {
             }
             else
             {
-                komodo_index2pubkey33(pubkey33,pindex,height-i);
-                memcpy(pubkeys[i],pubkey33,33);
-                if ( (mids[i]= komodo_minerid(height-i,pubkey33)) >= 0 )
+                komodo_pindex_init(pindex,height-i);
+                //komodo_index2pubkey33(pubkey33,pindex,height-i);
+                memcpy(pubkeys[i],pindex->pubkey33,33);
+                if ( (mids[i]= komodo_minerid(height-i,pindex->pubkey33)) >= 0 )
                 {
                     //mids[i] = *(int32_t *)pubkey33;
                     (*nonzpkeysp)++;
                 {
                     //mids[i] = *(int32_t *)pubkey33;
                     (*nonzpkeysp)++;
@@ -834,42 +863,63 @@ int32_t komodo_minerids(uint8_t *minerids,int32_t height,int32_t width) // depre
         minerids[i] = komodo_minerid(height - i,0);
     }
     return(n);*/
         minerids[i] = komodo_minerid(height - i,0);
     }
     return(n);*/
+    fprintf(stderr,"komodo_minerids is deprecated\n");
     return(-1);
 }
 
     return(-1);
 }
 
-int32_t komodo_is_special(int32_t height,uint8_t pubkey33[33],uint32_t timestamp)
+int32_t komodo_is_special(uint8_t pubkeys[66][33],int32_t mids[66],int32_t height,uint8_t pubkey33[33],uint32_t timestamp)
 {
 {
-    int32_t i,notaryid=0,minerid,limit,nid; //uint8_t _pubkey33[33];
-    if ( height >= 225000 )
-        komodo_chosennotary(&notaryid,height,pubkey33,timestamp);
-    if ( height >= 34000 && notaryid >= 0 )
+    int32_t i,notaryid=0,minerid,limit,nid;
+    /*if ( height >= 700000 )
+    {
+        if ( mids[0] >= 0 )
+        {
+            for (i=1; i<66; i++)
+            {
+                if ( mids[i] == mids[0] )
+                {
+                    fprintf(stderr,"ht.%d repeat notaryid.%d in mids[%d]\n",height,mids[0],i);
+                    if ( height > 792000 )
+                        return(-1);
+                    else break;
+                }
+            }
+            return(1);
+        } else return(0);
+    }
+    else*/
     {
     {
-        if ( height < 79693 )
-            limit = 64;
-        else if ( height < 82000 )
-            limit = 8;
-        else limit = 66;
-        for (i=1; i<limit; i++)
+        if ( height >= 225000 )
+            komodo_chosennotary(&notaryid,height,pubkey33,timestamp);
+        if ( height >= 34000 && notaryid >= 0 )
         {
         {
-            komodo_chosennotary(&nid,height-i,pubkey33,timestamp);
-            if ( nid == notaryid )
+            if ( height < 79693 )
+                limit = 64;
+            else if ( height < 82000 )
+                limit = 8;
+            else limit = 66;
+            for (i=1; i<limit; i++)
             {
             {
-                if ( (0) && notaryid > 0 )
-                    fprintf(stderr,"ht.%d notaryid.%d already mined -i.%d nid.%d\n",height,notaryid,i,nid);
-                if ( height > 225000 )
-                    return(-1);
+                komodo_chosennotary(&nid,height-i,pubkey33,timestamp);
+                if ( nid == notaryid )
+                {
+                    //if ( (0) && notaryid > 0 )
+                        fprintf(stderr,"ht.%d repeat notaryid.%d in mids[%d] nid.%d notaryid.%d\n",height,mids[0],i,nid,notaryid);
+                    if ( height > 225000 )
+                        return(-1);
+                }
             }
             }
+            //fprintf(stderr,"special notaryid.%d ht.%d limit.%d\n",notaryid,height,limit);
+            return(1);
         }
         }
-        //fprintf(stderr,"special notaryid.%d ht.%d limit.%d\n",notaryid,height,limit);
-        return(1);
     }
     return(0);
 }
 
     }
     return(0);
 }
 
-int32_t komodo_MoM(int32_t *notarized_heightp,uint256 *MoMp,uint256 *kmdtxidp,int32_t nHeight)
+int32_t komodo_MoM(int32_t *notarized_heightp,uint256 *MoMp,uint256 *kmdtxidp,int32_t nHeight,uint256 *MoMoMp,int32_t *MoMoMoffsetp,int32_t *MoMoMdepthp,int32_t *kmdstartip,int32_t *kmdendip)
 {
     int32_t depth,notarized_ht; uint256 MoM,kmdtxid;
 {
     int32_t depth,notarized_ht; uint256 MoM,kmdtxid;
-    depth = komodo_MoMdata(&notarized_ht,&MoM,&kmdtxid,nHeight);
+    depth = komodo_MoMdata(&notarized_ht,&MoM,&kmdtxid,nHeight,MoMoMp,MoMoMoffsetp,MoMoMdepthp,kmdstartip,kmdendip);
     memset(MoMp,0,sizeof(*MoMp));
     memset(kmdtxidp,0,sizeof(*kmdtxidp));
     *notarized_heightp = 0;
     memset(MoMp,0,sizeof(*MoMp));
     memset(kmdtxidp,0,sizeof(*kmdtxidp));
     *notarized_heightp = 0;
This page took 0.034031 seconds and 4 git commands to generate.