test
This commit is contained in:
@@ -19,7 +19,6 @@
|
||||
// Todo:
|
||||
// verify: reorgs
|
||||
|
||||
|
||||
#define KOMODO_ASSETCHAINS_WAITNOTARIZE
|
||||
#define KOMODO_PAXMAX (10000 * COIN)
|
||||
|
||||
@@ -303,7 +302,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar
|
||||
else if ( height != 0 )
|
||||
{
|
||||
//printf("ht.%d func N ht.%d errs.%d\n",height,NOTARIZED_HEIGHT,errs);
|
||||
if ( sp != 0 )
|
||||
if ( sp != 0 && (height < sp->CURRENT_HEIGHT-1000 || komodo_verifynotarization(symbol,dest,height,sp->NOTARIZED_HEIGHT,sp->NOTARIZED_HASH,sp->NOTARIZED_DESTTXID) == 0) )
|
||||
{
|
||||
fputc('N',fp);
|
||||
if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) )
|
||||
|
||||
@@ -346,6 +346,56 @@ char *komodo_issuemethod(char *userpass,char *method,char *params,uint16_t port)
|
||||
return(retstr2);
|
||||
}
|
||||
|
||||
int32_t komodo_verifynotarizedscript(uint8_t *script,int32_t len,uint256 NOTARIZED_HASH)
|
||||
{
|
||||
int32_t i; uint256 hash; char params[256];
|
||||
for (i=0; i<32; i++)
|
||||
printf("%02x",((uint8_t *)&NOTARIZED_HASH)[i]);
|
||||
printf(" notarized, ");
|
||||
for (i=0; i<32; i++)
|
||||
{
|
||||
((uint8_t *)&hash)[i] = script[31+2-i];
|
||||
printf("%02x",script[31+2-i]);
|
||||
}
|
||||
printf(" <- opreturn?\n");
|
||||
if ( hash == NOTARIZED_HASH )
|
||||
return(0);
|
||||
else return(-1);
|
||||
}
|
||||
|
||||
int32_t komodo_verifynotarization(char *symbol,char *dest,int32_t height,int32_t NOTARIZED_HEIGHT,uint256 NOTARIZED_HASH,uint256 NOTARIZED_DESTTXID)
|
||||
{
|
||||
char params[256],*jsonstr,*hexstr; uint8_t script[8192]; int32_t n,len,retval = -1; cJSON *txjson,*vouts,*vout,*skey;
|
||||
sprintf(params,"[\"%s\", 1]",NOTARIZED_DESTTXID.ToString().c_str());
|
||||
if ( strcmp(dest,"KMD") == 0 )
|
||||
jsonstr = komodo_issuemethod(KMDUSERPASS,(char *)"getrawtransaction",params,7771);
|
||||
else if ( strcmp(dest,"BTC") == 0 )
|
||||
jsonstr = komodo_issuemethod(BTCUSERPASS,(char *)"getrawtransaction",params,8332);
|
||||
else return(-1);
|
||||
if ( jsonstr != 0 )
|
||||
{
|
||||
if ( (txjson= cJSON_Parse(jsonstr)) != 0 )
|
||||
{
|
||||
if ( (vouts= jarray(&n,txjson,"vout")) > 0 )
|
||||
{
|
||||
vout = jitem(vouts,n-1);
|
||||
if ( (skey= jobj(vout,"scriptPubKey")) != 0 )
|
||||
{
|
||||
if ( (hexstr= jstr(skey,"hex")) != 0 )
|
||||
{
|
||||
len = strlen(hexstr) >> 1;
|
||||
decode_hex(script,len,hexstr);
|
||||
retval = komodo_verifynotarizedscript(script,len,NOTARIZED_HASH);
|
||||
}
|
||||
}
|
||||
}
|
||||
free_json(txjson);
|
||||
}
|
||||
free(jsonstr);
|
||||
}
|
||||
return(retval);
|
||||
}
|
||||
|
||||
uint256 komodo_getblockhash(int32_t height)
|
||||
{
|
||||
uint256 hash; char params[128],*hexstr,*jsonstr; cJSON *result; int32_t i; uint8_t revbuf[32];
|
||||
|
||||
@@ -47,5 +47,5 @@ uint32_t ASSETCHAINS_MAGIC = 2387029918;
|
||||
uint64_t ASSETCHAINS_SUPPLY = 10;
|
||||
|
||||
uint32_t KOMODO_INITDONE;
|
||||
char KMDUSERPASS[1024]; uint16_t BITCOIND_PORT = 7771;
|
||||
char KMDUSERPASS[4096],BTCUSERPASS[4096]; uint16_t BITCOIND_PORT = 7771;
|
||||
uint64_t PENDING_KOMODO_TX;
|
||||
|
||||
@@ -1347,7 +1347,11 @@ void komodo_configfile(char *symbol,uint16_t port)
|
||||
#else
|
||||
while ( fname[strlen(fname)-1] != '/' )
|
||||
fname[strlen(fname)-1] = 0;
|
||||
#ifdef __APPLE__
|
||||
strcat(fname,"Komodo.conf");
|
||||
#else
|
||||
strcat(fname,"komodo.conf");
|
||||
#endif
|
||||
#endif
|
||||
if ( (fp= fopen(fname,"rb")) != 0 )
|
||||
{
|
||||
@@ -1363,7 +1367,13 @@ int32_t komodo_userpass(char *userpass,char *symbol)
|
||||
FILE *fp; char fname[512],username[512],password[512],confname[16];
|
||||
userpass[0] = 0;
|
||||
if ( strcmp("KMD",symbol) == 0 )
|
||||
{
|
||||
#ifdef __APPLE__
|
||||
sprintf(confname,"Komodo.conf");
|
||||
#else
|
||||
sprintf(confname,"komodo.conf");
|
||||
#endif
|
||||
}
|
||||
else sprintf(confname,"%s.conf",symbol);
|
||||
komodo_statefname(fname,symbol,confname);
|
||||
if ( (fp= fopen(fname,"rb")) != 0 )
|
||||
@@ -1494,23 +1504,36 @@ void komodo_args()
|
||||
{
|
||||
char fname[512],username[512],password[4096]; FILE *fp;
|
||||
ASSETCHAINS_PORT = 8777;
|
||||
strcpy(fname,GetDataDir().string().c_str());
|
||||
#ifdef WIN32
|
||||
while ( fname[strlen(fname)-1] != '\\' )
|
||||
fname[strlen(fname)-1] = 0;
|
||||
strcat(fname,".komodo/komodo.conf");
|
||||
#else
|
||||
while ( fname[strlen(fname)-1] != '/' )
|
||||
fname[strlen(fname)-1] = 0;
|
||||
strcat(fname,".komodo/komodo.conf");
|
||||
#endif
|
||||
if ( (fp= fopen(fname,"rb")) != 0 )
|
||||
for (iter=0; iter<2; iter++)
|
||||
{
|
||||
komodo_userpass(username,password,fp);
|
||||
sprintf(KMDUSERPASS,"%s:%s",username,password);
|
||||
fclose(fp);
|
||||
//printf("KOMODO.(%s) -> userpass.(%s)\n",fname,KMDUSERPASS);
|
||||
} else printf("couldnt open.(%s)\n",fname);
|
||||
strcpy(fname,GetDataDir().string().c_str());
|
||||
#ifdef WIN32
|
||||
while ( fname[strlen(fname)-1] != '\\' )
|
||||
fname[strlen(fname)-1] = 0;
|
||||
if ( iter == 0 )
|
||||
strcat(fname,".komodo\\komodo.conf");
|
||||
else strcat(fname,".bitcoin\\bitcoin.conf");
|
||||
#else
|
||||
while ( fname[strlen(fname)-1] != '/' )
|
||||
fname[strlen(fname)-1] = 0;
|
||||
#ifdef __APPLE__
|
||||
if ( iter == 0 )
|
||||
strcat(fname,"Komodo/Komodo.conf");
|
||||
else strcat(fname,"Bitcoin/Bitcoin.conf");
|
||||
#else
|
||||
if ( iter == 0 )
|
||||
strcat(fname,".komodo/komodo.conf");
|
||||
else strcat(fname,".bitcoin/bitcoin.conf");
|
||||
#endif
|
||||
#endif
|
||||
if ( (fp= fopen(fname,"rb")) != 0 )
|
||||
{
|
||||
komodo_userpass(username,password,fp);
|
||||
sprintf(iter == 0 ? KMDUSERPASS : BTCUSERPASS,"%s:%s",username,password);
|
||||
fclose(fp);
|
||||
//printf("KOMODO.(%s) -> userpass.(%s)\n",fname,KMDUSERPASS);
|
||||
} else printf("couldnt open.(%s)\n",fname);
|
||||
}
|
||||
}
|
||||
//fprintf(stderr,"%s chain params initialized\n",ASSETCHAINS_SYMBOL);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user