|
|
@ -231,18 +231,32 @@ int32_t basilisk_request_create(struct basilisk_request *rp,cJSON *valsobj,bits2 |
|
|
|
|
|
|
|
char *basilisk_start(struct supernet_info *myinfo,struct basilisk_request *_rp,uint32_t statebits,int32_t optionduration) |
|
|
|
{ |
|
|
|
cJSON *retjson; struct basilisk_request *rp; |
|
|
|
cJSON *retjson; struct basilisk_request *rp=0; int32_t i; |
|
|
|
if ( (bits256_cmp(_rp->srchash,myinfo->myaddr.persistent) == 0 || bits256_cmp(_rp->desthash,myinfo->myaddr.persistent) == 0) ) |
|
|
|
{ |
|
|
|
rp = calloc(1,sizeof(*rp)); |
|
|
|
*rp = *_rp; |
|
|
|
printf("START thread to complete %u/%u for (%s %.8f) <-> (%s %.8f) q.%u\n",rp->requestid,rp->quoteid,rp->src,dstr(rp->srcamount),rp->dest,dstr(rp->destamount),rp->quoteid); |
|
|
|
if ( basilisk_thread_start(myinfo,rp,statebits,optionduration) != 0 ) |
|
|
|
for (i=0; i<myinfo->numswaps; i++) |
|
|
|
if ( myinfo->swaps[i]->I.req.requestid == _rp->requestid ) |
|
|
|
{ |
|
|
|
printf("basilisk_thread_start error trying to start requestid.%u which is already started\n",rp->requestid); |
|
|
|
break; |
|
|
|
} |
|
|
|
if ( i == myinfo->numswaps ) |
|
|
|
{ |
|
|
|
rp = calloc(1,sizeof(*rp)); |
|
|
|
*rp = *_rp; |
|
|
|
printf("START thread to complete %u/%u for (%s %.8f) <-> (%s %.8f) q.%u\n",rp->requestid,rp->quoteid,rp->src,dstr(rp->srcamount),rp->dest,dstr(rp->destamount),rp->quoteid); |
|
|
|
if ( basilisk_thread_start(myinfo,rp,statebits,optionduration) != 0 ) |
|
|
|
{ |
|
|
|
basilisk_request_enqueue(myinfo,rp); |
|
|
|
return(clonestr("{\"result\":\"started atomic swap thread\"}")); |
|
|
|
} |
|
|
|
else return(clonestr("{\"error\":\"couldnt atomic swap thread\"}")); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
basilisk_request_enqueue(myinfo,rp); |
|
|
|
return(clonestr("{\"result\":\"started atomic swap thread\"}")); |
|
|
|
printf("trying to start already pending swap.r%u\n",rp->requestid); |
|
|
|
return(clonestr("{\"error\":\"cant start pending swap\"}")); |
|
|
|
} |
|
|
|
else return(clonestr("{\"error\":\"couldnt atomic swap thread\"}")); |
|
|
|
} |
|
|
|
else if ( myinfo->IAMLP != 0 ) |
|
|
|
{ |
|
|
@ -296,7 +310,7 @@ void basilisk_requests_poll(struct supernet_info *myinfo) |
|
|
|
free(retstr); |
|
|
|
printf("my req hwm %f -> %u\n",hwm,issueR.requestid); |
|
|
|
basilisk_channelsend(myinfo,issueR.srchash,issueR.desthash,channel,0x4000000,(void *)&issueR.requestid,sizeof(issueR.requestid),60); |
|
|
|
numiters = 0; |
|
|
|
numiters = crc = 0; |
|
|
|
/*while ( numiters < 10 && (crc= basilisk_crcsend(myinfo,0,buf,sizeof(buf),issueR.srchash,issueR.desthash,channel,0x4000000,(void *)&issueR.requestid,sizeof(issueR.requestid),crcs)) == 0 )
|
|
|
|
{ |
|
|
|
printf("didnt get back what was sent\n"); |
|
|
@ -306,7 +320,7 @@ void basilisk_requests_poll(struct supernet_info *myinfo) |
|
|
|
} |
|
|
|
if ( crc != 0 )*/ |
|
|
|
{ |
|
|
|
//printf("crc.%08x -> basilisk_starta\n",crc);
|
|
|
|
printf("crc.%08x -> basilisk_starta\n",crc); |
|
|
|
if ( (retstr= basilisk_start(myinfo,&issueR,1,issueR.optionhours * 3600)) != 0 ) |
|
|
|
free(retstr); |
|
|
|
} // else printf("couldnt accept offer\n");
|
|
|
|