Browse Source

Test

etomic
jl777 8 years ago
parent
commit
fef621097c
  1. 2
      .gitignore
  2. 39
      basilisk/basilisk_swap.c
  3. 1
      iguana/iguana_payments.c

2
.gitignore

@ -350,3 +350,5 @@ iguana/DB/SWAPS/26534791-3105729230
*.finished *.finished
iguana/DB/SWAPS/2279906047-2580050792 iguana/DB/SWAPS/2279906047-2580050792
iguana/DB/SWAPS/1672096208-4211948211

39
basilisk/basilisk_swap.c

@ -18,7 +18,7 @@
make sure to broadcast deposit before claiming refund, or to just skip it if neither is done make sure to broadcast deposit before claiming refund, or to just skip it if neither is done
*/ */
#define DEX_SLEEP 15 #define DEX_SLEEP 10
#define BASILISK_DEFAULT_NUMCONFIRMS 5 #define BASILISK_DEFAULT_NUMCONFIRMS 5
// Todo: monitor blockchains, ie complete extracting scriptsig // Todo: monitor blockchains, ie complete extracting scriptsig
@ -555,6 +555,8 @@ int32_t _basilisk_rawtx_gen(char *str,struct supernet_info *myinfo,uint32_t swap
jaddstr(valsobj,"spendscript",scriptstr); jaddstr(valsobj,"spendscript",scriptstr);
jaddstr(valsobj,"changeaddr",rawtx->coin->changeaddr); jaddstr(valsobj,"changeaddr",rawtx->coin->changeaddr);
jadd64bits(valsobj,"satoshis",rawtx->I.amount); jadd64bits(valsobj,"satoshis",rawtx->I.amount);
if ( strcmp(rawtx->coin->symbol,"BTC") == 0 && txfee > 0 && txfee < 50000 )
txfee = 50000;
jadd64bits(valsobj,"txfee",txfee); jadd64bits(valsobj,"txfee",txfee);
jaddnum(valsobj,"minconf",minconf); jaddnum(valsobj,"minconf",minconf);
if ( locktime == 0 ) if ( locktime == 0 )
@ -571,7 +573,7 @@ int32_t _basilisk_rawtx_gen(char *str,struct supernet_info *myinfo,uint32_t swap
V = calloc(256,sizeof(*V)); V = calloc(256,sizeof(*V));
if ( (retstr= basilisk_bitcoinrawtx(myinfo,rawtx->coin,"",basilisktag,jint(valsobj,"timeout"),valsobj,V)) != 0 ) if ( (retstr= basilisk_bitcoinrawtx(myinfo,rawtx->coin,"",basilisktag,jint(valsobj,"timeout"),valsobj,V)) != 0 )
{ {
printf("%s %s basilisk_bitcoinrawtx.(%s)\n",rawtx->name,str,retstr); printf("%s %s basilisk_bitcoinrawtx.(%s) txfee %.8f\n",rawtx->name,str,retstr,dstr(txfee));
flag = 0; flag = 0;
if ( (retarray= cJSON_Parse(retstr)) != 0 ) if ( (retarray= cJSON_Parse(retstr)) != 0 )
{ {
@ -2111,7 +2113,7 @@ void basilisk_sendmostprivs(struct supernet_info *myinfo,struct basilisk_swap *s
int32_t basilisk_swapiteration(struct supernet_info *myinfo,struct basilisk_swap *swap,uint8_t *data,int32_t maxlen) int32_t basilisk_swapiteration(struct supernet_info *myinfo,struct basilisk_swap *swap,uint8_t *data,int32_t maxlen)
{ {
int32_t j,datalen,retval = 0; int32_t j,datalen,retval = 0; uint32_t savestatebits=0,saveotherbits=0;
if ( swap->I.iambob != 0 ) if ( swap->I.iambob != 0 )
swap->I.statebits |= 0x80; swap->I.statebits |= 0x80;
while ( swap->aborted == 0 && ((swap->I.otherstatebits & 0x80) == 0 || (swap->I.statebits & 0x80) == 0) && retval == 0 && time(NULL) < swap->I.expiration ) while ( swap->aborted == 0 && ((swap->I.otherstatebits & 0x80) == 0 || (swap->I.statebits & 0x80) == 0) && retval == 0 && time(NULL) < swap->I.expiration )
@ -2134,7 +2136,10 @@ int32_t basilisk_swapiteration(struct supernet_info *myinfo,struct basilisk_swap
basilisk_swapget(myinfo,swap,0x80000000,data,maxlen,basilisk_verify_otherstatebits); basilisk_swapget(myinfo,swap,0x80000000,data,maxlen,basilisk_verify_otherstatebits);
if ( (swap->I.otherstatebits & 0x80) != 0 && (swap->I.statebits & 0x80) != 0 ) if ( (swap->I.otherstatebits & 0x80) != 0 && (swap->I.statebits & 0x80) != 0 )
break; break;
sleep(DEX_SLEEP + (swap->I.iambob == 0)*1); if ( swap->I.statebits == savestatebits && swap->I.otherstatebits == saveotherbits )
sleep(DEX_SLEEP + (swap->I.iambob == 0)*1);
savestatebits = swap->I.statebits;
saveotherbits = swap->I.otherstatebits;
basilisk_swapget(myinfo,swap,0x80000000,data,maxlen,basilisk_verify_otherstatebits); basilisk_swapget(myinfo,swap,0x80000000,data,maxlen,basilisk_verify_otherstatebits);
basilisk_sendstate(myinfo,swap,data,maxlen); basilisk_sendstate(myinfo,swap,data,maxlen);
if ( (swap->I.otherstatebits & 0x80) == 0 ) if ( (swap->I.otherstatebits & 0x80) == 0 )
@ -2321,7 +2326,10 @@ int32_t basilisk_swapiteration(struct supernet_info *myinfo,struct basilisk_swap
} }
if ( (rand() % 30) == 0 ) if ( (rand() % 30) == 0 )
printf("finished swapstate.%x other.%x\n",swap->I.statebits,swap->I.otherstatebits); printf("finished swapstate.%x other.%x\n",swap->I.statebits,swap->I.otherstatebits);
sleep(DEX_SLEEP + (swap->I.iambob == 0)); if ( swap->I.statebits == savestatebits && swap->I.otherstatebits == saveotherbits )
sleep(DEX_SLEEP + (swap->I.iambob == 0)*1);
savestatebits = swap->I.statebits;
saveotherbits = swap->I.otherstatebits;
basilisk_sendstate(myinfo,swap,data,maxlen); basilisk_sendstate(myinfo,swap,data,maxlen);
basilisk_swapget(myinfo,swap,0x80000000,data,maxlen,basilisk_verify_otherstatebits); basilisk_swapget(myinfo,swap,0x80000000,data,maxlen,basilisk_verify_otherstatebits);
} }
@ -2466,7 +2474,7 @@ int32_t basilisk_alicetxs(struct supernet_info *myinfo,struct basilisk_swap *swa
void basilisk_swaploop(void *_swap) void basilisk_swaploop(void *_swap)
{ {
uint8_t *data; uint32_t expiration; uint32_t channel; int32_t iters,retval=0,j,datalen,maxlen; struct supernet_info *myinfo; struct basilisk_swap *swap = _swap; uint8_t *data; uint32_t expiration,savestatebits=0,saveotherbits=0; uint32_t channel; int32_t iters,retval=0,j,datalen,maxlen; struct supernet_info *myinfo; struct basilisk_swap *swap = _swap;
myinfo = swap->myinfoptr; myinfo = swap->myinfoptr;
fprintf(stderr,"start swap\n"); fprintf(stderr,"start swap\n");
maxlen = 1024*1024 + sizeof(*swap); maxlen = 1024*1024 + sizeof(*swap);
@ -2490,7 +2498,10 @@ void basilisk_swaploop(void *_swap)
if ( (swap->I.statebits & (0x08|0x02)) == (0x08|0x02) ) if ( (swap->I.statebits & (0x08|0x02)) == (0x08|0x02) )
break; break;
} }
sleep(DEX_SLEEP); if ( swap->I.statebits == savestatebits && swap->I.otherstatebits == saveotherbits )
sleep(DEX_SLEEP + (swap->I.iambob == 0)*1);
savestatebits = swap->I.statebits;
saveotherbits = swap->I.otherstatebits;
} }
if ( swap->connected == 0 ) if ( swap->connected == 0 )
{ {
@ -2510,7 +2521,10 @@ void basilisk_swaploop(void *_swap)
swap->I.statebits |= 0x20; swap->I.statebits |= 0x20;
break; break;
} }
sleep(DEX_SLEEP + (swap->I.iambob == 0)*1); if ( swap->I.statebits == savestatebits && swap->I.otherstatebits == saveotherbits )
sleep(DEX_SLEEP + (swap->I.iambob == 0)*1);
savestatebits = swap->I.statebits;
saveotherbits = swap->I.otherstatebits;
} }
myinfo->DEXactive = swap->I.expiration; myinfo->DEXactive = swap->I.expiration;
if ( time(NULL) >= expiration ) if ( time(NULL) >= expiration )
@ -2603,7 +2617,10 @@ void basilisk_swaploop(void *_swap)
} }
while ( swap->aborted == 0 && retval == 0 && basilisk_swapiteration(myinfo,swap,data,maxlen) == 0 ) while ( swap->aborted == 0 && retval == 0 && basilisk_swapiteration(myinfo,swap,data,maxlen) == 0 )
{ {
sleep(DEX_SLEEP); if ( swap->I.statebits == savestatebits && swap->I.otherstatebits == saveotherbits )
sleep(DEX_SLEEP + (swap->I.iambob == 0)*1);
savestatebits = swap->I.statebits;
saveotherbits = swap->I.otherstatebits;
basilisk_sendstate(myinfo,swap,data,maxlen); basilisk_sendstate(myinfo,swap,data,maxlen);
basilisk_swapget(myinfo,swap,0x80000000,data,maxlen,basilisk_verify_otherstatebits); basilisk_swapget(myinfo,swap,0x80000000,data,maxlen,basilisk_verify_otherstatebits);
basilisk_swap_saveupdate(myinfo,swap); basilisk_swap_saveupdate(myinfo,swap);
@ -2783,7 +2800,7 @@ cJSON *basilisk_swapgettxout(struct supernet_info *myinfo,char *symbol,bits256 t
{ {
if ( (retstr= dex_gettxout(myinfo,0,0,0,trigger,symbol,vout)) != 0 ) if ( (retstr= dex_gettxout(myinfo,0,0,0,trigger,symbol,vout)) != 0 )
{ {
//printf("dexgettxout.(%s)\n",retstr); printf("dexgettxout.(%s)\n",retstr);
retjson = cJSON_Parse(retstr); retjson = cJSON_Parse(retstr);
free(retstr); free(retstr);
} }
@ -3354,7 +3371,7 @@ cJSON *basilisk_remember(struct supernet_info *myinfo,int64_t *KMDtotals,int64_t
{ {
if ( sentflags[BASILISK_ALICEPAYMENT] == 0 && bits256_nonz(txids[BASILISK_ALICEPAYMENT]) != 0 ) if ( sentflags[BASILISK_ALICEPAYMENT] == 0 && bits256_nonz(txids[BASILISK_ALICEPAYMENT]) != 0 )
{ {
//printf("txbytes.%p Apayment.%s\n",txbytes[BASILISK_ALICEPAYMENT],bits256_str(str,txids[BASILISK_ALICEPAYMENT])); printf("txbytes.%p Apayment.%s\n",txbytes[BASILISK_ALICEPAYMENT],bits256_str(str,txids[BASILISK_ALICEPAYMENT]));
if ( txbytes[BASILISK_ALICEPAYMENT] != 0 ) if ( txbytes[BASILISK_ALICEPAYMENT] != 0 )
sentflags[BASILISK_ALICEPAYMENT] = 1; sentflags[BASILISK_ALICEPAYMENT] = 1;
else if ( (sentobj= basilisk_swapgettx(myinfo,alicecoin,txids[BASILISK_ALICEPAYMENT])) != 0 ) else if ( (sentobj= basilisk_swapgettx(myinfo,alicecoin,txids[BASILISK_ALICEPAYMENT])) != 0 )

1
iguana/iguana_payments.c

@ -530,6 +530,7 @@ char *iguana_calcrawtx(struct supernet_info *myinfo,struct iguana_info *coin,cJS
bitcoin_txoutput(txobj,opreturn,oplen,burnamount); bitcoin_txoutput(txobj,opreturn,oplen,burnamount);
} }
} }
printf("total %.8f txfee %.8f change %.8f\n",dstr(total),dstr(txfee),dstr(change));
if ( vins != 0 && V == 0 ) if ( vins != 0 && V == 0 )
{ {
V = calloc(cJSON_GetArraySize(vins),sizeof(*V)), allocflag = 1; V = calloc(cJSON_GetArraySize(vins),sizeof(*V)), allocflag = 1;

Loading…
Cancel
Save