Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
462d4991f0
  1. 12
      basilisk/basilisk.c
  2. 7
      gecko/gecko.c
  3. 4
      gecko/gecko_blocks.c
  4. 1
      gecko/gecko_headers.c
  5. 2
      gecko/gecko_mempool.c

12
basilisk/basilisk.c

@ -279,13 +279,19 @@ void basilisk_p2p(void *_myinfo,void *_addr,char *senderip,uint8_t *data,int32_t
void basilisk_sendback(struct supernet_info *myinfo,char *origCMD,char *symbol,char *remoteaddr,uint32_t basilisktag,char *retstr)
{
uint8_t *data,space[4096],*allocptr; cJSON *valsobj; int32_t datalen,encryptflag=0,delaymillis=0;
printf("%s retstr.(%s) -> remote.(%s) basilisktag.%u\n",origCMD,retstr,remoteaddr,basilisktag);
uint8_t *data,space[4096],*allocptr; struct iguana_info *virt; cJSON *valsobj; int32_t datalen,encryptflag=0,delaymillis=0;
//printf("%s retstr.(%s) -> remote.(%s) basilisktag.%u\n",origCMD,retstr,remoteaddr,basilisktag);
if ( retstr != 0 && remoteaddr != 0 && remoteaddr[0] != 0 && strcmp(remoteaddr,"127.0.0.1") != 0 )
{
if ( (valsobj= cJSON_Parse(retstr)) != 0 )
{
jaddstr(valsobj,"origcmd",origCMD);
jaddstr(valsobj,"symbol",symbol);
if ( (virt= iguana_coinfind(symbol)) != 0 )
{
jaddnum(valsobj,"hwm",virt->blocks.hwmchain.height);
jaddbits256(valsobj,"chaintip",virt->blocks.hwmchain.RO.hash2);
}
data = basilisk_jsondata(sizeof(struct iguana_msghdr),&allocptr,space,sizeof(space),&datalen,symbol,valsobj,basilisktag);
basilisk_sendcmd(myinfo,remoteaddr,"RET",&basilisktag,encryptflag,delaymillis,data,datalen,0,0);
if ( allocptr != 0 )
@ -752,7 +758,7 @@ void basilisk_geckoresult(struct supernet_info *myinfo,struct basilisk_item *ptr
uint8_t *data,space[16384],*allocptr = 0; struct iguana_info *virt; char *symbol,*str,*type; int32_t datalen; cJSON *retjson; bits256 hash2;
if ( (retjson= cJSON_Parse(ptr->retstr)) != 0 )
{
if ( (symbol= jstr(retjson,"coin")) != 0 && (virt= iguana_coinfind(symbol)) != 0 )
if ( (symbol= jstr(retjson,"symbol")) != 0 && (virt= iguana_coinfind(symbol)) != 0 )
{
if ( (data= get_dataptr(0,&allocptr,&datalen,space,sizeof(space),jstr(retjson,"data"))) != 0 )
{

7
gecko/gecko.c

@ -438,8 +438,10 @@ char *basilisk_standardreturn(char *CMD,char *type,struct iguana_info *virt,uint
jaddstr(retjson,"CMD",CMD);
jaddstr(retjson,"type",type);
jaddstr(retjson,"coin",virt->symbol);
jaddnum(retjson,"longest",virt->longestchain);
//jaddnum(retjson,"longest",virt->longestchain);
jaddnum(retjson,"hwm",virt->blocks.hwmchain.height);
jaddnum(retjson,"datalen",datalen);
jaddbits256(retjson,"chaintip",virt->blocks.hwmchain.RO.hash2);
jaddbits256(retjson,"hash",hash);
} else jaddstr(retjson,"error","no data to send");
if ( allocstr != 0 )
@ -450,7 +452,7 @@ char *basilisk_standardreturn(char *CMD,char *type,struct iguana_info *virt,uint
char *basilisk_respond_geckoget(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 hash2,int32_t from_basilisk)
{
int32_t (*getfunc)(struct supernet_info *myinfo,struct iguana_info *virt,uint8_t *serialized,int32_t maxsize,cJSON *valsobj,bits256 hash2);
uint8_t *serialized; int32_t maxsize,len = 0; char *symbol,*type; struct iguana_info *virt;
uint8_t *serialized; int32_t maxsize; char *symbol,*type; struct iguana_info *virt;
if ( (type= jstr(valsobj,"type")) != 0 )
{
if ( strcmp(type,"HDR") == 0 )
@ -466,6 +468,7 @@ char *basilisk_respond_geckoget(struct supernet_info *myinfo,char *CMD,void *add
if ( (symbol= jstr(valsobj,"symbol")) != 0 && (virt= iguana_coinfind(symbol)) != 0 )
{
datalen = (*getfunc)(myinfo,virt,serialized,maxsize,valsobj,hash2);
printf("return datalen.%d for %s\n",datalen,type);
return(basilisk_standardreturn(CMD,type,virt,serialized,datalen,hash2));
} else return(clonestr("{\"error\":\"couldt find gecko chain\"}"));
} else return(clonestr("{\"error\":\"invalid geckoget type, mustbe (HDR or BLK or GTX)\"}"));

4
gecko/gecko_blocks.c

@ -237,7 +237,11 @@ char *gecko_blockarrived(struct supernet_info *myinfo,struct iguana_info *virt,c
txdata.zblock.height = block->height;
txdata.zblock.mainchain = block->mainchain = 1;
if ( gecko_hwmset(virt,&txdata,virt->TXMEM.ptr,data,datalen,i+1) >= 0 )
{
if ( block->height > virt->longestchain )
virt->longestchain = block->height;
return(clonestr("{\"result\":\"gecko block created\"}"));
}
else return(clonestr("{\"error\":\"gecko error creating hwmblock\"}"));
} else return(clonestr("{\"results\":\"gecko block wasnt hwmblock\"}"));
}

1
gecko/gecko_headers.c

@ -54,6 +54,7 @@ char *gecko_headersarrived(struct supernet_info *myinfo,struct iguana_info *virt
{
bits256 hash2; struct iguana_block *block; int32_t firstheight,i,len=0,n;
n = (int32_t)(datalen / sizeof(bits256));
char str[65]; printf("headers arrived.%d from %s\n",n,bits256_str(str,firsthash2));
if ( (block= iguana_blockfind("geckohdrs",virt,firsthash2)) != 0 && (firstheight= block->height) >= 0 )
{
gecko_headerupdate(virt,firsthash2,firstheight);

2
gecko/gecko_mempool.c

@ -219,6 +219,7 @@ struct gecko_mempool *gecko_mempool_alloc(int32_t otherflag)
int32_t basilisk_respond_geckogettx(struct supernet_info *myinfo,struct iguana_info *virt,uint8_t *serialized,int32_t maxsize,cJSON *valsobj,bits256 hash2)
{
int32_t datalen = 0;
char str[65]; printf("got request for GTX.%s\n",bits256_str(str,hash2));
// find txid and set serialized
return(datalen);
}
@ -360,6 +361,7 @@ char *gecko_mempoolarrived(struct supernet_info *myinfo,struct iguana_info *virt
char *basilisk_respond_mempool(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)
{
char *symbol; struct iguana_info *virt;
printf("got getmempool request\n");
if ( (symbol= jstr(valsobj,"symbol")) != 0 && (virt= iguana_coinfind(symbol)) != 0 )
return(gecko_mempoolarrived(myinfo,virt,_addr,data,datalen,hash));
else return(clonestr("{\"error\":\"couldt find gecko chain\"}"));

Loading…
Cancel
Save