diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index 69d128c21..e864424c9 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -101,7 +101,7 @@ int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *typ else if ( fanout > BASILISK_MAXFANOUT ) fanout = BASILISK_MAXFANOUT; if ( type == 0 ) - type = ""; + type = "BTCD"; if ( strlen(type) > 3 ) { printf("basilisk_sendcmd illegal type(%s)\n",type); @@ -309,7 +309,7 @@ struct basilisk_item *basilisk_requestservice(struct basilisk_item *Lptr,struct timeoutmillis = BASILISK_TIMEOUT; encryptflag = jint(valsobj,"encrypt"); delaymillis = jint(valsobj,"delay"); - return(basilisk_issueremote(myinfo,&numsent,CMD,"",valsobj,1,minresults,basilisktag,timeoutmillis,0,0,encryptflag,delaymillis)); + return(basilisk_issueremote(myinfo,&numsent,CMD,"BTCD",valsobj,1,minresults,basilisktag,timeoutmillis,0,0,encryptflag,delaymillis)); } void basilisk_sendback(struct supernet_info *myinfo,char *symbol,char *remoteaddr,uint32_t basilisktag,char *retstr) @@ -383,9 +383,9 @@ char *basilisk_standardservice(char *CMD,basilisk_requestfunc *func,struct super if ( blockflag != 0 ) { ptr->vals = jduplicate(vals); - strcpy(ptr->symbol,""); + strcpy(ptr->symbol,"BTCD"); strcpy(ptr->CMD,CMD); - return(basilisk_block(myinfo,CMD,"",0,&Lptr,ptr)); + return(basilisk_block(myinfo,CMD,"BTCD",0,&Lptr,ptr)); } else if ( ptr->numsent > 0 ) { @@ -777,7 +777,7 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *addr,uint32_t sender data += sizeof(pubkey), datalen -= sizeof(pubkey); } else data = 0, datalen = 0; if ( (symbol= jstr(valsobj,"coin")) == 0 ) - symbol = ""; + symbol = "BTCD"; timeoutmillis = jint(valsobj,"timeout"); if ( (numrequired= jint(valsobj,"numrequired")) == 0 ) numrequired = 1; diff --git a/basilisk/basilisk_CMD.c b/basilisk/basilisk_CMD.c index 3121a1d2a..d1b0eeb81 100755 --- a/basilisk/basilisk_CMD.c +++ b/basilisk/basilisk_CMD.c @@ -33,7 +33,7 @@ void basilisk_request_goodbye(struct supernet_info *myinfo) char *basilisk_respond_setfield(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 prevhash,int32_t from_basilisk) { - bits256 hash,cathash; struct category_info *cat,*prevcat=0; char *category; char str[65]; + bits256 hash,cathash; struct category_info *rootcat,*cat,*prevcat=0; char *category; char str[65]; printf("from.(%s) SET.(%s) datalen.%d\n",remoteaddr,jprint(valsobj,0),datalen); if ( datalen <= 0 || (category= jstr(valsobj,"category")) == 0 ) return(0); @@ -47,11 +47,17 @@ char *basilisk_respond_setfield(struct supernet_info *myinfo,char *CMD,struct ig printf("basilisk_respond_publish: cant find prevhash.%s\n",bits256_str(str,prevhash)); } } else memset(prevhash.bytes,0,sizeof(prevhash)); - if ( (cat= category_find(cathash,hash)) == 0 ) + if ( (rootcat= category_find(cathash,GENESIS_PUBKEY)) == 0 ) + printf("error finding category.(%s)\n",category); + else if ( (cat= category_find(cathash,hash)) == 0 ) printf("error finding just added category\n"); - cat->prevhash = prevhash; - if ( prevcat != 0 ) - prevcat->next = cat; + else + { + rootcat->lasthash = hash; + cat->prevhash = prevhash; + if ( prevcat != 0 ) + prevcat->next = cat; + } return(0); } @@ -63,18 +69,31 @@ struct basilisk_item *basilisk_request_setfield(struct basilisk_item *Lptr,struc char *basilisk_respond_getfield(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 prevhash,int32_t from_basilisk) { bits256 cathash; struct category_info *cat; char *category,*hexstr; cJSON *retjson; - printf("from.(%s) GET.(%s) datalen.%d\n",remoteaddr,jprint(valsobj,0),datalen); if ( (category= jstr(valsobj,"category")) == 0 ) return(0); vcalc_sha256(0,cathash.bytes,(uint8_t *)category,(int32_t)strlen(category)); - if ( (cat= category_find(cathash,prevhash)) == 0 ) - printf("error finding just added category\n"); + char str[65]; printf("from.(%s) GET.(%s) datalen.%d %s\n",remoteaddr,jprint(valsobj,0),datalen,bits256_str(str,cathash)); retjson = cJSON_CreateObject(); - if ( cat->datalen > 0 ) + if ( bits256_nonz(prevhash) == 0 || bits256_cmp(GENESIS_PUBKEY,prevhash) == 0 ) { - hexstr = calloc(1,(cat->datalen << 1) + 1); - init_hexbytes_noT(hexstr,cat->data,cat->datalen); - jaddstr(retjson,"data",hexstr); + if ( (cat= category_find(cathash,GENESIS_PUBKEY)) == 0 ) + jaddstr(retjson,"error","cant find category"); + else + { + jaddbits256(retjson,"genesis",cat->hash); + jaddbits256(retjson,"last",cat->lasthash); + } + } + else + { + if ( (cat= category_find(cathash,prevhash)) == 0 ) + printf("error finding just added category\n"); + if ( cat->datalen > 0 ) + { + hexstr = calloc(1,(cat->datalen << 1) + 1); + init_hexbytes_noT(hexstr,cat->data,cat->datalen); + jaddstr(retjson,"data",hexstr); + } } return(jprint(retjson,1)); } diff --git a/iguana/SuperNET.h b/iguana/SuperNET.h index c5fa950e7..42d9fce29 100755 --- a/iguana/SuperNET.h +++ b/iguana/SuperNET.h @@ -130,7 +130,7 @@ struct category_info { UT_hash_handle hh; queue_t Q; char *(*processfunc)(struct supernet_info *myinfo,struct category_info *cat,void *data,int32_t datalen,char *remoteaddr); - struct category_chain *catchain; bits256 hash,prevhash; void *info; struct category_info *sub,*next; + struct category_chain *catchain; bits256 hash,prevhash,lasthash; void *info; struct category_info *sub,*next; int32_t datalen; uint8_t data[]; };