|
|
@ -792,10 +792,11 @@ void basilisk_swap_purge(struct supernet_info *myinfo,struct basilisk_swap *swap |
|
|
|
portable_mutex_unlock(&myinfo->DEX_swapmutex); |
|
|
|
} |
|
|
|
|
|
|
|
int32_t basilisk_verify_statebits(struct supernet_info *myinfo,struct basilisk_swap *swap,uint8_t *data,int32_t datalen) |
|
|
|
int32_t basilisk_verify_otherstatebits(struct supernet_info *myinfo,struct basilisk_swap *swap,uint8_t *data,int32_t datalen) |
|
|
|
{ |
|
|
|
iguana_rwnum(0,data,sizeof(swap->otherstatebits),&swap->otherstatebits); |
|
|
|
return(0); |
|
|
|
if ( datalen == sizeof(swap->otherstatebits) ) |
|
|
|
return(iguana_rwnum(0,data,sizeof(swap->otherstatebits),&swap->otherstatebits)); |
|
|
|
else return(-1); |
|
|
|
} |
|
|
|
|
|
|
|
int32_t basilisk_verify_choosei(struct supernet_info *myinfo,struct basilisk_swap *swap,uint8_t *data,int32_t datalen) |
|
|
@ -907,7 +908,7 @@ uint32_t basilisk_swapdata_rawtxsend(struct supernet_info *myinfo,struct basilis |
|
|
|
return(0); |
|
|
|
} |
|
|
|
|
|
|
|
void basilisk_swap01(struct supernet_info *myinfo,struct basilisk_swap *swap,uint8_t *data,int32_t maxlen) |
|
|
|
void basilisk_sendpubkeys(struct supernet_info *myinfo,struct basilisk_swap *swap,uint8_t *data,int32_t maxlen) |
|
|
|
{ |
|
|
|
int32_t datalen; |
|
|
|
datalen = basilisk_swapdata_deck(myinfo,swap,data,maxlen); |
|
|
@ -915,7 +916,7 @@ void basilisk_swap01(struct supernet_info *myinfo,struct basilisk_swap *swap,uin |
|
|
|
swap->statebits |= basilisk_swapsend(myinfo,swap,0x02,data,datalen,0x01); |
|
|
|
} |
|
|
|
|
|
|
|
void basilisk_swap02(struct supernet_info *myinfo,struct basilisk_swap *swap,uint8_t *data,int32_t maxlen) |
|
|
|
void basilisk_checkdeck(struct supernet_info *myinfo,struct basilisk_swap *swap,uint8_t *data,int32_t maxlen) |
|
|
|
{ |
|
|
|
if ( (swap->statebits & 0x02) == 0 ) |
|
|
|
{ |
|
|
@ -925,7 +926,14 @@ void basilisk_swap02(struct supernet_info *myinfo,struct basilisk_swap *swap,uin |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void basilisk_swap04(struct supernet_info *myinfo,struct basilisk_swap *swap,uint8_t *data,int32_t maxlen) |
|
|
|
void basilisk_sendstate(struct supernet_info *myinfo,struct basilisk_swap *swap,uint8_t *data,int32_t maxlen) |
|
|
|
{ |
|
|
|
int32_t datalen; |
|
|
|
datalen = iguana_rwnum(1,data,sizeof(swap->statebits),&swap->statebits); |
|
|
|
basilisk_swapsend(myinfo,swap,0x80000000,data,datalen,0); |
|
|
|
} |
|
|
|
|
|
|
|
void basilisk_sendchoosei(struct supernet_info *myinfo,struct basilisk_swap *swap,uint8_t *data,int32_t maxlen) |
|
|
|
{ |
|
|
|
int32_t i,datalen; char str[65]; |
|
|
|
datalen = iguana_rwnum(1,data,sizeof(swap->choosei),&swap->choosei); |
|
|
@ -948,7 +956,7 @@ void basilisk_swap04(struct supernet_info *myinfo,struct basilisk_swap *swap,uin |
|
|
|
swap->statebits |= basilisk_swapsend(myinfo,swap,0x08,data,datalen,0x04); |
|
|
|
} |
|
|
|
|
|
|
|
void basilisk_swap08(struct supernet_info *myinfo,struct basilisk_swap *swap,uint8_t *data,int32_t maxlen) |
|
|
|
void basilisk_waitchoosei(struct supernet_info *myinfo,struct basilisk_swap *swap,uint8_t *data,int32_t maxlen) |
|
|
|
{ |
|
|
|
uint8_t pubkey33[33]; char str[65]; |
|
|
|
printf("check otherchoosei\n"); |
|
|
@ -980,7 +988,7 @@ void basilisk_swap08(struct supernet_info *myinfo,struct basilisk_swap *swap,uin |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void basilisk_swap10(struct supernet_info *myinfo,struct basilisk_swap *swap,uint8_t *data,int32_t maxlen) |
|
|
|
void basilisk_sendmostprivs(struct supernet_info *myinfo,struct basilisk_swap *swap,uint8_t *data,int32_t maxlen) |
|
|
|
{ |
|
|
|
int32_t i,j,datalen; |
|
|
|
datalen = 0; |
|
|
@ -1022,33 +1030,29 @@ void basilisk_swaploop(void *_swap) |
|
|
|
data = malloc(maxlen); |
|
|
|
while ( time(NULL) < swap->expiration ) |
|
|
|
{ |
|
|
|
printf("r%u/q%u swapstate.%x\n",swap->req.requestid,swap->req.quoteid,swap->statebits); |
|
|
|
if ( (swap->statebits & 0x08) == 0 ) |
|
|
|
{ |
|
|
|
basilisk_swap01(myinfo,swap,data,maxlen); // send pubkeys
|
|
|
|
basilisk_swap08(myinfo,swap,data,maxlen); // wait for choosei
|
|
|
|
} |
|
|
|
if ( (swap->statebits & 0x10) == 0 ) |
|
|
|
{ |
|
|
|
basilisk_swap02(myinfo,swap,data,maxlen); // check for other deck
|
|
|
|
basilisk_swap04(myinfo,swap,data,maxlen); // send choosei
|
|
|
|
if ( (swap->statebits & 0x10) == 0 && swap->otherchoosei >= 0 && swap->otherchoosei < INSTANTDEX_DECKSIZE ) // send all but one privkeys
|
|
|
|
basilisk_swap10(myinfo,swap,data,maxlen); |
|
|
|
} |
|
|
|
if ( (swap->statebits & 0x1f) != 0x1f ) |
|
|
|
{ |
|
|
|
basilisk_swap04(myinfo,swap,data,maxlen); // send choosei
|
|
|
|
printf("initial setup incomplete state.%x\n",swap->statebits); |
|
|
|
sleep(1); |
|
|
|
continue; |
|
|
|
printf("A r%u/q%u swapstate.%x\n",swap->req.requestid,swap->req.quoteid,swap->statebits); |
|
|
|
basilisk_sendpubkeys(myinfo,swap,data,maxlen); // send pubkeys
|
|
|
|
basilisk_checkdeck(myinfo,swap,data,maxlen); // check for other deck 0x02
|
|
|
|
basilisk_waitchoosei(myinfo,swap,data,maxlen); // wait for choosei 0x08
|
|
|
|
if ( (swap->statebits & (0x08|0x02)) == (0x08|0x02) ) |
|
|
|
break; |
|
|
|
sleep(3); |
|
|
|
} |
|
|
|
if ( (swap->statebits & 0x20) == 0 ) // wait for all but one privkeys
|
|
|
|
while ( time(NULL) < swap->expiration ) |
|
|
|
{ |
|
|
|
basilisk_swap04(myinfo,swap,data,maxlen); // send choosei
|
|
|
|
printf("B r%u/q%u swapstate.%x\n",swap->req.requestid,swap->req.quoteid,swap->statebits); |
|
|
|
basilisk_sendmostprivs(myinfo,swap,data,maxlen); |
|
|
|
if ( basilisk_swapget(myinfo,swap,0x20,data,maxlen,basilisk_verify_privkeys) == 0 ) |
|
|
|
{ |
|
|
|
swap->statebits |= 0x20; |
|
|
|
break; |
|
|
|
} |
|
|
|
else if ( (swap->statebits & 0x40) == 0 ) // send fee
|
|
|
|
sleep(3); |
|
|
|
} |
|
|
|
while ( time(NULL) < swap->expiration ) |
|
|
|
{ |
|
|
|
printf("C r%u/q%u swapstate.%x\n",swap->req.requestid,swap->req.quoteid,swap->statebits); |
|
|
|
if ( (swap->statebits & 0x40) == 0 ) // send fee
|
|
|
|
{ |
|
|
|
if ( swap->myfee.txbytes == 0 ) |
|
|
|
{ |
|
|
@ -1106,19 +1110,30 @@ void basilisk_swaploop(void *_swap) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else if ( (swap->statebits & 0x80) == 0 ) // wait for fee
|
|
|
|
} |
|
|
|
while ( time(NULL) < swap->expiration ) |
|
|
|
{ |
|
|
|
printf("D r%u/q%u swapstate.%x otherstate.%x\n",swap->req.requestid,swap->req.quoteid,swap->statebits,swap->otherstatebits); |
|
|
|
if ( (swap->statebits & 0x80) == 0 ) // wait for fee
|
|
|
|
{ |
|
|
|
basilisk_swap10(myinfo,swap,data,maxlen); |
|
|
|
if ( basilisk_swapget(myinfo,swap,0x80,data,maxlen,basilisk_verify_otherfee) == 0 ) |
|
|
|
{ |
|
|
|
// verify and submit otherfee
|
|
|
|
swap->statebits |= 0x80; |
|
|
|
swap->sleeptime = 1; |
|
|
|
basilisk_sendstate(myinfo,swap,data,maxlen); |
|
|
|
} |
|
|
|
else if ( swap->sleeptime < 60 ) |
|
|
|
swap->sleeptime++; |
|
|
|
} |
|
|
|
else // both sides have setup required data and paid txfee
|
|
|
|
basilisk_swapget(myinfo,swap,0x80000000,data,maxlen,basilisk_verify_otherstatebits); |
|
|
|
if ( (swap->otherstatebits & 0x80) != 0 && (swap->statebits & 0x80) != 0 ) |
|
|
|
break; |
|
|
|
sleep(3); |
|
|
|
basilisk_swapget(myinfo,swap,0x80000000,data,maxlen,basilisk_verify_otherstatebits); |
|
|
|
if ( (swap->otherstatebits & 0x80) == 0 ) |
|
|
|
basilisk_swapdata_rawtxsend(myinfo,swap,0x80,data,maxlen,&swap->myfee,0x40); |
|
|
|
basilisk_sendstate(myinfo,swap,data,maxlen); |
|
|
|
} |
|
|
|
while ( time(NULL) < swap->expiration ) // both sides have setup required data and paid txfee
|
|
|
|
{ |
|
|
|
//if ( swap->sleeptime < 60 )
|
|
|
|
// swap->sleeptime++;
|
|
|
@ -1296,7 +1311,6 @@ void basilisk_swaploop(void *_swap) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
printf("finished swapstate.%x\n",swap->statebits); |
|
|
|
sleep(1); |
|
|
|
} |
|
|
|