From 907351af5c17ff122a6023e109336cd9f80dc11a Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Jun 2017 13:10:00 +0300 Subject: [PATCH] Test --- iguana/exchanges/LP_nativeDEX.c | 3 ++- iguana/exchanges/LP_remember.c | 2 ++ iguana/exchanges/LP_swap.c | 25 ++++++++++++++++++------- iguana/exchanges/LP_transaction.c | 4 ++-- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 6dcdb2bb7..d807a391a 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -32,7 +32,7 @@ char USERPASS[65],USERPASS_WIFSTR[64],USERHOME[512] = { "/root" }; char *default_LPnodes[] = { "5.9.253.196", "5.9.253.197", "5.9.253.198", "5.9.253.199", "5.9.253.200", "5.9.253.201", "5.9.253.202", "5.9.253.203", "5.9.253.204" }; //"5.9.253.195", -portable_mutex_t LP_peermutex,LP_utxomutex,LP_commandmutex,LP_cachemutex; +portable_mutex_t LP_peermutex,LP_utxomutex,LP_commandmutex,LP_cachemutex,LP_swaplistmutex; int32_t LP_mypubsock = -1; int32_t Client_connections; int32_t USERPASS_COUNTER,IAMCLIENT = 0; @@ -267,6 +267,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,double profit portable_mutex_init(&LP_peermutex); portable_mutex_init(&LP_utxomutex); portable_mutex_init(&LP_commandmutex); + portable_mutex_init(&LP_swaplistmutex); portable_mutex_init(&LP_cachemutex); if ( amclient == 0 ) { diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index 1756b86a7..485a71086 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -889,6 +889,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti char *basilisk_swaplist() { char fname[512]; FILE *fp; cJSON *item,*retjson,*array,*totalsobj; uint32_t quoteid,requestid; int64_t KMDtotals[16],BTCtotals[16],Btotal,Ktotal; int32_t i; + portable_mutex_lock(&LP_swaplistmutex); memset(KMDtotals,0,sizeof(KMDtotals)); memset(BTCtotals,0,sizeof(BTCtotals)); //,statebits; int32_t optionduration; struct basilisk_request R; bits256 privkey; @@ -949,6 +950,7 @@ char *basilisk_swaplist() jaddi(array,linfo_json(&myinfo->linfos[i])); } jadd(retjson,"quotes",array);*/ + portable_mutex_unlock(&LP_swaplistmutex); return(jprint(retjson,1)); } diff --git a/iguana/exchanges/LP_swap.c b/iguana/exchanges/LP_swap.c index f512b294e..f6195d74b 100644 --- a/iguana/exchanges/LP_swap.c +++ b/iguana/exchanges/LP_swap.c @@ -677,15 +677,17 @@ void LP_bobloop(void *_utxo) printf("error sending bobdeposit\n"); else if ( LP_waitfor(utxo->pair,swap,10,LP_verify_alicepayment) < 0 ) printf("error waiting for alicepayment\n"); - else if ( basilisk_bobscripts_set(swap,0,1) < 0 ) - printf("error bobscripts payment\n"); - else if ( LP_swapdata_rawtxsend(utxo->pair,swap,0x8000,data,maxlen,&swap->bobpayment,0x4000,0) == 0 ) - printf("error sending bobpayment\n"); else { swap->bobreclaim.utxovout = 0; swap->bobreclaim.utxotxid = swap->bobpayment.I.signedtxid; basilisk_bobpayment_reclaim(swap,swap->I.callduration); + while ( LP_numconfirms(swap,&swap->alicepayment) < 1 ) + sleep(3); + if ( basilisk_bobscripts_set(swap,0,1) < 0 ) + printf("error bobscripts payment\n"); + else if ( LP_swapdata_rawtxsend(utxo->pair,swap,0x8000,data,maxlen,&swap->bobpayment,0x4000,0) == 0 ) + printf("error sending bobpayment\n"); LP_swapwait(swap->I.req.requestid,swap->I.req.quoteid,4*3600,600); } } @@ -724,11 +726,20 @@ void LP_aliceloop(void *_qp) printf("error waiting for bobdeposit\n"); else if ( LP_swapdata_rawtxsend(qp->pair,swap,0x1000,data,maxlen,&swap->alicepayment,0x800,0) == 0 ) printf("error sending alicepayment\n"); - else if ( LP_waitfor(qp->pair,swap,10,LP_verify_bobpayment) < 0 ) - printf("error waiting for bobpayment\n"); else { - LP_swapwait(swap->I.req.requestid,swap->I.req.quoteid,4*3600,600); + while ( LP_numconfirms(swap,&swap->alicepayment) < 1 ) + sleep(3); + if ( LP_waitfor(qp->pair,swap,10,LP_verify_bobpayment) < 0 ) + printf("error waiting for bobpayment\n"); + else + { + while ( LP_numconfirms(swap,&swap->bobpayment) < 1 ) + sleep(3); + if ( LP_swapdata_rawtxsend(qp->pair,swap,0x20000,data,maxlen,&swap->alicespend,0x0,0) == 0 ) + printf("error sending alicepayment\n"); + LP_swapwait(swap->I.req.requestid,swap->I.req.quoteid,4*3600,600); + } } } basilisk_swap_finished(swap); diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index 6c5e68e95..cf541426b 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -79,7 +79,7 @@ uint64_t oldLP_txvalue(char *symbol,bits256 txid,int32_t vout) { if ( (interest= jdouble(utxoobj,"interest")) != 0. ) { - printf("add interest of %.8f to %.8f\n",interest,dstr(value)); + //printf("add interest of %.8f to %.8f\n",interest,dstr(value)); value += SATOSHIDEN * interest; } free_json(utxoobj); @@ -104,7 +104,7 @@ uint64_t LP_txvalue(char *symbol,bits256 txid,int32_t vout) { if ( (interest= jdouble(txobj,"interest")) != 0. ) { - printf("add interest of %.8f to %.8f\n",interest,dstr(value)); + //printf("add interest of %.8f to %.8f\n",interest,dstr(value)); value += SATOSHIDEN * interest; } }