diff --git a/.gitignore b/.gitignore index 3cbd517da..125465865 100755 --- a/.gitignore +++ b/.gitignore @@ -358,3 +358,5 @@ iguana/DB/SWAPS/3062665554-3128383014 iguana/DB/SWAPS/2668150969-2698996317 iguana/DB/SWAPS/3462690702-2419919594 + +iguana/DB/SWAPS/543051861-1532200070 diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index c37872b57..2743ddd0e 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -1202,7 +1202,9 @@ HASH_ARRAY_STRING(basilisk,value,hash,vals,hexstr) { if ( (txoutjson= dpow_gettxout(myinfo,coin,txid,vout)) != 0 ) { - if ( (coinaddr= jstr(txoutjson,"address")) != 0 && (value= SATOSHIDEN*jdouble(txoutjson,"value")) != 0 ) + if ( (value= SATOSHIDEN*jdouble(txoutjson,"value")) == 0 ) + value = SATOSHIDEN*jdouble(txoutjson,"amount"); + if ( (coinaddr= jstr(txoutjson,"address")) != 0 && value != 0 ) { retjson = cJSON_CreateObject(); jaddstr(retjson,"result","success"); @@ -1219,6 +1221,7 @@ HASH_ARRAY_STRING(basilisk,value,hash,vals,hexstr) } else { + printf("missing fields.(%s)\n",jprint(txoutjson,0)); free_json(txoutjson); return(clonestr("{\"error\":\"return from gettxout missing fields\"}")); } diff --git a/basilisk/basilisk_swap.c b/basilisk/basilisk_swap.c index 59ffcc783..8f1288879 100755 --- a/basilisk/basilisk_swap.c +++ b/basilisk/basilisk_swap.c @@ -313,7 +313,7 @@ int32_t basilisk_numconfirms(struct supernet_info *myinfo,struct basilisk_swap * jaddstr(argjson,"coin",rawtx->coin->symbol); if ( (valstr= basilisk_value(myinfo,rawtx->coin,0,0,swap->persistent_pubkey,argjson,0)) != 0 ) { - char str[65]; printf("basilisk_numconfirms %s %s valstr.(%s)\n",rawtx->name,bits256_str(str,rawtx->I.actualtxid),valstr); + char str[65]; printf("basilisk_numconfirms required.%d %s %s valstr.(%s)\n",rawtx->I.numconfirms,rawtx->name,bits256_str(str,rawtx->I.actualtxid),valstr); if ( (valuearray= cJSON_Parse(valstr)) != 0 ) { if ( is_cJSON_Array(valuearray) != 0 ) @@ -949,7 +949,9 @@ int32_t basilisk_verify_bobdeposit(struct supernet_info *myinfo,void *ptr,uint8_ uint8_t userdata[512]; int32_t i,retval,len = 0; static bits256 zero; struct basilisk_swap *swap = ptr; if ( basilisk_rawtx_spendscript(swap,swap->bobcoin->longestchain,&swap->bobdeposit,0,data,datalen,0) == 0 ) { - basilisk_swap_broadcast(swap->bobdeposit.name,myinfo,swap,swap->bobdeposit.coin,swap->bobdeposit.txbytes,swap->bobdeposit.I.datalen); + swap->bobdeposit.I.actualtxid = basilisk_swap_broadcast(swap->bobdeposit.name,myinfo,swap,swap->bobdeposit.coin,swap->bobdeposit.txbytes,swap->bobdeposit.I.datalen); + if ( bits256_nonz(swap->bobdeposit.I.actualtxid) != 0 ) + swap->depositunconf = 1; basilisk_dontforget_update(myinfo,swap,&swap->bobdeposit); len = basilisk_swapuserdata(userdata,zero,1,swap->I.myprivs[0],swap->bobdeposit.redeemscript,swap->bobdeposit.I.redeemlen); memcpy(swap->I.userdata_aliceclaim,userdata,len); @@ -1018,7 +1020,9 @@ int32_t basilisk_verify_bobpaid(struct supernet_info *myinfo,void *ptr,uint8_t * memset(revAm.bytes,0,sizeof(revAm)); if ( basilisk_rawtx_spendscript(swap,swap->bobcoin->longestchain,&swap->bobpayment,0,data,datalen,0) == 0 ) { - basilisk_swap_broadcast(swap->bobpayment.name,myinfo,swap,swap->bobpayment.coin,swap->bobpayment.txbytes,swap->bobpayment.I.datalen); + swap->bobpayment.I.actualtxid = basilisk_swap_broadcast(swap->bobpayment.name,myinfo,swap,swap->bobpayment.coin,swap->bobpayment.txbytes,swap->bobpayment.I.datalen); + if ( bits256_nonz(swap->bobpayment.I.actualtxid) != 0 ) + swap->paymentunconf = 1; basilisk_dontforget_update(myinfo,swap,&swap->bobpayment); for (i=0; i<32; i++) revAm.bytes[i] = swap->I.privAm.bytes[31-i]; @@ -1079,10 +1083,12 @@ int32_t basilisk_alicepayment_spend(struct supernet_info *myinfo,struct basilisk int32_t basilisk_verify_alicepaid(struct supernet_info *myinfo,void *ptr,uint8_t *data,int32_t datalen) { - struct basilisk_swap *swap = ptr; + bits256 txid; struct basilisk_swap *swap = ptr; if ( basilisk_rawtx_spendscript(swap,swap->alicecoin->longestchain,&swap->alicepayment,0,data,datalen,0) == 0 ) { - basilisk_swap_broadcast(swap->alicepayment.name,myinfo,swap,swap->alicepayment.coin,swap->alicepayment.txbytes,swap->alicepayment.I.datalen); + swap->alicepayment.I.actualtxid = basilisk_swap_broadcast(swap->alicepayment.name,myinfo,swap,swap->alicepayment.coin,swap->alicepayment.txbytes,swap->alicepayment.I.datalen); + if ( bits256_nonz(txid) != 0 ) + swap->aliceunconf = 1; basilisk_dontforget_update(myinfo,swap,&swap->alicepayment); return(0); } @@ -1770,7 +1776,7 @@ struct basilisk_swap *bitcoin_swapinit(struct supernet_info *myinfo,bits256 priv if ( swap->I.aliceconfirms == 0 ) swap->I.aliceconfirms = swap->alicecoin->chain->minconfirms; jumblrflag = (bits256_cmp(pubkey25519,myinfo->jumblr_pubkey) == 0 || bits256_cmp(pubkey25519,myinfo->jumblr_depositkey) == 0); - printf(">>>>>>>>>> jumblrflag.%d <<<<<<<<< use smart address\n",jumblrflag); + printf(">>>>>>>>>> jumblrflag.%d <<<<<<<<< use smart address, bobconfs.%d aliceconfs.%d\n",jumblrflag,swap->I.bobconfirms,swap->I.aliceconfirms); if ( swap->I.iambob != 0 ) { basilisk_rawtx_setparms("myfee",swap->I.req.quoteid,&swap->myfee,swap->bobcoin,0,0,swap->I.bobsatoshis/INSTANTDEX_DECKSIZE,0,0,jumblrflag); @@ -2183,7 +2189,7 @@ int32_t basilisk_swapiteration(struct supernet_info *myinfo,struct basilisk_swap } else if ( (swap->I.statebits & 0x2000) == 0 ) { - if ( basilisk_numconfirms(myinfo,swap,&swap->alicepayment) >= swap->I.aliceconfirms ) + if ( (swap->I.aliceconfirms == 0 && swap->aliceunconf != 0) || basilisk_numconfirms(myinfo,swap,&swap->alicepayment) >= swap->I.aliceconfirms ) { swap->I.statebits |= 0x2000; printf("alicepayment confirmed\n"); @@ -2260,7 +2266,7 @@ int32_t basilisk_swapiteration(struct supernet_info *myinfo,struct basilisk_swap } else if ( (swap->I.statebits & 0x400) == 0 ) { - if ( basilisk_istrustedbob(myinfo,swap) != 0 || basilisk_numconfirms(myinfo,swap,&swap->bobdeposit) >= swap->I.bobconfirms ) + if ( basilisk_istrustedbob(myinfo,swap) != 0 || (swap->I.bobconfirms == 0 && swap->depositunconf != 0) || basilisk_numconfirms(myinfo,swap,&swap->bobdeposit) >= swap->I.bobconfirms ) { printf("bobdeposit confirmed\n"); swap->I.statebits |= 0x400; @@ -2284,7 +2290,7 @@ int32_t basilisk_swapiteration(struct supernet_info *myinfo,struct basilisk_swap } else if ( (swap->I.statebits & 0x10000) == 0 ) { - if ( basilisk_istrustedbob(myinfo,swap) != 0 || basilisk_numconfirms(myinfo,swap,&swap->bobpayment) >= swap->I.bobconfirms ) + if ( basilisk_istrustedbob(myinfo,swap) != 0 || (swap->I.bobconfirms == 0 && swap->paymentunconf != 0) || basilisk_numconfirms(myinfo,swap,&swap->bobpayment) >= swap->I.bobconfirms ) { printf("bobpayment confirmed\n"); swap->I.statebits |= 0x10000; diff --git a/iguana/iguana777.h b/iguana/iguana777.h index f83fe19c5..26ba7d77f 100755 --- a/iguana/iguana777.h +++ b/iguana/iguana777.h @@ -182,7 +182,7 @@ struct basilisk_swap { struct supernet_info *myinfoptr; struct iguana_info *bobcoin,*alicecoin; void (*balancingtrade)(struct supernet_info *myinfo,struct basilisk_swap *swap,int32_t iambob); - int32_t subsock,pushsock,connected,DEXselector; uint32_t lasttime,aborted; + int32_t subsock,pushsock,connected,DEXselector,aliceunconf,depositunconf,paymentunconf; uint32_t lasttime,aborted; FILE *fp; bits256 persistent_privkey,persistent_pubkey; struct basilisk_swapinfo I; diff --git a/iguana/iguana_payments.c b/iguana/iguana_payments.c index 6fdcebffc..a5b2876cf 100755 --- a/iguana/iguana_payments.c +++ b/iguana/iguana_payments.c @@ -448,7 +448,7 @@ char *iguana_calcrawtx(struct supernet_info *myinfo,struct iguana_info *coin,cJS coinaddr = jstri(addresses,i); if ( (array= basilisk_unspents(myinfo,coin,coinaddr)) != 0 ) { - //printf("unspents.(%s) %s\n",coinaddr,jprint(array,0)); + //printf("iguana_calcrawtx unspents.(%s) %s\n",coinaddr,jprint(array,0)); if ( (m= cJSON_GetArraySize(array)) > 0 ) { for (j=0; jjumblr_passphrase[0] != 0 && coin->FULLNODE < 0 ) { diff --git a/iguana/tests/dexlistunspent b/iguana/tests/dexlistunspent index dfc4bda64..2aa0e56ab 100755 --- a/iguana/tests/dexlistunspent +++ b/iguana/tests/dexlistunspent @@ -1,2 +1,2 @@ #!/bin/bash -curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RUDpN6PEBsE7ZFbGjUxk1W3QVsxnjBLYw6\",\"symbol\":\"KMD\"}" +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RSZ7dc164T9gpDLmXU7spYEScru1mGzPMB\",\"symbol\":\"KMD\"}"