New method of ac_notarypay
This commit is contained in:
75
src/komodo.h
75
src/komodo.h
@@ -37,7 +37,7 @@
|
||||
|
||||
int32_t gettxout_scriptPubKey(uint8_t *scriptPubkey,int32_t maxsize,uint256 txid,int32_t n);
|
||||
void komodo_event_rewind(struct komodo_state *sp,char *symbol,int32_t height);
|
||||
int32_t komodo_connectblock(CBlockIndex *pindex,CBlock& block);
|
||||
int32_t komodo_connectblock(bool fJustCheck, CBlockIndex *pindex,CBlock& block);
|
||||
|
||||
#include "komodo_structs.h"
|
||||
#include "komodo_globals.h"
|
||||
@@ -531,7 +531,7 @@ int32_t komodo_validate_chain(uint256 srchash,int32_t notarized_height)
|
||||
} else return(1);
|
||||
}
|
||||
|
||||
int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen,int32_t height,uint256 txhash,int32_t i,int32_t j,uint64_t *voutmaskp,int32_t *specialtxp,int32_t *notarizedheightp,uint64_t value,int32_t notarized,uint64_t signedmask,uint32_t timestamp)
|
||||
int32_t komodo_voutupdate(bool fJustCheck,int32_t *isratificationp,int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen,int32_t height,uint256 txhash,int32_t i,int32_t j,uint64_t *voutmaskp,int32_t *specialtxp,int32_t *notarizedheightp,uint64_t value,int32_t notarized,uint64_t signedmask,uint32_t timestamp)
|
||||
{
|
||||
static uint256 zero; static FILE *signedfp;
|
||||
int32_t opretlen,nid,offset,k,MoMdepth,matched,len = 0; uint256 MoM,srchash,desttxid; uint8_t crypto777[33]; struct komodo_state *sp; char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN];
|
||||
@@ -616,7 +616,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr
|
||||
if ( j == 1 && opretlen >= len+offset-opoffset )
|
||||
{
|
||||
memset(&MoMoMdata,0,sizeof(MoMoMdata));
|
||||
if ( matched == 0 && bitweight(signedmask) >= KOMODO_MINRATIFY )
|
||||
if ( matched == 0 && signedmask != 0 && bitweight(signedmask) >= KOMODO_MINRATIFY )
|
||||
notarized = 1;
|
||||
if ( strcmp("PIZZA",ccdata.symbol) == 0 || strncmp("TXSCL",ccdata.symbol,5) == 0 )
|
||||
notarized = 1;
|
||||
@@ -685,7 +685,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr
|
||||
else
|
||||
{
|
||||
komodo_rwccdata(ASSETCHAINS_SYMBOL,1,&ccdata,&MoMoMdata);
|
||||
if ( matched != 0 )
|
||||
if ( !fJustCheck && matched != 0 )
|
||||
printf("[%s] matched.%d VALID (%s) MoM.%s [%d] CCid.%u\n",ASSETCHAINS_SYMBOL,matched,ccdata.symbol,MoM.ToString().c_str(),MoMdepth&0xffff,(MoMdepth>>16)&0xffff);
|
||||
}
|
||||
if ( MoMoMdata.pairs != 0 )
|
||||
@@ -695,13 +695,10 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr
|
||||
}
|
||||
else if ( ASSETCHAINS_SYMBOL[0] == 0 && matched != 0 && notarized != 0 && validated != 0 )
|
||||
komodo_rwccdata((char *)"KMD",1,&ccdata,0);
|
||||
else if ( ASSETCHAINS_NOTARY_PAY != 0 )
|
||||
{
|
||||
fprintf(stderr, "NOT matched NOTARISATION\n");
|
||||
return (-2);
|
||||
}
|
||||
if ( matched != 0 && *notarizedheightp > sp->NOTARIZED_HEIGHT && *notarizedheightp < height )
|
||||
{
|
||||
if ( fJustCheck )
|
||||
return(-2);
|
||||
sp->NOTARIZED_HEIGHT = *notarizedheightp;
|
||||
sp->NOTARIZED_HASH = srchash;
|
||||
sp->NOTARIZED_DESTTXID = desttxid;
|
||||
@@ -744,7 +741,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr
|
||||
}
|
||||
else if ( matched != 0 && i == 0 && j == 1 && opretlen == 149 )
|
||||
{
|
||||
if ( notaryid >= 0 && notaryid < 64 )
|
||||
if ( !fJustCheck && notaryid >= 0 && notaryid < 64 )
|
||||
komodo_paxpricefeed(height,&scriptbuf[len],opretlen);
|
||||
}
|
||||
else if ( matched != 0 )
|
||||
@@ -801,18 +798,18 @@ int32_t komodo_notarycmp(uint8_t *scriptPubKey,int32_t scriptlen,uint8_t pubkeys
|
||||
}
|
||||
|
||||
// int32_t !
|
||||
int32_t komodo_connectblock(CBlockIndex *pindex,CBlock& block)
|
||||
int32_t komodo_connectblock(bool fJustCheck, CBlockIndex *pindex,CBlock& block)
|
||||
{
|
||||
static int32_t hwmheight;
|
||||
int32_t staked_era; static int32_t lastStakedEra;
|
||||
|
||||
std::vector<int32_t> notarisations;
|
||||
uint64_t signedmask,voutmask; char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp;
|
||||
uint8_t scriptbuf[10001],pubkeys[64][33],rmd160[20],scriptPubKey[35]; uint256 zero,btctxid,txhash;
|
||||
int32_t i,j,k,numnotaries,notarized,scriptlen,isratification,nid,numvalid,specialtx,notarizedheight,notaryid,len,numvouts,numvins,height,txn_count;
|
||||
if ( pindex == 0 )
|
||||
{
|
||||
fprintf(stderr,"komodo_connectblock null pindex\n");
|
||||
return -1;
|
||||
return(0);
|
||||
}
|
||||
memset(&zero,0,sizeof(zero));
|
||||
komodo_init(pindex->GetHeight());
|
||||
@@ -820,13 +817,13 @@ int32_t komodo_connectblock(CBlockIndex *pindex,CBlock& block)
|
||||
if ( (sp= komodo_stateptr(symbol,dest)) == 0 )
|
||||
{
|
||||
fprintf(stderr,"unexpected null komodostateptr.[%s]\n",ASSETCHAINS_SYMBOL);
|
||||
return -1;
|
||||
return(0);
|
||||
}
|
||||
//fprintf(stderr,"%s connect.%d\n",ASSETCHAINS_SYMBOL,pindex->nHeight);
|
||||
if ( is_STAKED(ASSETCHAINS_SYMBOL) != 0 || IS_STAKED_NOTARY > -1 )
|
||||
{
|
||||
staked_era = STAKED_era(pindex->GetBlockTime());
|
||||
if ( staked_era != lastStakedEra )
|
||||
if ( !fJustCheck && staked_era != lastStakedEra )
|
||||
{
|
||||
uint8_t tmp_pubkeys[64][33];
|
||||
int8_t numSN = numStakedNotaries(tmp_pubkeys,staked_era);
|
||||
@@ -842,8 +839,8 @@ int32_t komodo_connectblock(CBlockIndex *pindex,CBlock& block)
|
||||
fprintf(stderr, "Staked Notary Protection Active! NotaryID.%d RADD.%s ERA.%d MIN_TX_VALUE.%lu \n",IS_STAKED_NOTARY,NOTARY_ADDRESS.c_str(),staked_era,MIN_RECV_SATS);
|
||||
}
|
||||
}
|
||||
lastStakedEra = staked_era;
|
||||
}
|
||||
lastStakedEra = staked_era;
|
||||
}
|
||||
numnotaries = komodo_notaries(pubkeys,pindex->GetHeight(),pindex->GetBlockTime());
|
||||
calc_rmd160_sha256(rmd160,pubkeys[0],33);
|
||||
@@ -857,11 +854,13 @@ int32_t komodo_connectblock(CBlockIndex *pindex,CBlock& block)
|
||||
komodo_purge_ccdata((int32_t)pindex->GetHeight());
|
||||
hwmheight = pindex->GetHeight();
|
||||
}
|
||||
komodo_event_rewind(sp,symbol,pindex->GetHeight());
|
||||
komodo_stateupdate(pindex->GetHeight(),0,0,0,zero,0,0,0,0,-pindex->GetHeight(),pindex->nTime,0,0,0,0,zero,0);
|
||||
if (!fJustCheck)
|
||||
{
|
||||
komodo_event_rewind(sp,symbol,pindex->GetHeight());
|
||||
komodo_stateupdate(pindex->GetHeight(),0,0,0,zero,0,0,0,0,-pindex->GetHeight(),pindex->nTime,0,0,0,0,zero,0);
|
||||
}
|
||||
}
|
||||
komodo_currentheight_set(chainActive.LastTip()->GetHeight());
|
||||
int transaction = 0;
|
||||
if ( pindex != 0 )
|
||||
{
|
||||
height = pindex->GetHeight();
|
||||
@@ -869,9 +868,12 @@ int32_t komodo_connectblock(CBlockIndex *pindex,CBlock& block)
|
||||
for (i=0; i<txn_count; i++)
|
||||
{
|
||||
if ( (is_STAKED(ASSETCHAINS_SYMBOL) != 0 && staked_era == 0) || (is_STAKED(ASSETCHAINS_SYMBOL) == 255) ) {
|
||||
// in era gap no point checking any invlaid notarisations.
|
||||
// in era gap or chain banned, no point checking any invlaid notarisations.
|
||||
break;
|
||||
}
|
||||
// Notary pay chains need notarisation in position 1, ignore the rest on validation. Check notarisation is 1 on check.
|
||||
if ( !fJustCheck && ASSETCHAINS_NOTARY_PAY != 0 && i > 1)
|
||||
break;
|
||||
txhash = block.vtx[i].GetHash();
|
||||
numvouts = block.vtx[i].vout.size();
|
||||
notaryid = -1;
|
||||
@@ -900,7 +902,7 @@ int32_t komodo_connectblock(CBlockIndex *pindex,CBlock& block)
|
||||
(numvalid >= KOMODO_MINRATIFY && ASSETCHAINS_SYMBOL[0] != 0) ||
|
||||
numvalid > (numnotaries/5) )
|
||||
{
|
||||
if ( ASSETCHAINS_SYMBOL[0] != 0)
|
||||
if ( !fJustCheck && ASSETCHAINS_SYMBOL[0] != 0)
|
||||
{
|
||||
static FILE *signedfp;
|
||||
if ( signedfp == 0 )
|
||||
@@ -917,7 +919,6 @@ int32_t komodo_connectblock(CBlockIndex *pindex,CBlock& block)
|
||||
fwrite(&signedmask,1,sizeof(signedmask),signedfp);
|
||||
fflush(signedfp);
|
||||
}
|
||||
transaction = i;
|
||||
printf("[%s] ht.%d txi.%d signedmask.%llx numvins.%d numvouts.%d <<<<<<<<<<< notarized\n",ASSETCHAINS_SYMBOL,height,i,(long long)signedmask,numvins,numvouts);
|
||||
}
|
||||
notarized = 1;
|
||||
@@ -947,9 +948,13 @@ int32_t komodo_connectblock(CBlockIndex *pindex,CBlock& block)
|
||||
if ( len >= sizeof(uint32_t) && len <= sizeof(scriptbuf) )
|
||||
{
|
||||
memcpy(scriptbuf,(uint8_t *)&block.vtx[i].vout[j].scriptPubKey[0],len);
|
||||
notaryid = komodo_voutupdate(&isratification,notaryid,scriptbuf,len,height,txhash,i,j,&voutmask,&specialtx,¬arizedheight,(uint64_t)block.vtx[i].vout[j].nValue,notarized,signedmask,(uint32_t)chainActive.LastTip()->GetBlockTime());
|
||||
if ( notaryid == -2 )
|
||||
return(-1);
|
||||
notaryid = komodo_voutupdate(fJustCheck,&isratification,notaryid,scriptbuf,len,height,txhash,i,j,&voutmask,&specialtx,¬arizedheight,(uint64_t)block.vtx[i].vout[j].nValue,notarized,signedmask,(uint32_t)chainActive.LastTip()->GetBlockTime());
|
||||
if ( fJustCheck && notaryid == -2 )
|
||||
{
|
||||
// We see a valid notarisation here, save its location.
|
||||
notarisations.push_back(i);
|
||||
}
|
||||
//fprintf(stderr, "notaryid.%i\n",notaryid);
|
||||
if ( 0 && i > 0 )
|
||||
{
|
||||
for (k=0; k<len; k++)
|
||||
@@ -962,7 +967,7 @@ int32_t komodo_connectblock(CBlockIndex *pindex,CBlock& block)
|
||||
printf(") ");
|
||||
if ( 0 && ASSETCHAINS_SYMBOL[0] == 0 )
|
||||
printf("[%s] ht.%d txi.%d signedmask.%llx numvins.%d numvouts.%d notarized.%d special.%d isratification.%d\n",ASSETCHAINS_SYMBOL,height,i,(long long)signedmask,numvins,numvouts,notarized,specialtx,isratification);
|
||||
if ( notarized != 0 && (notarizedheight != 0 || specialtx != 0) )
|
||||
if ( !fJustCheck && (notarized != 0 && (notarizedheight != 0 || specialtx != 0)) )
|
||||
{
|
||||
if ( isratification != 0 )
|
||||
{
|
||||
@@ -1000,17 +1005,23 @@ int32_t komodo_connectblock(CBlockIndex *pindex,CBlock& block)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( IS_KOMODO_NOTARY != 0 && ASSETCHAINS_SYMBOL[0] == 0 )
|
||||
if ( !fJustCheck && IS_KOMODO_NOTARY != 0 && ASSETCHAINS_SYMBOL[0] == 0 )
|
||||
printf("%s ht.%d\n",ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL,height);
|
||||
if ( pindex->GetHeight() == hwmheight )
|
||||
if ( !fJustCheck && pindex->GetHeight() == hwmheight )
|
||||
komodo_stateupdate(height,0,0,0,zero,0,0,0,0,height,(uint32_t)pindex->nTime,0,0,0,0,zero,0);
|
||||
} else fprintf(stderr,"komodo_connectblock: unexpected null pindex\n");
|
||||
//KOMODO_INITDONE = (uint32_t)time(NULL);
|
||||
//fprintf(stderr,"%s end connect.%d\n",ASSETCHAINS_SYMBOL,pindex->GetHeight());
|
||||
if (notarized = 1)
|
||||
return(transaction);
|
||||
else
|
||||
return(-1);
|
||||
if (fJustCheck)
|
||||
{
|
||||
if (notarisations.size() == 0)
|
||||
return(0);
|
||||
if ( notarisations.size() == 1 && notarisations[0] == 1 )
|
||||
return(1);
|
||||
else
|
||||
return(-1);
|
||||
}
|
||||
else return(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user