|
|
@ -1004,152 +1004,3 @@ struct basilisk_swap *LP_swapinit(int32_t iambob,int32_t optionduration,bits256 |
|
|
|
return(swap); |
|
|
|
} |
|
|
|
|
|
|
|
#ifdef notanymore |
|
|
|
struct basilisk_swap *basilisk_thread_start(bits256 privkey,struct basilisk_request *rp,uint32_t statebits,int32_t optionduration,int32_t reinit) |
|
|
|
{ |
|
|
|
int32_t i,m,n,iter; uint8_t pubkey33[33]; bits256 pubkey25519; uint32_t channel,starttime; cJSON *retarray,*item,*msgobj; struct iguana_info *coin; double pending=0.; struct basilisk_swap *swap = 0; |
|
|
|
// statebits 1 -> client, 0 -> LP
|
|
|
|
/*if ( myinfo->numswaps > 0 )
|
|
|
|
{ |
|
|
|
if ( (coin= LP_coinfind(rp->src)) == 0 || coin->FULLNODE >= 0 ) |
|
|
|
{ |
|
|
|
printf("dont have SRC coin.%s or not native and already swap pending\n",rp->src); |
|
|
|
return(0); |
|
|
|
} |
|
|
|
if ( (coin= LP_coinfind(rp->dest)) == 0 || coin->FULLNODE >= 0 ) |
|
|
|
{ |
|
|
|
printf("dont have DEST coin.%s or not native and already swap pending\n",rp->dest); |
|
|
|
return(0); |
|
|
|
} |
|
|
|
} |
|
|
|
portable_mutex_lock(&myinfo->DEX_swapmutex); |
|
|
|
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 && i < sizeof(myinfo->swaps)/sizeof(*myinfo->swaps) )*/ |
|
|
|
{ |
|
|
|
swap = calloc(1,sizeof(*swap)); |
|
|
|
swap->ctx = bitcoin_ctx(); |
|
|
|
swap->subsock = swap->pushsock = -1; |
|
|
|
vcalc_sha256(0,swap->I.orderhash.bytes,(uint8_t *)rp,sizeof(*rp)); |
|
|
|
swap->I.req = *rp; |
|
|
|
//swap->myinfoptr = myinfo;
|
|
|
|
printf("basilisk_thread_start request.%u statebits.%d (%s/%s) reinit.%d\n",rp->requestid,statebits,rp->src,rp->dest,reinit); |
|
|
|
bitcoin_pubkey33(swap->ctx,pubkey33,privkey); |
|
|
|
pubkey25519 = curve25519(privkey,curve25519_basepoint9()); |
|
|
|
swap->persistent_pubkey = pubkey25519; |
|
|
|
swap->persistent_privkey = privkey; |
|
|
|
memcpy(swap->persistent_pubkey33,pubkey33,33); |
|
|
|
m = n = 0; |
|
|
|
if ( bitcoin_swapinit(privkey,pubkey33,pubkey25519,swap,optionduration,statebits,reinit) != 0 ) |
|
|
|
{ |
|
|
|
for (iter=0; iter<16; iter++) |
|
|
|
{ |
|
|
|
basilisk_psockinit(swap,statebits == 0); |
|
|
|
sleep(3); |
|
|
|
if ( swap->connected > 0 ) |
|
|
|
break; |
|
|
|
sleep(10); |
|
|
|
/*basilisk_sendstate(swap,data,sizeof(data));
|
|
|
|
basilisk_swapget(swap,0x80000000,data,sizeof(data),basilisk_verify_statebits); |
|
|
|
if ( swap->connected > 0 ) |
|
|
|
break; |
|
|
|
printf("loopback didntwork with %d %d\n",swap->pushsock,swap->subsock);*/ |
|
|
|
} |
|
|
|
if ( reinit != 0 ) |
|
|
|
{ |
|
|
|
if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)basilisk_swaploop,(void *)swap) != 0 ) |
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
|
//myinfo->swaps[myinfo->numswaps++] = swap;
|
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
starttime = (uint32_t)time(NULL); |
|
|
|
printf("statebits.%x m.%d n.%d\n",statebits,m,n); |
|
|
|
while ( statebits == 0 && m <= n/2 && time(NULL) < starttime+7*BASILISK_MSGDURATION ) |
|
|
|
{ |
|
|
|
uint32_t msgid; uint8_t data[1024]; int32_t datalen; |
|
|
|
m = n = 0; |
|
|
|
sleep(DEX_SLEEP); |
|
|
|
printf("waiting for offer to be accepted\n"); |
|
|
|
channel = 'D' + ((uint32_t)'E' << 8) + ((uint32_t)'X' << 16); |
|
|
|
datalen = basilisk_rwDEXquote(1,data,rp); |
|
|
|
msgid = (uint32_t)time(NULL); |
|
|
|
printf("other req.%d >>>>>>>>>>> send response (%llx -> %llx) r.%u quoteid.%u\n",i,(long long)rp->desthash.txid,(long long)rp->srchash.txid,rp->requestid,rp->quoteid); |
|
|
|
LP_channelsend(rp->desthash,rp->srchash,channel,msgid,data,datalen); |
|
|
|
if ( (retarray= basilisk_channelget(rp->srchash,rp->desthash,channel,0x4000000,30)) != 0 ) |
|
|
|
{ |
|
|
|
if ( is_cJSON_Array(retarray) != 0 && (n= cJSON_GetArraySize(retarray)) > 0 ) |
|
|
|
{ |
|
|
|
for (i=0; i<n; i++) |
|
|
|
{ |
|
|
|
item = jitem(retarray,i); |
|
|
|
if ( (msgobj= jarray(&n,item,"messages")) != 0 && n > 0 ) |
|
|
|
{ |
|
|
|
item = jitem(msgobj,0); |
|
|
|
if ( jobj(item,"data") != 0 && jobj(item,"key") != 0 ) |
|
|
|
m++; |
|
|
|
else printf("(%s)\n",jprint(item,0)); |
|
|
|
} //else printf("msgobj.%p m.%d n.%d\n",msgobj,m,n);
|
|
|
|
} |
|
|
|
} |
|
|
|
} else printf("no retarray\n"); |
|
|
|
} |
|
|
|
printf("LAUNCH check.%d m.%d\n",statebits,m); |
|
|
|
if ( statebits != 0 || m > 0 )//n/2 )
|
|
|
|
{ |
|
|
|
//for (i=0; i<sizeof(swap->I.req); i++)
|
|
|
|
// fprintf(stderr,"%02x",((uint8_t *)&swap->I.req)[i]);
|
|
|
|
if ( (swap->fp= basilisk_swap_save(swap,privkey,rp,statebits,optionduration,reinit)) != 0 ) |
|
|
|
{ |
|
|
|
} |
|
|
|
if ( reinit == 0 ) |
|
|
|
{ |
|
|
|
static FILE *swapsfp; |
|
|
|
if ( swapsfp == 0 ) |
|
|
|
{ |
|
|
|
char fname[512]; |
|
|
|
sprintf(fname,"%s/SWAPS/list",GLOBAL_DBDIR), OS_compatible_path(fname); |
|
|
|
if ( (swapsfp= fopen(fname,"rb+")) == 0 ) |
|
|
|
swapsfp = fopen(fname,"wb+"); |
|
|
|
else fseek(swapsfp,0,SEEK_END); |
|
|
|
printf("LIST fp.%p\n",swapsfp); |
|
|
|
} |
|
|
|
if ( swapsfp != 0 ) |
|
|
|
{ |
|
|
|
fwrite(&rp->requestid,1,sizeof(rp->requestid),swapsfp); |
|
|
|
fwrite(&rp->quoteid,1,sizeof(rp->quoteid),swapsfp); |
|
|
|
fflush(swapsfp); |
|
|
|
} |
|
|
|
} |
|
|
|
if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)basilisk_swaploop,(void *)swap) != 0 ) |
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
|
//myinfo->swaps[myinfo->numswaps++] = swap;
|
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
if ( statebits != 0 ) |
|
|
|
{ |
|
|
|
if ( (coin= LP_coinfind(rp->src)) != 0 ) |
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
printf("%u/%u offer wasnt accepted statebits.%d m.%d n.%d pending %.8f\n",rp->requestid,rp->quoteid,statebits,m,n,pending); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
//portable_mutex_unlock(&myinfo->DEX_swapmutex);
|
|
|
|
return(swap); |
|
|
|
} |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|