From f60002915ff70d25bd8d8228cfbe9ee2ef80a3ff Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Jun 2016 16:09:58 -0300 Subject: [PATCH] test --- basilisk/basilisk.c | 2 +- basilisk/basilisk_CMD.c | 115 ----------- deprecated/obsolete.h | 448 ++++++++++++++++++++++++++++++++++++++++ gecko/gecko.c | 338 +----------------------------- gecko/gecko_blocks.c | 3 +- gecko/gecko_miner.c | 2 +- 6 files changed, 453 insertions(+), 455 deletions(-) diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index d87381e66..8b9471b69 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -17,7 +17,7 @@ //typedef char *basilisk_coinfunc(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen); typedef char *basilisk_servicefunc(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 hash,int32_t from_basilisk); -typedef struct basilisk_item *basilisk_requestfunc(struct basilisk_item *Lptr,struct supernet_info *myinfo,bits256 hash,cJSON *valsobj,uint8_t *data,int32_t datalen); +//typedef struct basilisk_item *basilisk_requestfunc(struct basilisk_item *Lptr,struct supernet_info *myinfo,bits256 hash,cJSON *valsobj,uint8_t *data,int32_t datalen); uint32_t basilisk_calcnonce(struct supernet_info *myinfo,uint8_t *data,int32_t datalen,uint32_t nBits) { diff --git a/basilisk/basilisk_CMD.c b/basilisk/basilisk_CMD.c index b2a15c582..252a27c2b 100755 --- a/basilisk/basilisk_CMD.c +++ b/basilisk/basilisk_CMD.c @@ -78,83 +78,6 @@ char *basilisk_addrelay_info(struct supernet_info *myinfo,uint8_t *pubkey33,uint return(clonestr("{\"result\":\"relay added\"}")); } -/*char *basilisk_respond_relays(struct supernet_info *myinfo,char *CMD,void *_addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 hash,int32_t from_basilisk) -{ - bits256 txhash2; uint32_t ipbits; int32_t i,n,len,siglen; uint8_t pubkey33[65],sig[128]; char *sigstr = 0,*retstr,pubstr[128]; - if ( (sigstr= jstr(valsobj,"sig")) != 0 ) - { - siglen = (int32_t)strlen(sigstr) >> 1; - if ( siglen < sizeof(sig) ) - { - decode_hex(sig,siglen,sigstr); - vcalc_sha256(0,txhash2.bytes,data,datalen); - memset(pubkey33,0,33); - if ( bitcoin_recoververify(myinfo->ctx,"BTCD",sig,txhash2,pubkey33) == 0 ) - { - // compare with existing - init_hexbytes_noT(pubstr,pubkey33,33); - printf(" verified relay data siglen.%d pub33.%s\n",siglen,pubstr); - if ( (retstr= basilisk_addrelay_info(myinfo,pubkey33,(uint32_t)calc_ipbits(remoteaddr),hash)) != 0 ) - free(retstr); - n = (int32_t)(datalen / sizeof(uint32_t)); - for (i=len=0; irelaybits)]; cJSON *vals; bits256 hash; char *retstr,hexstr[sizeof(myinfo->relaybits)*2 + 1]; - //printf("skip sending relays\n"); - if ( 0 && myinfo != 0 ) - { - vals = cJSON_CreateObject(); - hash = myinfo->myaddr.persistent; - for (i=0; inumrelays; i++) - len += iguana_rwnum(1,&serialized[len],sizeof(uint32_t),&myinfo->relaybits[i]); - init_hexbytes_noT(hexstr,serialized,len); - //printf("send relays.(%s)\n",hexstr); - vcalc_sha256(0,txhash2.bytes,serialized,len); - if ( 0 && bits256_nonz(myinfo->persistent_priv) != 0 && (siglen= bitcoin_sign(myinfo->ctx,"BTCD",sig,txhash2,myinfo->persistent_priv,1)) > 0 ) - { - init_hexbytes_noT(strbuf,sig,siglen); - jaddstr(vals,"sig",strbuf); - } - if ( (retstr= basilisk_standardservice("RLY",myinfo,hash,vals,hexstr,0)) != 0 ) - free(retstr); - free_json(vals); - return(0); - } else return(-1); -} - -char *basilisk_respond_relays(struct supernet_info *myinfo,char *CMD,void *_addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 hash,int32_t from_basilisk) -{ - uint32_t *ipbits = (uint32_t *)data; int32_t num,i,j,n = datalen >> 2; - for (i=num=0; inumrelays; j++) - if ( ipbits[i] == myinfo->relays[j].ipbits ) - break; - if ( j == myinfo->numrelays ) - { - num++; - printf("i.%d j.%d ensure new relay.(%s)\n",i,j,remoteaddr); - basilisk_ensurerelay(iguana_coinfind("BTCD"),ipbits[i]); - } - } - if ( num == 0 ) - return(clonestr("{\"result\":\"no new relays found\"}")); - else return(clonestr("{\"result\":\"relay added\"}")); -}*/ - char *basilisk_respond_goodbye(struct supernet_info *myinfo,char *CMD,void *_addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 hash,int32_t from_basilisk) { struct iguana_peer *addr = _addr; @@ -276,30 +199,6 @@ HASH_ARRAY_STRING(basilisk,value,hash,vals,hexstr) //return(basilisk_standardcmd(myinfo,"VAL",activecoin,remoteaddr,basilisktag,vals,coin->basilisk_value,coin->basilisk_valuemetric)); } -/*char *basilisk_checkrawtx(int32_t *timeoutmillisp,uint32_t *basilisktagp,char *symbol,cJSON *vals) -{ - cJSON *addresses=0; char *changeaddr,*spendscriptstr; int32_t i,n; - *timeoutmillisp = -1; - changeaddr = jstr(vals,"changeaddr"); - spendscriptstr = jstr(vals,"spendscript"); - addresses = jarray(&n,vals,"addresses"); - if ( addresses == 0 || changeaddr == 0 || changeaddr[0] == 0 ) - return(clonestr("{\"error\":\"invalid addresses[] or changeaddr\"}")); - else - { - for (i=0; ibasilisk_rawtx,coin->basilisk_rawtxmetric,myinfo,remoteaddr,basilisktag,activecoin,timeoutmillis,vals)) != 0 ) - { - if ( (ptr->numrequired= juint(vals,"numrequired")) == 0 ) - ptr->numrequired = 1; - //ptr->uniqueflag = 1; - //ptr->metricdir = -1; - return(basilisk_waitresponse(myinfo,"RAW",coin->symbol,remoteaddr,&Lptr,vals,ptr)); - } else return(clonestr("{\"error\":\"error issuing basilisk rawtx\"}")); - } //else return(retstr);*/ } HASH_ARRAY_STRING(basilisk,addrelay,hash,vals,hexstr) diff --git a/deprecated/obsolete.h b/deprecated/obsolete.h index b37f95416..7bd1e7d29 100755 --- a/deprecated/obsolete.h +++ b/deprecated/obsolete.h @@ -17766,6 +17766,454 @@ len = 0; } else Lptr->retstr = clonestr("{\"error\":\"error missing coin\"}"); return(Lptr); } + /*int32_t gecko_chainvals(struct supernet_info *myinfo,char *CMD,cJSON *valsobj) + { + struct iguana_info *virt; struct gecko_chain *chain; bits256 hash,prevhash; struct iguana_block *block; char chainname[GECKO_MAXNAMELEN]; + if ( strcmp(CMD,"SET") == 0 || strcmp(CMD,"GET") == 0 ) + { + if ( (chain= gecko_chain(myinfo,chainname,valsobj)) == 0 || (virt= chain->info) == 0 ) + clonestr("{\"error\":\"cant find gecko chain\"}"); + if ( strcmp(CMD,"SET") == 0 ) + { + hash = GENESIS_PUBKEY; + if ( jobj(valsobj,"prev") != 0 ) + { + prevhash = jbits256(valsobj,"prev"); + if ( (block= iguana_blockfind("basilisk",virt,prevhash)) == 0 ) + { + char str[65]; printf("warning couldnt find %s in %s\n",bits256_str(str,prevhash),chainname); + prevhash = virt->blocks.hwmchain.RO.hash2; + } + } else prevhash = virt->blocks.hwmchain.RO.hash2; + hash = prevhash; + if ( jobj(valsobj,"prev") != 0 ) + jdelete(valsobj,"prev"); + } + return(0); + } + return(-1); + } + + cJSON *gecko_genesisargs(char *symbol,char *chainname,char *chain,char *keystr,char *genesishash,char *genesisblock,char *magicstr,uint16_t port,uint16_t blocktime,char *nbitstr,char *pubval,char *p2shval,char *wifval,uint32_t isPoS) + { + int32_t timespan,targetspacing; cJSON *argvals = cJSON_CreateObject(); + if ( genesishash != 0 && genesishash[0] != 0 ) + jaddstr(argvals,"genesishash",genesishash); + if ( genesisblock != 0 && genesisblock[0] != 0 ) + jaddstr(argvals,"genesisblock",genesisblock); + jaddstr(argvals,"netmagic",magicstr); + jaddstr(argvals,"symbol",symbol); + jaddstr(argvals,"name",chainname); + if ( pubval == 0 || is_hexstr(pubval,0) != 2 ) + pubval = "00"; + jaddstr(argvals,"pubval",pubval); + if ( p2shval == 0 || is_hexstr(p2shval,0) != 2 ) + p2shval = "05"; + jaddstr(argvals,"p2shval",p2shval); + if ( wifval == 0 || is_hexstr(wifval,0) != 2 ) + wifval = "80"; + jaddstr(argvals,"wifval",wifval); + if ( nbitstr == 0 || nbitstr[0] == 0 ) + nbitstr = GECKO_DEFAULTDIFFSTR; + jaddstr(argvals,"nBits",nbitstr); + jaddstr(argvals,"chain",chain); + if ( keystr != 0 ) + jaddstr(argvals,"key",keystr); + jaddnum(argvals,"isPoS",isPoS); + //printf("argvals isPoS.%d\n",isPoS); + if ( port == 0 ) + { + jaddstr(argvals,"geckochain",chainname); + jaddnum(argvals,"services",128); + } + else + { + jaddnum(argvals,"services",129); + jaddnum(argvals,"portp2p",port); + } + if ( blocktime == 0 ) + blocktime = 1; + jaddnum(argvals,"blocktime",blocktime); + if ( blocktime != 0 && 0 ) + { + if ( blocktime == 0xffff ) + targetspacing = 24 * 60 * 60; // one day + else targetspacing = blocktime; // one minute + jaddnum(argvals,"targetspacing",targetspacing); + if ( (timespan= sqrt(604800 / targetspacing)) < 7 ) + timespan = 7; + jaddnum(argvals,"targettimespan",targetspacing * timespan); + } + return(argvals); + } + + cJSON *gecko_genesisjson(struct supernet_info *myinfo,struct iguana_info *btcd,int32_t isPoS,char *symbol,char *chainname,cJSON *valsobj,char *magicstr,uint16_t blocktime) + { + char str2[64],hashstr[65],argbuf[1024],*pubstr,*p2shstr,*wifvalstr,*nbitstr,*blockstr; uint8_t buf[4]; int32_t i; uint32_t nBits; struct iguana_block genesis; + if ( (nbitstr= jstr(valsobj,"nBits")) == 0 ) + { + nBits = GECKO_DEFAULTDIFF; + nbitstr = GECKO_DEFAULTDIFFSTR; + } + else + { + for (i=0; i<4; i++) + decode_hex(&buf[3-i],1,&nbitstr[i*2]); + memcpy(&nBits,buf,sizeof(nBits)); + } + if ( (blocktime= juint(valsobj,"blocktime")) == 0 ) + blocktime = 1; + if ( (pubstr= jstr(valsobj,"pubval")) == 0 ) + pubstr = "00"; + if ( (p2shstr= jstr(valsobj,"p2shval")) == 0 ) + p2shstr = "05"; + if ( (wifvalstr= jstr(valsobj,"wifval")) == 0 ) + wifvalstr = "80"; + printf("json netmagic.%s\n",magicstr); + memset(&genesis,0,sizeof(genesis)); + genesis.RO.version = GECKO_DEFAULTVERSION; + genesis.RO.bits = nBits; + if ( (blockstr= gecko_createblock(myinfo,blocktime,0,btcd,isPoS,&genesis,symbol,0,0,10000,0,0)) != 0 ) + { + bits256_str(hashstr,genesis.RO.hash2); + sprintf(argbuf,"{\"isPoS\":%d,\"name\":\"%s\",\"symbol\":\"%s\",\"netmagic\":\"%s\",\"port\":%u,\"blocktime\":%u,\"pubval\":\"%s\",\"p2shval\":\"%s\",\"wifval\":\"%s\",\"isPoS\":%u,\"unitval\":\"%02x\",\"genesishash\":\"%s\",\"genesis\":{\"version\":1,\"timestamp\":%u,\"nBits\":\"%s\",\"nonce\":%d,\"merkle_root\":\"%s\"},\"genesisblock\":\"%s\"}",isPoS,chainname,symbol,magicstr,juint(valsobj,"port"),blocktime,pubstr,p2shstr,wifvalstr,juint(valsobj,"isPoS"),(nBits >> 24) & 0xff,hashstr,genesis.RO.timestamp,nbitstr,genesis.RO.nonce,bits256_str(str2,genesis.RO.merkle_root),blockstr); + free(blockstr); + printf("argbuf.(%s) hash.%s\n",argbuf,hashstr); + return(cJSON_Parse(argbuf)); + } else return(cJSON_Parse("{\"error\":\"couldnt create block\"}")); + } + + cJSON *gecko_genesisissue(char *symbol,char *chainname,char *chainstr,cJSON *valsobj) + { + printf("issue blocktime.%d\n",juint(valsobj,"blocktime")); + return(gecko_genesisargs(symbol,chainname,chainstr,jstr(valsobj,"key"),jstr(valsobj,"genesishash"),jstr(valsobj,"genesisblock"),jstr(valsobj,"netmagic"),juint(valsobj,"port"),juint(valsobj,"blocktime"),jstr(valsobj,"nBits"),jstr(valsobj,"pubval"),jstr(valsobj,"p2shval"),jstr(valsobj,"wifval"),juint(valsobj,"isPoS"))); + }*/ + /*char *basilisk_respond_newgeckochain(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 prevhash,int32_t from_basilisk) + { + struct iguana_info *virt,*btcd; struct gecko_chain *chain; char fname[512],*symbol,*retstr,*chainstr,chainname[GECKO_MAXNAMELEN],*genesises; cJSON *chainjson,*retjson,*genesisjson; long filesize; FILE *fp; + if ( (chain= gecko_chain(myinfo,chainname,valsobj)) != 0 && (virt= chain->info) != 0 ) + { + //printf("%s already exists\n",chainname); + return(clonestr("{\"error\":\"cant create duplicate geckochain\"}")); + } + if ( (btcd= iguana_coinfind("BTCD")) != 0 && (symbol= jstr(valsobj,"symbol")) != 0 && (chainstr= jstr(valsobj,"chain")) != 0 ) + { + if ( (virt= basilisk_geckochain(myinfo,symbol,chainname,valsobj)) != 0 ) + { + chain->info = virt; + if ( (retjson= gecko_genesisissue(symbol,chainname,chainstr,valsobj)) != 0 ) + { + jaddstr(retjson,"result","success"); + retstr = jprint(retjson,0); + sprintf(fname,"genesis/%s",symbol); + genesisjson = 0; + filesize = 0; + if ( (fp= fopen(fname,"wb")) != 0 ) + { + if ( fwrite(retstr,1,strlen(retstr),fp) == strlen(retstr) ) + { + if ( (genesises= OS_filestr(&filesize,"genesis/list")) != 0 ) + { + genesisjson = cJSON_Parse(genesises); + free(genesises); + } else genesisjson = cJSON_CreateArray(); + chainjson = cJSON_CreateObject(); + jaddstr(chainjson,"chain",chainname); + jaddstr(chainjson,"symbol",symbol); + jaddstr(chainjson,"agent","basilisk"); + jaddstr(chainjson,"method","newgeckochain"); + jadd(chainjson,"vals",retjson); + jaddi(genesisjson,chainjson); + } + fclose(fp); + } + if ( genesisjson != 0 ) + { + genesises = jprint(genesisjson,1); + if ( strlen(genesises) > filesize ) + { + if ( (fp= fopen("genesis/list","wb")) != 0 ) + { + fwrite(genesises,1,strlen(genesises),fp); + fclose(fp); + } + } + } else free_json(retjson); + return(retstr); + } else return(clonestr("{\"error\":\"couldnt create gecko genesis\"}")); + } + } + return(clonestr("{\"error\":-22}")); + } + + int32_t gecko_genesises(struct supernet_info *myinfo,cJSON *array) + { + char *chainstr,chainname[GECKO_MAXNAMELEN],*symbol; int32_t i,n,num=0; cJSON *item,*valsobj; struct iguana_info *btcd,*virt; struct gecko_chain *chain; + if ( (btcd= iguana_coinfind("BTCD")) == 0 ) + return(0); + if ( array != 0 && (n= cJSON_GetArraySize(array)) != 0 ) + { + for (i=0; iinfo) != 0 ) + { + //printf("%s %s already exists\n",chainname,symbol); + continue; + } + if ( (virt= basilisk_geckochain(myinfo,symbol,chainname,valsobj)) != 0 ) + { + myinfo->genesisresults++; + chain->info = virt; + num++; + } + } + } + } + return(num); + } + + char *basilisk_respond_geckogenesis(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 txid,int32_t from_basilisk) + { + long filesize; + return(OS_filestr(&filesize,"genesis/list")); + }*/ + /*HASH_ARRAY_STRING(basilisk,sequence,hash,vals,hexstr) + { + return(basilisk_standardservice("SEQ",myinfo,hash,vals,hexstr,1)); + } + + HASH_ARRAY_STRING(basilisk,newgeckochain,hash,vals,hexstr) + { + char chainname[GECKO_MAXNAMELEN],magicstr[9],*retstr=0,*symbol,*chainstr; struct iguana_info *btcd; cJSON *argjson,*argvals,*retjson=0; int32_t i,isPoS; uint32_t magic; struct gecko_chain *chain; + if ( (btcd= iguana_coinfind("BTCD")) != 0 && (symbol= jstr(vals,"symbol")) != 0 && (chainstr= jstr(vals,"chain")) != 0 ) + { + if ( iguana_coinfind(symbol) == 0 && (chain= gecko_chain(myinfo,chainname,vals)) != 0 && chain->info != 0 ) + { + printf("%s already exists\n",chainname); + return(clonestr("{\"error\":\"cant create duplicate geckochain\"}")); + } + if ( jobj(vals,"netmagic") == 0 ) + { + OS_randombytes((void *)&magic,sizeof(magic)); + for (i=0; iRELAYNODE != 0 || btcd->VALIDATENODE != 0 ) + { + basilisk_wait(myinfo,0); + retstr = basilisk_respond_newgeckochain(myinfo,"NEW",0,0,0,argvals,0,0,GENESIS_PUBKEY,0); + } + if ( retstr == 0 ) + retstr = basilisk_standardservice("NEW",myinfo,GENESIS_PUBKEY,argvals,0,1); + free_json(argvals); + if ( (argvals= cJSON_Parse(retstr)) != 0 ) + { + if ( jobj(argvals,"result") != 0 && strcmp(jstr(argvals,"result"),"success") == 0 ) + { + if ( basilisk_geckochain(myinfo,symbol,chainname,argvals) != 0 ) + jaddstr(argvals,"status","active"); + } else jaddstr(argvals,"error","couldnt initialize geckochain"); + free(retstr); + return(jprint(argvals,1)); + } + if ( retjson != 0 ) + free_json(retjson); + free_json(argvals); + return(retstr); + } else return(clonestr("{\"error\":\"couldnt create genesis_block\"}")); + } + return(clonestr("{\"error\":\"need symbol and chain and BTCD to create new gecko chain\"}")); + }*/ + + /*HASH_ARRAY_STRING(basilisk,geckogenesis,hash,vals,hexstr) + { + long filesize; int32_t i,j,n,m; struct iguana_info *btcd; char *ref,*symbol,*retstr=0; cJSON *item,*array = 0,*arrayB = 0; FILE *fp; + if ( (btcd= iguana_coinfind("BTCD")) != 0 ) + { + if ( (retstr= basilisk_standardservice("GEN",myinfo,hash,vals,hexstr,1)) != 0 ) + { + arrayB = cJSON_Parse(retstr); + free(retstr); + } + if ( btcd->RELAYNODE != 0 || btcd->VALIDATENODE != 0 ) + { + if ( (retstr= OS_filestr(&filesize,"genesis/list")) != 0 ) + { + array = cJSON_Parse(retstr); + free(retstr); + } + if ( array == 0 ) + array = arrayB; + else if ( arrayB != 0 ) + { + if ( (n= cJSON_GetArraySize(array)) > 0 ) + { + if ( (m= cJSON_GetArraySize(arrayB)) > 0 ) + { + for (j=0; j> 1; + if ( siglen < sizeof(sig) ) + { + decode_hex(sig,siglen,sigstr); + vcalc_sha256(0,txhash2.bytes,data,datalen); + memset(pubkey33,0,33); + if ( bitcoin_recoververify(myinfo->ctx,"BTCD",sig,txhash2,pubkey33) == 0 ) + { + // compare with existing + init_hexbytes_noT(pubstr,pubkey33,33); + printf(" verified relay data siglen.%d pub33.%s\n",siglen,pubstr); + if ( (retstr= basilisk_addrelay_info(myinfo,pubkey33,(uint32_t)calc_ipbits(remoteaddr),hash)) != 0 ) + free(retstr); + n = (int32_t)(datalen / sizeof(uint32_t)); + for (i=len=0; irelaybits)]; cJSON *vals; bits256 hash; char *retstr,hexstr[sizeof(myinfo->relaybits)*2 + 1]; + //printf("skip sending relays\n"); + if ( 0 && myinfo != 0 ) + { + vals = cJSON_CreateObject(); + hash = myinfo->myaddr.persistent; + for (i=0; inumrelays; i++) + len += iguana_rwnum(1,&serialized[len],sizeof(uint32_t),&myinfo->relaybits[i]); + init_hexbytes_noT(hexstr,serialized,len); + //printf("send relays.(%s)\n",hexstr); + vcalc_sha256(0,txhash2.bytes,serialized,len); + if ( 0 && bits256_nonz(myinfo->persistent_priv) != 0 && (siglen= bitcoin_sign(myinfo->ctx,"BTCD",sig,txhash2,myinfo->persistent_priv,1)) > 0 ) + { + init_hexbytes_noT(strbuf,sig,siglen); + jaddstr(vals,"sig",strbuf); + } + if ( (retstr= basilisk_standardservice("RLY",myinfo,hash,vals,hexstr,0)) != 0 ) + free(retstr); + free_json(vals); + return(0); + } else return(-1); + } + + char *basilisk_respond_relays(struct supernet_info *myinfo,char *CMD,void *_addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 hash,int32_t from_basilisk) + { + uint32_t *ipbits = (uint32_t *)data; int32_t num,i,j,n = datalen >> 2; + for (i=num=0; inumrelays; j++) + if ( ipbits[i] == myinfo->relays[j].ipbits ) + break; + if ( j == myinfo->numrelays ) + { + num++; + printf("i.%d j.%d ensure new relay.(%s)\n",i,j,remoteaddr); + basilisk_ensurerelay(iguana_coinfind("BTCD"),ipbits[i]); + } + } + if ( num == 0 ) + return(clonestr("{\"result\":\"no new relays found\"}")); + else return(clonestr("{\"result\":\"relay added\"}")); + }*/ + + /*char *basilisk_checkrawtx(int32_t *timeoutmillisp,uint32_t *basilisktagp,char *symbol,cJSON *vals) + { + cJSON *addresses=0; char *changeaddr,*spendscriptstr; int32_t i,n; + *timeoutmillisp = -1; + changeaddr = jstr(vals,"changeaddr"); + spendscriptstr = jstr(vals,"spendscript"); + addresses = jarray(&n,vals,"addresses"); + if ( addresses == 0 || changeaddr == 0 || changeaddr[0] == 0 ) + return(clonestr("{\"error\":\"invalid addresses[] or changeaddr\"}")); + else + { + for (i=0; ibasilisk_rawtx,coin->basilisk_rawtxmetric,myinfo,remoteaddr,basilisktag,activecoin,timeoutmillis,vals)) != 0 ) + { + if ( (ptr->numrequired= juint(vals,"numrequired")) == 0 ) + ptr->numrequired = 1; + //ptr->uniqueflag = 1; + //ptr->metricdir = -1; + return(basilisk_waitresponse(myinfo,"RAW",coin->symbol,remoteaddr,&Lptr,vals,ptr)); + } else return(clonestr("{\"error\":\"error issuing basilisk rawtx\"}")); + } //else return(retstr);*/ #endif #endif diff --git a/gecko/gecko.c b/gecko/gecko.c index 99062b8e7..994494afe 100755 --- a/gecko/gecko.c +++ b/gecko/gecko.c @@ -56,7 +56,7 @@ void gecko_iteration(struct supernet_info *myinfo,struct iguana_info *btcd,struc virt->hdrstime = (uint32_t)time(NULL); } } - //if ( btcd->RELAYNODE != 0 )//&& virt->blocks.hwmchain.height >= virt->longestchain-virt->chain->bundlesize ) + if ( btcd->RELAYNODE != 0 && myinfo->RELAYID == 0 )//&& virt->blocks.hwmchain.height >= virt->longestchain-virt->chain->bundlesize ) { bitcoin_address(mineraddr,virt->chain->pubtype,myinfo->persistent_pubkey33,33); //fprintf(stderr,"mine.%s %s\n",virt->symbol,mineraddr); @@ -162,129 +162,6 @@ struct gecko_chain *gecko_chain(struct supernet_info *myinfo,char chainname[GECK return(chain); } -/*int32_t gecko_chainvals(struct supernet_info *myinfo,char *CMD,cJSON *valsobj) -{ - struct iguana_info *virt; struct gecko_chain *chain; bits256 hash,prevhash; struct iguana_block *block; char chainname[GECKO_MAXNAMELEN]; - if ( strcmp(CMD,"SET") == 0 || strcmp(CMD,"GET") == 0 ) - { - if ( (chain= gecko_chain(myinfo,chainname,valsobj)) == 0 || (virt= chain->info) == 0 ) - clonestr("{\"error\":\"cant find gecko chain\"}"); - if ( strcmp(CMD,"SET") == 0 ) - { - hash = GENESIS_PUBKEY; - if ( jobj(valsobj,"prev") != 0 ) - { - prevhash = jbits256(valsobj,"prev"); - if ( (block= iguana_blockfind("basilisk",virt,prevhash)) == 0 ) - { - char str[65]; printf("warning couldnt find %s in %s\n",bits256_str(str,prevhash),chainname); - prevhash = virt->blocks.hwmchain.RO.hash2; - } - } else prevhash = virt->blocks.hwmchain.RO.hash2; - hash = prevhash; - if ( jobj(valsobj,"prev") != 0 ) - jdelete(valsobj,"prev"); - } - return(0); - } - return(-1); -} - -cJSON *gecko_genesisargs(char *symbol,char *chainname,char *chain,char *keystr,char *genesishash,char *genesisblock,char *magicstr,uint16_t port,uint16_t blocktime,char *nbitstr,char *pubval,char *p2shval,char *wifval,uint32_t isPoS) -{ - int32_t timespan,targetspacing; cJSON *argvals = cJSON_CreateObject(); - if ( genesishash != 0 && genesishash[0] != 0 ) - jaddstr(argvals,"genesishash",genesishash); - if ( genesisblock != 0 && genesisblock[0] != 0 ) - jaddstr(argvals,"genesisblock",genesisblock); - jaddstr(argvals,"netmagic",magicstr); - jaddstr(argvals,"symbol",symbol); - jaddstr(argvals,"name",chainname); - if ( pubval == 0 || is_hexstr(pubval,0) != 2 ) - pubval = "00"; - jaddstr(argvals,"pubval",pubval); - if ( p2shval == 0 || is_hexstr(p2shval,0) != 2 ) - p2shval = "05"; - jaddstr(argvals,"p2shval",p2shval); - if ( wifval == 0 || is_hexstr(wifval,0) != 2 ) - wifval = "80"; - jaddstr(argvals,"wifval",wifval); - if ( nbitstr == 0 || nbitstr[0] == 0 ) - nbitstr = GECKO_DEFAULTDIFFSTR; - jaddstr(argvals,"nBits",nbitstr); - jaddstr(argvals,"chain",chain); - if ( keystr != 0 ) - jaddstr(argvals,"key",keystr); - jaddnum(argvals,"isPoS",isPoS); - //printf("argvals isPoS.%d\n",isPoS); - if ( port == 0 ) - { - jaddstr(argvals,"geckochain",chainname); - jaddnum(argvals,"services",128); - } - else - { - jaddnum(argvals,"services",129); - jaddnum(argvals,"portp2p",port); - } - if ( blocktime == 0 ) - blocktime = 1; - jaddnum(argvals,"blocktime",blocktime); - if ( blocktime != 0 && 0 ) - { - if ( blocktime == 0xffff ) - targetspacing = 24 * 60 * 60; // one day - else targetspacing = blocktime; // one minute - jaddnum(argvals,"targetspacing",targetspacing); - if ( (timespan= sqrt(604800 / targetspacing)) < 7 ) - timespan = 7; - jaddnum(argvals,"targettimespan",targetspacing * timespan); - } - return(argvals); -} - -cJSON *gecko_genesisjson(struct supernet_info *myinfo,struct iguana_info *btcd,int32_t isPoS,char *symbol,char *chainname,cJSON *valsobj,char *magicstr,uint16_t blocktime) -{ - char str2[64],hashstr[65],argbuf[1024],*pubstr,*p2shstr,*wifvalstr,*nbitstr,*blockstr; uint8_t buf[4]; int32_t i; uint32_t nBits; struct iguana_block genesis; - if ( (nbitstr= jstr(valsobj,"nBits")) == 0 ) - { - nBits = GECKO_DEFAULTDIFF; - nbitstr = GECKO_DEFAULTDIFFSTR; - } - else - { - for (i=0; i<4; i++) - decode_hex(&buf[3-i],1,&nbitstr[i*2]); - memcpy(&nBits,buf,sizeof(nBits)); - } - if ( (blocktime= juint(valsobj,"blocktime")) == 0 ) - blocktime = 1; - if ( (pubstr= jstr(valsobj,"pubval")) == 0 ) - pubstr = "00"; - if ( (p2shstr= jstr(valsobj,"p2shval")) == 0 ) - p2shstr = "05"; - if ( (wifvalstr= jstr(valsobj,"wifval")) == 0 ) - wifvalstr = "80"; - printf("json netmagic.%s\n",magicstr); - memset(&genesis,0,sizeof(genesis)); - genesis.RO.version = GECKO_DEFAULTVERSION; - genesis.RO.bits = nBits; - if ( (blockstr= gecko_createblock(myinfo,blocktime,0,btcd,isPoS,&genesis,symbol,0,0,10000,0,0)) != 0 ) - { - bits256_str(hashstr,genesis.RO.hash2); - sprintf(argbuf,"{\"isPoS\":%d,\"name\":\"%s\",\"symbol\":\"%s\",\"netmagic\":\"%s\",\"port\":%u,\"blocktime\":%u,\"pubval\":\"%s\",\"p2shval\":\"%s\",\"wifval\":\"%s\",\"isPoS\":%u,\"unitval\":\"%02x\",\"genesishash\":\"%s\",\"genesis\":{\"version\":1,\"timestamp\":%u,\"nBits\":\"%s\",\"nonce\":%d,\"merkle_root\":\"%s\"},\"genesisblock\":\"%s\"}",isPoS,chainname,symbol,magicstr,juint(valsobj,"port"),blocktime,pubstr,p2shstr,wifvalstr,juint(valsobj,"isPoS"),(nBits >> 24) & 0xff,hashstr,genesis.RO.timestamp,nbitstr,genesis.RO.nonce,bits256_str(str2,genesis.RO.merkle_root),blockstr); - free(blockstr); - printf("argbuf.(%s) hash.%s\n",argbuf,hashstr); - return(cJSON_Parse(argbuf)); - } else return(cJSON_Parse("{\"error\":\"couldnt create block\"}")); -} - -cJSON *gecko_genesisissue(char *symbol,char *chainname,char *chainstr,cJSON *valsobj) -{ - printf("issue blocktime.%d\n",juint(valsobj,"blocktime")); - return(gecko_genesisargs(symbol,chainname,chainstr,jstr(valsobj,"key"),jstr(valsobj,"genesishash"),jstr(valsobj,"genesisblock"),jstr(valsobj,"netmagic"),juint(valsobj,"port"),juint(valsobj,"blocktime"),jstr(valsobj,"nBits"),jstr(valsobj,"pubval"),jstr(valsobj,"p2shval"),jstr(valsobj,"wifval"),juint(valsobj,"isPoS"))); -}*/ - struct iguana_info *basilisk_geckochain(struct supernet_info *myinfo,char *symbol,char *chainname,cJSON *valsobj) { int32_t datalen,hdrsize,len=0; struct iguana_info *virt=0; char *hexstr; uint8_t hexbuf[8192],*ptr,*serialized; struct iguana_peer *addr; struct iguana_txblock txdata; @@ -343,100 +220,6 @@ struct iguana_info *basilisk_geckochain(struct supernet_info *myinfo,char *symbo return(virt); } -/*char *basilisk_respond_newgeckochain(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 prevhash,int32_t from_basilisk) -{ - struct iguana_info *virt,*btcd; struct gecko_chain *chain; char fname[512],*symbol,*retstr,*chainstr,chainname[GECKO_MAXNAMELEN],*genesises; cJSON *chainjson,*retjson,*genesisjson; long filesize; FILE *fp; - if ( (chain= gecko_chain(myinfo,chainname,valsobj)) != 0 && (virt= chain->info) != 0 ) - { - //printf("%s already exists\n",chainname); - return(clonestr("{\"error\":\"cant create duplicate geckochain\"}")); - } - if ( (btcd= iguana_coinfind("BTCD")) != 0 && (symbol= jstr(valsobj,"symbol")) != 0 && (chainstr= jstr(valsobj,"chain")) != 0 ) - { - if ( (virt= basilisk_geckochain(myinfo,symbol,chainname,valsobj)) != 0 ) - { - chain->info = virt; - if ( (retjson= gecko_genesisissue(symbol,chainname,chainstr,valsobj)) != 0 ) - { - jaddstr(retjson,"result","success"); - retstr = jprint(retjson,0); - sprintf(fname,"genesis/%s",symbol); - genesisjson = 0; - filesize = 0; - if ( (fp= fopen(fname,"wb")) != 0 ) - { - if ( fwrite(retstr,1,strlen(retstr),fp) == strlen(retstr) ) - { - if ( (genesises= OS_filestr(&filesize,"genesis/list")) != 0 ) - { - genesisjson = cJSON_Parse(genesises); - free(genesises); - } else genesisjson = cJSON_CreateArray(); - chainjson = cJSON_CreateObject(); - jaddstr(chainjson,"chain",chainname); - jaddstr(chainjson,"symbol",symbol); - jaddstr(chainjson,"agent","basilisk"); - jaddstr(chainjson,"method","newgeckochain"); - jadd(chainjson,"vals",retjson); - jaddi(genesisjson,chainjson); - } - fclose(fp); - } - if ( genesisjson != 0 ) - { - genesises = jprint(genesisjson,1); - if ( strlen(genesises) > filesize ) - { - if ( (fp= fopen("genesis/list","wb")) != 0 ) - { - fwrite(genesises,1,strlen(genesises),fp); - fclose(fp); - } - } - } else free_json(retjson); - return(retstr); - } else return(clonestr("{\"error\":\"couldnt create gecko genesis\"}")); - } - } - return(clonestr("{\"error\":-22}")); -} - -int32_t gecko_genesises(struct supernet_info *myinfo,cJSON *array) -{ - char *chainstr,chainname[GECKO_MAXNAMELEN],*symbol; int32_t i,n,num=0; cJSON *item,*valsobj; struct iguana_info *btcd,*virt; struct gecko_chain *chain; - if ( (btcd= iguana_coinfind("BTCD")) == 0 ) - return(0); - if ( array != 0 && (n= cJSON_GetArraySize(array)) != 0 ) - { - for (i=0; iinfo) != 0 ) - { - //printf("%s %s already exists\n",chainname,symbol); - continue; - } - if ( (virt= basilisk_geckochain(myinfo,symbol,chainname,valsobj)) != 0 ) - { - myinfo->genesisresults++; - chain->info = virt; - num++; - } - } - } - } - return(num); -} - -char *basilisk_respond_geckogenesis(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 txid,int32_t from_basilisk) -{ - long filesize; - return(OS_filestr(&filesize,"genesis/list")); -}*/ - char *basilisk_standardreturn(char *CMD,char *type,struct iguana_info *virt,uint8_t *serialized,int32_t datalen,bits256 hash) { char space[16384],*allocstr = 0; cJSON *retjson = cJSON_CreateObject(); @@ -445,7 +228,6 @@ char *basilisk_standardreturn(char *CMD,char *type,struct iguana_info *virt,uint jaddstr(retjson,"CMD",CMD); jaddstr(retjson,"type",type); jaddstr(retjson,"symbol",virt->symbol); - //jaddnum(retjson,"longest",virt->longestchain); jaddnum(retjson,"hwm",virt->blocks.hwmchain.height); jaddnum(retjson,"datalen",datalen); jaddbits256(retjson,"chaintip",virt->blocks.hwmchain.RO.hash2); @@ -484,61 +266,6 @@ char *basilisk_respond_geckoget(struct supernet_info *myinfo,char *CMD,void *add #include "../includes/iguana_apidefs.h" #include "../includes/iguana_apideclares.h" -/*HASH_ARRAY_STRING(basilisk,sequence,hash,vals,hexstr) -{ - return(basilisk_standardservice("SEQ",myinfo,hash,vals,hexstr,1)); -} - -HASH_ARRAY_STRING(basilisk,newgeckochain,hash,vals,hexstr) -{ - char chainname[GECKO_MAXNAMELEN],magicstr[9],*retstr=0,*symbol,*chainstr; struct iguana_info *btcd; cJSON *argjson,*argvals,*retjson=0; int32_t i,isPoS; uint32_t magic; struct gecko_chain *chain; - if ( (btcd= iguana_coinfind("BTCD")) != 0 && (symbol= jstr(vals,"symbol")) != 0 && (chainstr= jstr(vals,"chain")) != 0 ) - { - if ( iguana_coinfind(symbol) == 0 && (chain= gecko_chain(myinfo,chainname,vals)) != 0 && chain->info != 0 ) - { - printf("%s already exists\n",chainname); - return(clonestr("{\"error\":\"cant create duplicate geckochain\"}")); - } - if ( jobj(vals,"netmagic") == 0 ) - { - OS_randombytes((void *)&magic,sizeof(magic)); - for (i=0; iRELAYNODE != 0 || btcd->VALIDATENODE != 0 ) - { - basilisk_wait(myinfo,0); - retstr = basilisk_respond_newgeckochain(myinfo,"NEW",0,0,0,argvals,0,0,GENESIS_PUBKEY,0); - } - if ( retstr == 0 ) - retstr = basilisk_standardservice("NEW",myinfo,GENESIS_PUBKEY,argvals,0,1); - free_json(argvals); - if ( (argvals= cJSON_Parse(retstr)) != 0 ) - { - if ( jobj(argvals,"result") != 0 && strcmp(jstr(argvals,"result"),"success") == 0 ) - { - if ( basilisk_geckochain(myinfo,symbol,chainname,argvals) != 0 ) - jaddstr(argvals,"status","active"); - } else jaddstr(argvals,"error","couldnt initialize geckochain"); - free(retstr); - return(jprint(argvals,1)); - } - if ( retjson != 0 ) - free_json(retjson); - free_json(argvals); - return(retstr); - } else return(clonestr("{\"error\":\"couldnt create genesis_block\"}")); - } - return(clonestr("{\"error\":\"need symbol and chain and BTCD to create new gecko chain\"}")); -}*/ - char *gecko_sendrawtransaction(struct supernet_info *myinfo,char *symbol,uint8_t *data,int32_t datalen,bits256 txid,cJSON *vals,char *signedtx) { char *retstr = 0; struct iguana_info *virt,*btcd = iguana_coinfind("BTCD"); @@ -595,69 +322,6 @@ HASH_ARRAY_STRING(basilisk,geckoget,hash,vals,hexstr) return(clonestr("{\"error\":\"geckoget needs BTCD\"}")); } -/*HASH_ARRAY_STRING(basilisk,geckogenesis,hash,vals,hexstr) -{ - long filesize; int32_t i,j,n,m; struct iguana_info *btcd; char *ref,*symbol,*retstr=0; cJSON *item,*array = 0,*arrayB = 0; FILE *fp; - if ( (btcd= iguana_coinfind("BTCD")) != 0 ) - { - if ( (retstr= basilisk_standardservice("GEN",myinfo,hash,vals,hexstr,1)) != 0 ) - { - arrayB = cJSON_Parse(retstr); - free(retstr); - } - if ( btcd->RELAYNODE != 0 || btcd->VALIDATENODE != 0 ) - { - if ( (retstr= OS_filestr(&filesize,"genesis/list")) != 0 ) - { - array = cJSON_Parse(retstr); - free(retstr); - } - if ( array == 0 ) - array = arrayB; - else if ( arrayB != 0 ) - { - if ( (n= cJSON_GetArraySize(array)) > 0 ) - { - if ( (m= cJSON_GetArraySize(arrayB)) > 0 ) - { - for (j=0; jnumrelays - 1); jaddnum(valsobj,"timeout",3000); jaddnum(valsobj,"fanout",-1); + jaddnum(valsobj,"height",height); jaddstr(valsobj,"symbol",virt->symbol); - if ( (str2= basilisk_standardservice("BLK",myinfo,hash2,valsobj,blockstr,1)) != 0 ) + if ( (str2= basilisk_standardservice("BLK",myinfo,hash2,valsobj,blockstr,0)) != 0 ) { if ( (retarray= cJSON_Parse(str2)) != 0 ) { diff --git a/gecko/gecko_miner.c b/gecko/gecko_miner.c index 14b5cb924..bc9f9429a 100755 --- a/gecko/gecko_miner.c +++ b/gecko/gecko_miner.c @@ -331,7 +331,7 @@ int32_t gecko_blocksubmit(struct supernet_info *myinfo,struct iguana_info *btcd, void gecko_miner(struct supernet_info *myinfo,struct iguana_info *btcd,struct iguana_info *virt,int32_t maxmillis,uint8_t *minerpubkey33) { struct iguana_zblock newblock; uint32_t prevtimestamp,nBits; int64_t reward = 0; int32_t i,gap,txn_count; char *blockstr,*space[256]; struct gecko_memtx **txptrs; void *ptr; //struct iguana_bundle *bp; - if ( virt->virtualchain == 0 )//|| myinfo->RELAYID < 0 || myinfo->numrelays < 1 ) + if ( virt->virtualchain == 0 || myinfo->RELAYID < 0 || myinfo->numrelays < 1 ) return; if ( (virt->blocks.hwmchain.height % myinfo->numrelays) != myinfo->RELAYID ) {