From 2db0f96ae53040688b8d4b001d5d2a49b0e9d447 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 12 Nov 2017 10:51:32 +0200 Subject: [PATCH 01/48] Timestamp in swapstatus --- iguana/exchanges/LP_ordermatch.c | 2 +- iguana/exchanges/LP_remember.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index c2eba14fb..08721bcaf 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -699,7 +699,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, printf("%s src %s failed SPV check\n",Q.srccoin,bits256_str(str,Q.txid)); return(retval); } - else if (LP_validSPV(Q.srccoin,Q.coinaddr,Q.txid2,Q.vout2) < 0 ) + else if ( LP_validSPV(Q.srccoin,Q.coinaddr,Q.txid2,Q.vout2) < 0 ) { printf("%s src2 %s failed SPV check\n",Q.srccoin,bits256_str(str,Q.txid2)); return(retval); diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index f8bc1a227..5b145da5c 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -450,6 +450,7 @@ cJSON *LP_swap_json(struct LP_swap_remember *rswap) { cJSON *item,*array; int32_t i; item = cJSON_CreateObject(); + jaddnum(item,"timestamp",rswap->expiration - INSTANTDEX_LOCKTIME*2); jaddnum(item,"tradeid",rswap->tradeid); jaddnum(item,"requestid",rswap->requestid); jaddnum(item,"quoteid",rswap->quoteid); From 1c5de221b88783ff4b520bc0b44b332722d1b38f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 12 Nov 2017 11:19:00 +0200 Subject: [PATCH 02/48] Finishtime in swapstatus --- iguana/exchanges/LP_include.h | 1 + iguana/exchanges/LP_remember.c | 5 ++++ iguana/exchanges/LP_rpc.c | 46 ++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 3922708ed..5d07367d3 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -443,6 +443,7 @@ struct LP_address_utxo *LP_address_utxofind(struct iguana_info *coin,char *coina int32_t LP_destaddr(char *destaddr,cJSON *item); int32_t LP_waitmempool(char *symbol,char *coinaddr,bits256 txid,int32_t vout,int32_t duration); char *LP_statslog_disp(int32_t n,uint32_t starttime,uint32_t endtime,char *refgui,bits256 refpubkey); +uint32_t LP_heighttime(char *symbol,int32_t height); uint64_t LP_unspents_load(char *symbol,char *addr); int32_t LP_validSPV(char *symbol,char *coinaddr,bits256 txid,int32_t vout); struct LP_transaction *LP_transactionfind(struct iguana_info *coin,bits256 txid); diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index 5b145da5c..4d189f6d0 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -477,7 +477,12 @@ cJSON *LP_swap_json(struct LP_swap_remember *rswap) jadd(item,"values",array); jaddstr(item,"result","success"); if ( rswap->finishedflag != 0 ) + { jaddstr(item,"status","finished"); + if ( rswap->iambob == 0 ) + jaddnum(item,"finishtime",LP_txtime(rswap->dest,rswap->paymentspent)); + else jaddnum(item,"finishtime",LP_txtime(rswap->dest,rswap->depositspent)); + } else jaddstr(item,"status","pending"); jaddbits256(item,"bobdeposit",rswap->txids[BASILISK_BOBDEPOSIT]); jaddbits256(item,"alicepayment",rswap->txids[BASILISK_ALICEPAYMENT]); diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 661c476e6..3b77916af 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -447,6 +447,22 @@ uint32_t LP_locktime(char *symbol,bits256 txid) return(locktime); } +uint32_t LP_txtime(char *symbol,bits256 txid) +{ + struct LP_transaction *tx; struct iguana_info *coin; int32_t timestamp=0,height = 0; + if ( (timestamp= LP_locktime(symbol,txid)) != 0 ) + return(timestamp); + if ( (coin= LP_coinfind(symbol)) != 0 ) + { + if ( (tx= LP_transactionfind(coin,txid)) != 0 ) + { + height = tx->height; + timestamp = LP_heighttime(symbol,height); + } + } + return(height); +} + cJSON *LP_gettxout_json(bits256 txid,int32_t vout,int32_t height,char *coinaddr,uint64_t value) { cJSON *retjson,*addresses,*sobj; @@ -1013,6 +1029,36 @@ cJSON *LP_getblockhashstr(char *symbol,char *blockhashstr) return(bitcoin_json(coin,"getblock",buf)); } +uint32_t LP_heighttime(char *symbol,int32_t height) +{ + struct electrum_info *ep; uint32_t timestamp = 0; cJSON *retjson; char *blockhashstr; struct iguana_info *coin = LP_coinfind(symbol); + if ( coin != 0 ) + { + if ( (ep= coin->electrum) == 0 ) + { + if ( (blockhashstr= LP_blockhashstr(symbol,height)) != 0 ) + { + if ( (retjson= cJSON_Parse(blockhashstr)) != 0 ) + { + timestamp = juint(retjson,"time"); + free_json(retjson); + } + free(blockhashstr); + } + } + else + { + if ( (retjson= electrum_getheader(coin->symbol,ep,&retjson,height)) != 0 ) + { + printf("%s\n",jprint(retjson,0)); + timestamp = juint(retjson,"timestamp"); + free_json(retjson); + } + } + } + return(timestamp); +} + cJSON *LP_blockjson(int32_t *heightp,char *symbol,char *blockhashstr,int32_t height) { cJSON *json = 0; int32_t flag = 0; struct iguana_info *coin; From d7ef7be5e21630bc7e4555d2a0bc0892b4cbb7d6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 12 Nov 2017 11:35:43 +0200 Subject: [PATCH 03/48] Test --- iguana/exchanges/LP_commands.c | 3 +++ iguana/exchanges/LP_remember.c | 15 ++++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 9d0f4ff47..25bb1ee70 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -260,7 +260,10 @@ bot_resume(botid)\n\ { uint32_t requestid,quoteid; if ( (requestid= juint(argjson,"requestid")) != 0 && (quoteid= juint(argjson,"quoteid")) != 0 ) + { + printf("swapentry %u %u\n",requestid,quoteid); return(basilisk_swapentry(requestid,quoteid)); + } else if ( coin[0] != 0 ) return(basilisk_swapentries(coin,0,jint(argjson,"limit"))); else if ( base[0] != 0 && rel[0] != 0 ) diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index 4d189f6d0..a25325258 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -481,7 +481,7 @@ cJSON *LP_swap_json(struct LP_swap_remember *rswap) jaddstr(item,"status","finished"); if ( rswap->iambob == 0 ) jaddnum(item,"finishtime",LP_txtime(rswap->dest,rswap->paymentspent)); - else jaddnum(item,"finishtime",LP_txtime(rswap->dest,rswap->depositspent)); + else jaddnum(item,"finishtime",LP_txtime(rswap->src,rswap->depositspent)); } else jaddstr(item,"status","pending"); jaddbits256(item,"bobdeposit",rswap->txids[BASILISK_BOBDEPOSIT]); @@ -1137,7 +1137,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti char *basilisk_swaplist(uint32_t origrequestid,uint32_t origquoteid) { - uint64_t ridqids[4096],ridqid; char fname[512]; FILE *fp; cJSON *item,*retjson,*array,*totalsobj; uint32_t r,q,quoteid,requestid; int64_t KMDtotals[16],BTCtotals[16],Btotal,Ktotal; int32_t i,j,count=0; + uint64_t ridqids[4096],ridqid; char fname[512]; FILE *fp; cJSON *item,*retjson,*array,*totalsobj; uint32_t r,q,quoteid,requestid; int64_t KMDtotals[LP_MAXPRICEINFOS],BTCtotals[LP_MAXPRICEINFOS],Btotal,Ktotal; int32_t i,j,count=0; portable_mutex_lock(&LP_swaplistmutex); memset(ridqids,0,sizeof(ridqids)); memset(KMDtotals,0,sizeof(KMDtotals)); @@ -1229,8 +1229,13 @@ char *basilisk_swaplist(uint32_t origrequestid,uint32_t origquoteid) char *basilisk_swapentry(uint32_t requestid,uint32_t quoteid) { - char *liststr,*retstr = 0; cJSON *retjson,*array,*item; int32_t i,n; - if ( (liststr= basilisk_swaplist(requestid,quoteid)) != 0 ) + cJSON *item; int64_t KMDtotals[LP_MAXPRICEINFOS],BTCtotals[LP_MAXPRICEINFOS]; + memset(KMDtotals,0,sizeof(KMDtotals)); + memset(BTCtotals,0,sizeof(BTCtotals)); + if ( (item= basilisk_remember(KMDtotals,BTCtotals,requestid,quoteid)) != 0 ) + return(jprint(item,1)); + else return(clonestr("{\"error\":\"cant find requestid-quoteid\"}")); + /*if ( (liststr= basilisk_swaplist(requestid,quoteid)) != 0 ) { //printf("swapentry.(%s)\n",liststr); if ( (retjson= cJSON_Parse(liststr)) != 0 ) @@ -1252,7 +1257,7 @@ char *basilisk_swapentry(uint32_t requestid,uint32_t quoteid) } free(liststr); } - return(retstr); + return(retstr);*/ } extern struct LP_quoteinfo LP_Alicequery; From 011064ed3a7a89cd8461cf47a44700c179dca0e4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 12 Nov 2017 11:42:19 +0200 Subject: [PATCH 04/48] Test --- iguana/exchanges/LP_rpc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 3b77916af..5b2a654ee 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -450,6 +450,7 @@ uint32_t LP_locktime(char *symbol,bits256 txid) uint32_t LP_txtime(char *symbol,bits256 txid) { struct LP_transaction *tx; struct iguana_info *coin; int32_t timestamp=0,height = 0; + char str[65]; printf("LP_txtime (%s %s)\n",symbol,bits256_str(str,txid)); if ( (timestamp= LP_locktime(symbol,txid)) != 0 ) return(timestamp); if ( (coin= LP_coinfind(symbol)) != 0 ) @@ -1040,6 +1041,7 @@ uint32_t LP_heighttime(char *symbol,int32_t height) { if ( (retjson= cJSON_Parse(blockhashstr)) != 0 ) { + printf("height.(%s)\n",jprint(retjson,0)); timestamp = juint(retjson,"time"); free_json(retjson); } From b1e4171eb7bc4ae17003baa4955c0f2a3bd90d58 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 12 Nov 2017 11:45:43 +0200 Subject: [PATCH 05/48] Test --- iguana/exchanges/LP_remember.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index a25325258..75e582bd0 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -480,7 +480,7 @@ cJSON *LP_swap_json(struct LP_swap_remember *rswap) { jaddstr(item,"status","finished"); if ( rswap->iambob == 0 ) - jaddnum(item,"finishtime",LP_txtime(rswap->dest,rswap->paymentspent)); + jaddnum(item,"finishtime",LP_txtime(rswap->src,rswap->paymentspent)); else jaddnum(item,"finishtime",LP_txtime(rswap->src,rswap->depositspent)); } else jaddstr(item,"status","pending"); From 88243c22f79d2bf7c6d31caaaa79e6573920934a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 12 Nov 2017 11:53:40 +0200 Subject: [PATCH 06/48] Test --- iguana/exchanges/LP_commands.c | 3 --- iguana/exchanges/LP_include.h | 2 +- iguana/exchanges/LP_remember.c | 6 +++--- iguana/exchanges/LP_rpc.c | 4 ++-- 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 25bb1ee70..9d0f4ff47 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -260,10 +260,7 @@ bot_resume(botid)\n\ { uint32_t requestid,quoteid; if ( (requestid= juint(argjson,"requestid")) != 0 && (quoteid= juint(argjson,"quoteid")) != 0 ) - { - printf("swapentry %u %u\n",requestid,quoteid); return(basilisk_swapentry(requestid,quoteid)); - } else if ( coin[0] != 0 ) return(basilisk_swapentries(coin,0,jint(argjson,"limit"))); else if ( base[0] != 0 && rel[0] != 0 ) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 5d07367d3..4e3a1e5f2 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -238,7 +238,7 @@ struct LP_swap_remember bits256 pubA0,pubB0,pubB1,privAm,privBn,paymentspent,Apaymentspent,depositspent,myprivs[2],txids[sizeof(txnames)/sizeof(*txnames)]; uint64_t Atxfee,Btxfee,srcamount,destamount,aliceid; int64_t values[sizeof(txnames)/sizeof(*txnames)]; - uint32_t tradeid,requestid,quoteid,plocktime,dlocktime,expiration,state,otherstate; + uint32_t finishtime,tradeid,requestid,quoteid,plocktime,dlocktime,expiration,state,otherstate; int32_t iambob,finishedflag,origfinishedflag,Predeemlen,Dredeemlen,sentflags[sizeof(txnames)/sizeof(*txnames)]; uint8_t secretAm[20],secretAm256[32],secretBn[20],secretBn256[32],Predeemscript[1024],Dredeemscript[1024],pubkey33[33],other33[33]; char src[64],dest[64],destaddr[64],Adestaddr[64],Sdestaddr[64],alicepaymentaddr[64],bobpaymentaddr[64],bobdepositaddr[64],alicecoin[64],bobcoin[64],*txbytes[sizeof(txnames)/sizeof(*txnames)]; diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index 75e582bd0..b50caa432 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -479,9 +479,7 @@ cJSON *LP_swap_json(struct LP_swap_remember *rswap) if ( rswap->finishedflag != 0 ) { jaddstr(item,"status","finished"); - if ( rswap->iambob == 0 ) - jaddnum(item,"finishtime",LP_txtime(rswap->src,rswap->paymentspent)); - else jaddnum(item,"finishtime",LP_txtime(rswap->src,rswap->depositspent)); + jaddnum(item,"finishtime",rswap->finishtime); } else jaddstr(item,"status","pending"); jaddbits256(item,"bobdeposit",rswap->txids[BASILISK_BOBDEPOSIT]); @@ -663,6 +661,7 @@ int32_t LP_swap_load(struct LP_swap_remember *rswap) { if ( (fileobj= cJSON_Parse(fstr)) != 0 ) { + rswap->finishtime = juint(fileobj,"finishtime"); rswap->origfinishedflag = rswap->finishedflag = 1; free_json(fileobj); } @@ -1121,6 +1120,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti if ( (fp= fopen(fname,"wb")) != 0 ) { jaddstr(item,"method","tradestatus"); + jaddnum(item,"finishtime",rswap.finishtime); jaddstr(item,"gui",G.gui); itemstr = jprint(item,0); fprintf(fp,"%s\n",itemstr); diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 5b2a654ee..1d952ff6d 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -447,7 +447,7 @@ uint32_t LP_locktime(char *symbol,bits256 txid) return(locktime); } -uint32_t LP_txtime(char *symbol,bits256 txid) +/*uint32_t LP_txtime(char *symbol,bits256 txid) { struct LP_transaction *tx; struct iguana_info *coin; int32_t timestamp=0,height = 0; char str[65]; printf("LP_txtime (%s %s)\n",symbol,bits256_str(str,txid)); @@ -462,7 +462,7 @@ uint32_t LP_txtime(char *symbol,bits256 txid) } } return(height); -} +}*/ cJSON *LP_gettxout_json(bits256 txid,int32_t vout,int32_t height,char *coinaddr,uint64_t value) { From 4720157afd869030f8ec5d4b260bb40824406a6f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 12 Nov 2017 12:00:14 +0200 Subject: [PATCH 07/48] Test --- iguana/exchanges/LP_remember.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index b50caa432..44d93a71a 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -450,7 +450,7 @@ cJSON *LP_swap_json(struct LP_swap_remember *rswap) { cJSON *item,*array; int32_t i; item = cJSON_CreateObject(); - jaddnum(item,"timestamp",rswap->expiration - INSTANTDEX_LOCKTIME*2); + jaddnum(item,"expiration",rswap->expiration);// - INSTANTDEX_LOCKTIME*2); jaddnum(item,"tradeid",rswap->tradeid); jaddnum(item,"requestid",rswap->requestid); jaddnum(item,"quoteid",rswap->quoteid); From acc7a27089f5ad01e937d982351a9a48f0dce09f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 12 Nov 2017 12:36:45 +0200 Subject: [PATCH 08/48] Test --- iguana/exchanges/LP_ordermatch.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 08721bcaf..ac4034a29 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -1011,7 +1011,7 @@ struct LP_utxoinfo *LP_buyutxo(double *ordermatchpricep,int64_t *bestsatoshisp,i char *LP_autobuy(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel,double maxprice,double relvolume,int32_t timeout,int32_t duration,char *gui,uint32_t nonce,bits256 destpubkey,uint32_t tradeid) { - uint64_t desttxfee,txfee; uint32_t lastnonce; int32_t i,maxiters,numpubs = 0; int64_t bestsatoshis=0,destsatoshis,bestdestsatoshis=0; struct iguana_info *basecoin,*relcoin; struct LP_utxoinfo *autxo,*bestutxo = 0; double qprice,ordermatchprice=0.; struct LP_quoteinfo Q; bits256 pubkeys[100]; + uint64_t desttxfee,txfee; uint32_t lastnonce; int32_t i,maxiters,numpubs = 0; int64_t bestsatoshis=0,destsatoshis,bestdestsatoshis=0; struct iguana_info *basecoin,*relcoin; struct LP_utxoinfo *autxo,B,*bestutxo = 0; double qprice,ordermatchprice=0.; struct LP_quoteinfo Q; bits256 pubkeys[100]; basecoin = LP_coinfind(base); relcoin = LP_coinfind(rel); if ( gui == 0 ) @@ -1076,8 +1076,16 @@ char *LP_autobuy(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel printf("destsatoshis %.8f vs utxo %.8f this would have triggered an quote error -13\n",dstr(destsatoshis),dstr(autxo->payment.value)); return(clonestr("{\"error\":\"cant find alice utxo that is small enough\"}")); } + bestsatoshis = LP_basesatoshis(relvolume,maxprice,txfee,desttxfee); + memset(&B,0,sizeof(B)); + strcpy(B.coin,base); + if ( LP_quoteinfoinit(&Q,&B,rel,maxprice,bestsatoshis,destsatoshis) < 0 ) + return(clonestr("{\"error\":\"cant set ordermatch quote\"}")); + if ( LP_quotedestinfo(&Q,autxo->payment.txid,autxo->payment.vout,autxo->fee.txid,autxo->fee.vout,G.LP_mypub25519,autxo->coinaddr) < 0 ) + return(clonestr("{\"error\":\"cant set ordermatch quote info\"}")); + return(LP_trade(ctx,myipaddr,mypubsock,&Q,maxprice,timeout,duration,tradeid)); + LP_RTmetrics_update(base,rel); - //return(LP_trade(ctx,myipaddr,mypubsock,&Q,maxprice,timeout,duration,tradeid)); while ( 1 ) { if ( (bestutxo= LP_buyutxo(&ordermatchprice,&bestsatoshis,&bestdestsatoshis,autxo,base,maxprice,duration,txfee,desttxfee,gui,pubkeys,numpubs,destpubkey)) == 0 || ordermatchprice == 0. || bestdestsatoshis == 0 ) From e428bc183f8afb7c7f9c856f4b9335d3767f9725 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 12 Nov 2017 13:07:42 +0200 Subject: [PATCH 09/48] Test --- iguana/exchanges/LP_commands.c | 1 - iguana/exchanges/LP_nativeDEX.c | 2 ++ iguana/exchanges/LP_socket.c | 4 ++-- iguana/exchanges/LP_utxo.c | 1 + iguana/exchanges/LP_utxos.c | 1 + 5 files changed, 6 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 9d0f4ff47..1b25666c9 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -395,7 +395,6 @@ bot_resume(botid)\n\ LP_address(ptr,coinaddr); if ( strcmp(coinaddr,ptr->smartaddr) == 0 && bits256_nonz(G.LP_privkey) != 0 ) { - LP_listunspent_issue(coin,coinaddr,2); LP_privkey_init(-1,ptr,G.LP_privkey,G.LP_mypub25519); //LP_smartutxos_push(ptr); if ( ptr->electrum != 0 ) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 279276789..a3f9a648f 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -813,12 +813,14 @@ void LP_reserved_msgs(void *ignore) if ( num_Reserved_msgs[1] > 0 ) { num_Reserved_msgs[1]--; + printf("PRIORITY BROADCAST.(%s)\n",Reserved_msgs[1][num_Reserved_msgs[1]]); LP_broadcast_message(LP_mypubsock,"","",zero,Reserved_msgs[1][num_Reserved_msgs[1]]); Reserved_msgs[1][num_Reserved_msgs[1]] = 0; } else if ( num_Reserved_msgs[0] > 0 ) { num_Reserved_msgs[0]--; + printf("BROADCAST.(%s)\n",Reserved_msgs[0][num_Reserved_msgs[0]]); LP_broadcast_message(LP_mypubsock,"","",zero,Reserved_msgs[0][num_Reserved_msgs[0]]); Reserved_msgs[0][num_Reserved_msgs[0]] = 0; } diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 5be93ba33..0dc2d6596 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -288,7 +288,7 @@ int32_t electrum_process_array(struct iguana_info *coin,struct electrum_info *ep int32_t i,v,n,ht,flag = 0; char str[65]; uint64_t value; bits256 txid; cJSON *item,*retjson,*txobj; struct LP_transaction *tx; if ( array != 0 && coin != 0 && (n= cJSON_GetArraySize(array)) > 0 ) { - //printf("PROCESS %s/%s %s num.%d\n",coin->symbol,ep!=0?ep->symbol:"nanolistunspent",coinaddr,n); + printf("PROCESS %s/%s %s num.%d\n",coin->symbol,ep!=0?ep->symbol:"nanolistunspent",coinaddr,n); for (i=0; i 1 ) + if ( 1 && electrumflag > 1 ) printf("%s.%d u.%u/%d t.%ld %s LISTUNSPENT.(%d)\n",coin->symbol,height,ap->unspenttime,ap->unspentheight,time(NULL),addr,(int32_t)strlen(jprint(retjson,0))); updatedflag = 0; if ( electrum_process_array(coin,ep,addr,retjson,electrumflag) != 0 ) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index e76b74a54..855794a45 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -145,6 +145,7 @@ int32_t LP_address_utxo_ptrs(struct iguana_info *coin,int32_t iambob,struct LP_a //printf("LP_address_utxo_ptrs for (%s).(%s)\n",ap->coinaddr,coinaddr); if ( strcmp(ap->coinaddr,coinaddr) != 0 ) printf("UNEXPECTED coinaddr mismatch (%s) != (%s)\n",ap->coinaddr,coinaddr); + LP_listunspent_issue(coin->symbol,coin->smartaddr,2); portable_mutex_lock(&LP_utxomutex); DL_FOREACH_SAFE(ap->utxos,up,tmp) { diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index e82541a63..c453368f2 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -550,6 +550,7 @@ int32_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypri return(0); coin->privkeydepth++; //printf("privkey init.(%s) %s depth.%d\n",coin->symbol,coin->smartaddr,coin->privkeydepth); + LP_listunspent_issue(coin->symbol,coin->smartaddr,2); if ( coin->inactive == 0 ) LP_listunspent_issue(coin->symbol,coin->smartaddr,0); array = LP_listunspent(coin->symbol,coin->smartaddr); From 197fffb8466d125939a41920b82eefaff46a93a2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 12 Nov 2017 13:16:54 +0200 Subject: [PATCH 10/48] Test --- iguana/exchanges/LP_utxo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 855794a45..16ecba91d 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -186,7 +186,7 @@ int32_t LP_address_utxo_ptrs(struct iguana_info *coin,int32_t iambob,struct LP_a continue; } } - if ( LP_allocated(up->U.txid,up->U.vout) == 0 && _LP_utxofind(iambob,up->U.txid,up->U.vout) == 0 && _LP_utxo2find(iambob,up->U.txid,up->U.vout) == 0 ) + if ( LP_allocated(up->U.txid,up->U.vout) == 0 && (iambob == 0 || (_LP_utxofind(iambob,up->U.txid,up->U.vout) == 0 && _LP_utxo2find(iambob,up->U.txid,up->U.vout) == 0)) ) { utxos[n++] = up; if ( n >= max ) From 8fe188021c5610b5776ae06efbe8d8b198954084 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 12 Nov 2017 13:28:28 +0200 Subject: [PATCH 11/48] Test --- iguana/exchanges/LP_socket.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 0dc2d6596..5be93ba33 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -288,7 +288,7 @@ int32_t electrum_process_array(struct iguana_info *coin,struct electrum_info *ep int32_t i,v,n,ht,flag = 0; char str[65]; uint64_t value; bits256 txid; cJSON *item,*retjson,*txobj; struct LP_transaction *tx; if ( array != 0 && coin != 0 && (n= cJSON_GetArraySize(array)) > 0 ) { - printf("PROCESS %s/%s %s num.%d\n",coin->symbol,ep!=0?ep->symbol:"nanolistunspent",coinaddr,n); + //printf("PROCESS %s/%s %s num.%d\n",coin->symbol,ep!=0?ep->symbol:"nanolistunspent",coinaddr,n); for (i=0; i 1 ) + if ( 0 && electrumflag > 1 ) printf("%s.%d u.%u/%d t.%ld %s LISTUNSPENT.(%d)\n",coin->symbol,height,ap->unspenttime,ap->unspentheight,time(NULL),addr,(int32_t)strlen(jprint(retjson,0))); updatedflag = 0; if ( electrum_process_array(coin,ep,addr,retjson,electrumflag) != 0 ) From 8571a0e1cb6f00af15b48a0daafa6c2d89dbebf4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 12 Nov 2017 13:38:53 +0200 Subject: [PATCH 12/48] Test --- iguana/exchanges/LP_ordermatch.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index ac4034a29..305322e22 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -676,7 +676,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, LP_quoteparse(&Q,argjson); LP_requestinit(&Q.R,Q.srchash,Q.desthash,Q.srccoin,Q.satoshis-Q.txfee,Q.destcoin,Q.destsatoshis-Q.desttxfee,Q.timestamp,Q.quotetime,DEXselector); LP_tradecommand_log(argjson); - //printf("LP_tradecommand: check received method %s aliceid.%llx\n",method,(long long)Q.aliceid); + printf("LP_tradecommand: check received method %s aliceid.%llx %s/%s %.8f -> %.8f\n",method,(long long)Q.aliceid,Q.srccoin,Q.destcoin,dstr(Q.satoshis),dstr(Q.destsatoshis)); retval = 1; autxo = &A; butxo = &B; @@ -761,7 +761,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, if ( strcmp(method,"request") == 0 ) { char str[65],str2[65]; - //printf("address.(%s/%s) request.(%s)\n",Q.coinaddr,coin->smartaddr,jprint(argjson,0)); + printf("address.(%s/%s) request.(%s)\n",Q.coinaddr,coin->smartaddr,jprint(argjson,0)); recalc = 0; if ( bits256_cmp(Q.srchash,G.LP_mypub25519) != 0 || strcmp(butxo->coinaddr,coin->smartaddr) != 0 ) { @@ -808,7 +808,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, printf("request from blacklisted %s, ignore\n",bits256_str(str,Q.desthash)); return(retval); } - //printf("butxo.%p recalc path %p %s, %p %s, %.8f\n",butxo,LP_allocated(butxo->payment.txid,butxo->payment.vout),bits256_str(str,butxo->payment.txid),LP_allocated(butxo->deposit.txid,butxo->deposit.vout),bits256_str(str2,butxo->deposit.txid),LP_quote_validate(autxo,butxo,&Q,1)); + printf("butxo.%p recalc path %p %s, %p %s, %.8f\n",butxo,LP_allocated(butxo->payment.txid,butxo->payment.vout),bits256_str(str,butxo->payment.txid),LP_allocated(butxo->deposit.txid,butxo->deposit.vout),bits256_str(str2,butxo->deposit.txid),LP_quote_validate(autxo,butxo,&Q,1)); LP_listunspent_both(Q.srccoin,Q.coinaddr,0); if ( (butxo= LP_address_utxopair(1,utxos,max,LP_coinfind(Q.srccoin),Q.coinaddr,Q.txfee,dstr(Q.destsatoshis),price,Q.desttxfee)) != 0 ) { From 9bc00587a7920a8af8e01cf5080c45d72cd23036 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 12 Nov 2017 13:41:32 +0200 Subject: [PATCH 13/48] Test --- iguana/exchanges/LP_nativeDEX.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index a3f9a648f..7fc952235 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -813,14 +813,14 @@ void LP_reserved_msgs(void *ignore) if ( num_Reserved_msgs[1] > 0 ) { num_Reserved_msgs[1]--; - printf("PRIORITY BROADCAST.(%s)\n",Reserved_msgs[1][num_Reserved_msgs[1]]); + //printf("PRIORITY BROADCAST.(%s)\n",Reserved_msgs[1][num_Reserved_msgs[1]]); LP_broadcast_message(LP_mypubsock,"","",zero,Reserved_msgs[1][num_Reserved_msgs[1]]); Reserved_msgs[1][num_Reserved_msgs[1]] = 0; } else if ( num_Reserved_msgs[0] > 0 ) { num_Reserved_msgs[0]--; - printf("BROADCAST.(%s)\n",Reserved_msgs[0][num_Reserved_msgs[0]]); + //printf("BROADCAST.(%s)\n",Reserved_msgs[0][num_Reserved_msgs[0]]); LP_broadcast_message(LP_mypubsock,"","",zero,Reserved_msgs[0][num_Reserved_msgs[0]]); Reserved_msgs[0][num_Reserved_msgs[0]] = 0; } From 05ba34f9b14beb2dd8dbe35b8a90b72fe98a79e2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 12 Nov 2017 13:53:55 +0200 Subject: [PATCH 14/48] Test --- iguana/exchanges/LP_ordermatch.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 305322e22..9e7305d72 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -486,14 +486,6 @@ char *LP_connectedalice(cJSON *argjson) // alice return(clonestr("{\"result\",\"update stats\"}")); } printf("CONNECTED.(%s) numpending.%d tradeid.%u\n",jprint(argjson,0),G.LP_pendingswaps,Q.tradeid); - /*if ( LP_alice_eligible() == 0 || LP_quotecmp(&Q,&LP_Alicequery) != 0 ) - { - printf("reject mismatched alice query\n"); - return(clonestr("{\"error\",\"mismatched alice query\"}")); - } - memset(&LP_Alicequery,0,sizeof(LP_Alicequery)); - LP_Alicemaxprice = 0.; - Alice_expiration = 0;*/ if ( (autxo= LP_utxopairfind(0,Q.desttxid,Q.destvout,Q.feetxid,Q.feevout)) == 0 ) { printf("cant find autxo\n"); @@ -761,9 +753,8 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, if ( strcmp(method,"request") == 0 ) { char str[65],str2[65]; - printf("address.(%s/%s) request.(%s)\n",Q.coinaddr,coin->smartaddr,jprint(argjson,0)); recalc = 0; - if ( bits256_cmp(Q.srchash,G.LP_mypub25519) != 0 || strcmp(butxo->coinaddr,coin->smartaddr) != 0 ) + if ( bits256_cmp(Q.srchash,G.LP_mypub25519) != 0 || strcmp(butxo->coinaddr,coin->smartaddr) != 0 || bits256_nonz(butxo->payment.txid) == 0 || bits256_nonz(butxo->deposit.txid) == 0 ) { strcpy(Q.gui,G.gui); strcpy(Q.coinaddr,coin->smartaddr); @@ -800,6 +791,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, recalc = 1; } } + printf("recalc.%d address.(%s/%s) request.(%s)\n",recalc,Q.coinaddr,coin->smartaddr,jprint(argjson,0)); if ( recalc != 0 ) { LP_RTmetrics_update(Q.srccoin,Q.destcoin); @@ -1083,6 +1075,8 @@ char *LP_autobuy(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel return(clonestr("{\"error\":\"cant set ordermatch quote\"}")); if ( LP_quotedestinfo(&Q,autxo->payment.txid,autxo->payment.vout,autxo->fee.txid,autxo->fee.vout,G.LP_mypub25519,autxo->coinaddr) < 0 ) return(clonestr("{\"error\":\"cant set ordermatch quote info\"}")); + int32_t changed; + LP_mypriceset(&changed,autxo->coin,base,1. / maxprice); return(LP_trade(ctx,myipaddr,mypubsock,&Q,maxprice,timeout,duration,tradeid)); LP_RTmetrics_update(base,rel); From 91eb8aadb1efbab4a342bd037a4913cad9439479 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 12 Nov 2017 13:59:27 +0200 Subject: [PATCH 15/48] Test --- iguana/exchanges/LP_ordermatch.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 9e7305d72..6a10898a9 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -494,6 +494,7 @@ char *LP_connectedalice(cJSON *argjson) // alice } if ( autxo->S.swap != 0 ) { + printf("ignore duplicate swap\n"); LP_aliceid(Q.tradeid,Q.aliceid,"error3",0,0); return(clonestr("{\"error\":\"ignore duplicate swap\"}")); } @@ -510,7 +511,7 @@ char *LP_connectedalice(cJSON *argjson) // alice } if ( LP_myprice(&bid,&ask,Q.srccoin,Q.destcoin) <= SMALLVAL || bid <= SMALLVAL ) { - //printf("this node has no price for %s/%s (%.8f %.8f)\n",Q.destcoin,Q.srccoin,bid,ask); + printf("this node has no price for %s/%s (%.8f %.8f)\n",Q.destcoin,Q.srccoin,bid,ask); LP_availableset(autxo); LP_aliceid(Q.tradeid,Q.aliceid,"error5",0,0); return(clonestr("{\"error\":\"no price set\"}")); From 94013d9cd04c54f2ba138b3100a5eebbcef4d1ec Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 12 Nov 2017 14:11:31 +0200 Subject: [PATCH 16/48] Test --- iguana/exchanges/LP_ordermatch.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 6a10898a9..a0a6ca5f2 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -801,7 +801,6 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, printf("request from blacklisted %s, ignore\n",bits256_str(str,Q.desthash)); return(retval); } - printf("butxo.%p recalc path %p %s, %p %s, %.8f\n",butxo,LP_allocated(butxo->payment.txid,butxo->payment.vout),bits256_str(str,butxo->payment.txid),LP_allocated(butxo->deposit.txid,butxo->deposit.vout),bits256_str(str2,butxo->deposit.txid),LP_quote_validate(autxo,butxo,&Q,1)); LP_listunspent_both(Q.srccoin,Q.coinaddr,0); if ( (butxo= LP_address_utxopair(1,utxos,max,LP_coinfind(Q.srccoin),Q.coinaddr,Q.txfee,dstr(Q.destsatoshis),price,Q.desttxfee)) != 0 ) { @@ -817,7 +816,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, } else { - //printf("cant find utxopair\n"); + printf("cant find utxopair\n"); return(retval); } } From eb3984aecea9d628f5d68743c168cd62779474a6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 12 Nov 2017 14:17:08 +0200 Subject: [PATCH 17/48] Test --- iguana/exchanges/LP_ordermatch.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index a0a6ca5f2..a43b776da 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -261,7 +261,7 @@ int32_t LP_nearest_utxovalue(struct iguana_info *coin,char *coinaddr,struct LP_a uint64_t LP_basesatoshis(double relvolume,double price,uint64_t txfee,uint64_t desttxfee) { - //printf("basesatoshis %.8f (rel %.8f / price %.8f)\n",dstr(SATOSHIDEN * ((relvolume) / price) + 2*txfee),relvolume,price); + printf("basesatoshis %.8f (rel %.8f / price %.8f)\n",dstr(SATOSHIDEN * ((relvolume) / price) + 2*txfee),relvolume,price); if ( relvolume > dstr(desttxfee) && price > SMALLVAL ) return(SATOSHIDEN * (relvolume / price) + 2*txfee); else return(0); @@ -669,7 +669,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, LP_quoteparse(&Q,argjson); LP_requestinit(&Q.R,Q.srchash,Q.desthash,Q.srccoin,Q.satoshis-Q.txfee,Q.destcoin,Q.destsatoshis-Q.desttxfee,Q.timestamp,Q.quotetime,DEXselector); LP_tradecommand_log(argjson); - printf("LP_tradecommand: check received method %s aliceid.%llx %s/%s %.8f -> %.8f\n",method,(long long)Q.aliceid,Q.srccoin,Q.destcoin,dstr(Q.satoshis),dstr(Q.destsatoshis)); + printf("LP_tradecommand: check received method %s aliceid.%llx %s/%s %.8f -> %.8f price %.8f\n",method,(long long)Q.aliceid,Q.srccoin,Q.destcoin,dstr(Q.satoshis),dstr(Q.destsatoshis),(double)Q.destsatoshis/Q.satoshis); retval = 1; autxo = &A; butxo = &B; @@ -771,6 +771,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, else { char tmp[64]; + printf("price %.8f qprice %.8f -> %.8f\n",dstr(price),dstr(qprice),dstr((qprice * 0.5) + (0.5 * price))); price = (qprice * 0.5) + (0.5 * price); if ( bits256_nonz(Q.txid) != 0 ) LP_utxos_remove(Q.txid,Q.vout); From a45ced08e94badf081f7c4c2500c53b0e790ac52 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 12 Nov 2017 14:44:29 +0200 Subject: [PATCH 18/48] Test --- iguana/exchanges/LP_ordermatch.c | 53 +++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 11 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index a43b776da..a46ba3902 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -18,6 +18,31 @@ // LP_ordermatch.c // marketmaker // +struct LP_quoteinfo LP_Alicequery; +double LP_Alicemaxprice; +uint32_t Alice_expiration; +struct { uint64_t aliceid; double bestprice; } Bob_competition[512]; + +double LP_bob_competition(uint64_t aliceid,double price) +{ + int32_t i,firsti = -1; + for (i=0; i dstr(desttxfee) && price > SMALLVAL ) return(SATOSHIDEN * (relvolume / price) + 2*txfee); else return(0); @@ -413,9 +438,6 @@ int32_t LP_connectstartbob(void *ctx,int32_t pubsock,struct LP_utxoinfo *utxo,cJ return(retval); } -struct LP_quoteinfo LP_Alicequery; -double LP_Alicemaxprice; -uint32_t Alice_expiration; char *LP_trade(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo *qp,double maxprice,int32_t timeout,int32_t duration,uint32_t tradeid) { struct LP_utxoinfo *aliceutxo; double price; //cJSON *bestitem=0; int32_t DEXselector=0; uint32_t expiration; double price; struct LP_pubkeyinfo *pubp; struct basilisk_swap *swap; @@ -662,14 +684,14 @@ int32_t LP_validSPV(char *symbol,char *coinaddr,bits256 txid,int32_t vout) int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,uint8_t *data,int32_t datalen) { - char *method,*msg,*retstr,str[65]; int32_t DEXselector = 0; uint64_t value,value2; cJSON *retjson; double qprice,price,bid,ask; struct LP_utxoinfo A,B,*autxo,*butxo; struct iguana_info *coin; struct LP_address_utxo *utxos[1000]; struct LP_quoteinfo Q; int32_t retval = -1,recalc,max=(int32_t)(sizeof(utxos)/sizeof(*utxos)); + char *method,*msg,*retstr,str[65]; int32_t DEXselector = 0; uint64_t aliceid,value,value2; cJSON *retjson; double qprice,bestprice,price,bid,ask; struct LP_utxoinfo A,B,*autxo,*butxo; struct iguana_info *coin; struct LP_address_utxo *utxos[1000]; struct LP_quoteinfo Q; int32_t retval = -1,recalc,max=(int32_t)(sizeof(utxos)/sizeof(*utxos)); if ( (method= jstr(argjson,"method")) != 0 && (strcmp(method,"reserved") == 0 ||strcmp(method,"connected") == 0 || strcmp(method,"request") == 0 || strcmp(method,"connect") == 0) ) { // LP_checksig LP_quoteparse(&Q,argjson); LP_requestinit(&Q.R,Q.srchash,Q.desthash,Q.srccoin,Q.satoshis-Q.txfee,Q.destcoin,Q.destsatoshis-Q.desttxfee,Q.timestamp,Q.quotetime,DEXselector); LP_tradecommand_log(argjson); - printf("LP_tradecommand: check received method %s aliceid.%llx %s/%s %.8f -> %.8f price %.8f\n",method,(long long)Q.aliceid,Q.srccoin,Q.destcoin,dstr(Q.satoshis),dstr(Q.destsatoshis),(double)Q.destsatoshis/Q.satoshis); + printf("LP_tradecommand: check received method %12s aliceid.%16llx %5s/%-5s %12.8f -> %12.8f price %12.8f\n",method,(long long)Q.aliceid,Q.srccoin,Q.destcoin,dstr(Q.satoshis),dstr(Q.destsatoshis),(double)Q.destsatoshis/Q.satoshis); retval = 1; autxo = &A; butxo = &B; @@ -678,6 +700,10 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, LP_abutxo_set(autxo,butxo,&Q); if ( strcmp(method,"reserved") == 0 ) { + aliceid = j64bits(argjson,"aliceid"); + price = jdouble(argjson,"price"); + bestprice = LP_bob_competition(aliceid,price); + printf("aliceid.%llx price %.8f -> bestprice %.8f\n",(long long)aliceid,price,bestprice); if ( LP_Alicemaxprice == 0. ) return(retval); if ( bits256_cmp(G.LP_mypub25519,Q.desthash) == 0 && bits256_cmp(G.LP_mypub25519,Q.srchash) != 0 && LP_alice_eligible() > 0 ) @@ -768,11 +794,16 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, } else if ( (qprice= LP_quote_validate(autxo,butxo,&Q,1)) < SMALLVAL ) recalc = 1; - else + else if ( price < qprice ) { - char tmp[64]; - printf("price %.8f qprice %.8f -> %.8f\n",dstr(price),dstr(qprice),dstr((qprice * 0.5) + (0.5 * price))); - price = (qprice * 0.5) + (0.5 * price); + char tmp[64]; double range; int32_t r; + r = (rand() % 100); + range = (qprice - price); + bestprice = LP_bob_competition(j64bits(argjson,"aliceid"),price); + printf(">>>>>>>>>>>>> price %.8f qprice %.8f r.%d range %.8f -> %.8f vs bestprice %.8f\n",dstr(price),dstr(qprice),r,range,price + r*range,bestprice); + price += (r * range); + if ( price < bestprice+SMALLVAL ) + return(retval); if ( bits256_nonz(Q.txid) != 0 ) LP_utxos_remove(Q.txid,Q.vout); else recalc = 1; @@ -792,7 +823,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, if ( bits256_cmp(Q.txid,butxo->payment.txid) != 0 || Q.vout != butxo->payment.vout || bits256_cmp(Q.txid2,butxo->deposit.txid) != 0 || Q.vout2 != butxo->deposit.vout ) recalc = 1; } - } + } else return(retval); printf("recalc.%d address.(%s/%s) request.(%s)\n",recalc,Q.coinaddr,coin->smartaddr,jprint(argjson,0)); if ( recalc != 0 ) { From 2c9e15808345dc40464b55b562a31301a9e6a4ee Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 12 Nov 2017 14:53:43 +0200 Subject: [PATCH 19/48] Test --- iguana/exchanges/LP_ordermatch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index a46ba3902..bedd8223b 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -1100,7 +1100,7 @@ char *LP_autobuy(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel printf("destsatoshis %.8f vs utxo %.8f this would have triggered an quote error -13\n",dstr(destsatoshis),dstr(autxo->payment.value)); return(clonestr("{\"error\":\"cant find alice utxo that is small enough\"}")); } - bestsatoshis = LP_basesatoshis(relvolume,maxprice,txfee,desttxfee); + bestsatoshis = LP_basesatoshis(dstr(destsatoshis),maxprice,txfee,desttxfee); memset(&B,0,sizeof(B)); strcpy(B.coin,base); if ( LP_quoteinfoinit(&Q,&B,rel,maxprice,bestsatoshis,destsatoshis) < 0 ) From c01ef0fe05f0f00ea9df78e805ed7a05f0d77bd7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 12 Nov 2017 14:59:14 +0200 Subject: [PATCH 20/48] Test --- iguana/exchanges/LP_ordermatch.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index bedd8223b..fb7e8103c 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -30,8 +30,11 @@ double LP_bob_competition(uint64_t aliceid,double price) { if ( Bob_competition[i].aliceid == aliceid ) { - if ( price < Bob_competition[i].bestprice ) + if ( price != 0. && (Bob_competition[i].bestprice == 0. || price < Bob_competition[i].bestprice) ) + { Bob_competition[i].bestprice = price; + printf("Bob competition aliceid.%llx <- bestprice %.8f\n",(long long)aliceid,price); + } return(Bob_competition[i].bestprice); } else if ( Bob_competition[i].aliceid == 0 ) @@ -41,7 +44,8 @@ double LP_bob_competition(uint64_t aliceid,double price) firsti = (rand() % (sizeof(Bob_competition)/sizeof(*Bob_competition))); Bob_competition[firsti].aliceid = aliceid; Bob_competition[firsti].bestprice = price; - return(Bob_competition[i].bestprice); + printf("Bob competition aliceid.%llx %.8f\n",(long long)aliceid,price); + return(price); } uint64_t LP_txfeecalc(struct iguana_info *coin,uint64_t txfee,int32_t txlen) From 1c6eaf859d6a7a3811f2afd1db0443e97ec2adcd Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 12 Nov 2017 15:22:46 +0200 Subject: [PATCH 21/48] Test --- iguana/exchanges/LP_ordermatch.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index fb7e8103c..5f8c7b81f 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -800,14 +800,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, recalc = 1; else if ( price < qprice ) { - char tmp[64]; double range; int32_t r; - r = (rand() % 100); - range = (qprice - price); - bestprice = LP_bob_competition(j64bits(argjson,"aliceid"),price); - printf(">>>>>>>>>>>>> price %.8f qprice %.8f r.%d range %.8f -> %.8f vs bestprice %.8f\n",dstr(price),dstr(qprice),r,range,price + r*range,bestprice); - price += (r * range); - if ( price < bestprice+SMALLVAL ) - return(retval); + char tmp[64]; if ( bits256_nonz(Q.txid) != 0 ) LP_utxos_remove(Q.txid,Q.vout); else recalc = 1; @@ -828,6 +821,14 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, recalc = 1; } } else return(retval); + double range; int32_t r; + r = (rand() % 100); + range = (qprice - price); + bestprice = LP_bob_competition(j64bits(argjson,"aliceid"),price); + printf(">>>>>>>>>>>>> price %.8f qprice %.8f r.%d range %.8f -> %.8f vs bestprice %.8f\n",dstr(price),dstr(qprice),r,range,price + r*range,bestprice); + price += (r * range); + if ( price < bestprice+SMALLVAL ) + return(retval); printf("recalc.%d address.(%s/%s) request.(%s)\n",recalc,Q.coinaddr,coin->smartaddr,jprint(argjson,0)); if ( recalc != 0 ) { From 006cf524691402583f2ffbd510a836274107f073 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 12 Nov 2017 15:26:47 +0200 Subject: [PATCH 22/48] Test --- iguana/exchanges/LP_ordermatch.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 5f8c7b81f..defd94f6b 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -787,6 +787,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, recalc = 0; if ( bits256_cmp(Q.srchash,G.LP_mypub25519) != 0 || strcmp(butxo->coinaddr,coin->smartaddr) != 0 || bits256_nonz(butxo->payment.txid) == 0 || bits256_nonz(butxo->deposit.txid) == 0 ) { + qprice = (double)Q.destsatoshis / Q.satoshis; strcpy(Q.gui,G.gui); strcpy(Q.coinaddr,coin->smartaddr); strcpy(butxo->coinaddr,coin->smartaddr); From be8e18ac41caf85f2ee8ecf443068f7597c89409 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 12 Nov 2017 15:27:52 +0200 Subject: [PATCH 23/48] Test --- iguana/exchanges/LP_ordermatch.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index defd94f6b..59ea546c0 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -760,7 +760,8 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, } return(retval); } - if ( (coin= LP_coinfind(Q.srccoin)) == 0 || (price= LP_myprice(&bid,&ask,Q.srccoin,Q.destcoin)) <= SMALLVAL || ask <= SMALLVAL ) + price = LP_myprice(&bid,&ask,Q.srccoin,Q.destcoin); + if ( (coin= LP_coinfind(Q.srccoin)) == 0 || ask <= SMALLVAL ) { //printf("this node has no price for %s/%s\n",Q.srccoin,Q.destcoin); return(retval); From 913504797fcf93a972cdc327b19e6b40670eb5ae Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 12 Nov 2017 15:38:15 +0200 Subject: [PATCH 24/48] Test --- iguana/exchanges/LP_ordermatch.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 59ea546c0..354c5c762 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -761,7 +761,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, return(retval); } price = LP_myprice(&bid,&ask,Q.srccoin,Q.destcoin); - if ( (coin= LP_coinfind(Q.srccoin)) == 0 || ask <= SMALLVAL ) + if ( (coin= LP_coinfind(Q.srccoin)) == 0 || price <= SMALLVAL || ask <= SMALLVAL ) { //printf("this node has no price for %s/%s\n",Q.srccoin,Q.destcoin); return(retval); @@ -816,10 +816,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, //printf("call LP_utxoadd.(%s) %.8f %.8f\n",Q.coinaddr,dstr(value),dstr(value2)); if ( (butxo= LP_utxoadd(1,coin->symbol,Q.txid,Q.vout,value,Q.txid2,Q.vout2,value2,Q.coinaddr,Q.srchash,G.gui,0,Q.satoshis)) == 0 ) recalc = 1; - } - else - { - if ( bits256_cmp(Q.txid,butxo->payment.txid) != 0 || Q.vout != butxo->payment.vout || bits256_cmp(Q.txid2,butxo->deposit.txid) != 0 || Q.vout2 != butxo->deposit.vout ) + else if ( bits256_cmp(Q.txid,butxo->payment.txid) != 0 || Q.vout != butxo->payment.vout || bits256_cmp(Q.txid2,butxo->deposit.txid) != 0 || Q.vout2 != butxo->deposit.vout ) recalc = 1; } } else return(retval); @@ -831,7 +828,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, price += (r * range); if ( price < bestprice+SMALLVAL ) return(retval); - printf("recalc.%d address.(%s/%s) request.(%s)\n",recalc,Q.coinaddr,coin->smartaddr,jprint(argjson,0)); + printf("recalc.%d address.(%s/%s) price %.8f request.(%s)\n",recalc,Q.coinaddr,coin->smartaddr,price,jprint(argjson,0)); if ( recalc != 0 ) { LP_RTmetrics_update(Q.srccoin,Q.destcoin); From b95f610e890a67a4d3e23aae1995cb5a262b48e5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 12 Nov 2017 15:47:42 +0200 Subject: [PATCH 25/48] Test --- iguana/exchanges/LP_ordermatch.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 354c5c762..3630e89aa 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -702,12 +702,12 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, memset(autxo,0,sizeof(*autxo)); memset(butxo,0,sizeof(*butxo)); LP_abutxo_set(autxo,butxo,&Q); + aliceid = j64bits(argjson,"aliceid"); + qprice = jdouble(argjson,"price"); if ( strcmp(method,"reserved") == 0 ) { - aliceid = j64bits(argjson,"aliceid"); - price = jdouble(argjson,"price"); - bestprice = LP_bob_competition(aliceid,price); - printf("aliceid.%llx price %.8f -> bestprice %.8f\n",(long long)aliceid,price,bestprice); + bestprice = LP_bob_competition(aliceid,qprice); + printf("aliceid.%llx price %.8f -> bestprice %.8f\n",(long long)aliceid,qprice,bestprice); if ( LP_Alicemaxprice == 0. ) return(retval); if ( bits256_cmp(G.LP_mypub25519,Q.desthash) == 0 && bits256_cmp(G.LP_mypub25519,Q.srchash) != 0 && LP_alice_eligible() > 0 ) @@ -823,9 +823,9 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, double range; int32_t r; r = (rand() % 100); range = (qprice - price); - bestprice = LP_bob_competition(j64bits(argjson,"aliceid"),price); - printf(">>>>>>>>>>>>> price %.8f qprice %.8f r.%d range %.8f -> %.8f vs bestprice %.8f\n",dstr(price),dstr(qprice),r,range,price + r*range,bestprice); + printf(">>>>>>>>>>>>> price %.8f qprice %.8f r.%d range %.8f -> %.8f vs bestprice %.8f\n",dstr(price),dstr(qprice),r,range,price + r*range,LP_bob_competition(aliceid,price)); price += (r * range); + bestprice = LP_bob_competition(aliceid,price); if ( price < bestprice+SMALLVAL ) return(retval); printf("recalc.%d address.(%s/%s) price %.8f request.(%s)\n",recalc,Q.coinaddr,coin->smartaddr,price,jprint(argjson,0)); From 6ff2d4fdfd513d571fc7b9094e4ba1995924c905 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 12 Nov 2017 15:58:20 +0200 Subject: [PATCH 26/48] Test --- iguana/exchanges/LP_ordermatch.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 3630e89aa..53342ae2d 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -688,7 +688,7 @@ int32_t LP_validSPV(char *symbol,char *coinaddr,bits256 txid,int32_t vout) int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,uint8_t *data,int32_t datalen) { - char *method,*msg,*retstr,str[65]; int32_t DEXselector = 0; uint64_t aliceid,value,value2; cJSON *retjson; double qprice,bestprice,price,bid,ask; struct LP_utxoinfo A,B,*autxo,*butxo; struct iguana_info *coin; struct LP_address_utxo *utxos[1000]; struct LP_quoteinfo Q; int32_t retval = -1,recalc,max=(int32_t)(sizeof(utxos)/sizeof(*utxos)); + char *method,*msg,*retstr,str[65]; int32_t DEXselector = 0; uint64_t aliceid,value,value2; cJSON *retjson; double qprice,range,bestprice,price,bid,ask; struct LP_utxoinfo A,B,*autxo,*butxo; struct iguana_info *coin; struct LP_address_utxo *utxos[1000]; struct LP_quoteinfo Q; int32_t r,retval = -1,recalc,max=(int32_t)(sizeof(utxos)/sizeof(*utxos)); if ( (method= jstr(argjson,"method")) != 0 && (strcmp(method,"reserved") == 0 ||strcmp(method,"connected") == 0 || strcmp(method,"request") == 0 || strcmp(method,"connect") == 0) ) { // LP_checksig @@ -766,6 +766,8 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, //printf("this node has no price for %s/%s\n",Q.srccoin,Q.destcoin); return(retval); } + price = ask; + printf("MYPRICE %s/%s %.8f\n",Q.srccoin,Q.destcoin,price); if ( LP_validSPV(Q.destcoin,Q.destaddr,Q.desttxid,Q.destvout) < 0 ) { printf("%s dest %s failed SPV check\n",Q.destcoin,bits256_str(str,Q.desttxid)); @@ -776,7 +778,6 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, printf("%s dexfee %s failed SPV check\n",Q.destcoin,bits256_str(str,Q.feetxid)); return(retval); } - price = ask; if ( LP_aliceonly(Q.srccoin) > 0 ) { printf("{\"error\":\"GAME can only be alice coin\"}\n"); @@ -809,6 +810,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, if ( bits256_nonz(Q.txid2) != 0 ) LP_utxos_remove(Q.txid2,Q.vout2); else recalc = 1; + printf("price %.8f qprice %.8f\n",price,qprice); if ( recalc == 0 ) { value = LP_txvalue(tmp,Q.srccoin,Q.txid,Q.vout); @@ -820,10 +822,9 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, recalc = 1; } } else return(retval); - double range; int32_t r; r = (rand() % 100); range = (qprice - price); - printf(">>>>>>>>>>>>> price %.8f qprice %.8f r.%d range %.8f -> %.8f vs bestprice %.8f\n",dstr(price),dstr(qprice),r,range,price + r*range,LP_bob_competition(aliceid,price)); + printf(">>>>>>>>>>>>> price %.8f qprice %.8f r.%d range %.8f -> %.8f vs bestprice %.8f\n",price,qprice,r,range,price + r*range,LP_bob_competition(aliceid,price)); price += (r * range); bestprice = LP_bob_competition(aliceid,price); if ( price < bestprice+SMALLVAL ) @@ -847,7 +848,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, Q.vout = butxo->payment.vout; Q.txid2 = butxo->deposit.txid; Q.vout2 = butxo->deposit.vout; - butxo->S.satoshis = Q.satoshis; + Q.satoshis = butxo->S.satoshis; printf("set butxo.%p %s/v%d %s/v%d %.8f %.8f -> bsat %.8f asat %.8f\n",butxo,bits256_str(str,butxo->payment.txid),butxo->payment.vout,bits256_str(str2,butxo->deposit.txid),butxo->deposit.vout,dstr(butxo->payment.value),dstr(butxo->deposit.value),dstr(butxo->S.satoshis),dstr(autxo->S.satoshis)); } else From 0eba6792441aeb61943594d241ade40866a9efed Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 12 Nov 2017 16:01:08 +0200 Subject: [PATCH 27/48] Test --- iguana/exchanges/LP_ordermatch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 53342ae2d..6f21fc40d 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -825,7 +825,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, r = (rand() % 100); range = (qprice - price); printf(">>>>>>>>>>>>> price %.8f qprice %.8f r.%d range %.8f -> %.8f vs bestprice %.8f\n",price,qprice,r,range,price + r*range,LP_bob_competition(aliceid,price)); - price += (r * range); + price += (r * range) / 100.; bestprice = LP_bob_competition(aliceid,price); if ( price < bestprice+SMALLVAL ) return(retval); From 6e799be950afe0be666b7b16ecac86de5329b7ff Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 12 Nov 2017 16:05:27 +0200 Subject: [PATCH 28/48] Test --- iguana/exchanges/LP_ordermatch.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 6f21fc40d..f6a947e69 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -707,7 +707,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, if ( strcmp(method,"reserved") == 0 ) { bestprice = LP_bob_competition(aliceid,qprice); - printf("aliceid.%llx price %.8f -> bestprice %.8f\n",(long long)aliceid,qprice,bestprice); + //printf("aliceid.%llx price %.8f -> bestprice %.8f\n",(long long)aliceid,qprice,bestprice); if ( LP_Alicemaxprice == 0. ) return(retval); if ( bits256_cmp(G.LP_mypub25519,Q.desthash) == 0 && bits256_cmp(G.LP_mypub25519,Q.srchash) != 0 && LP_alice_eligible() > 0 ) @@ -767,7 +767,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, return(retval); } price = ask; - printf("MYPRICE %s/%s %.8f\n",Q.srccoin,Q.destcoin,price); + //printf("MYPRICE %s/%s %.8f\n",Q.srccoin,Q.destcoin,price); if ( LP_validSPV(Q.destcoin,Q.destaddr,Q.desttxid,Q.destvout) < 0 ) { printf("%s dest %s failed SPV check\n",Q.destcoin,bits256_str(str,Q.desttxid)); @@ -785,7 +785,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, } if ( strcmp(method,"request") == 0 ) { - char str[65],str2[65]; + char str[65];//,str2[65]; recalc = 0; if ( bits256_cmp(Q.srchash,G.LP_mypub25519) != 0 || strcmp(butxo->coinaddr,coin->smartaddr) != 0 || bits256_nonz(butxo->payment.txid) == 0 || bits256_nonz(butxo->deposit.txid) == 0 ) { @@ -829,7 +829,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, bestprice = LP_bob_competition(aliceid,price); if ( price < bestprice+SMALLVAL ) return(retval); - printf("recalc.%d address.(%s/%s) price %.8f request.(%s)\n",recalc,Q.coinaddr,coin->smartaddr,price,jprint(argjson,0)); + //printf("recalc.%d address.(%s/%s) price %.8f request.(%s)\n",recalc,Q.coinaddr,coin->smartaddr,price,jprint(argjson,0)); if ( recalc != 0 ) { LP_RTmetrics_update(Q.srccoin,Q.destcoin); @@ -849,7 +849,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, Q.txid2 = butxo->deposit.txid; Q.vout2 = butxo->deposit.vout; Q.satoshis = butxo->S.satoshis; - printf("set butxo.%p %s/v%d %s/v%d %.8f %.8f -> bsat %.8f asat %.8f\n",butxo,bits256_str(str,butxo->payment.txid),butxo->payment.vout,bits256_str(str2,butxo->deposit.txid),butxo->deposit.vout,dstr(butxo->payment.value),dstr(butxo->deposit.value),dstr(butxo->S.satoshis),dstr(autxo->S.satoshis)); + //printf("set butxo.%p %s/v%d %s/v%d %.8f %.8f -> bsat %.8f asat %.8f\n",butxo,bits256_str(str,butxo->payment.txid),butxo->payment.vout,bits256_str(str2,butxo->deposit.txid),butxo->deposit.vout,dstr(butxo->payment.value),dstr(butxo->deposit.value),dstr(butxo->S.satoshis),dstr(autxo->S.satoshis)); } else { From 525411bc891f77e6312b8948b6eb0f18453fde94 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 12 Nov 2017 16:20:54 +0200 Subject: [PATCH 29/48] Test --- iguana/exchanges/LP_commands.c | 1 + iguana/exchanges/LP_utxos.c | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 1b25666c9..9d0f4ff47 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -395,6 +395,7 @@ bot_resume(botid)\n\ LP_address(ptr,coinaddr); if ( strcmp(coinaddr,ptr->smartaddr) == 0 && bits256_nonz(G.LP_privkey) != 0 ) { + LP_listunspent_issue(coin,coinaddr,2); LP_privkey_init(-1,ptr,G.LP_privkey,G.LP_mypub25519); //LP_smartutxos_push(ptr); if ( ptr->electrum != 0 ) diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index c453368f2..e82541a63 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -550,7 +550,6 @@ int32_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypri return(0); coin->privkeydepth++; //printf("privkey init.(%s) %s depth.%d\n",coin->symbol,coin->smartaddr,coin->privkeydepth); - LP_listunspent_issue(coin->symbol,coin->smartaddr,2); if ( coin->inactive == 0 ) LP_listunspent_issue(coin->symbol,coin->smartaddr,0); array = LP_listunspent(coin->symbol,coin->smartaddr); From 633473fc9c38b3259dd1439027e4874f779d196c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 12 Nov 2017 16:30:54 +0200 Subject: [PATCH 30/48] Test --- iguana/exchanges/LP_utxos.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index e82541a63..36612ddaa 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -549,12 +549,12 @@ int32_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypri if ( coin->privkeydepth > 0 ) return(0); coin->privkeydepth++; + LP_address(coin,coin->smartaddr); //printf("privkey init.(%s) %s depth.%d\n",coin->symbol,coin->smartaddr,coin->privkeydepth); if ( coin->inactive == 0 ) LP_listunspent_issue(coin->symbol,coin->smartaddr,0); array = LP_listunspent(coin->symbol,coin->smartaddr); - //printf("unspent array %ld\n",strlen(jprint(array,0))); - LP_address(coin,coin->smartaddr); + printf("unspent array %ld\n",strlen(jprint(array,0))); if ( array != 0 ) { txfee = LP_txfeecalc(coin,0,0); From 5e2655b301b6932595addc3221d54c499862ac71 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 12 Nov 2017 16:47:29 +0200 Subject: [PATCH 31/48] Test --- iguana/exchanges/LP_ordermatch.c | 25 ++++++++++++++----------- iguana/exchanges/LP_socket.c | 2 +- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index f6a947e69..af7f7c5e2 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -33,7 +33,7 @@ double LP_bob_competition(uint64_t aliceid,double price) if ( price != 0. && (Bob_competition[i].bestprice == 0. || price < Bob_competition[i].bestprice) ) { Bob_competition[i].bestprice = price; - printf("Bob competition aliceid.%llx <- bestprice %.8f\n",(long long)aliceid,price); + //printf("Bob competition aliceid.%llx <- bestprice %.8f\n",(long long)aliceid,price); } return(Bob_competition[i].bestprice); } @@ -44,7 +44,7 @@ double LP_bob_competition(uint64_t aliceid,double price) firsti = (rand() % (sizeof(Bob_competition)/sizeof(*Bob_competition))); Bob_competition[firsti].aliceid = aliceid; Bob_competition[firsti].bestprice = price; - printf("Bob competition aliceid.%llx %.8f\n",(long long)aliceid,price); + //printf("Bob competition aliceid.%llx %.8f\n",(long long)aliceid,price); return(price); } @@ -695,7 +695,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, LP_quoteparse(&Q,argjson); LP_requestinit(&Q.R,Q.srchash,Q.desthash,Q.srccoin,Q.satoshis-Q.txfee,Q.destcoin,Q.destsatoshis-Q.desttxfee,Q.timestamp,Q.quotetime,DEXselector); LP_tradecommand_log(argjson); - printf("LP_tradecommand: check received method %12s aliceid.%16llx %5s/%-5s %12.8f -> %12.8f price %12.8f\n",method,(long long)Q.aliceid,Q.srccoin,Q.destcoin,dstr(Q.satoshis),dstr(Q.destsatoshis),(double)Q.destsatoshis/Q.satoshis); + //printf("LP_tradecommand: check received method %12s aliceid.%16llx %5s/%-5s %12.8f -> %12.8f price %12.8f\n",method,(long long)Q.aliceid,Q.srccoin,Q.destcoin,dstr(Q.satoshis),dstr(Q.destsatoshis),(double)Q.destsatoshis/Q.satoshis); retval = 1; autxo = &A; butxo = &B; @@ -822,13 +822,16 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, recalc = 1; } } else return(retval); - r = (rand() % 100); - range = (qprice - price); - printf(">>>>>>>>>>>>> price %.8f qprice %.8f r.%d range %.8f -> %.8f vs bestprice %.8f\n",price,qprice,r,range,price + r*range,LP_bob_competition(aliceid,price)); - price += (r * range) / 100.; - bestprice = LP_bob_competition(aliceid,price); - if ( price < bestprice+SMALLVAL ) - return(retval); + if ( qprice > price ) + { + r = (rand() % 100); + range = (qprice - price); + printf(">>>>>>>>>>>>> price %.8f qprice %.8f r.%d range %.8f -> %.8f vs bestprice %.8f\n",price,qprice,r,range,price + r*range,LP_bob_competition(aliceid,price)); + price += (r * range) / 100.; + bestprice = LP_bob_competition(aliceid,price); + if ( price < bestprice+SMALLVAL ) + return(retval); + } else return(retval); //printf("recalc.%d address.(%s/%s) price %.8f request.(%s)\n",recalc,Q.coinaddr,coin->smartaddr,price,jprint(argjson,0)); if ( recalc != 0 ) { @@ -853,7 +856,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, } else { - printf("cant find utxopair\n"); + //printf("cant find utxopair\n"); return(retval); } } diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 5be93ba33..e679ef67f 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -329,7 +329,7 @@ int32_t electrum_process_array(struct iguana_info *coin,struct electrum_info *ep tx->height = ht; if ( ep != 0 && coin != 0 && tx->SPV == 0 ) { - if ( strcmp(coinaddr,coin->smartaddr) == 0 ) + if ( 0 && strcmp(coinaddr,coin->smartaddr) == 0 ) tx->SPV = LP_merkleproof(coin,coin->smartaddr,ep,txid,tx->height); //printf("%s %s >>>>>>>>>> set %s <- height %d\n",coin->symbol,coinaddr,bits256_str(str,txid),tx->height); } From b420153811bd6bc1c1d71d5fd6fc1d99bd6109c1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 12 Nov 2017 16:52:02 +0200 Subject: [PATCH 32/48] Test --- iguana/exchanges/LP_nativeDEX.c | 1 - iguana/exchanges/LP_utxos.c | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 7fc952235..6383119ff 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -521,7 +521,6 @@ void LP_coinsloop(void *_coins) free_json(retjson); DL_FOREACH_SAFE(ap->utxos,up,tmp) { - break; if ( up->U.height > 0 && up->spendheight < 0 ) { if ( up->SPV == 0 ) diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 36612ddaa..2d5a04915 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -554,7 +554,7 @@ int32_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypri if ( coin->inactive == 0 ) LP_listunspent_issue(coin->symbol,coin->smartaddr,0); array = LP_listunspent(coin->symbol,coin->smartaddr); - printf("unspent array %ld\n",strlen(jprint(array,0))); + //printf("unspent array %ld\n",strlen(jprint(array,0))); if ( array != 0 ) { txfee = LP_txfeecalc(coin,0,0); From 1d11d9a78f458a20a6e331338c0a0270873cf468 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 12 Nov 2017 16:59:46 +0200 Subject: [PATCH 33/48] Test --- iguana/exchanges/LP_tradebots.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/iguana/exchanges/LP_tradebots.c b/iguana/exchanges/LP_tradebots.c index 9f7a94b4e..a2e82ac10 100644 --- a/iguana/exchanges/LP_tradebots.c +++ b/iguana/exchanges/LP_tradebots.c @@ -476,13 +476,14 @@ char *LP_tradebot_buy(int32_t dispdir,char *base,char *rel,double maxprice,doubl free(retstr); txfee = LP_txfeecalc(relcoin,0,0); txfees = 10 * txfee; - printf("%s inventory balance %.8f, relvolume %.8f + txfees %.8f\n",rel,dstr(abalance),relvolume,dstr(txfees)); - if ( dstr(abalance) < relvolume + dstr(txfees) ) + if ( relcoin->electrum != 0 ) + balance = LP_unspents_load(relcoin->symbol,relcoin->smartaddr); + else balance = LP_RTsmartbalance(relcoin); + sum = (relvolume+2*dstr(txfees)) + 3 * ((relvolume+2*dstr(txfees))/777); + printf("%s inventory balance %.8f, relvolume %.8f + txfees %.8f, utxobal %.8f sum %.8f\n",rel,dstr(abalance),relvolume,dstr(txfees),dstr(balance),dstr(sum)); + if ( dstr(abalance) < relvolume + dstr(txfees) && balance > sum+txfee ) { retjson = cJSON_CreateObject(); - if ( relcoin->electrum != 0 ) - balance = LP_unspents_load(relcoin->symbol,relcoin->smartaddr); - else balance = LP_RTsmartbalance(relcoin); jaddstr(retjson,"error","not enough funds"); jaddstr(retjson,"coin",rel); jaddnum(retjson,"abalance",dstr(abalance)); @@ -491,7 +492,6 @@ char *LP_tradebot_buy(int32_t dispdir,char *base,char *rel,double maxprice,doubl jaddnum(retjson,"txfees",dstr(txfees)); shortfall = (relvolume + dstr(txfees)) - dstr(balance); jaddnum(retjson,"shortfall",shortfall); - sum = (relvolume+2*dstr(txfees)) + 3 * ((relvolume+2*dstr(txfees))/777); if ( balance >= sum+txfee ) { char *withdrawstr; cJSON *outputjson,*withdrawjson,*outputs,*item; From 7909aed3f146fcd8c3598cf3d6e08062e89a038e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 12 Nov 2017 17:57:24 +0200 Subject: [PATCH 34/48] Fix native missed numconfirms --- iguana/exchanges/LP_nativeDEX.c | 4 ++-- iguana/exchanges/LP_ordermatch.c | 2 +- iguana/exchanges/LP_utxo.c | 5 +++++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 6383119ff..0bb66c9bf 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -18,9 +18,9 @@ // LP_nativeDEX.c // marketmaker // -// immediate "request", actual auction +// alice waiting for bestprice // previously, it used to show amount, kmd equiv, perc -//there is still a pending one with `-1 wait for bobpayment bYoNxkfvwQ42Yufry8J5y8BYi6mQxokvW9 numconfs.1 MNZ c0ea4aa808a653222a15122d96692fecf734dbbacfb9a54cb4711306ea0c3cef`, but that tx is already spent including 6 confirmation +// there is still a pending one with `-1 wait for bobpayment bYoNxkfvwQ42Yufry8J5y8BYi6mQxokvW9 numconfs.1 MNZ c0ea4aa808a653222a15122d96692fecf734dbbacfb9a54cb4711306ea0c3cef`, but that tx is already spent including 6 confirmation // bot safe to exit? // // BCH signing diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index af7f7c5e2..8222443ed 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -826,7 +826,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, { r = (rand() % 100); range = (qprice - price); - printf(">>>>>>>>>>>>> price %.8f qprice %.8f r.%d range %.8f -> %.8f vs bestprice %.8f\n",price,qprice,r,range,price + r*range,LP_bob_competition(aliceid,price)); + printf(">>>>>>>>>>>>> price %.8f qprice %.8f r.%d range %.8f -> %.8f vs bestprice %.8f\n",price,qprice,r,range,price + (r*range)/100.,LP_bob_competition(aliceid,price)); price += (r * range) / 100.; bestprice = LP_bob_competition(aliceid,price); if ( price < bestprice+SMALLVAL ) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 16ecba91d..54cb5a27d 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -661,6 +661,11 @@ int32_t LP_numconfirms(char *symbol,char *coinaddr,bits256 txid,int32_t vout,int } else if ( mempool != 0 && LP_mempoolscan(symbol,txid) >= 0 ) numconfirms = 0; + else if ( (txobj= LP_gettx(symbol,txid)) != 0 ) + { + numconfirms = jint(txobj,"confirmations"); + free_json(txobj); + } } else { From 4f171163db4444e249e9ca179afef3b4df31b181 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 12 Nov 2017 18:12:43 +0200 Subject: [PATCH 35/48] Test --- iguana/exchanges/LP_nativeDEX.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 0bb66c9bf..4cad2061d 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -466,7 +466,7 @@ void utxosQ_loop(void *myipaddr) void LP_coinsloop(void *_coins) { - struct LP_address *ap=0; struct LP_transaction *tx; cJSON *retjson; struct LP_address_utxo *up,*tmp; struct iguana_info *coin,*ctmp; char str[65]; struct electrum_info *ep,*backupep=0; bits256 zero; int32_t oldht,j,nonz; char *coins = _coins; + struct LP_address *ap=0,*atmp; struct LP_transaction *tx; cJSON *retjson; struct LP_address_utxo *up,*tmp; struct iguana_info *coin,*ctmp; char str[65]; struct electrum_info *ep,*backupep=0; bits256 zero; int32_t oldht,j,nonz; char *coins = _coins; if ( strcmp("BTC",coins) == 0 ) { strcpy(LP_coinsloopBTC_stats.name,"BTC coin loop"); @@ -514,11 +514,18 @@ void LP_coinsloop(void *_coins) { if ( (backupep= ep->prev) == 0 ) backupep = ep; - //HASH_ITER(hh,coin->addresses,ap,atmp) if ( (ap= LP_addressfind(coin,coin->smartaddr)) != 0 ) { if ( (retjson= electrum_address_listunspent(coin->symbol,ep,&retjson,ap->coinaddr,1)) != 0 ) free_json(retjson); + } + HASH_ITER(hh,coin->addresses,ap,atmp) + { + if ( (retjson= electrum_address_listunspent(coin->symbol,ep,&retjson,ap->coinaddr,1)) != 0 ) + free_json(retjson); + } + HASH_ITER(hh,coin->addresses,ap,atmp) + { DL_FOREACH_SAFE(ap->utxos,up,tmp) { if ( up->U.height > 0 && up->spendheight < 0 ) From 65e276c004560e88fe126928bfcb981fa27fb125 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 12 Nov 2017 18:31:57 +0200 Subject: [PATCH 36/48] Test --- iguana/exchanges/LP_nativeDEX.c | 1 + iguana/exchanges/LP_socket.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 4cad2061d..158d51b48 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -521,6 +521,7 @@ void LP_coinsloop(void *_coins) } HASH_ITER(hh,coin->addresses,ap,atmp) { + printf("call unspent %s\n",ap->coinaddr); if ( (retjson= electrum_address_listunspent(coin->symbol,ep,&retjson,ap->coinaddr,1)) != 0 ) free_json(retjson); } diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index e679ef67f..b60f91c34 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -596,7 +596,7 @@ cJSON *electrum_address_listunspent(char *symbol,struct electrum_info *ep,cJSON { if ( jobj(retjson,"error") == 0 && is_cJSON_Array(retjson) != 0 ) { - if ( 0 && electrumflag > 1 ) + //if ( 0 && electrumflag > 1 ) printf("%s.%d u.%u/%d t.%ld %s LISTUNSPENT.(%d)\n",coin->symbol,height,ap->unspenttime,ap->unspentheight,time(NULL),addr,(int32_t)strlen(jprint(retjson,0))); updatedflag = 0; if ( electrum_process_array(coin,ep,addr,retjson,electrumflag) != 0 ) From 19aec0f9ce34f23d21297504a478b61e5ca95a1b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 12 Nov 2017 18:40:03 +0200 Subject: [PATCH 37/48] Test --- iguana/exchanges/LP_utxo.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 54cb5a27d..29446521f 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -64,7 +64,10 @@ struct LP_address *_LP_address(struct iguana_info *coin,char *coinaddr) { struct LP_address *ap = 0; if ( (ap= _LP_addressfind(coin,coinaddr)) == 0 ) + { ap = _LP_addressadd(coin,coinaddr); + printf("LP_address %s %s\n",coin->symbol,coinaddr); + } return(ap); } From 026c707045cde6035db7ed4f15cc0b09ebf71d62 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 12 Nov 2017 18:45:41 +0200 Subject: [PATCH 38/48] Test --- iguana/exchanges/LP_nativeDEX.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 158d51b48..972c04374 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -514,6 +514,7 @@ void LP_coinsloop(void *_coins) { if ( (backupep= ep->prev) == 0 ) backupep = ep; + printf("electrum %s\n",coin->symbol); if ( (ap= LP_addressfind(coin,coin->smartaddr)) != 0 ) { if ( (retjson= electrum_address_listunspent(coin->symbol,ep,&retjson,ap->coinaddr,1)) != 0 ) From d085e808602041c28c79afb0718fa275e77568ad Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 12 Nov 2017 18:47:31 +0200 Subject: [PATCH 39/48] Test --- iguana/exchanges/LP_utxo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 29446521f..33554c05e 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -66,7 +66,7 @@ struct LP_address *_LP_address(struct iguana_info *coin,char *coinaddr) if ( (ap= _LP_addressfind(coin,coinaddr)) == 0 ) { ap = _LP_addressadd(coin,coinaddr); - printf("LP_address %s %s\n",coin->symbol,coinaddr); + //printf("LP_address %s %s\n",coin->symbol,coinaddr); } return(ap); } From 4da0f241b00a141fb48ae0e43f49539eea01080f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 12 Nov 2017 20:35:54 +0200 Subject: [PATCH 40/48] Test --- iguana/exchanges/LP_nativeDEX.c | 5 +++-- iguana/exchanges/LP_socket.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 972c04374..27ab16469 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -514,7 +514,8 @@ void LP_coinsloop(void *_coins) { if ( (backupep= ep->prev) == 0 ) backupep = ep; - printf("electrum %s\n",coin->symbol); + // skip cLP_address MNZ bXcSsYBiVKtTzYErqxvma4UsojZTEf5L6H + //printf("electrum %s\n",coin->symbol); if ( (ap= LP_addressfind(coin,coin->smartaddr)) != 0 ) { if ( (retjson= electrum_address_listunspent(coin->symbol,ep,&retjson,ap->coinaddr,1)) != 0 ) @@ -522,7 +523,7 @@ void LP_coinsloop(void *_coins) } HASH_ITER(hh,coin->addresses,ap,atmp) { - printf("call unspent %s\n",ap->coinaddr); + //printf("call unspent %s\n",ap->coinaddr); if ( (retjson= electrum_address_listunspent(coin->symbol,ep,&retjson,ap->coinaddr,1)) != 0 ) free_json(retjson); } diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index b60f91c34..e679ef67f 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -596,7 +596,7 @@ cJSON *electrum_address_listunspent(char *symbol,struct electrum_info *ep,cJSON { if ( jobj(retjson,"error") == 0 && is_cJSON_Array(retjson) != 0 ) { - //if ( 0 && electrumflag > 1 ) + if ( 0 && electrumflag > 1 ) printf("%s.%d u.%u/%d t.%ld %s LISTUNSPENT.(%d)\n",coin->symbol,height,ap->unspenttime,ap->unspentheight,time(NULL),addr,(int32_t)strlen(jprint(retjson,0))); updatedflag = 0; if ( electrum_process_array(coin,ep,addr,retjson,electrumflag) != 0 ) From fda20a4b9edafed1e0e5d091851437020e59c12a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 12 Nov 2017 20:37:38 +0200 Subject: [PATCH 41/48] Test --- iguana/exchanges/sell | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/sell b/iguana/exchanges/sell index fccc4d61e..a48ffaac1 100755 --- a/iguana/exchanges/sell +++ b/iguana/exchanges/sell @@ -1,3 +1,3 @@ #!/bin/bash source userpass -curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"sell\",\"base\":\"KMD\",\"rel\":\"BTC\",\"basevolume\":10.0\",price\":0.0005}" +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"sell\",\"base\":\"KMD\",\"rel\":\"BTC\",\"basevolume\":10.0\",\"price\":0.0005}" From 645351ae44e6c4b5ba80542c6bcf0611e70805d0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 12 Nov 2017 22:03:01 +0200 Subject: [PATCH 42/48] Test --- iguana/exchanges/LP_ordermatch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 8222443ed..1aa138e33 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -883,7 +883,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, printf("quote validate error %.0f\n",qprice); return(-3); } - if ( qprice < (price - 0.00000001) * 0.998 ) + if ( qprice < (ask - 0.00000001) * 0.998 ) { printf("(%.8f %.8f) quote price %.8f too low vs %.8f for %s/%s\n",bid,ask,qprice,price,Q.srccoin,Q.destcoin); return(retval); From 59e688208289c6299b43272cadebc698687f7850 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 12 Nov 2017 22:22:19 +0200 Subject: [PATCH 43/48] Test --- iguana/exchanges/LP_ordermatch.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 1aa138e33..7bb60dd40 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -144,7 +144,7 @@ double LP_quote_validate(struct LP_utxoinfo *autxo,struct LP_utxoinfo *butxo,str { if ( LP_iseligible(&destvalue,&destvalue2,0,qp->destcoin,qp->desttxid,qp->destvout,qp->destsatoshis,qp->feetxid,qp->feevout) == 0 ) { - char str[65]; printf("alice not eligible destsatoshis %.8f (%.8f %.8f) %s/v%d\n",dstr(qp->destsatoshis),dstr(destvalue),dstr(destvalue2),bits256_str(str,qp->feetxid),qp->feevout); + char str[65],str2[65]; printf("alice not eligible %.8f -> dest %.8f %.8f (%.8f %.8f) %s/v%d %s/v%d\n",dstr(qp->satoshis),dstr(qp->destsatoshis),(double)qp->destsatoshis/qp->satoshis,dstr(destvalue),dstr(destvalue2),bits256_str(str,qp->desttxid),qp->destvout,bits256_str(str2,qp->feetxid),qp->feevout); return(-3); } if ( (txout= LP_gettxout(qp->destcoin,qp->destaddr,qp->desttxid,qp->destvout)) != 0 ) @@ -885,7 +885,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, } if ( qprice < (ask - 0.00000001) * 0.998 ) { - printf("(%.8f %.8f) quote price %.8f too low vs %.8f for %s/%s\n",bid,ask,qprice,price,Q.srccoin,Q.destcoin); + printf("(%.8f %.8f) quote price %.8f too low vs %.8f for %s/%s %.8f < %.8f\n",bid,ask,qprice,price,Q.srccoin,Q.destcoin,qprice,(ask - 0.00000001) * 0.998); return(retval); } char str[65],str2[65]; printf("butxo.%p (%s %s) TRADECOMMAND.(%s)\n",butxo,butxo!=0?bits256_str(str,butxo->payment.txid):"",butxo!=0?bits256_str(str2,butxo->deposit.txid):"",jprint(argjson,0)); @@ -906,7 +906,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, jaddstr(retjson,"method","reserved"); msg = jprint(retjson,0); butxo->T.lasttime = (uint32_t)time(NULL); - printf("return after queued RESERVED: set swappending.%u accept qprice %.8f, min %.8f\n(%s)\n",butxo->T.swappending,qprice,price,msg); + printf("return after queued RESERVED: set swappending.%u accept qprice %.8f, min %.8f\n(%s)\n",butxo->T.swappending,qprice,ask,msg); // LP_addsig //msg2 = clonestr(msg); LP_reserved_msg(1,Q.srccoin,Q.destcoin,butxo->S.otherpubkey,clonestr(msg)); From d8fad6895fb658b9854e3df122ee4ade6102e70b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 12 Nov 2017 22:23:35 +0200 Subject: [PATCH 44/48] Test --- iguana/exchanges/LP_transaction.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index d9939432d..bc582236c 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -652,7 +652,7 @@ char *basilisk_swap_bobtxspend(bits256 *signedtxidp,uint64_t txfee,char *name,ch satoshis = value - 3*txfee/4; printf("reduce satoshis %.8f by txfee %.8f to value %.8f\n",dstr(satoshis),dstr(txfee),dstr(value)); } - else if ( value == satoshis && (double)txfee/value < 0.1 ) + else if ( value == satoshis && (double)txfee/value < 0.25 ) { satoshis = value - txfee; printf("txfee allocation from value %.8f identical to satoshis: %.8f txfee %.8f\n",dstr(value),dstr(satoshis),dstr(txfee)); From 4dfa34bf9069399e703ec154a47b2476fb5039d0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 12 Nov 2017 22:53:01 +0200 Subject: [PATCH 45/48] Test --- iguana/exchanges/LP_nativeDEX.c | 3 ++- iguana/exchanges/LP_utxo.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 27ab16469..c24f24cd4 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -856,7 +856,8 @@ int32_t LP_reserved_msg(int32_t priority,char *base,char *rel,bits256 pubkey,cha if ( num_Reserved_msgs[priority] > max_Reserved_msgs[priority] ) { max_Reserved_msgs[priority] = num_Reserved_msgs[priority]; - printf("New priority.%d max_Reserved_msgs.%d\n",priority,max_Reserved_msgs[priority]); + if ( (max_Reserved_msgs[priority] % 100) == 0 )) + printf("New priority.%d max_Reserved_msgs.%d\n",priority,max_Reserved_msgs[priority]); } portable_mutex_unlock(&LP_reservedmutex); return(n); diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 33554c05e..bfd1103f3 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -856,7 +856,7 @@ int32_t LP_iseligible(uint64_t *valp,uint64_t *val2p,int32_t iambob,char *symbol } return(1); } - } // else printf("no val2\n"); + } else printf("no val2 %.8f < threshold %.8f\n",dstr(val),dstr(threshold)); } /*char str2[65]; if ( val != 0 && val2 != 0 ) From 8140631cdc21af687e87ffe7b1825e4d9703bc5c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 12 Nov 2017 22:55:32 +0200 Subject: [PATCH 46/48] Test --- iguana/exchanges/LP_nativeDEX.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index c24f24cd4..0e427191c 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -856,7 +856,7 @@ int32_t LP_reserved_msg(int32_t priority,char *base,char *rel,bits256 pubkey,cha if ( num_Reserved_msgs[priority] > max_Reserved_msgs[priority] ) { max_Reserved_msgs[priority] = num_Reserved_msgs[priority]; - if ( (max_Reserved_msgs[priority] % 100) == 0 )) + if ( (max_Reserved_msgs[priority] % 100) == 0 ) printf("New priority.%d max_Reserved_msgs.%d\n",priority,max_Reserved_msgs[priority]); } portable_mutex_unlock(&LP_reservedmutex); From f7e2cfb985e70cb36118873af9bdb6ab09073a91 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 12 Nov 2017 23:49:04 +0200 Subject: [PATCH 47/48] Test --- iguana/exchanges/LP_nativeDEX.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 0e427191c..ce4574d09 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -19,6 +19,7 @@ // marketmaker // // alice waiting for bestprice +// regen inventory // previously, it used to show amount, kmd equiv, perc // there is still a pending one with `-1 wait for bobpayment bYoNxkfvwQ42Yufry8J5y8BYi6mQxokvW9 numconfs.1 MNZ c0ea4aa808a653222a15122d96692fecf734dbbacfb9a54cb4711306ea0c3cef`, but that tx is already spent including 6 confirmation // bot safe to exit? From 047df333a036d79c9adb911e4963a045b6cfb2ba Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 12 Nov 2017 23:49:39 +0200 Subject: [PATCH 48/48] No MUSTFIX --- iguana/exchanges/LP_include.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 4e3a1e5f2..a46edacae 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -23,7 +23,7 @@ #define LP_MAJOR_VERSION "0" #define LP_MINOR_VERSION "1" -#define LP_BUILD_NUMBER "14288" +#define LP_BUILD_NUMBER "14336" #ifdef FROM_JS #include