int32_t iguana_peerhdrrequest(struct iguana_info *coin,uint8_t *serialized,int32_t maxsize,struct iguana_peer *addr,bits256 hash2) { int32_t len=0,i,flag=0,height,n,hdrsi,bundlei,bundlesize,firstvout,retval=-1; struct iguana_block *block; struct iguana_bundle *bp; if ( (firstvout= iguana_unspentindfind(coin,0,0,0,0,&height,hash2,0,coin->bundlescount-1,0)) != 0 ) { bundlesize = coin->chain->bundlesize; hdrsi = (height / bundlesize); bundlei = height - (hdrsi * bundlesize); if ( hdrsi >= 0 && hdrsi < bundlesize && bundlei >= 0 && bundlei < bundlesize && (bp= coin->bundles[hdrsi]) != 0 ) { for (i=0; i<coin->chain->bundlesize; i++) { if ( (block= bp->blocks[i]) != 0 ) { if ( (n= iguana_headerget(coin,&serialized[len],maxsize-len,block)) < 0 ) { printf("%s error getting header ht.%d\n",coin->symbol,block->height); continue; } len += n; } else printf("cant find block at ht.%d\n",height+i); } } if ( flag != 0 ) retval = iguana_queue_send(addr,0,serialized,"headers",len); //printf("hdrs request retval.%d len.%d\n",retval,len); } //else printf("couldnt find header\n"); return(retval); }
int32_t basilisk_respond_geckogetheaders(struct supernet_info *myinfo,struct iguana_info *virt,uint8_t *serialized,int32_t maxsize,cJSON *valsobj,bits256 hash2) { int32_t i,n,num,height,len=0; struct iguana_block *block; if ( (block= iguana_blockfind("geckohdr",virt,hash2)) != 0 ) { if ( (height= block->height) >= 0 ) { if ( (num= juint(valsobj,"num")) == 0 || num > virt->chain->bundlesize ) num = virt->chain->bundlesize; for (i=0; i<num; i++) { if ( block != 0 ) { if ( (n= iguana_headerget(myinfo,virt,&serialized[len],maxsize-len,block)) > 0 ) len += n; } hash2 = iguana_blockhash(virt,height+i+1); block = iguana_blockfind("geckohdri",virt,hash2); } return(len); } } return(-1); }