From b1d772b8aa619bd997b8356edaeb30c7b41fb75a Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Nov 2017 14:16:09 +0200 Subject: [PATCH 001/306] Test --- iguana/exchanges/LP_nativeDEX.c | 1 - iguana/exchanges/LP_swap.c | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index ce4574d09..6486bfa83 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -21,7 +21,6 @@ // 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? // // BCH signing diff --git a/iguana/exchanges/LP_swap.c b/iguana/exchanges/LP_swap.c index f923ad161..11dba75e7 100644 --- a/iguana/exchanges/LP_swap.c +++ b/iguana/exchanges/LP_swap.c @@ -1121,20 +1121,20 @@ struct basilisk_swap *bitcoin_swapinit(bits256 privkey,uint8_t *pubkey33,bits256 } swap->myfee.I.locktime = swap->I.started + 1; swap->otherfee.I.locktime = swap->I.started + 1; - basilisk_rawtx_setparms("bobdeposit",swap->I.req.quoteid,&swap->bobdeposit,&swap->bobcoin,swap->I.bobconfirms,0,LP_DEPOSITSATOSHIS(swap->I.bobsatoshis) + 0*swap->bobcoin.txfee,4,0,jumblrflag); + basilisk_rawtx_setparms("bobdeposit",swap->I.req.quoteid,&swap->bobdeposit,&swap->bobcoin,swap->I.bobconfirms,0,LP_DEPOSITSATOSHIS(swap->I.bobsatoshis) + swap->bobcoin.txfee,4,0,jumblrflag); basilisk_rawtx_setparms("bobrefund",swap->I.req.quoteid,&swap->bobrefund,&swap->bobcoin,1,4,LP_DEPOSITSATOSHIS(swap->I.bobsatoshis),1,bobpub33,jumblrflag); swap->bobrefund.I.suppress_pubkeys = 1; basilisk_rawtx_setparms("aliceclaim",swap->I.req.quoteid,&swap->aliceclaim,&swap->bobcoin,1,4,LP_DEPOSITSATOSHIS(swap->I.bobsatoshis),1,alicepub33,jumblrflag); swap->aliceclaim.I.suppress_pubkeys = 1; swap->aliceclaim.I.locktime = swap->I.started + swap->I.putduration+swap->I.callduration + 1; - basilisk_rawtx_setparms("bobpayment",swap->I.req.quoteid,&swap->bobpayment,&swap->bobcoin,swap->I.bobconfirms,0,swap->I.bobsatoshis + 0*swap->bobcoin.txfee,3,0,jumblrflag); + basilisk_rawtx_setparms("bobpayment",swap->I.req.quoteid,&swap->bobpayment,&swap->bobcoin,swap->I.bobconfirms,0,swap->I.bobsatoshis + swap->bobcoin.txfee,3,0,jumblrflag); basilisk_rawtx_setparms("alicespend",swap->I.req.quoteid,&swap->alicespend,&swap->bobcoin,swap->I.bobconfirms,3,swap->I.bobsatoshis,1,alicepub33,jumblrflag); swap->alicespend.I.suppress_pubkeys = 1; basilisk_rawtx_setparms("bobreclaim",swap->I.req.quoteid,&swap->bobreclaim,&swap->bobcoin,swap->I.bobconfirms,3,swap->I.bobsatoshis,1,bobpub33,jumblrflag); swap->bobreclaim.I.suppress_pubkeys = 1; swap->bobreclaim.I.locktime = swap->I.started + swap->I.putduration + 1; - basilisk_rawtx_setparms("alicepayment",swap->I.req.quoteid,&swap->alicepayment,&swap->alicecoin,swap->I.aliceconfirms,0,swap->I.alicesatoshis + 0*swap->alicecoin.txfee,2,0,jumblrflag); + basilisk_rawtx_setparms("alicepayment",swap->I.req.quoteid,&swap->alicepayment,&swap->alicecoin,swap->I.aliceconfirms,0,swap->I.alicesatoshis + swap->alicecoin.txfee,2,0,jumblrflag); basilisk_rawtx_setparms("bobspend",swap->I.req.quoteid,&swap->bobspend,&swap->alicecoin,swap->I.aliceconfirms,2,swap->I.alicesatoshis,1,bobpub33,jumblrflag); swap->bobspend.I.suppress_pubkeys = 1; basilisk_rawtx_setparms("alicereclaim",swap->I.req.quoteid,&swap->alicereclaim,&swap->alicecoin,swap->I.aliceconfirms,2,swap->I.alicesatoshis,1,alicepub33,jumblrflag); From 4cd023ccfc1bea17364a8fe3fe80279019de954e Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Nov 2017 14:26:08 +0200 Subject: [PATCH 002/306] 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 7bb60dd40..b04094aa1 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -852,6 +852,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("found %.8f -> %.8f newprice %.8f vs ask %.8f += %.8f qprice %.8f\n",dstr(Q.satoshis),dstr(Q.destsatoshis),(double)Q.destsatoshis/Q.satoshis,ask,price,qprice); //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 c0672f2658ea17ccad8c0c78336e70143699cca6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Nov 2017 14:34:15 +0200 Subject: [PATCH 003/306] 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 b04094aa1..bd480c224 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -842,7 +842,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, return(retval); } 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 ) + if ( (butxo= LP_address_utxopair(1,utxos,max,LP_coinfind(Q.srccoin),Q.coinaddr,2*Q.txfee,dstr(Q.destsatoshis),price,Q.desttxfee)) != 0 ) { strcpy(Q.gui,G.gui); strcpy(Q.coinaddr,coin->smartaddr); From 37349c8e4db7af3b3ce90fad1d3b671b5b9f9665 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Nov 2017 14:38:12 +0200 Subject: [PATCH 004/306] 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 bd480c224..b04094aa1 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -842,7 +842,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, return(retval); } LP_listunspent_both(Q.srccoin,Q.coinaddr,0); - if ( (butxo= LP_address_utxopair(1,utxos,max,LP_coinfind(Q.srccoin),Q.coinaddr,2*Q.txfee,dstr(Q.destsatoshis),price,Q.desttxfee)) != 0 ) + if ( (butxo= LP_address_utxopair(1,utxos,max,LP_coinfind(Q.srccoin),Q.coinaddr,Q.txfee,dstr(Q.destsatoshis),price,Q.desttxfee)) != 0 ) { strcpy(Q.gui,G.gui); strcpy(Q.coinaddr,coin->smartaddr); From 2bc60b60ddcb372a5e10890fec91eb575b865ad4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Nov 2017 14:52:32 +0200 Subject: [PATCH 005/306] Test --- iguana/exchanges/LP_include.h | 2 +- iguana/exchanges/LP_ordermatch.c | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index a46edacae..b23ba015f 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -43,7 +43,7 @@ void emscripten_usleep(int32_t x); // returns immediate, no sense for sleeping #define LP_MAXVINS 64 #define LP_HTTP_TIMEOUT 3 // 1 is too small due to edge cases of time(NULL) -#define LP_AUTOTRADE_TIMEOUT 40 +#define LP_AUTOTRADE_TIMEOUT 30 #define ELECTRUM_TIMEOUT 7 #define LP_ELECTRUM_KEEPALIVE 60 #define LP_ELECTRUM_MAXERRORS 777 diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index b04094aa1..c210ba075 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -21,15 +21,20 @@ struct LP_quoteinfo LP_Alicequery; double LP_Alicemaxprice; uint32_t Alice_expiration; -struct { uint64_t aliceid; double bestprice; } Bob_competition[512]; +struct { uint64_t aliceid; double bestprice; uint32_t starttime; } Bob_competition[512]; double LP_bob_competition(uint64_t aliceid,double price) { - int32_t i,firsti = -1; + int32_t i,firsti = -1; uint32_t now = (uint32_t)time(NULL); for (i=0; i Bob_competition[i].starttime+LP_AUTOTRADE_TIMEOUT ) + { + printf("aliceid.%llx expired\n",(long long)aliceid); + Bob_competition[i].bestprice = 0.; + } if ( price != 0. && (Bob_competition[i].bestprice == 0. || price < Bob_competition[i].bestprice) ) { Bob_competition[i].bestprice = price; @@ -42,6 +47,7 @@ double LP_bob_competition(uint64_t aliceid,double price) } if ( firsti < 0 ) firsti = (rand() % (sizeof(Bob_competition)/sizeof(*Bob_competition))); + Bob_competition[firsti].starttime = (uint32_t)time(NULL); Bob_competition[firsti].aliceid = aliceid; Bob_competition[firsti].bestprice = price; //printf("Bob competition aliceid.%llx %.8f\n",(long long)aliceid,price); From d2e53f072467989e37bb25dcaa3b72d683de0a55 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Nov 2017 14:59:12 +0200 Subject: [PATCH 006/306] 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 c210ba075..22f503cd1 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -832,7 +832,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)/100.,LP_bob_competition(aliceid,price)); + printf(">>>>>>>>>>>>> price %.8f qprice %.8f r.%d range %.8f -> %.8f\n",price,qprice,r,range,price + (r*range)/100.); price += (r * range) / 100.; bestprice = LP_bob_competition(aliceid,price); if ( price < bestprice+SMALLVAL ) From 5e6710410fc116aa2198d68d20a1b5bc6140e1a6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Nov 2017 15:02:35 +0200 Subject: [PATCH 007/306] 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 22f503cd1..d6b929b84 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -32,8 +32,9 @@ double LP_bob_competition(uint64_t aliceid,double price) { if ( now > Bob_competition[i].starttime+LP_AUTOTRADE_TIMEOUT ) { - printf("aliceid.%llx expired\n",(long long)aliceid); + //printf("aliceid.%llx expired\n",(long long)aliceid); Bob_competition[i].bestprice = 0.; + Bob_competition[i].starttime = now; } if ( price != 0. && (Bob_competition[i].bestprice == 0. || price < Bob_competition[i].bestprice) ) { From ea468bab7f89b7df42c4e00a6df576495d8abf89 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Nov 2017 15:19:35 +0200 Subject: [PATCH 008/306] Test --- iguana/exchanges/LP_include.h | 2 +- iguana/exchanges/LP_ordermatch.c | 21 ++++++++++++++------- iguana/exchanges/LP_socket.c | 2 ++ 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index b23ba015f..c7eeca62e 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -96,7 +96,7 @@ void emscripten_usleep(int32_t x); // returns immediate, no sense for sleeping #define JUMBLR_RMD160 "5177f8b427e5f47342a4b8ab5dac770815d4389e" #define TIERNOLAN_RMD160 "daedddd8dbe7a2439841ced40ba9c3d375f98146" #define INSTANTDEX_BTC "1KRhTPvoxyJmVALwHFXZdeeWFbcJSbkFPu" -#define INSTANTDEX_BTCD "RThtXup6Zo7LZAi8kRWgjAyi1s4u6U9Cpf" +#define INSTANTDEX_KMD "RThtXup6Zo7LZAi8kRWgjAyi1s4u6U9Cpf" //#define BASILISK_DISABLEWAITTX //#define BASILISK_DISABLESENDTX diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index d6b929b84..57e8d451b 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -21,11 +21,12 @@ struct LP_quoteinfo LP_Alicequery; double LP_Alicemaxprice; uint32_t Alice_expiration; -struct { uint64_t aliceid; double bestprice; uint32_t starttime; } Bob_competition[512]; +struct { uint64_t aliceid; double bestprice; uint32_t starttime,counter; } Bob_competition[512]; -double LP_bob_competition(uint64_t aliceid,double price) +double LP_bob_competition(int32_t *counterp,uint64_t aliceid,double price,int32_t counter) { int32_t i,firsti = -1; uint32_t now = (uint32_t)time(NULL); + *counterp = 0; for (i=0; i bestprice %.8f\n",(long long)aliceid,qprice,bestprice); if ( LP_Alicemaxprice == 0. ) return(retval); @@ -744,6 +750,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, } else if ( strcmp(method,"connected") == 0 ) { + bestprice = LP_bob_competition(&counter,aliceid,qprice,1000); if ( bits256_cmp(G.LP_mypub25519,Q.desthash) == 0 && bits256_cmp(G.LP_mypub25519,Q.srchash) != 0 ) { if ( (qprice= LP_quote_validate(autxo,butxo,&Q,0)) <= SMALLVAL ) @@ -833,10 +840,10 @@ 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\n",price,qprice,r,range,price + (r*range)/100.); price += (r * range) / 100.; - bestprice = LP_bob_competition(aliceid,price); - if ( price < bestprice+SMALLVAL ) + bestprice = LP_bob_competition(&counter,aliceid,price,0); + printf(">>>>>>>>>>>>> price %.8f qprice %.8f r.%d range %.8f -> %.8f, bestprice %.8f counter.%d\n",ask,qprice,r,range,price,bestprice,counter); + if ( counter > 2 || price > bestprice*1.1 ) 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)); diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index e679ef67f..8d8cbb908 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -578,6 +578,8 @@ cJSON *electrum_address_listunspent(char *symbol,struct electrum_info *ep,cJSON cJSON *retjson=0; char *retstr; struct LP_address *ap; struct iguana_info *coin; int32_t updatedflag,height,usecache=1; if ( (coin= LP_coinfind(symbol)) == 0 ) return(0); + if ( strcmp(addr,INSTANTDEX_KMD) == 0 ) + return(cJSON_Parse("[]")); if ( ep == 0 || ep->heightp == 0 ) height = coin->longestchain; else height = *(ep->heightp); From 99e6f263dcdf1e130047b1a23e77508f178c7231 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Nov 2017 15:28:01 +0200 Subject: [PATCH 009/306] test --- iguana/exchanges/LP_socket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 8d8cbb908..951e14923 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -703,7 +703,7 @@ cJSON *_electrum_transaction(char *symbol,struct electrum_info *ep,cJSON **retjs } hexjson = electrum_hasharg(symbol,ep,&hexjson,"blockchain.transaction.get",txid,ELECTRUM_TIMEOUT); hexstr = jprint(hexjson,0); - if ( strlen(hexstr) > 60000 ) + if ( strlen(hexstr) > 100000 ) { static uint32_t counter; if ( counter++ < 3 ) From 5284db6b197faba46e3c3a815492350c94f1ed12 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Nov 2017 17:25:44 +0200 Subject: [PATCH 010/306] Test --- iguana/exchanges/LP_coins.c | 2 +- iguana/exchanges/LP_nativeDEX.c | 4 ++++ iguana/exchanges/LP_stats.c | 11 +++++++++-- iguana/exchanges/LP_swap.c | 6 +++--- iguana/exchanges/LP_tradebots.c | 6 +++--- 5 files changed, 20 insertions(+), 9 deletions(-) diff --git a/iguana/exchanges/LP_coins.c b/iguana/exchanges/LP_coins.c index 38c62ac64..7f43a005a 100644 --- a/iguana/exchanges/LP_coins.c +++ b/iguana/exchanges/LP_coins.c @@ -229,7 +229,7 @@ cJSON *LP_coinjson(struct iguana_info *coin,int32_t showwif) jaddnum(item,"pubtype",coin->pubtype); jaddnum(item,"p2shtype",coin->p2shtype); jaddnum(item,"wiftype",coin->wiftype); - jaddnum(item,"txfee",coin->txfee); + jaddnum(item,"txfee",strcmp(coin->symbol,"BTC") != 0 ? coin->txfee : LP_txfeecalc(coin,0,0)); return(item); } diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 6486bfa83..c41f82f88 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -666,6 +666,8 @@ void LP_initcoins(void *ctx,int32_t pubsock,cJSON *coins) if ( LP_getheight(coin) <= 0 ) coin->inactive = (uint32_t)time(NULL); else LP_unspents_load(coin->symbol,coin->smartaddr); + if ( coin->txfee == 0 && strcmp(coin->symbol,"BTC") != 0 ) + coin->txfee = LP_MIN_TXFEE; } } if ( (n= cJSON_GetArraySize(coins)) > 0 ) @@ -683,6 +685,8 @@ void LP_initcoins(void *ctx,int32_t pubsock,cJSON *coins) if ( LP_getheight(coin) <= 0 ) coin->inactive = (uint32_t)time(NULL); else LP_unspents_load(coin->symbol,coin->smartaddr); + if ( coin->txfee == 0 && strcmp(coin->symbol,"BTC") != 0 ) + coin->txfee = LP_MIN_TXFEE; } } } diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index 1fcea0355..853ce8bd0 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -34,6 +34,13 @@ int32_t LP_statslog_parsequote(char *method,cJSON *lineobj); char *LP_stats_methods[] = { "unknown", "request", "reserved", "connect", "connected", "tradestatus" }; +uint32_t LP_atomic_locktime(char *base,char *rel) +{ + if ( strcmp(base,"BTC") != 0 && strcmp(rel,"BTC") != 0 ) + return(INSTANTDEX_LOCKTIME); + else return(INSTANTDEX_LOCKTIME * 10); +} + static uint32_t LP_requests,LP_reserveds,LP_connects,LP_connecteds,LP_tradestatuses,LP_parse_errors,LP_unknowns,LP_duplicates,LP_aliceids; void LP_tradecommand_log(cJSON *argjson) @@ -195,7 +202,7 @@ int32_t LP_swapstats_update(struct LP_swapstats *sp,struct LP_quoteinfo *qp,cJSO if ( (sp->finished= juint(lineobj,"timestamp")) == 0 ) sp->finished = (uint32_t)time(NULL); } - if ( sp->finished == 0 && time(NULL) > sp->Q.timestamp+INSTANTDEX_LOCKTIME*2 ) + if ( sp->finished == 0 && time(NULL) > sp->Q.timestamp+LP_atomic_locktime(base,rel)*2 ) sp->expired = (uint32_t)time(NULL); return(0); } @@ -337,7 +344,7 @@ char *LP_statslog_disp(int32_t n,uint32_t starttime,uint32_t endtime,char *refgu array = cJSON_CreateArray(); HASH_ITER(hh,LP_swapstats,sp,tmp) { - if ( sp->finished == 0 && time(NULL) > sp->Q.timestamp+INSTANTDEX_LOCKTIME*2 ) + if ( sp->finished == 0 && time(NULL) > sp->Q.timestamp+LP_atomic_locktime(sp->Q.srccoin,sp->Q.destcoin)*2 ) sp->expired = (uint32_t)time(NULL); dispflag = 0; if ( starttime == 0 && endtime == 0 ) diff --git a/iguana/exchanges/LP_swap.c b/iguana/exchanges/LP_swap.c index 11dba75e7..fb6adf940 100644 --- a/iguana/exchanges/LP_swap.c +++ b/iguana/exchanges/LP_swap.c @@ -801,7 +801,7 @@ void LP_bobloop(void *_swap) basilisk_bobpayment_reclaim(swap,swap->I.callduration); if ( swap->N.pair >= 0 ) nn_close(swap->N.pair), swap->N.pair = -1; - LP_swapwait(swap->I.req.requestid,swap->I.req.quoteid,INSTANTDEX_LOCKTIME*2,30); + LP_swapwait(swap->I.req.requestid,swap->I.req.quoteid,LP_atomic_locktime(swap->bobcoin.symbol,swap->alicecoin.symbol)*2,30); } } } @@ -867,7 +867,7 @@ void LP_aliceloop(void *_swap) }*/ if ( swap->N.pair >= 0 ) nn_close(swap->N.pair), swap->N.pair = -1; - LP_swapwait(swap->I.req.requestid,swap->I.req.quoteid,INSTANTDEX_LOCKTIME*2,30); + LP_swapwait(swap->I.req.requestid,swap->I.req.quoteid,LP_atomic_locktime(swap->bobcoin.symbol,swap->alicecoin.symbol)*2,30); } } } @@ -1009,7 +1009,7 @@ struct basilisk_swap *bitcoin_swapinit(bits256 privkey,uint8_t *pubkey33,bits256 printf("bitcoin_swapinit %s Btxfee %.8f rejected\n",swap->I.req.src,dstr(swap->I.Btxfee)); return(0); } - swap->I.putduration = swap->I.callduration = INSTANTDEX_LOCKTIME; + swap->I.putduration = swap->I.callduration = LP_atomic_locktime(swap->bobcoin.symbol,swap->alicecoin.symbol); if ( optionduration < 0 ) swap->I.putduration -= optionduration; else if ( optionduration > 0 ) diff --git a/iguana/exchanges/LP_tradebots.c b/iguana/exchanges/LP_tradebots.c index a2e82ac10..a0b4406cb 100644 --- a/iguana/exchanges/LP_tradebots.c +++ b/iguana/exchanges/LP_tradebots.c @@ -27,13 +27,13 @@ struct LP_tradebot_trade uint64_t aliceid; int32_t dispdir; uint32_t started,finished,requestid,quoteid,tradeid,expired; - char base[32],rel[32],event[32]; + char base[65],rel[65],event[32]; }; struct LP_tradebot { struct LP_tradebot *next,*prev; - char name[128],base[32],rel[32]; + char name[128],base[65],rel[65]; int32_t numtrades,numpending,completed,dispdir; double maxprice,totalrelvolume,totalbasevolume,basesum,relsum,pendbasesum,pendrelsum; uint32_t lasttime,dead,pause,userpause,started,id; @@ -74,7 +74,7 @@ void LP_tradebot_calcstats(struct LP_tradebot *bot) { if ( (tp= bot->trades[i]) == 0 ) continue; - if ( tp->finished == 0 && time(NULL) > tp->started+INSTANTDEX_LOCKTIME*2 ) + if ( tp->finished == 0 && time(NULL) > tp->started+LP_atomic_locktime(bot->base,bot->rel)*2 ) { tp->expired = tp->finished = (uint32_t)time(NULL); printf("tradeid.%u expired\n",tp->tradeid); From d59aca98d1791190854436185140d23649e2cf22 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Nov 2017 18:51:52 +0200 Subject: [PATCH 011/306] Test --- iguana/exchanges/DEXstats.h | 4 ++-- iguana/exchanges/LP_RTmetrics.c | 2 +- iguana/exchanges/LP_include.h | 12 ++++++------ iguana/exchanges/LP_nativeDEX.c | 3 +++ iguana/exchanges/LP_portfolio.c | 8 ++++---- iguana/exchanges/LP_prices.c | 2 +- iguana/exchanges/LP_remember.c | 10 ++++++++++ iguana/exchanges/LP_rpc.c | 2 +- iguana/exchanges/LP_scan.c | 2 +- iguana/exchanges/LP_socket.c | 6 +++--- iguana/exchanges/mm.c | 4 ++-- iguana/exchanges/stats.c | 4 ++-- 12 files changed, 36 insertions(+), 23 deletions(-) diff --git a/iguana/exchanges/DEXstats.h b/iguana/exchanges/DEXstats.h index edf2157cb..dc1f89864 100644 --- a/iguana/exchanges/DEXstats.h +++ b/iguana/exchanges/DEXstats.h @@ -51,7 +51,7 @@ struct DEXstats_pricepoint struct DEXstats_pairinfo { - char dest[16]; + char dest[128]; int32_t numprices; struct DEXstats_pricepoint *prices; }; @@ -64,7 +64,7 @@ struct DEXstats_datenuminfo struct DEXstats_priceinfo { - char symbol[16]; + char symbol[128]; int32_t firstdatenum,numdates; struct DEXstats_datenuminfo *dates; } Prices[1024]; diff --git a/iguana/exchanges/LP_RTmetrics.c b/iguana/exchanges/LP_RTmetrics.c index 54d9300bd..ac01d3025 100644 --- a/iguana/exchanges/LP_RTmetrics.c +++ b/iguana/exchanges/LP_RTmetrics.c @@ -29,7 +29,7 @@ struct LP_metricinfo struct LP_RTmetrics_pendings { - char refbase[16],refrel[16]; + char refbase[65],refrel[65]; int32_t numswaps,numavoidtxids,numwhitelist,numblacklist,numpendings,pending_swaps[1024]; bits256 avoidtxids[8192],whitelist[1024],blacklist[1024],pending_pubkeys[1024]; } LP_RTmetrics; diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index c7eeca62e..a8d31fc40 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -166,7 +166,7 @@ struct basilisk_swap; struct basilisk_rawtxinfo { - char destaddr[64],coinstr[16]; + char destaddr[64],coinstr[128]; bits256 txid,signedtxid,actualtxid; int64_t amount,change,inputsum; int32_t redeemlen,datalen,completed,vintype,vouttype,numconfirms,spendlen,secretstart,suppress_pubkeys; @@ -200,7 +200,7 @@ struct basilisk_rawtx struct basilisk_swapinfo { struct basilisk_request req; - char bobstr[64],alicestr[64]; + char bobstr[128],alicestr[128]; bits256 myhash,otherhash,orderhash; uint32_t statebits,otherstatebits,started,expiration,finished,dead,reftime,putduration,callduration; int32_t bobconfirms,aliceconfirms,iambob,reclaimed,bobspent,alicespent,pad,aliceistrusted,bobistrusted,otheristrusted,otherstrust,alicemaxconfirms,bobmaxconfirms; @@ -270,7 +270,7 @@ struct iguana_info int32_t numutxos,longestchain,firstrefht,firstscanht,lastscanht,bussock,height; uint16_t busport; uint32_t loadedcache,electrumlist,lastunspent,importedprivkey,lastpushtime,lastutxosync,addr_listunspent_requested,lastutxos,updaterate,counter,inactive,lastmempool,lastgetinfo,ratetime,heighttime,lastmonitor,obooktime; uint8_t pubtype,p2shtype,isPoS,wiftype,wiftaddr,taddr,noimportprivkey_flag,userconfirms,isassetchain,maxconfirms; - char symbol[16],smartaddr[64],userpass[1024],serverport[128]; + char symbol[128],smartaddr[64],userpass[1024],serverport[128]; // portfolio double price_kmd,force,perc,goal,goalperc,relvolume,rate; void *electrum; void *ctx; @@ -301,7 +301,7 @@ struct LP_utxoinfo int32_t iambob,iamlp; uint8_t key[sizeof(bits256) + sizeof(int32_t)]; uint8_t key2[sizeof(bits256) + sizeof(int32_t)]; - char coin[16],coinaddr[64],gui[16];//spendscript[256]; + char coin[65],coinaddr[64],gui[16];//spendscript[256]; }; struct LP_address_utxo @@ -340,7 +340,7 @@ struct LP_quoteinfo uint64_t satoshis,txfee,destsatoshis,desttxfee,aliceid; uint32_t timestamp,quotetime,tradeid; int32_t vout,vout2,destvout,feevout,pair; - char srccoin[16],coinaddr[64],destcoin[16],destaddr[64],gui[64]; + char srccoin[65],coinaddr[64],destcoin[65],destaddr[64],gui[64]; }; struct LP_endpoint { int32_t pair; char ipaddr[64]; uint16_t port; }; @@ -384,7 +384,7 @@ struct electrum_info int32_t bufsize,sock,*heightp,numerrors; struct iguana_info *coin; uint32_t stratumid,lasttime,keepalive,pending,*heighttimep; - char ipaddr[64],symbol[16]; + char ipaddr[64],symbol[66]; uint16_t port; uint8_t buf[]; }; diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index c41f82f88..782fa35ce 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -26,6 +26,9 @@ // BCH signing // dPoW security -> 4: KMD notarized, 5: BTC notarized, after next notary elections // bigendian architectures need to use little endian for sighash calcs +//BTC LP_transaction_fromdata mismatched txid f78c80e831c02c89c0888e7d4438287030238e09e33f88da6df4dc84b949959b vs 1390f386f5997607e646be9c93f30018aa68ea971790b92b7b06e892656f0769 +//failed blockchain.transaction.get BTC f78c80e831c02c89c0888e7d4438287030238e09e33f88da6df4dc84b949959b +//02000000000101242344292f9117c8318adb84f7991239361da2ff0a15ad2106d402945072cc110a0000001716001470eb5212b558cfc10b31f0849ef88ecf17097ac1ffffffff0c4a8321000000000017a914baed1c79cc6325333d5013b44dc17e8256bf5b718704bf3c000000000017a914255cf2809a1f42569c5c47c71e6234aac35a800f873099f400000000001976a914049877b81a8d6d8592919b75b9bcb4182f7c52cd88acb907e200000000001976a9140614fc114940e867210b09cc900db14d8bc58d2b88ac40771b00000000001976a9148cadbb1d7002d22d60e38ca238678d00f04ed22988ac002d3101000000001976a9140d05714431cf478846cea1435f9eabae9ad5c65388acc0f280010000000017a914c17a70c74154fc53263652aaca26c8d71683f1ba87aa2a4e00000000001976a914feea6b867954b1072962083233796d47e4c1665e88ace0e1de02000000001976a91445b71fbb02df53be5563257b77780b9afcc55bdc88acf6fe6700000000001976a91492332f8ff3b26e3ce2666afa5fee2e45308225af88ace74c1500000000001976a914fc7580f1ce24b2c85c80b2c8e641592b9bbf974588ac081ad000000000001976a9145e61c81c9b3ac55bf90ab00240023e8ddaf43e1788ac02483045022100a74be4e00585637c6792eeff9279508f09163db525f8b16c03e57283d12b0a6a022042cc061d70e78e9260ff30635db4f4e0b317831a8cb1f30473a25b93b4d1b4fb01210238288b60e8c50785809a69517ae3ca2fe3e407cac8b5868c5fb3803c233dfbcc00000000 data2json n.219 vs len.586 #include struct LP_millistats diff --git a/iguana/exchanges/LP_portfolio.c b/iguana/exchanges/LP_portfolio.c index 43fd77c89..4004a8c41 100644 --- a/iguana/exchanges/LP_portfolio.c +++ b/iguana/exchanges/LP_portfolio.c @@ -18,7 +18,7 @@ // marketmaker // -char LP_portfolio_base[16],LP_portfolio_rel[16]; +char LP_portfolio_base[128],LP_portfolio_rel[128]; double LP_portfolio_relvolume; cJSON *LP_portfolio_entry(struct iguana_info *coin) @@ -203,7 +203,7 @@ int32_t LP_autoprices,num_LP_autorefs; struct LP_autoprice_ref { - char refbase[16],refrel[16],base[16],rel[16]; + char refbase[65],refrel[65],base[65],rel[65]; } LP_autorefs[100]; /*int32_t LP_autofill(char *base,char *rel,double maxprice,double totalrelvolume) @@ -325,7 +325,7 @@ double LP_pricesparse(void *ctx,int32_t trexflag,char *retstr,struct LP_priceinf { //{"success":true,"message":"","result":[{"MarketName":"BTC-KMD","High":0.00040840,"Low":0.00034900,"Volume":328042.46061669,"Last":0.00037236,"BaseVolume":123.36439511,"TimeStamp":"2017-07-15T13:50:21.87","Bid":0.00035721,"Ask":0.00037069,"OpenBuyOrders":343,"OpenSellOrders":1690,"PrevDay":0.00040875,"Created":"2017-02-11T23:04:01.853"}, //{"TradePairId":4762,"Label":"WAVES/BTC","AskPrice":0.00099989,"BidPrice":0.00097350,"Low":0.00095000,"High":0.00108838,"Volume":6501.24403100,"LastPrice":0.00098028,"BuyVolume":1058994.86554882,"SellVolume":2067.87377158,"Change":-7.46,"Open":0.00105926,"Close":0.00098028,"BaseVolume":6.52057452,"BuyBaseVolume":2.33098660,"SellBaseVolume":1167.77655709}, - int32_t i,j,n,iter; double price,kmdbtc,bid,ask,nxtkmd=0.; struct LP_priceinfo *coinpp,*refpp; char symbol[16],*name,*refcoin; cJSON *retjson,*array,*item; + int32_t i,j,n,iter; double price,kmdbtc,bid,ask,nxtkmd=0.; struct LP_priceinfo *coinpp,*refpp; char symbol[65],*name,*refcoin; cJSON *retjson,*array,*item; if ( (retjson= cJSON_Parse(retstr)) != 0 ) { //printf("got.(%s)\n",retstr); @@ -553,7 +553,7 @@ int32_t LP_portfolio_trade(void *ctx,uint32_t *requestidp,uint32_t *quoteidp,str else return(-1); } -struct LP_portfoliotrade { double metric; char buycoin[16],sellcoin[16]; }; +struct LP_portfoliotrade { double metric; char buycoin[65],sellcoin[65]; }; int32_t LP_portfolio_order(struct LP_portfoliotrade *trades,int32_t max,cJSON *array) { diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 66bb2fdc3..7313c733b 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -22,7 +22,7 @@ struct LP_orderbookentry { bits256 pubkey; double price; uint64_t minsatoshis,ma struct LP_priceinfo { - char symbol[16]; + char symbol[68]; uint64_t coinbits; int32_t ind,pad; double diagval,high[2],low[2],last[2],bid[2],ask[2]; //volume,btcvolume,prevday; // mostly bittrex info diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index 44d93a71a..2180a498c 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -94,6 +94,10 @@ void basilisk_dontforget(struct basilisk_swap *swap,struct basilisk_rawtx *rawtx if ( (fp= fopen(fname,"wb")) != 0 ) { fprintf(fp,"{\"tradeid\":%u,\"aliceid\":\"%llu\",\"src\":\"%s\",\"srcamount\":%.8f,\"dest\":\"%s\",\"destamount\":%.8f,\"requestid\":%u,\"quoteid\":%u,\"iambob\":%d,\"state\":%u,\"otherstate\":%u,\"expiration\":%u,\"dlocktime\":%u,\"plocktime\":%u,\"Atxfee\":%llu,\"Btxfee\":%llu",swap->tradeid,(long long)swap->aliceid,swap->I.req.src,dstr(swap->I.req.srcamount),swap->I.req.dest,dstr(swap->I.req.destamount),swap->I.req.requestid,swap->I.req.quoteid,swap->I.iambob,swap->I.statebits,swap->I.otherstatebits,swap->I.expiration,swap->bobdeposit.I.locktime,swap->bobpayment.I.locktime,(long long)swap->I.Atxfee,(long long)swap->I.Btxfee); + if ( swap->I.iambob == 0 ) + fprintf(fp,",\"Agui\":\"%s\"",G.gui); + else fprintf(fp,",\"Bgui\":\"%s\"",G.gui); + fprintf(fp,",\"gui\":\"%s\"",G.gui); if ( memcmp(zeroes,swap->I.secretAm,20) != 0 ) { init_hexbytes_noT(secretAmstr,swap->I.secretAm,20); @@ -455,6 +459,9 @@ cJSON *LP_swap_json(struct LP_swap_remember *rswap) jaddnum(item,"requestid",rswap->requestid); jaddnum(item,"quoteid",rswap->quoteid); jaddnum(item,"iambob",rswap->iambob); + jaddstr(item,"Bgui",rswap->Bgui); + jaddstr(item,"Agui",rswap->Agui); + jaddstr(item,"gui",rswap->gui); jaddstr(item,"bob",rswap->src); jaddnum(item,"srcamount",dstr(rswap->srcamount)); jaddnum(item,"bobtxfee",dstr(rswap->Btxfee)); @@ -503,6 +510,9 @@ int32_t LP_rswap_init(struct LP_swap_remember *rswap,uint32_t requestid,uint32_t if ( (item= cJSON_Parse(fstr)) != 0 ) { rswap->iambob = jint(item,"iambob"); + safecopy(rswap->Bgui,jstr(item,"Bgui"),sizeof(rswap->Bgui)); + safecopy(rswap->Agui,jstr(item,"Agui"),sizeof(rswap->Agui)); + safecopy(rswap->gui,jstr(item,"gui"),sizeof(rswap->gui)); rswap->tradeid = juint(item,"tradeid"); rswap->aliceid = j64bits(item,"aliceid"); if ( (secretstr= jstr(item,"secretAm")) != 0 && strlen(secretstr) == 40 ) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 1d952ff6d..30789efe7 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -208,7 +208,7 @@ cJSON *LP_NXT_decrypt(uint64_t txnum,char *account,char *data,char *nonce,char * cJSON *LP_NXT_redeems() { - char url[1024],*retstr,*recv,*method,*msgstr,assetname[16]; uint64_t totals[20],mult,txnum,assetid,qty; int32_t i,ind,numtx,past_marker=0; cJSON *item,*attach,*decjson,*array,*msgjson,*encjson,*retjson=0; + char url[1024],*retstr,*recv,*method,*msgstr,assetname[128]; uint64_t totals[20],mult,txnum,assetid,qty; int32_t i,ind,numtx,past_marker=0; cJSON *item,*attach,*decjson,*array,*msgjson,*encjson,*retjson=0; uint64_t txnum_marker = calc_nxt64bits("0"); uint64_t txnum_marker2 = calc_nxt64bits("7256847492742571143"); char *passphrase = ""; diff --git a/iguana/exchanges/LP_scan.c b/iguana/exchanges/LP_scan.c index a8c33fc28..5a5a12051 100644 --- a/iguana/exchanges/LP_scan.c +++ b/iguana/exchanges/LP_scan.c @@ -127,7 +127,7 @@ int sort_balance(void *a,void *b) cJSON *LP_snapshot(struct iguana_info *coin,int32_t height) { - static bits256 bannedarray[64]; static int32_t numbanned,indallvouts,maxsnapht; static char lastcoin[16]; + static bits256 bannedarray[64]; static int32_t numbanned,indallvouts,maxsnapht; static char lastcoin[65]; struct LP_transaction *tx,*tmp; struct LP_address *ap,*atmp; int32_t isKMD,i,j,n,skipflag=0,startht,endht,ht; uint64_t banned_balance=0,balance=0,noaddr_balance=0; cJSON *retjson,*array,*item; if ( bannedarray[0].txid == 0 ) numbanned = komodo_bannedset(&indallvouts,bannedarray,(int32_t)(sizeof(bannedarray)/sizeof(*bannedarray))); diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 951e14923..96855e6d7 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -98,7 +98,7 @@ int32_t LP_socket(int32_t bindflag,char *hostname,uint16_t port) #endif expand_ipbits(checkipaddr,saddr.sin_addr.s_addr); if ( strcmp(ipaddr,checkipaddr) != 0 ) - printf("bindflag.%d iguana_socket mismatch (%s) -> (%s)?\n",bindflag,checkipaddr,ipaddr); + printf("bindflag.%d iguana_socket mismatch (%s) -> (%s)\n",bindflag,checkipaddr,ipaddr); //#endif if ( (sock= socket(AF_INET,SOCK_STREAM,0)) < 0 ) { @@ -578,8 +578,8 @@ cJSON *electrum_address_listunspent(char *symbol,struct electrum_info *ep,cJSON cJSON *retjson=0; char *retstr; struct LP_address *ap; struct iguana_info *coin; int32_t updatedflag,height,usecache=1; if ( (coin= LP_coinfind(symbol)) == 0 ) return(0); - if ( strcmp(addr,INSTANTDEX_KMD) == 0 ) - return(cJSON_Parse("[]")); + //if ( strcmp(addr,INSTANTDEX_KMD) == 0 ) + // return(cJSON_Parse("[]")); if ( ep == 0 || ep->heightp == 0 ) height = coin->longestchain; else height = *(ep->heightp); diff --git a/iguana/exchanges/mm.c b/iguana/exchanges/mm.c index 12c8f1496..1d2a1bd5e 100644 --- a/iguana/exchanges/mm.c +++ b/iguana/exchanges/mm.c @@ -74,7 +74,7 @@ struct mmpending_order int32_t dir; uint32_t pending,completed,canceled,cancelstarted,reported; cJSON *errorjson; - char exchange[16],base[16],rel[16],orderid[64]; + char exchange[16],base[65],rel[65],orderid[64]; } *Pending_orders; int32_t Num_Pending; @@ -415,7 +415,7 @@ void marketmaker_pendingupdate(char *exchange,char *base,char *rel) void marketmaker_pendinginit(char *exchange,char *base,char *rel) { - char *retstr,*orderid,*pairstr,relbase[64]; cJSON *retjson,*array,*item; int32_t i,j,n,dir; struct mmpending_order *ptr; + char *retstr,*orderid,*pairstr,relbase[65]; cJSON *retjson,*array,*item; int32_t i,j,n,dir; struct mmpending_order *ptr; sprintf(relbase,"%s-%s",rel,base); if ( (retstr= DEX_openorders(exchange)) != 0 ) { diff --git a/iguana/exchanges/stats.c b/iguana/exchanges/stats.c index 6453b85d5..d283b1301 100644 --- a/iguana/exchanges/stats.c +++ b/iguana/exchanges/stats.c @@ -62,7 +62,7 @@ char CURRENCIES[][8] = { "USD", "EUR", "JPY", "GBP", "AUD", "CAD", "CHF", "NZD", "CNY", "RUB", "MXN", "BRL", "INR", "HKD", "TRY", "ZAR", "PLN", "NOK", "SEK", "DKK", "CZK", "HUF", "ILS", "KRW", "MYR", "PHP", "RON", "SGD", "THB", "BGN", "IDR", "HRK", // end of currencies }; -char ASSETCHAINS_SYMBOL[16] = { "KV" }; +char ASSETCHAINS_SYMBOL[65] = { "KV" }; struct komodo_state { @@ -1090,7 +1090,7 @@ int32_t komodo_parsestatefile(FILE *logfp,struct komodo_state *sp,FILE *fp,char int32_t stats_stateupdate(FILE *logfp,char *destdir,char *statefname,int32_t maxseconds,char *komodofile) { static long lastpos[2]; - char symbol[64],base[64]; int32_t iter,n; FILE *fp; uint32_t starttime; struct komodo_state *sp; + char symbol[65],base[65]; int32_t iter,n; FILE *fp; uint32_t starttime; struct komodo_state *sp; starttime = (uint32_t)time(NULL); strcpy(base,"KV"); strcpy(symbol,"KV"); From 987e52e408abefeebe6d8834e7380f60e82b80f4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Nov 2017 19:07:25 +0200 Subject: [PATCH 012/306] Test --- iguana/exchanges/LP_cache.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_cache.c b/iguana/exchanges/LP_cache.c index 95fbe6f99..65140dc2c 100644 --- a/iguana/exchanges/LP_cache.c +++ b/iguana/exchanges/LP_cache.c @@ -247,7 +247,7 @@ int32_t LP_merkleproof(struct iguana_info *coin,char *coinaddr,struct electrum_i if ( (merkobj= electrum_getmerkle(coin->symbol,ep,&merkobj,txid,height)) != 0 ) { char str[65],str2[65],str3[65]; - SPV = -1; + SPV = 0; memset(roothash.bytes,0,sizeof(roothash)); if ( (merkles= jarray(&m,merkobj,"merkle")) != 0 ) { @@ -271,7 +271,11 @@ int32_t LP_merkleproof(struct iguana_info *coin,char *coinaddr,struct electrum_i } //printf("validated MERK %s ht.%d -> %s root.(%s)\n",bits256_str(str,txid),height,jprint(merkobj,0),bits256_str(str2,roothash)); } - else printf("ERROR MERK %s ht.%d -> %s root.(%s) vs %s\n",bits256_str(str,txid),height,jprint(merkobj,0),bits256_str(str2,roothash),bits256_str(str3,merkleroot)); + else + { + SPV = -1; + printf("ERROR MERK %s ht.%d -> %s root.(%s) vs %s\n",bits256_str(str,txid),height,jprint(merkobj,0),bits256_str(str2,roothash),bits256_str(str3,merkleroot)); + } } else SPV = 0; } if ( SPV < 0 ) From 7b451b5cb16284bb5672dc6f03bf354cabf01e7b Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Nov 2017 19:11:01 +0200 Subject: [PATCH 013/306] Test --- iguana/exchanges/LP_include.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index a8d31fc40..cda3f0348 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -180,7 +180,7 @@ struct basilisk_request int64_t srcamount,unused; // 16 to 31 bits256 srchash; // 32 to 63 bits256 desthash; - char src[8],dest[8]; + char src[65],dest[65]; uint64_t destamount; int32_t optionhours,DEXselector; }; @@ -241,7 +241,7 @@ struct LP_swap_remember 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)]; + char Agui[65],Bgui[65],gui[65],src[65],dest[65],destaddr[64],Adestaddr[64],Sdestaddr[64],alicepaymentaddr[64],bobpaymentaddr[64],bobdepositaddr[64],alicecoin[65],bobcoin[65],*txbytes[sizeof(txnames)/sizeof(*txnames)]; }; struct LP_outpoint From 34bd4fab06ebe8747e0f929fdc42b41042099180 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Nov 2017 19:47:27 +0200 Subject: [PATCH 014/306] Test --- iguana/exchanges/LP_bitcoin.c | 9 +++++++++ iguana/exchanges/LP_nativeDEX.c | 10 ++++++++++ iguana/exchanges/LP_tradebots.c | 2 +- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_bitcoin.c b/iguana/exchanges/LP_bitcoin.c index 0eef539d1..cd70c13d4 100644 --- a/iguana/exchanges/LP_bitcoin.c +++ b/iguana/exchanges/LP_bitcoin.c @@ -3328,6 +3328,15 @@ int32_t iguana_rwjoinsplit(int32_t rwflag,uint8_t *serialized,struct iguana_msgj return(len); } +/* + normal: nVersion|txins|txouts|nLockTime. + segwit + nVersion|marker|flag|txins|txouts|witness|nLockTime +Format of nVersion, txins, txouts, and nLockTime are same as the original format +The marker MUST be 0x00 +The flag MUST be 0x01 +*/ + int32_t iguana_rwmsgtx(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t isPoS,int32_t height,int32_t rwflag,cJSON *json,uint8_t *serialized,int32_t maxsize,struct iguana_msgtx *msg,bits256 *txidp,char *vpnstr,uint8_t *extraspace,int32_t extralen,cJSON *vins,int32_t suppress_pubkeys,int32_t zcash) { int32_t i,n,len = 0,extraused=0; uint8_t spendscript[IGUANA_MAXSCRIPTSIZE],*txstart = serialized,*sigser=0; char txidstr[65]; cJSON *vinarray=0,*voutarray=0; bits256 sigtxid; diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 782fa35ce..05ce41c36 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -30,6 +30,16 @@ //failed blockchain.transaction.get BTC f78c80e831c02c89c0888e7d4438287030238e09e33f88da6df4dc84b949959b //02000000000101242344292f9117c8318adb84f7991239361da2ff0a15ad2106d402945072cc110a0000001716001470eb5212b558cfc10b31f0849ef88ecf17097ac1ffffffff0c4a8321000000000017a914baed1c79cc6325333d5013b44dc17e8256bf5b718704bf3c000000000017a914255cf2809a1f42569c5c47c71e6234aac35a800f873099f400000000001976a914049877b81a8d6d8592919b75b9bcb4182f7c52cd88acb907e200000000001976a9140614fc114940e867210b09cc900db14d8bc58d2b88ac40771b00000000001976a9148cadbb1d7002d22d60e38ca238678d00f04ed22988ac002d3101000000001976a9140d05714431cf478846cea1435f9eabae9ad5c65388acc0f280010000000017a914c17a70c74154fc53263652aaca26c8d71683f1ba87aa2a4e00000000001976a914feea6b867954b1072962083233796d47e4c1665e88ace0e1de02000000001976a91445b71fbb02df53be5563257b77780b9afcc55bdc88acf6fe6700000000001976a91492332f8ff3b26e3ce2666afa5fee2e45308225af88ace74c1500000000001976a914fc7580f1ce24b2c85c80b2c8e641592b9bbf974588ac081ad000000000001976a9145e61c81c9b3ac55bf90ab00240023e8ddaf43e1788ac02483045022100a74be4e00585637c6792eeff9279508f09163db525f8b16c03e57283d12b0a6a022042cc061d70e78e9260ff30635db4f4e0b317831a8cb1f30473a25b93b4d1b4fb01210238288b60e8c50785809a69517ae3ca2fe3e407cac8b5868c5fb3803c233dfbcc00000000 data2json n.219 vs len.586 + +//BTC LP_transaction_fromdata mismatched txid ae7af65215554964b7af01babb58fce10fc51d9812ced07ee4a62a1ffe10c0bb vs 051ef4f75898b511dd3aebd687d5a5bdb004226d811aaf13e64be741dbe81ff2 +//failed blockchain.transaction.get BTC ae7af65215554964b7af01babb58fce10fc51d9812ced07ee4a62a1ffe10c0bb +//errortxobj.({"version":1}) +//010000000001010c590740b0c558f75b64cc0d00b0533ff951e403d993b866a87c7c52981388a60300000017160014cd2b7646f9931c85bb9d4d353b652c76b40aff84ffffffff0240420f000000000017a914239ae54cd403a91b084d3244e7e423f05c25ec268728fe28010000000017a914b96e21dd6e11bb67479f9072df55881e7fb17f788702473044022076e4c1cfba0dab889598efdfdcbc7a1046cc0eecfb8fec379994d559143d271c02206b16d9a0e3c425434d1b793d61e1e491f269abc7e7d3af52d95f6a26c1c2aa0d0121037f88a6ccdd608645024b05f408324550cf6fa1c74e3d7c1f94a1e9b57369d10600000000 data2json n.-1 vs len.247 + + +//ScriptSig: PUSHDATA(34)[002072d8f7debd607b94c95ced6cff38265ed99c7c1ee58b67d0a3f3ed43b6d9a977] +//Witness: 040047304402206f23bb2dd06bc70d78312e27d53954420d0defbda7ad638718b9dc2c1efb93100220270f79bfb3230194d2e625875073799f6f07d96d5bce43b19cfe6be9957d95540148304502210081842f5987009e65f1d7de6140433da541b9da52ed211e87e1ae6fc25260d7680220798de97c682541d7b26b0795b19994f045f3ef4f433c55da0b5f1506ddeec413014752210305345798069ac85285628732485a3ce7e96b85696ed7da72287f6eae3b275363210268aace9c841b8d61fe3532981c8b25e235690003916c5a90c23a708e5d8f929752ae + #include struct LP_millistats { diff --git a/iguana/exchanges/LP_tradebots.c b/iguana/exchanges/LP_tradebots.c index a0b4406cb..1f6fa7c48 100644 --- a/iguana/exchanges/LP_tradebots.c +++ b/iguana/exchanges/LP_tradebots.c @@ -481,7 +481,7 @@ char *LP_tradebot_buy(int32_t dispdir,char *base,char *rel,double maxprice,doubl 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 ) + if ( dstr(abalance) < relvolume && balance > sum+txfee ) { retjson = cJSON_CreateObject(); jaddstr(retjson,"error","not enough funds"); From 989bffe20a0b7d7e10520db1cedfce86edb42d4c Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Nov 2017 20:38:14 +0200 Subject: [PATCH 015/306] Test --- iguana/exchanges/LP_bitcoin.c | 28 ++++++++++++++++++---------- iguana/exchanges/LP_ordermatch.c | 24 +++++++++++++++++------- 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/iguana/exchanges/LP_bitcoin.c b/iguana/exchanges/LP_bitcoin.c index cd70c13d4..4106f0399 100644 --- a/iguana/exchanges/LP_bitcoin.c +++ b/iguana/exchanges/LP_bitcoin.c @@ -3328,18 +3328,9 @@ int32_t iguana_rwjoinsplit(int32_t rwflag,uint8_t *serialized,struct iguana_msgj return(len); } -/* - normal: nVersion|txins|txouts|nLockTime. - segwit - nVersion|marker|flag|txins|txouts|witness|nLockTime -Format of nVersion, txins, txouts, and nLockTime are same as the original format -The marker MUST be 0x00 -The flag MUST be 0x01 -*/ - int32_t iguana_rwmsgtx(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t isPoS,int32_t height,int32_t rwflag,cJSON *json,uint8_t *serialized,int32_t maxsize,struct iguana_msgtx *msg,bits256 *txidp,char *vpnstr,uint8_t *extraspace,int32_t extralen,cJSON *vins,int32_t suppress_pubkeys,int32_t zcash) { - int32_t i,n,len = 0,extraused=0; uint8_t spendscript[IGUANA_MAXSCRIPTSIZE],*txstart = serialized,*sigser=0; char txidstr[65]; cJSON *vinarray=0,*voutarray=0; bits256 sigtxid; + int32_t i,n,len = 0,extraused=0; uint8_t segwitflag=0,spendscript[IGUANA_MAXSCRIPTSIZE],*txstart = serialized,*sigser=0; char txidstr[65]; cJSON *vinarray=0,*voutarray=0; bits256 sigtxid; len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->version),&msg->version); if ( json != 0 ) @@ -3359,6 +3350,19 @@ int32_t iguana_rwmsgtx(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t is if ( json != 0 ) jaddnum(json,"timestamp",msg->timestamp); } + if ( rwflag == 0 ) + { + /* + normal: nVersion|txins|txouts|nLockTime. + segwit + nVersion|marker|flag|txins|txouts|witness|nLockTime + Format of nVersion, txins, txouts, and nLockTime are same as the original format + The marker MUST be 0x00 + The flag MUST be 0x01 + */ + if ( serialized[len] == 0x00 && (segwitflag= serialized[len+1]) == 0x01 ) + len += 2; + } len += iguana_rwvarint32(rwflag,&serialized[len],&msg->tx_in); if ( rwflag == 0 ) { @@ -3425,6 +3429,10 @@ int32_t iguana_rwmsgtx(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t is } if ( voutarray != 0 ) jaddi(voutarray,iguana_voutjson(taddr,pubtype,p2shtype,&msg->vouts[i],i,*txidp)); + } + if ( segwitflag != 0 ) + { + } len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->lock_time),&msg->lock_time); //printf("lock_time.%08x len.%d\n",msg->lock_time,len); diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 57e8d451b..5a9b2031b 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -20,6 +20,7 @@ // struct LP_quoteinfo LP_Alicequery; double LP_Alicemaxprice; +bits256 LP_Alicedestpubkey; uint32_t Alice_expiration; struct { uint64_t aliceid; double bestprice; uint32_t starttime,counter; } Bob_competition[512]; @@ -455,7 +456,7 @@ int32_t LP_connectstartbob(void *ctx,int32_t pubsock,struct LP_utxoinfo *utxo,cJ return(retval); } -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) +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,bits256 destpubkey) { 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; if ( (aliceutxo= LP_utxopairfind(0,qp->desttxid,qp->destvout,qp->feetxid,qp->feevout)) == 0 ) @@ -469,14 +470,16 @@ char *LP_trade(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo *q qp->aliceid = LP_aliceid_calc(qp->desttxid,qp->destvout,qp->feetxid,qp->feevout); qp->tradeid = tradeid; LP_query(ctx,myipaddr,mypubsock,"request",qp); - LP_Alicequery = *qp, LP_Alicemaxprice = maxprice, Alice_expiration = qp->timestamp + timeout; - printf("LP_trade %s/%s %.8f vol %.8f\n",qp->srccoin,qp->destcoin,dstr(qp->satoshis),dstr(qp->destsatoshis)); + LP_Alicequery = *qp, LP_Alicemaxprice = maxprice, Alice_expiration = qp->timestamp + timeout, LP_Alicedestpubkey = destpubkey; + char str[65]; printf("LP_trade %s/%s %.8f vol %.8f dest.(%s)\n",qp->srccoin,qp->destcoin,dstr(qp->satoshis),dstr(qp->destsatoshis),bits256_str(str,LP_Alicedestpubkey)); return(LP_recent_swaps(0)); } int32_t LP_quotecmp(struct LP_quoteinfo *qp,struct LP_quoteinfo *qp2) { - if ( bits256_cmp(qp->desthash,qp2->desthash) == 0 && strcmp(qp->srccoin,qp2->srccoin) == 0 && strcmp(qp->destcoin,qp2->destcoin) == 0 && bits256_cmp(qp->desttxid,qp2->desttxid) == 0 && qp->destvout == qp2->destvout && bits256_cmp(qp->feetxid,qp2->feetxid) == 0 && qp->feevout == qp2->feevout && qp->destsatoshis == qp2->destsatoshis && qp->txfee >= qp2->txfee && qp->desttxfee == qp2->desttxfee ) //bits256_cmp(qp->srchash,qp2->srchash) == 0 && + if ( bits256_nonz(LP_Alicedestpubkey) != 0 && bits256_cmp(LP_Alicedestpubkey,qp->srchash) != 0 ) + return(-1); + else if ( bits256_cmp(qp->desthash,qp2->desthash) == 0 && strcmp(qp->srccoin,qp2->srccoin) == 0 && strcmp(qp->destcoin,qp2->destcoin) == 0 && bits256_cmp(qp->desttxid,qp2->desttxid) == 0 && qp->destvout == qp2->destvout && bits256_cmp(qp->feetxid,qp2->feetxid) == 0 && qp->feevout == qp2->feevout && qp->destsatoshis == qp2->destsatoshis && qp->txfee >= qp2->txfee && qp->desttxfee == qp2->desttxfee ) //bits256_cmp(qp->srchash,qp2->srchash) == 0 && return(0); else return(-1); } @@ -487,6 +490,7 @@ int32_t LP_alice_eligible() { printf("time expired for Alice_request\n"); memset(&LP_Alicequery,0,sizeof(LP_Alicequery)); + memset(&LP_Alicedestpubkey,0,sizeof(LP_Alicedestpubkey)); LP_Alicemaxprice = 0.; Alice_expiration = 0; } @@ -503,6 +507,7 @@ void LP_reserved(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo { qp->tradeid = LP_Alicequery.tradeid; memset(&LP_Alicequery,0,sizeof(LP_Alicequery)); + memset(&LP_Alicedestpubkey,0,sizeof(LP_Alicedestpubkey)); LP_Alicemaxprice = 0.; Alice_expiration = 0; printf("send CONNECT\n"); @@ -723,6 +728,11 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, //printf("aliceid.%llx price %.8f -> bestprice %.8f\n",(long long)aliceid,qprice,bestprice); if ( LP_Alicemaxprice == 0. ) return(retval); + if ( bits256_nonz(LP_Alicedestpubkey) != 0 && bits256_cmp(LP_Alicedestpubkey,Q.srchash) != 0 ) + { + printf("got reserved response from different node\n"); + return(retval); + } if ( bits256_cmp(G.LP_mypub25519,Q.desthash) == 0 && bits256_cmp(G.LP_mypub25519,Q.srchash) != 0 && LP_alice_eligible() > 0 ) { if ( (qprice= LP_quote_validate(autxo,butxo,&Q,0)) <= SMALLVAL ) @@ -801,7 +811,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, { 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 ) + if ( bits256_nonz(Q.srchash) == 0 || 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); @@ -1132,7 +1142,7 @@ char *LP_autobuy(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel 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)); + return(LP_trade(ctx,myipaddr,mypubsock,&Q,maxprice,timeout,duration,tradeid,destpubkey)); LP_RTmetrics_update(base,rel); while ( 1 ) @@ -1172,7 +1182,7 @@ char *LP_autobuy(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel else return(clonestr("{\"error\":\"cant ordermatch to destpubkey\"}")); } printf("i.%d maxiters.%d qprice %.8f vs maxprice %.8f\n",i,maxiters,dstr(qprice),dstr(maxprice)); - return(LP_trade(ctx,myipaddr,mypubsock,&Q,maxprice,timeout,duration,tradeid)); + return(LP_trade(ctx,myipaddr,mypubsock,&Q,maxprice,timeout,duration,tradeid,destpubkey)); } return(clonestr("{\"error\":\"cant get here\"}")); } From 147d0b124998af842aa49d554abd8c020f2005c7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Nov 2017 20:47:50 +0200 Subject: [PATCH 016/306] Test --- iguana/exchanges/LP_bitcoin.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_bitcoin.c b/iguana/exchanges/LP_bitcoin.c index 4106f0399..f2ebd671d 100644 --- a/iguana/exchanges/LP_bitcoin.c +++ b/iguana/exchanges/LP_bitcoin.c @@ -3330,7 +3330,7 @@ int32_t iguana_rwjoinsplit(int32_t rwflag,uint8_t *serialized,struct iguana_msgj int32_t iguana_rwmsgtx(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t isPoS,int32_t height,int32_t rwflag,cJSON *json,uint8_t *serialized,int32_t maxsize,struct iguana_msgtx *msg,bits256 *txidp,char *vpnstr,uint8_t *extraspace,int32_t extralen,cJSON *vins,int32_t suppress_pubkeys,int32_t zcash) { - int32_t i,n,len = 0,extraused=0; uint8_t segwitflag=0,spendscript[IGUANA_MAXSCRIPTSIZE],*txstart = serialized,*sigser=0; char txidstr[65]; cJSON *vinarray=0,*voutarray=0; bits256 sigtxid; + int32_t i,n,len = 0,extraused=0; uint32_t seglen; uint8_t segwitflag=0,spendscript[IGUANA_MAXSCRIPTSIZE],*txstart = serialized,*sigser=0; char txidstr[65]; cJSON *vinarray=0,*voutarray=0; bits256 sigtxid; len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->version),&msg->version); if ( json != 0 ) @@ -3432,7 +3432,14 @@ int32_t iguana_rwmsgtx(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t is } if ( segwitflag != 0 ) { - + if ( rwflag != 0 ) + printf("unsupported rwflag.%d when segwitflag\n",rwflag); + else + { + len += iguana_rwvarint32(rwflag,&serialized[len],&seglen); + if ( seglen+len < maxsize ) + len += maxsize; + } } len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->lock_time),&msg->lock_time); //printf("lock_time.%08x len.%d\n",msg->lock_time,len); From a3c72ca74d911627e13d94d19aa0f56d64c7fc6a Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Nov 2017 20:55:00 +0200 Subject: [PATCH 017/306] Test --- iguana/exchanges/LP_bitcoin.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/iguana/exchanges/LP_bitcoin.c b/iguana/exchanges/LP_bitcoin.c index f2ebd671d..d408de24d 100644 --- a/iguana/exchanges/LP_bitcoin.c +++ b/iguana/exchanges/LP_bitcoin.c @@ -3361,7 +3361,10 @@ int32_t iguana_rwmsgtx(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t is The flag MUST be 0x01 */ if ( serialized[len] == 0x00 && (segwitflag= serialized[len+1]) == 0x01 ) + { len += 2; + printf("SEGWIT transaction\n"); + } } len += iguana_rwvarint32(rwflag,&serialized[len],&msg->tx_in); if ( rwflag == 0 ) @@ -3437,6 +3440,7 @@ int32_t iguana_rwmsgtx(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t is else { len += iguana_rwvarint32(rwflag,&serialized[len],&seglen); + printf("witness len.%d sum %d vs max.%d\n",seglen,seglen+len,maxsize); if ( seglen+len < maxsize ) len += maxsize; } From 61368ea65751d22aa465fafa525682c025f84d85 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Nov 2017 21:00:04 +0200 Subject: [PATCH 018/306] Test --- iguana/exchanges/LP_bitcoin.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iguana/exchanges/LP_bitcoin.c b/iguana/exchanges/LP_bitcoin.c index d408de24d..5e4e78a33 100644 --- a/iguana/exchanges/LP_bitcoin.c +++ b/iguana/exchanges/LP_bitcoin.c @@ -3366,6 +3366,7 @@ int32_t iguana_rwmsgtx(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t is printf("SEGWIT transaction\n"); } } + printf("segwit.%d \n",segwitflag); len += iguana_rwvarint32(rwflag,&serialized[len],&msg->tx_in); if ( rwflag == 0 ) { From feb53d0648a797fa49d99b2c7b9286b3108ed076 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Nov 2017 21:02:50 +0200 Subject: [PATCH 019/306] Test --- iguana/exchanges/LP_bitcoin.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_bitcoin.c b/iguana/exchanges/LP_bitcoin.c index 5e4e78a33..ab3bd968a 100644 --- a/iguana/exchanges/LP_bitcoin.c +++ b/iguana/exchanges/LP_bitcoin.c @@ -3628,7 +3628,7 @@ cJSON *bitcoin_data2json(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t txobj = cJSON_CreateObject(); jaddstr(txobj,"error","couldnt decode transaction"); } - //printf("msgtx.(%s)\n",jprint(txobj,0)); + printf("msgtx.(%s)\n",jprint(txobj,0)); if ( n != len ) { int32_t i; From 5bc027c57b8d50206b5d86090d8987e3591168c5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Nov 2017 21:05:18 +0200 Subject: [PATCH 020/306] Test --- iguana/exchanges/LP_bitcoin.c | 4 ++-- iguana/exchanges/LP_socket.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_bitcoin.c b/iguana/exchanges/LP_bitcoin.c index ab3bd968a..c934ea48e 100644 --- a/iguana/exchanges/LP_bitcoin.c +++ b/iguana/exchanges/LP_bitcoin.c @@ -3628,11 +3628,11 @@ cJSON *bitcoin_data2json(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t txobj = cJSON_CreateObject(); jaddstr(txobj,"error","couldnt decode transaction"); } - printf("msgtx.(%s)\n",jprint(txobj,0)); + //printf("msgtx.(%s)\n",jprint(txobj,0)); if ( n != len ) { int32_t i; - for (i=0; iserialized != 0 ) { - //char str[65]; printf("%s cache hit -> TRANSACTION.(%s)\n",symbol,bits256_str(str,txid)); + char str[65]; printf("%s cache hit -> TRANSACTION.(%s)\n",symbol,bits256_str(str,txid)); if ( (txobj= LP_transaction_fromdata(coin,txid,tx->serialized,tx->len)) != 0 ) { *retjsonp = txobj; From 3df69fab0a75c942661faec84ca87b98a623777b Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Nov 2017 21:08:36 +0200 Subject: [PATCH 021/306] Test --- iguana/exchanges/LP_ordermatch.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 5a9b2031b..cb9a88bf9 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -477,9 +477,15 @@ char *LP_trade(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo *q int32_t LP_quotecmp(struct LP_quoteinfo *qp,struct LP_quoteinfo *qp2) { - if ( bits256_nonz(LP_Alicedestpubkey) != 0 && bits256_cmp(LP_Alicedestpubkey,qp->srchash) != 0 ) - return(-1); - else if ( bits256_cmp(qp->desthash,qp2->desthash) == 0 && strcmp(qp->srccoin,qp2->srccoin) == 0 && strcmp(qp->destcoin,qp2->destcoin) == 0 && bits256_cmp(qp->desttxid,qp2->desttxid) == 0 && qp->destvout == qp2->destvout && bits256_cmp(qp->feetxid,qp2->feetxid) == 0 && qp->feevout == qp2->feevout && qp->destsatoshis == qp2->destsatoshis && qp->txfee >= qp2->txfee && qp->desttxfee == qp2->desttxfee ) //bits256_cmp(qp->srchash,qp2->srchash) == 0 && + if ( bits256_nonz(LP_Alicedestpubkey) != 0 ) + { + if (bits256_cmp(LP_Alicedestpubkey,qp->srchash) != 0 ) + { + printf("reject quote from non-matching pubkey\n"); + return(-1); + } else printf("dont reject quote from destpubkey\n"); + } + if ( bits256_cmp(qp->desthash,qp2->desthash) == 0 && strcmp(qp->srccoin,qp2->srccoin) == 0 && strcmp(qp->destcoin,qp2->destcoin) == 0 && bits256_cmp(qp->desttxid,qp2->desttxid) == 0 && qp->destvout == qp2->destvout && bits256_cmp(qp->feetxid,qp2->feetxid) == 0 && qp->feevout == qp2->feevout && qp->destsatoshis == qp2->destsatoshis && qp->txfee >= qp2->txfee && qp->desttxfee == qp2->desttxfee ) //bits256_cmp(qp->srchash,qp2->srchash) == 0 && return(0); else return(-1); } @@ -728,10 +734,13 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, //printf("aliceid.%llx price %.8f -> bestprice %.8f\n",(long long)aliceid,qprice,bestprice); if ( LP_Alicemaxprice == 0. ) return(retval); - if ( bits256_nonz(LP_Alicedestpubkey) != 0 && bits256_cmp(LP_Alicedestpubkey,Q.srchash) != 0 ) + if ( bits256_nonz(LP_Alicedestpubkey) != 0 ) { - printf("got reserved response from different node\n"); - return(retval); + if (bits256_cmp(LP_Alicedestpubkey,Q.srchash) != 0 ) + { + printf("got reserved response from different node %s\n",bits256_str(str,Q.srchash)); + return(retval); + } else printf("got reserved response from destpubkey %s\n",bits256_str(str,Q.srchash)); } if ( bits256_cmp(G.LP_mypub25519,Q.desthash) == 0 && bits256_cmp(G.LP_mypub25519,Q.srchash) != 0 && LP_alice_eligible() > 0 ) { From 6f5bb98d6b3d2a978447bb70e812efe43f351622 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Nov 2017 21:13:26 +0200 Subject: [PATCH 022/306] Test --- iguana/exchanges/LP_bitcoin.c | 3 +-- iguana/exchanges/LP_socket.c | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_bitcoin.c b/iguana/exchanges/LP_bitcoin.c index c934ea48e..19c34cf6b 100644 --- a/iguana/exchanges/LP_bitcoin.c +++ b/iguana/exchanges/LP_bitcoin.c @@ -3350,7 +3350,7 @@ int32_t iguana_rwmsgtx(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t is if ( json != 0 ) jaddnum(json,"timestamp",msg->timestamp); } - if ( rwflag == 0 ) + if ( rwflag == 0 && zcash == 0 ) { /* normal: nVersion|txins|txouts|nLockTime. @@ -3366,7 +3366,6 @@ int32_t iguana_rwmsgtx(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t is printf("SEGWIT transaction\n"); } } - printf("segwit.%d \n",segwitflag); len += iguana_rwvarint32(rwflag,&serialized[len],&msg->tx_in); if ( rwflag == 0 ) { diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 673412be8..96855e6d7 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -681,12 +681,12 @@ cJSON *LP_cache_transaction(struct iguana_info *coin,bits256 txid,uint8_t *seria cJSON *_electrum_transaction(char *symbol,struct electrum_info *ep,cJSON **retjsonp,bits256 txid) { char *hexstr,str[65]; int32_t len; cJSON *hexjson,*txobj=0; struct iguana_info *coin; uint8_t *serialized; struct LP_transaction *tx; - printf("electrum_transaction %s %s\n",symbol,bits256_str(str,txid)); + //printf("electrum_transaction %s %s\n",symbol,bits256_str(str,txid)); if ( bits256_nonz(txid) != 0 && (coin= LP_coinfind(symbol)) != 0 ) { if ( (tx= LP_transactionfind(coin,txid)) != 0 && tx->serialized != 0 ) { - char str[65]; printf("%s cache hit -> TRANSACTION.(%s)\n",symbol,bits256_str(str,txid)); + //char str[65]; printf("%s cache hit -> TRANSACTION.(%s)\n",symbol,bits256_str(str,txid)); if ( (txobj= LP_transaction_fromdata(coin,txid,tx->serialized,tx->len)) != 0 ) { *retjsonp = txobj; From e84cf291f30d757137bf896c16e65a93b83842a5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Nov 2017 21:19:00 +0200 Subject: [PATCH 023/306] Test --- iguana/exchanges/LP_bitcoin.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iguana/exchanges/LP_bitcoin.c b/iguana/exchanges/LP_bitcoin.c index 19c34cf6b..373af373b 100644 --- a/iguana/exchanges/LP_bitcoin.c +++ b/iguana/exchanges/LP_bitcoin.c @@ -3435,6 +3435,7 @@ int32_t iguana_rwmsgtx(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t is } if ( segwitflag != 0 ) { + printf("tx_out %d, tx_in %d %02x %02x %02x\n",msg->tx_out,msg->tx_in,serialized[len],serialized[len+1],serialized[len+2]); if ( rwflag != 0 ) printf("unsupported rwflag.%d when segwitflag\n",rwflag); else From d9cca82171819ef9885908f6f5c71af6f6278dec Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Nov 2017 21:41:39 +0200 Subject: [PATCH 024/306] Test --- iguana/exchanges/LP_socket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 96855e6d7..24aa88653 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -598,7 +598,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 ( 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 1c1c1467b273c6a4df4cfeccb77da72e30440653 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Nov 2017 21:49:48 +0200 Subject: [PATCH 025/306] 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 05ce41c36..0901d9c0b 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -540,7 +540,7 @@ void LP_coinsloop(void *_coins) if ( (retjson= electrum_address_listunspent(coin->symbol,ep,&retjson,ap->coinaddr,1)) != 0 ) free_json(retjson); } - HASH_ITER(hh,coin->addresses,ap,atmp) + if ( (ap= LP_addressfind(coin,coin->smartaddr)) != 0 ) { DL_FOREACH_SAFE(ap->utxos,up,tmp) { From 6ce04c99c883f44c9be0cb2b77d85defd662487e Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Nov 2017 22:02:01 +0200 Subject: [PATCH 026/306] 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 24aa88653..e200c5891 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -598,7 +598,7 @@ cJSON *electrum_address_listunspent(char *symbol,struct electrum_info *ep,cJSON { if ( jobj(retjson,"error") == 0 && is_cJSON_Array(retjson) != 0 ) { - if ( 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 ) @@ -707,7 +707,7 @@ cJSON *_electrum_transaction(char *symbol,struct electrum_info *ep,cJSON **retjs { static uint32_t counter; if ( counter++ < 3 ) - printf("rawtransaction too big %d\n",(int32_t)strlen(hexstr)); + printf("rawtransaction %s %s too big %d\n",coin->symbol,bits256_str(str,txid),(int32_t)strlen(hexstr)); free(hexstr); free_json(hexjson); *retjsonp = cJSON_Parse("{\"error\":\"transaction too big\"}"); From f2a39dcc835bb3bf1d3b38cb1d74958585ec2815 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Nov 2017 22:13:25 +0200 Subject: [PATCH 027/306] Test --- iguana/exchanges/LP_transaction.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index bc582236c..6990da6e6 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -978,7 +978,7 @@ int32_t LP_vins_select(void *ctx,struct iguana_info *coin,int64_t *totalp,int64_ char str[65]; printf("%s/%d %.8f interest %.8f -> sum %.8f\n",bits256_str(str,up->U.txid),up->U.vout,dstr(up->U.value),dstr(interest),dstr(interestsum)); } } - printf("numunspents.%d vini.%d value %.8f, total %.8f remains %.8f interest %.8f sum %.8f\n",numunspents,n,dstr(up->U.value),dstr(total),dstr(remains),dstr(interest),dstr(interestsum)); + printf("numunspents.%d vini.%d value %.8f, total %.8f remains %.8f interest %.8f sum %.8f %s/v%d\n",numunspents,n,dstr(up->U.value),dstr(total),dstr(remains),dstr(interest),dstr(interestsum),bits256_str(str,up->U.txid),up->U.vout); vp = &V[n++]; vp->N = vp->M = 1; vp->signers[0].privkey = privkey; @@ -1059,6 +1059,10 @@ char *LP_createrawtransaction(cJSON **txobjp,int32_t *numvinsp,struct iguana_inf printf("LP_createrawtransaction: address_utxo_ptrs %d, error\n",numutxos); //return(0); } + char str[65]; + for (i=0; iU.txid),utxos[i]->U.vout,dstr(utxos[i]->U.value)); + ignore_cltverr = 0; suppress_pubkeys = 1; scriptlen = bitcoin_standardspend(script,0,G.LP_myrmd160); From 0a84293c5d2c2f3acef0f22299d6314c29ffea3c Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Nov 2017 22:29:15 +0200 Subject: [PATCH 028/306] Test --- iguana/exchanges/LP_transaction.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index 6990da6e6..8ee70ca89 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -1002,7 +1002,7 @@ int32_t LP_vins_select(void *ctx,struct iguana_info *coin,int64_t *totalp,int64_ char *LP_createrawtransaction(cJSON **txobjp,int32_t *numvinsp,struct iguana_info *coin,struct vin_info *V,int32_t max,bits256 privkey,cJSON *outputs,cJSON *vins,cJSON *privkeys,int64_t txfee,bits256 utxotxid,int32_t utxovout,uint32_t locktime) { static void *ctx; - cJSON *txobj,*item; uint8_t addrtype,rmd160[20],script[64],spendscript[256]; char *coinaddr,*rawtxbytes; bits256 txid; uint32_t timestamp; int64_t change=0,adjust=0,total,value,amount = 0; int32_t i,dustcombine,scriptlen,spendlen,suppress_pubkeys,ignore_cltverr,numvouts=0,numvins=0,numutxos=0; struct LP_address_utxo *utxos[LP_MAXVINS]; struct LP_address *ap; + cJSON *txobj,*item,*array; uint8_t addrtype,rmd160[20],script[64],spendscript[256]; char *coinaddr,*rawtxbytes; bits256 txid; uint32_t timestamp; int64_t change=0,adjust=0,total,value,amount = 0; int32_t i,n,dustcombine,scriptlen,spendlen,suppress_pubkeys,ignore_cltverr,numvouts=0,numvins=0,numutxos=0; struct LP_address_utxo *utxos[LP_MAXVINS]; struct LP_address *ap; if ( ctx == 0 ) ctx = bitcoin_ctx(); *numvinsp = 0; @@ -1047,13 +1047,31 @@ char *LP_createrawtransaction(cJSON **txobjp,int32_t *numvinsp,struct iguana_inf return(0); } } - LP_listunspent_issue(coin->symbol,coin->smartaddr,1); + LP_listunspent_issue(coin->symbol,coin->smartaddr,2); if ( (ap= LP_addressfind(coin,coin->smartaddr)) == 0 ) { printf("LP_createrawtransaction: cant find address data\n"); return(0); } memset(utxos,0,sizeof(utxos)); + if ( (array= LP_listunspent(coin->symbol,coin->smartaddr)) != 0 ) + { + int32_t vout,height; + ap->utxos = 0; + if ( (n= cJSON_GetArraySize(array)) > 0 ) + { + for (i=0; ismartaddr,txid,vout,value,height,-1); + } + } + } if ( (numutxos= LP_address_utxo_ptrs(coin,0,utxos,max,ap,coin->smartaddr)) <= 0 ) { printf("LP_createrawtransaction: address_utxo_ptrs %d, error\n",numutxos); From 7923b76d4311dd722f79c092fa4296f8bccae0ed Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Nov 2017 22:39:19 +0200 Subject: [PATCH 029/306] Test --- iguana/exchanges/LP_commands.c | 10 +++--- iguana/exchanges/LP_nativeDEX.c | 2 +- iguana/exchanges/LP_transaction.c | 56 ++++++++++++++++++------------- iguana/exchanges/LP_utxos.c | 1 + 4 files changed, 40 insertions(+), 29 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 9d0f4ff47..a084c0e0d 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -103,7 +103,7 @@ notarizations(coin)\n\ parselog()\n\ statsdisp(starttime=0, endtime=0, gui="", pubkey="")\n\ getrawtransaction(coin, txid)\n\ -inventory(coin)\n\ +inventory(coin, reset=0)\n\ bestfit(rel, relvolume)\n\ lastnonce()\n\ buy(base, rel, price, relvolume, timeout=10, duration=3600, nonce, destpubkey="")\n\ @@ -484,10 +484,12 @@ bot_resume(botid)\n\ struct iguana_info *ptr; if ( (ptr= LP_coinfind(coin)) != 0 ) { - //privkey = LP_privkeycalc(ctx,pubkey33,&pubkey,ptr,"",USERPASS_WIFSTR); - //LP_utxopurge(0); LP_address(ptr,ptr->smartaddr); - LP_listunspent_issue(coin,ptr->smartaddr,2); + if ( jint(argjson,"reset") != 0 ) + { + LP_address_utxo_reset(ptr); + LP_passphrase_init(G.PASSPHRASE,G.gui); + } if ( bits256_nonz(G.LP_privkey) != 0 ) LP_privkey_init(-1,ptr,G.LP_privkey,G.LP_mypub25519); else printf("no LP_privkey\n"); diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 0901d9c0b..047c485c9 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -122,7 +122,7 @@ struct LP_globals uint8_t LP_myrmd160[20],LP_pubsecp[33]; uint32_t LP_sessionid,counter; int32_t LP_IAMLP,LP_pendingswaps,USERPASS_COUNTER,LP_numprivkeys,initializing,waiting,LP_numskips; - char USERPASS[65],USERPASS_WIFSTR[64],LP_myrmd160str[41],gui[16]; + char USERPASS[65],USERPASS_WIFSTR[64],PASSPHRASE[1024],LP_myrmd160str[41],gui[16]; struct LP_privkey LP_privkeys[100]; } G; diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index 8ee70ca89..574fcbbb2 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -999,10 +999,40 @@ int32_t LP_vins_select(void *ctx,struct iguana_info *coin,int64_t *totalp,int64_ return(n); } +struct LP_address *LP_address_utxo_reset(struct iguana_info *coin) +{ + struct LP_address *ap; int32_t i,n; cJSON *array,*item; int64_t value; bits256 txid; int32_t vout,height; + LP_listunspent_issue(coin->symbol,coin->smartaddr,2); + if ( (ap= LP_addressfind(coin,coin->smartaddr)) == 0 ) + { + printf("LP_createrawtransaction: cant find address data\n"); + return(0); + } + if ( (array= LP_listunspent(coin->symbol,coin->smartaddr)) != 0 ) + { + ap->utxos = 0; + if ( (n= cJSON_GetArraySize(array)) > 0 ) + { + for (i=0; ismartaddr,txid,vout,value,height,-1); + } + } + free_json(array); + } + return(ap); +} + char *LP_createrawtransaction(cJSON **txobjp,int32_t *numvinsp,struct iguana_info *coin,struct vin_info *V,int32_t max,bits256 privkey,cJSON *outputs,cJSON *vins,cJSON *privkeys,int64_t txfee,bits256 utxotxid,int32_t utxovout,uint32_t locktime) { static void *ctx; - cJSON *txobj,*item,*array; uint8_t addrtype,rmd160[20],script[64],spendscript[256]; char *coinaddr,*rawtxbytes; bits256 txid; uint32_t timestamp; int64_t change=0,adjust=0,total,value,amount = 0; int32_t i,n,dustcombine,scriptlen,spendlen,suppress_pubkeys,ignore_cltverr,numvouts=0,numvins=0,numutxos=0; struct LP_address_utxo *utxos[LP_MAXVINS]; struct LP_address *ap; + cJSON *txobj,*item; uint8_t addrtype,rmd160[20],script[64],spendscript[256]; char *coinaddr,*rawtxbytes; bits256 txid; uint32_t timestamp; int64_t change=0,adjust=0,total,value,amount = 0; int32_t i,dustcombine,scriptlen,spendlen,suppress_pubkeys,ignore_cltverr,numvouts=0,numvins=0,numutxos=0; struct LP_address_utxo *utxos[LP_MAXVINS]; struct LP_address *ap; if ( ctx == 0 ) ctx = bitcoin_ctx(); *numvinsp = 0; @@ -1047,31 +1077,9 @@ char *LP_createrawtransaction(cJSON **txobjp,int32_t *numvinsp,struct iguana_inf return(0); } } - LP_listunspent_issue(coin->symbol,coin->smartaddr,2); - if ( (ap= LP_addressfind(coin,coin->smartaddr)) == 0 ) - { - printf("LP_createrawtransaction: cant find address data\n"); + if ( (ap= LP_address_utxo_reset(coin)) == 0 ) return(0); - } memset(utxos,0,sizeof(utxos)); - if ( (array= LP_listunspent(coin->symbol,coin->smartaddr)) != 0 ) - { - int32_t vout,height; - ap->utxos = 0; - if ( (n= cJSON_GetArraySize(array)) > 0 ) - { - for (i=0; ismartaddr,txid,vout,value,height,-1); - } - } - } if ( (numutxos= LP_address_utxo_ptrs(coin,0,utxos,max,ap,coin->smartaddr)) <= 0 ) { printf("LP_createrawtransaction: address_utxo_ptrs %d, error\n",numutxos); diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 2d5a04915..3fbf10371 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -870,6 +870,7 @@ int32_t LP_passphrase_init(char *passphrase,char *gui) } } memset(&G,0,sizeof(G)); + strcpy(G.PASSPHRASE,passphrase); LP_privkey_updates(ctx,LP_mypubsock,passphrase); init_hexbytes_noT(G.LP_myrmd160str,G.LP_myrmd160,20); G.LP_sessionid = (uint32_t)time(NULL); From f955f2a28f3587bd89ae4fab1738a1aa7cd1790d Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Nov 2017 22:42:30 +0200 Subject: [PATCH 030/306] Test --- iguana/exchanges/LP_utxos.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 3fbf10371..0c7fa39a5 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -870,12 +870,13 @@ int32_t LP_passphrase_init(char *passphrase,char *gui) } } memset(&G,0,sizeof(G)); - strcpy(G.PASSPHRASE,passphrase); LP_privkey_updates(ctx,LP_mypubsock,passphrase); init_hexbytes_noT(G.LP_myrmd160str,G.LP_myrmd160,20); G.LP_sessionid = (uint32_t)time(NULL); safecopy(G.gui,gui,sizeof(G.gui)); G.USERPASS_COUNTER = counter; + strcpy(G.PASSPHRASE,passphrase); + printf("set PASSPHRASE.(%s)\n",G.PASSPHRASE); G.initializing = 0; return(0); } From b9cc5ba6bb6d002628e6be7b09a7afe1b11ce8ff Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Nov 2017 22:46:20 +0200 Subject: [PATCH 031/306] Test --- iguana/exchanges/LP_commands.c | 4 ++-- iguana/exchanges/LP_nativeDEX.c | 2 +- iguana/exchanges/LP_utxos.c | 2 -- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index a084c0e0d..9e68ead18 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -103,7 +103,7 @@ notarizations(coin)\n\ parselog()\n\ statsdisp(starttime=0, endtime=0, gui="", pubkey="")\n\ getrawtransaction(coin, txid)\n\ -inventory(coin, reset=0)\n\ +inventory(coin, reset=0, [passphrase=])\n\ bestfit(rel, relvolume)\n\ lastnonce()\n\ buy(base, rel, price, relvolume, timeout=10, duration=3600, nonce, destpubkey="")\n\ @@ -488,7 +488,7 @@ bot_resume(botid)\n\ if ( jint(argjson,"reset") != 0 ) { LP_address_utxo_reset(ptr); - LP_passphrase_init(G.PASSPHRASE,G.gui); + LP_passphrase_init(jstr(argjson,"passphrase"),G.gui); } if ( bits256_nonz(G.LP_privkey) != 0 ) LP_privkey_init(-1,ptr,G.LP_privkey,G.LP_mypub25519); diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 047c485c9..0901d9c0b 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -122,7 +122,7 @@ struct LP_globals uint8_t LP_myrmd160[20],LP_pubsecp[33]; uint32_t LP_sessionid,counter; int32_t LP_IAMLP,LP_pendingswaps,USERPASS_COUNTER,LP_numprivkeys,initializing,waiting,LP_numskips; - char USERPASS[65],USERPASS_WIFSTR[64],PASSPHRASE[1024],LP_myrmd160str[41],gui[16]; + char USERPASS[65],USERPASS_WIFSTR[64],LP_myrmd160str[41],gui[16]; struct LP_privkey LP_privkeys[100]; } G; diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 0c7fa39a5..2d5a04915 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -875,8 +875,6 @@ int32_t LP_passphrase_init(char *passphrase,char *gui) G.LP_sessionid = (uint32_t)time(NULL); safecopy(G.gui,gui,sizeof(G.gui)); G.USERPASS_COUNTER = counter; - strcpy(G.PASSPHRASE,passphrase); - printf("set PASSPHRASE.(%s)\n",G.PASSPHRASE); G.initializing = 0; return(0); } From 1d7ac2dc9da2ef963acc7dce01e03e696ff1bfb3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Nov 2017 22:55:29 +0200 Subject: [PATCH 032/306] Test --- iguana/exchanges/LP_commands.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 9e68ead18..eda89f9f7 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -488,6 +488,7 @@ bot_resume(botid)\n\ if ( jint(argjson,"reset") != 0 ) { LP_address_utxo_reset(ptr); + ptr->privkeydepth = 0; LP_passphrase_init(jstr(argjson,"passphrase"),G.gui); } if ( bits256_nonz(G.LP_privkey) != 0 ) From 06c4d96c866f6689c26c79985497af3fe43a3842 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Nov 2017 22:56:01 +0200 Subject: [PATCH 033/306] Test --- iguana/exchanges/LP_commands.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index eda89f9f7..3aca6ee1c 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -484,11 +484,11 @@ bot_resume(botid)\n\ struct iguana_info *ptr; if ( (ptr= LP_coinfind(coin)) != 0 ) { + ptr->privkeydepth = 0; LP_address(ptr,ptr->smartaddr); if ( jint(argjson,"reset") != 0 ) { LP_address_utxo_reset(ptr); - ptr->privkeydepth = 0; LP_passphrase_init(jstr(argjson,"passphrase"),G.gui); } if ( bits256_nonz(G.LP_privkey) != 0 ) From d716a534da7412222b4a2542e2d1da1c4d4b9f2d Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Nov 2017 23:01:06 +0200 Subject: [PATCH 034/306] Test --- iguana/exchanges/LP_socket.c | 2 +- iguana/exchanges/install | 2 +- iguana/exchanges/invreset | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-) create mode 100755 iguana/exchanges/invreset diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index e200c5891..282124a6f 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -598,7 +598,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 ( 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/install b/iguana/exchanges/install index 86709f0ab..efb2c7a2e 100755 --- a/iguana/exchanges/install +++ b/iguana/exchanges/install @@ -1,5 +1,5 @@ #!/bin/bash -cp sendrawtransaction processfiles stop millis mnzservers bot_buy bot_list bot_statuslist bot_pause bot_resume bot_sell bot_settings bot_status bot_stop guistats pubkeystats pendings coinswaps baserelswaps setpassphrase notarizations getrawtransaction parselog statsdisp m_js trust trusted setconfirms balance listunspent electrum snapshot_balance snapshot_loop secretaddresses dividends snapshot goals goal portfolio autoprice deletemessages getmessages debug buy sell bestfit orderbook client run_osx client_osx run coins disable enable myprice myprices getcoins getpeers getpeersIP getprices help inv setprice status ../dexscripts +cp invreset sendrawtransaction processfiles stop millis mnzservers bot_buy bot_list bot_statuslist bot_pause bot_resume bot_sell bot_settings bot_status bot_stop guistats pubkeystats pendings coinswaps baserelswaps setpassphrase notarizations getrawtransaction parselog statsdisp m_js trust trusted setconfirms balance listunspent electrum snapshot_balance snapshot_loop secretaddresses dividends snapshot goals goal portfolio autoprice deletemessages getmessages debug buy sell bestfit orderbook client run_osx client_osx run coins disable enable myprice myprices getcoins getpeers getpeersIP getprices help inv setprice status ../dexscripts cp coins.json .. cd ../dexscripts #cp ../exchanges/passphrase ../exchanges/userpass . diff --git a/iguana/exchanges/invreset b/iguana/exchanges/invreset new file mode 100755 index 000000000..f0b1c79e3 --- /dev/null +++ b/iguana/exchanges/invreset @@ -0,0 +1,3 @@ +source userpass +source passphrase +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"inventory\",\"coin\":\"KMD\",\"reset\":1,\"passphrase\":\"$passphrase\"}" From c874bfbe676682440489d61fec213dad6074f229 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Nov 2017 23:07:33 +0200 Subject: [PATCH 035/306] Test --- iguana/exchanges/LP_commands.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 3aca6ee1c..5773bf88a 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -388,13 +388,16 @@ bot_resume(botid)\n\ if ( (ptr= LP_coinsearch(coin)) != 0 ) { char *coinaddr; + printf("listunspent\n"); if ( (coinaddr= jstr(argjson,"address")) != 0 ) { if ( coinaddr[0] != 0 ) { LP_address(ptr,coinaddr); + printf("check addr\n"); if ( strcmp(coinaddr,ptr->smartaddr) == 0 && bits256_nonz(G.LP_privkey) != 0 ) { + printf("my addr\n"); LP_listunspent_issue(coin,coinaddr,2); LP_privkey_init(-1,ptr,G.LP_privkey,G.LP_mypub25519); //LP_smartutxos_push(ptr); From 0c30756bd149e613b76405a14f58142931191381 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Nov 2017 23:15:35 +0200 Subject: [PATCH 036/306] 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 574fcbbb2..661319305 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -989,7 +989,7 @@ int32_t LP_vins_select(void *ctx,struct iguana_info *coin,int64_t *totalp,int64_ jaddi(vins,LP_inputjson(up->U.txid,up->U.vout,spendscriptstr)); if ( remains <= 0 && i >= numpre-1 ) break; - if ( numunspents == 0 ) + if ( numunspents < 0 ) { printf("total %.8f not enough for amount %.8f\n",dstr(total),dstr(amount)); return(0); From 3db4ea83ef1de3c2247ffbc9701a43aba62dbcbb Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Nov 2017 23:23:13 +0200 Subject: [PATCH 037/306] Test --- iguana/exchanges/LP_utxos.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 2d5a04915..93d6ff688 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -550,7 +550,7 @@ int32_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypri return(0); coin->privkeydepth++; LP_address(coin,coin->smartaddr); - //printf("privkey init.(%s) %s depth.%d\n",coin->symbol,coin->smartaddr,coin->privkeydepth); + 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); From 8dd3b6520637eb5e2867ffefedfd3d4f890337b7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Nov 2017 23:26:02 +0200 Subject: [PATCH 038/306] Test --- iguana/exchanges/LP_commands.c | 3 --- iguana/exchanges/LP_socket.c | 2 +- iguana/exchanges/LP_utxos.c | 6 +++--- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 5773bf88a..3aca6ee1c 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -388,16 +388,13 @@ bot_resume(botid)\n\ if ( (ptr= LP_coinsearch(coin)) != 0 ) { char *coinaddr; - printf("listunspent\n"); if ( (coinaddr= jstr(argjson,"address")) != 0 ) { if ( coinaddr[0] != 0 ) { LP_address(ptr,coinaddr); - printf("check addr\n"); if ( strcmp(coinaddr,ptr->smartaddr) == 0 && bits256_nonz(G.LP_privkey) != 0 ) { - printf("my addr\n"); LP_listunspent_issue(coin,coinaddr,2); LP_privkey_init(-1,ptr,G.LP_privkey,G.LP_mypub25519); //LP_smartutxos_push(ptr); diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 282124a6f..e200c5891 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -598,7 +598,7 @@ cJSON *electrum_address_listunspent(char *symbol,struct electrum_info *ep,cJSON { if ( jobj(retjson,"error") == 0 && is_cJSON_Array(retjson) != 0 ) { - if ( 1 && 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 ) diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 93d6ff688..770b84b89 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -542,15 +542,15 @@ int32_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypri //printf("coin not active\n"); return(0); } - if ( bits256_cmp(myprivkey,coin->lastprivkey) == 0 && time(NULL) < coin->lastprivkeytime+60 ) - return(0); + /*if ( bits256_cmp(myprivkey,coin->lastprivkey) == 0 && time(NULL) < coin->lastprivkeytime+60 ) + return(0);*/ coin->lastprivkey = myprivkey; coin->lastprivkeytime = (uint32_t)time(NULL); 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); + //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); From 0660c741744b47f62c0b78a3511d33bb068455d5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Nov 2017 23:47:27 +0200 Subject: [PATCH 039/306] 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 770b84b89..8991e141c 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -238,11 +238,11 @@ struct LP_utxoinfo *LP_utxo_bestfit(char *symbol,uint64_t destsatoshis) // jl777 remove mempool HASH_ITER(hh,G.LP_utxoinfos[iambob],utxo,tmp) { - //char str[65]; printf("s%u %d [%.8f vs %.8f] check %s.%s avail.%d ismine.%d >= %d\n",utxo->T.spentflag,LP_iseligible(&srcvalue,&srcvalue2,utxo->iambob,symbol,utxo->payment.txid,utxo->payment.vout,utxo->S.satoshis,utxo->fee.txid,utxo->fee.vout),dstr(destsatoshis),dstr(utxo->S.satoshis),utxo->coin,bits256_str(str,utxo->payment.txid),LP_isavailable(utxo) > 0,LP_ismine(utxo) > 0,utxo->S.satoshis >= destsatoshis); if ( strcmp(symbol,utxo->coin) != 0 ) continue; if ( LP_isavailable(utxo) > 0 && LP_ismine(utxo) > 0 ) { + char str[65]; printf("s%u %d [%.8f vs %.8f] check %s.%s avail.%d ismine.%d >= %d\n",utxo->T.spentflag,LP_iseligible(&srcvalue,&srcvalue2,utxo->iambob,symbol,utxo->payment.txid,utxo->payment.vout,utxo->S.satoshis,utxo->fee.txid,utxo->fee.vout),dstr(destsatoshis),dstr(utxo->S.satoshis),utxo->coin,bits256_str(str,utxo->payment.txid),LP_isavailable(utxo) > 0,LP_ismine(utxo) > 0,utxo->S.satoshis >= destsatoshis); bestsize = 0; if ( bestutxo == 0 ) { @@ -273,7 +273,7 @@ struct LP_utxoinfo *LP_utxo_bestfit(char *symbol,uint64_t destsatoshis) continue; } bestutxo = utxo; - } // else printf("skip alice utxo %.8f vs dest %.8f\n",dstr(utxo->S.satoshis),dstr(destsatoshis)); + } else printf("skip alice utxo %.8f vs dest %.8f, bestsize.%d\n",dstr(utxo->S.satoshis),dstr(destsatoshis),bestsize); } } return(bestutxo); From ca4c233201dade6d1931de95ba23cae4fa7e7607 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Nov 2017 23:55:49 +0200 Subject: [PATCH 040/306] Test --- iguana/exchanges/LP_ordermatch.c | 1 + iguana/exchanges/LP_utxos.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index cb9a88bf9..47fc78296 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -1125,6 +1125,7 @@ char *LP_autobuy(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel destsatoshis = SATOSHIDEN * relvolume; if ( (autxo= LP_utxo_bestfit(rel,destsatoshis + 2*desttxfee)) == 0 ) return(clonestr("{\"error\":\"cant find alice utxo that is big enough\"}")); + printf("bestfit selected alice (%.8f %.8f) for %.8f sats %.8f\n",dstr(autxo->payment.value),dstr(autxo->fee.value),dstr(destsatoshis),dstr(autxo->S.satoshis)); if ( destsatoshis - desttxfee < autxo->S.satoshis ) { destsatoshis -= desttxfee; diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 8991e141c..0a5546d5e 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -266,6 +266,7 @@ struct LP_utxoinfo *LP_utxo_bestfit(char *symbol,uint64_t destsatoshis) } if ( bestsize > 0 ) { + printf("bestsize.%d %.8f %.8f\n",dstr(utxo->payment.value),dstr(utxo->fee.value),dstr(utxo->S.satoshis)); if ( LP_iseligible(&srcvalue,&srcvalue2,utxo->iambob,symbol,utxo->payment.txid,utxo->payment.vout,utxo->S.satoshis,utxo->fee.txid,utxo->fee.vout) == 0 ) { //if ( utxo->T.spentflag == 0 ) @@ -273,7 +274,7 @@ struct LP_utxoinfo *LP_utxo_bestfit(char *symbol,uint64_t destsatoshis) continue; } bestutxo = utxo; - } else printf("skip alice utxo %.8f vs dest %.8f, bestsize.%d\n",dstr(utxo->S.satoshis),dstr(destsatoshis),bestsize); + } else printf("skip alice utxo %.8f vs dest %.8f, bestsize.%d %p\n",dstr(utxo->S.satoshis),dstr(destsatoshis),bestsize,bestutxo); } } return(bestutxo); From f4d9d95f7a6dd9a7eb02836125d2fa3c8a5b7d89 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Nov 2017 23:59:18 +0200 Subject: [PATCH 041/306] Test --- iguana/exchanges/LP_utxos.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 0a5546d5e..96a20984e 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -242,7 +242,8 @@ struct LP_utxoinfo *LP_utxo_bestfit(char *symbol,uint64_t destsatoshis) continue; if ( LP_isavailable(utxo) > 0 && LP_ismine(utxo) > 0 ) { - char str[65]; printf("s%u %d [%.8f vs %.8f] check %s.%s avail.%d ismine.%d >= %d\n",utxo->T.spentflag,LP_iseligible(&srcvalue,&srcvalue2,utxo->iambob,symbol,utxo->payment.txid,utxo->payment.vout,utxo->S.satoshis,utxo->fee.txid,utxo->fee.vout),dstr(destsatoshis),dstr(utxo->S.satoshis),utxo->coin,bits256_str(str,utxo->payment.txid),LP_isavailable(utxo) > 0,LP_ismine(utxo) > 0,utxo->S.satoshis >= destsatoshis); + printf("(%.8f %.8f %.8f)\n",dstr(utxo->payment.value),dstr(utxo->fee.value),dstr(utxo->S.satoshis)); + //char str[65]; printf("s%u %d [%.8f vs %.8f] check %s.%s avail.%d ismine.%d >= %d\n",utxo->T.spentflag,LP_iseligible(&srcvalue,&srcvalue2,utxo->iambob,symbol,utxo->payment.txid,utxo->payment.vout,utxo->S.satoshis,utxo->fee.txid,utxo->fee.vout),dstr(destsatoshis),dstr(utxo->S.satoshis),utxo->coin,bits256_str(str,utxo->payment.txid),LP_isavailable(utxo) > 0,LP_ismine(utxo) > 0,utxo->S.satoshis >= destsatoshis); bestsize = 0; if ( bestutxo == 0 ) { @@ -266,7 +267,7 @@ struct LP_utxoinfo *LP_utxo_bestfit(char *symbol,uint64_t destsatoshis) } if ( bestsize > 0 ) { - printf("bestsize.%d %.8f %.8f\n",dstr(utxo->payment.value),dstr(utxo->fee.value),dstr(utxo->S.satoshis)); + printf("bestsize.%d %.8f %.8f -> %.8f\n",bestsize,dstr(utxo->payment.value),dstr(utxo->fee.value),dstr(utxo->S.satoshis)); if ( LP_iseligible(&srcvalue,&srcvalue2,utxo->iambob,symbol,utxo->payment.txid,utxo->payment.vout,utxo->S.satoshis,utxo->fee.txid,utxo->fee.vout) == 0 ) { //if ( utxo->T.spentflag == 0 ) From 194a356815d786b2b7787bfc446a047347919433 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 00:04:38 +0200 Subject: [PATCH 042/306] Test --- iguana/exchanges/LP_utxos.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 96a20984e..20aadc7a9 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -414,7 +414,7 @@ struct LP_utxoinfo *LP_utxoadd(int32_t iambob,char *symbol,bits256 txid,int32_t printf("utxoadd selector.%d spent in mempool %s vini.%d",selector,bits256_str(str,spendtxid),spendvini); utxo->T.spentflag = (uint32_t)time(NULL); } - //printf(" %s %.8f %.8f %p addutxo.%d (%s %s) session.%u iambob.%d <<<<<<<<<<<<<<<\n",symbol,dstr(value),dstr(value2),utxo,LP_ismine(utxo) > 0,bits256_str(str,utxo->payment.txid),bits256_str(str2,iambob != 0 ? utxo->deposit.txid : utxo->fee.txid),utxo->T.sessionid,iambob); + printf(" %s %.8f %.8f %p addutxo.%d (%s %s) session.%u iambob.%d <<<<<<<<<<<<<<<\n",symbol,dstr(value),dstr(value2),utxo,LP_ismine(utxo) > 0,bits256_str(str,utxo->payment.txid),bits256_str(str2,iambob != 0 ? utxo->deposit.txid : utxo->fee.txid),utxo->T.sessionid,iambob); portable_mutex_lock(&LP_utxomutex); HASH_ADD_KEYPTR(hh,G.LP_utxoinfos[iambob],utxo->key,sizeof(utxo->key),utxo); if ( _LP_utxo2find(iambob,txid2,vout2) == 0 ) From e7f594d9968a26cc64054e1a6997a68c5ee6f190 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 00:11:46 +0200 Subject: [PATCH 043/306] Test --- iguana/exchanges/LP_utxos.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 20aadc7a9..5aa0d7554 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -414,7 +414,7 @@ struct LP_utxoinfo *LP_utxoadd(int32_t iambob,char *symbol,bits256 txid,int32_t printf("utxoadd selector.%d spent in mempool %s vini.%d",selector,bits256_str(str,spendtxid),spendvini); utxo->T.spentflag = (uint32_t)time(NULL); } - printf(" %s %.8f %.8f %p addutxo.%d (%s %s) session.%u iambob.%d <<<<<<<<<<<<<<<\n",symbol,dstr(value),dstr(value2),utxo,LP_ismine(utxo) > 0,bits256_str(str,utxo->payment.txid),bits256_str(str2,iambob != 0 ? utxo->deposit.txid : utxo->fee.txid),utxo->T.sessionid,iambob); + printf(" %s %.8f %.8f %p addutxo.%d (%s %s) session.%u iambob.%d <<<<<<<<<<<<<<< %.8f\n",symbol,dstr(value),dstr(value2),utxo,LP_ismine(utxo) > 0,bits256_str(str,utxo->payment.txid),bits256_str(str2,iambob != 0 ? utxo->deposit.txid : utxo->fee.txid),utxo->T.sessionid,iambob,dstr(satoshis)); portable_mutex_lock(&LP_utxomutex); HASH_ADD_KEYPTR(hh,G.LP_utxoinfos[iambob],utxo->key,sizeof(utxo->key),utxo); if ( _LP_utxo2find(iambob,txid2,vout2) == 0 ) @@ -538,7 +538,7 @@ int32_t LP_nearestvalue(int32_t iambob,uint64_t *values,int32_t n,uint64_t targe int32_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 myprivkey,bits256 mypub) { int32_t enable_utxos = 0; - char *script,destaddr[64]; struct LP_utxoinfo *utxo; cJSON *array,*item; bits256 txid,deposittxid; int32_t used,i,flag=0,height,n,cmpflag,iambob,vout,depositvout; uint64_t *values=0,satoshis,txfee,depositval,value,total = 0; int64_t targetval; + char *script,destaddr[64]; struct LP_utxoinfo *utxo; cJSON *array,*item; bits256 txid,deposittxid; int32_t used,i,flag=0,height,n,cmpflag,iambob,vout,depositvout; uint64_t *values=0,satoshis,txfee,biggerval,value,total = 0; int64_t targetval; if ( coin == 0 || (IAMLP == 0 && coin->inactive != 0) ) { //printf("coin not active\n"); @@ -617,15 +617,15 @@ int32_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypri depositvout = juint(item,"tx_pos"); script = coin->smartaddr; } - depositval = values[i]; + biggerval = values[i]; values[i] = 0, used++; if ( iambob == 0 ) - targetval = (depositval / 776) + txfee; - else targetval = (depositval / 9) * 8 + 2*txfee; + targetval = (biggerval / 776) + txfee; + else targetval = (biggerval / 9) * 8 + 2*txfee; if ( targetval < txfee*2 ) targetval = txfee*2; - //printf("iambob.%d i.%d deposit %.8f min %.8f target %.8f\n",iambob,i,dstr(depositval),dstr((1+LP_MINSIZE_TXFEEMULT)*txfee),dstr(targetval)); - if ( depositval < (1+LP_MINSIZE_TXFEEMULT)*txfee ) + //printf("iambob.%d i.%d deposit %.8f min %.8f target %.8f\n",iambob,i,dstr(biggerval),dstr((1+LP_MINSIZE_TXFEEMULT)*txfee),dstr(targetval)); + if ( biggerval < (1+LP_MINSIZE_TXFEEMULT)*txfee ) continue; i = -1; if ( iambob != 0 ) @@ -637,7 +637,7 @@ int32_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypri } if ( i >= 0 || (i= LP_nearestvalue(iambob,values,n,targetval)) >= 0 ) { - //printf("iambob.%d i.%d %.8f target %.8f\n",iambob,i,dstr(depositval),dstr(targetval)); + //printf("iambob.%d i.%d %.8f target %.8f\n",iambob,i,dstr(biggerval),dstr(targetval)); item = jitem(array,i); cmpflag = 0; if ( coin->electrum == 0 ) @@ -660,14 +660,14 @@ int32_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypri portable_mutex_lock(&LP_UTXOmutex); if ( iambob != 0 ) { - if ( (utxo= LP_utxoadd(1,coin->symbol,txid,vout,value,deposittxid,depositvout,depositval,coin->smartaddr,mypub,LP_gui,G.LP_sessionid,value)) != 0 ) + if ( (utxo= LP_utxoadd(1,coin->symbol,txid,vout,value,deposittxid,depositvout,biggerval,coin->smartaddr,mypub,LP_gui,G.LP_sessionid,value)) != 0 ) { } } else { //printf("call utxoadd\n"); - if ( (utxo= LP_utxoadd(0,coin->symbol,deposittxid,depositvout,depositval,txid,vout,value,coin->smartaddr,mypub,LP_gui,G.LP_sessionid,value)) != 0 ) + if ( (utxo= LP_utxoadd(0,coin->symbol,deposittxid,depositvout,biggerval,txid,vout,value,coin->smartaddr,mypub,LP_gui,G.LP_sessionid,biggerval)) != 0 ) { } } From 287310ae293e46098148bf1ad6fd8c0e09be564c Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 00:17:30 +0200 Subject: [PATCH 044/306] Test --- iguana/exchanges/LP_ordermatch.c | 2 +- iguana/exchanges/LP_tradebots.c | 4 ++-- iguana/exchanges/LP_utxos.c | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 47fc78296..12e8dccb0 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -1125,7 +1125,7 @@ char *LP_autobuy(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel destsatoshis = SATOSHIDEN * relvolume; if ( (autxo= LP_utxo_bestfit(rel,destsatoshis + 2*desttxfee)) == 0 ) return(clonestr("{\"error\":\"cant find alice utxo that is big enough\"}")); - printf("bestfit selected alice (%.8f %.8f) for %.8f sats %.8f\n",dstr(autxo->payment.value),dstr(autxo->fee.value),dstr(destsatoshis),dstr(autxo->S.satoshis)); + //printf("bestfit selected alice (%.8f %.8f) for %.8f sats %.8f\n",dstr(autxo->payment.value),dstr(autxo->fee.value),dstr(destsatoshis),dstr(autxo->S.satoshis)); if ( destsatoshis - desttxfee < autxo->S.satoshis ) { destsatoshis -= desttxfee; diff --git a/iguana/exchanges/LP_tradebots.c b/iguana/exchanges/LP_tradebots.c index 1f6fa7c48..022b7d3d9 100644 --- a/iguana/exchanges/LP_tradebots.c +++ b/iguana/exchanges/LP_tradebots.c @@ -481,7 +481,7 @@ char *LP_tradebot_buy(int32_t dispdir,char *base,char *rel,double maxprice,doubl 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 && balance > sum+txfee ) + if ( dstr(abalance) < relvolume && balance > sum+2*txfee ) { retjson = cJSON_CreateObject(); jaddstr(retjson,"error","not enough funds"); @@ -492,7 +492,7 @@ 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); - if ( balance >= sum+txfee ) + if ( balance > sum+2*txfee ) { char *withdrawstr; cJSON *outputjson,*withdrawjson,*outputs,*item; outputjson = cJSON_CreateObject(); diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 5aa0d7554..b24c47ff3 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -242,7 +242,7 @@ struct LP_utxoinfo *LP_utxo_bestfit(char *symbol,uint64_t destsatoshis) continue; if ( LP_isavailable(utxo) > 0 && LP_ismine(utxo) > 0 ) { - printf("(%.8f %.8f %.8f)\n",dstr(utxo->payment.value),dstr(utxo->fee.value),dstr(utxo->S.satoshis)); + //printf("(%.8f %.8f %.8f)\n",dstr(utxo->payment.value),dstr(utxo->fee.value),dstr(utxo->S.satoshis)); //char str[65]; printf("s%u %d [%.8f vs %.8f] check %s.%s avail.%d ismine.%d >= %d\n",utxo->T.spentflag,LP_iseligible(&srcvalue,&srcvalue2,utxo->iambob,symbol,utxo->payment.txid,utxo->payment.vout,utxo->S.satoshis,utxo->fee.txid,utxo->fee.vout),dstr(destsatoshis),dstr(utxo->S.satoshis),utxo->coin,bits256_str(str,utxo->payment.txid),LP_isavailable(utxo) > 0,LP_ismine(utxo) > 0,utxo->S.satoshis >= destsatoshis); bestsize = 0; if ( bestutxo == 0 ) @@ -267,7 +267,7 @@ struct LP_utxoinfo *LP_utxo_bestfit(char *symbol,uint64_t destsatoshis) } if ( bestsize > 0 ) { - printf("bestsize.%d %.8f %.8f -> %.8f\n",bestsize,dstr(utxo->payment.value),dstr(utxo->fee.value),dstr(utxo->S.satoshis)); + //printf("bestsize.%d %.8f %.8f -> %.8f\n",bestsize,dstr(utxo->payment.value),dstr(utxo->fee.value),dstr(utxo->S.satoshis)); if ( LP_iseligible(&srcvalue,&srcvalue2,utxo->iambob,symbol,utxo->payment.txid,utxo->payment.vout,utxo->S.satoshis,utxo->fee.txid,utxo->fee.vout) == 0 ) { //if ( utxo->T.spentflag == 0 ) @@ -275,7 +275,7 @@ struct LP_utxoinfo *LP_utxo_bestfit(char *symbol,uint64_t destsatoshis) continue; } bestutxo = utxo; - } else printf("skip alice utxo %.8f vs dest %.8f, bestsize.%d %p\n",dstr(utxo->S.satoshis),dstr(destsatoshis),bestsize,bestutxo); + } //else printf("skip alice utxo %.8f vs dest %.8f, bestsize.%d %p\n",dstr(utxo->S.satoshis),dstr(destsatoshis),bestsize,bestutxo); } } return(bestutxo); @@ -414,7 +414,7 @@ struct LP_utxoinfo *LP_utxoadd(int32_t iambob,char *symbol,bits256 txid,int32_t printf("utxoadd selector.%d spent in mempool %s vini.%d",selector,bits256_str(str,spendtxid),spendvini); utxo->T.spentflag = (uint32_t)time(NULL); } - printf(" %s %.8f %.8f %p addutxo.%d (%s %s) session.%u iambob.%d <<<<<<<<<<<<<<< %.8f\n",symbol,dstr(value),dstr(value2),utxo,LP_ismine(utxo) > 0,bits256_str(str,utxo->payment.txid),bits256_str(str2,iambob != 0 ? utxo->deposit.txid : utxo->fee.txid),utxo->T.sessionid,iambob,dstr(satoshis)); + //printf(" %s %.8f %.8f %p addutxo.%d (%s %s) session.%u iambob.%d <<<<<<<<<<<<<<< %.8f\n",symbol,dstr(value),dstr(value2),utxo,LP_ismine(utxo) > 0,bits256_str(str,utxo->payment.txid),bits256_str(str2,iambob != 0 ? utxo->deposit.txid : utxo->fee.txid),utxo->T.sessionid,iambob,dstr(satoshis)); portable_mutex_lock(&LP_utxomutex); HASH_ADD_KEYPTR(hh,G.LP_utxoinfos[iambob],utxo->key,sizeof(utxo->key),utxo); if ( _LP_utxo2find(iambob,txid2,vout2) == 0 ) From f892e94d3bd43470ec2d012a611b280d6b1a2ae6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 00:21:43 +0200 Subject: [PATCH 045/306] Test --- crypto777/iguana_utils.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crypto777/iguana_utils.c b/crypto777/iguana_utils.c index 153cd4529..8d461fa13 100755 --- a/crypto777/iguana_utils.c +++ b/crypto777/iguana_utils.c @@ -446,6 +446,7 @@ char *clonestr(char *str) return(clone); } +int32_t zeroval() { return(0); } int32_t safecopy(char *dest,char *src,long len) { @@ -459,6 +460,7 @@ int32_t safecopy(char *dest,char *src,long len) if ( i == len ) { printf("safecopy: %s too long %ld\n",src,len); + printf("divide by zero! %d\n",1/zeroval()); #ifdef __APPLE__ //getchar(); #endif From b457e62a9b158266128ea37c2c95bd5957898985 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 00:30:28 +0200 Subject: [PATCH 046/306] Test --- iguana/exchanges/LP_include.h | 2 +- iguana/exchanges/LP_tradebots.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index cda3f0348..ce65acb43 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -43,7 +43,7 @@ void emscripten_usleep(int32_t x); // returns immediate, no sense for sleeping #define LP_MAXVINS 64 #define LP_HTTP_TIMEOUT 3 // 1 is too small due to edge cases of time(NULL) -#define LP_AUTOTRADE_TIMEOUT 30 +#define LP_AUTOTRADE_TIMEOUT 60 #define ELECTRUM_TIMEOUT 7 #define LP_ELECTRUM_KEEPALIVE 60 #define LP_ELECTRUM_MAXERRORS 777 diff --git a/iguana/exchanges/LP_tradebots.c b/iguana/exchanges/LP_tradebots.c index 022b7d3d9..ce3a6a65a 100644 --- a/iguana/exchanges/LP_tradebots.c +++ b/iguana/exchanges/LP_tradebots.c @@ -479,7 +479,7 @@ char *LP_tradebot_buy(int32_t dispdir,char *base,char *rel,double maxprice,doubl 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); + sum = (SATOSHIDEN*relvolume+2*dstr(txfees)) + 3 * ((SATOSHIDEN*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 && balance > sum+2*txfee ) { From a93ea0a7f7a8bb094532b37cd02580b53e59e5cd Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 00:31:33 +0200 Subject: [PATCH 047/306] 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 0901d9c0b..430b104dd 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -856,8 +856,8 @@ void LP_reserved_msgs(void *ignore) if ( ignore == 0 ) break; if ( nonz != 0 ) - usleep(3000); - else usleep(25000); + usleep(1000); + else usleep(5000); } } From d7795cc3723cbead3c799c8fe43d742fa58f539a Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 00:39:48 +0200 Subject: [PATCH 048/306] Test --- iguana/exchanges/LP_signatures.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index 1ac171c03..6b5643bb6 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -104,6 +104,7 @@ cJSON *LP_quotejson(struct LP_quoteinfo *qp) int32_t LP_quoteparse(struct LP_quoteinfo *qp,cJSON *argjson) { uint32_t rid,qid; + memset(qp,0,sizeof(*qp)); safecopy(qp->gui,LP_gui,sizeof(qp->gui)); safecopy(qp->srccoin,jstr(argjson,"base"),sizeof(qp->srccoin)); safecopy(qp->coinaddr,jstr(argjson,"address"),sizeof(qp->coinaddr)); From d738c7b99abdb37aeeaa03c888a56bd9536e0aa2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 00:40:07 +0200 Subject: [PATCH 049/306] Test --- crypto777/iguana_utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crypto777/iguana_utils.c b/crypto777/iguana_utils.c index 8d461fa13..e75257149 100755 --- a/crypto777/iguana_utils.c +++ b/crypto777/iguana_utils.c @@ -460,7 +460,7 @@ int32_t safecopy(char *dest,char *src,long len) if ( i == len ) { printf("safecopy: %s too long %ld\n",src,len); - printf("divide by zero! %d\n",1/zeroval()); + //printf("divide by zero! %d\n",1/zeroval()); #ifdef __APPLE__ //getchar(); #endif From b9a5c02bdfa6c90e4f18bebc88cb63e59ede1463 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 00:53:29 +0200 Subject: [PATCH 050/306] Test --- iguana/exchanges/LP_socket.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index e200c5891..f345e9ab6 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -922,9 +922,11 @@ int32_t LP_recvfunc(struct electrum_info *ep,char *str,int32_t len) if ( item->type == idnum ) { DL_DELETE(ep->pendingQ.list,item); - *((cJSON **)stritem->retptrp) = (resultjson != 0 ? jduplicate(resultjson) : jduplicate(strjson)); + if ( resultjson != 0 ) + *((cJSON **)stritem->retptrp) = jduplicate(resultjson); + else *((cJSON **)stritem->retptrp) = strjson, strjson = 0; //printf("matched idnum.%d result.(%s)\n",idnum,jprint(*((cJSON **)stritem->retptrp),0)); - resultjson = strjson = 0; + //resultjson = strjson = 0; free(item); break; } From bcf793e545f9304ad315cc74930d277a53992490 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 01:10:50 +0200 Subject: [PATCH 051/306] Test --- iguana/exchanges/LP_include.h | 2 +- iguana/exchanges/LP_remember.c | 12 ++-- iguana/exchanges/LP_swap.c | 94 +++++++++++++++---------------- iguana/exchanges/LP_transaction.c | 78 ++++++++++++------------- 4 files changed, 93 insertions(+), 93 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index ce65acb43..ec9a2eca5 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -347,7 +347,7 @@ struct LP_endpoint { int32_t pair; char ipaddr[64]; uint16_t port; }; struct basilisk_swap { - void *ctx; struct iguana_info bobcoin,alicecoin; struct LP_utxoinfo *utxo; + void *ctx; struct iguana_info *bobcoin,*alicecoin; struct LP_utxoinfo *utxo; struct LP_endpoint N; void (*balancingtrade)(struct basilisk_swap *swap,int32_t iambob); int32_t subsock,pushsock,connected,aliceunconf,depositunconf,paymentunconf; diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index 2180a498c..0820bf82b 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -47,10 +47,10 @@ void basilisk_dontforget(struct basilisk_swap *swap,struct basilisk_rawtx *rawtx fprintf(fp,"\",\"txid\":\"%s\"",bits256_str(str,bits256_doublesha256(0,rawtx->txbytes,rawtx->I.datalen))); if ( rawtx == &swap->bobdeposit || rawtx == &swap->bobpayment ) { - LP_swap_coinaddr(&swap->bobcoin,coinaddr,0,rawtx->txbytes,rawtx->I.datalen,0); + LP_swap_coinaddr(swap->bobcoin,coinaddr,0,rawtx->txbytes,rawtx->I.datalen,0); if ( coinaddr[0] != 0 ) { - LP_importaddress(swap->bobcoin.symbol,coinaddr); + LP_importaddress(swap->bobcoin->symbol,coinaddr); if ( rawtx == &swap->bobdeposit ) safecopy(swap->Bdeposit,coinaddr,sizeof(swap->Bdeposit)); else safecopy(swap->Bpayment,coinaddr,sizeof(swap->Bpayment)); @@ -63,16 +63,16 @@ void basilisk_dontforget(struct basilisk_swap *swap,struct basilisk_rawtx *rawtx fprintf(fp,",\"%s\":\"%s\"","Bpayment",swap->Bpayment); fprintf(fp,",\"expiration\":%u",swap->I.expiration); fprintf(fp,",\"iambob\":%d",swap->I.iambob); - fprintf(fp,",\"bobcoin\":\"%s\"",swap->bobcoin.symbol); - fprintf(fp,",\"alicecoin\":\"%s\"",swap->alicecoin.symbol); + fprintf(fp,",\"bobcoin\":\"%s\"",swap->bobcoin->symbol); + fprintf(fp,",\"alicecoin\":\"%s\"",swap->alicecoin->symbol); fprintf(fp,",\"lock\":%u",locktime); fprintf(fp,",\"amount\":%.8f",dstr(rawtx->I.amount)); if ( bits256_nonz(triggertxid) != 0 ) fprintf(fp,",\"trigger\":\"%s\"",bits256_str(str,triggertxid)); if ( bits256_nonz(swap->I.pubAm) != 0 && bits256_nonz(swap->I.pubBn) != 0 ) { - basilisk_alicescript(redeemscript,&len,script,0,coinaddr,swap->alicecoin.taddr,swap->alicecoin.p2shtype,swap->I.pubAm,swap->I.pubBn); - LP_importaddress(swap->alicecoin.symbol,coinaddr); + basilisk_alicescript(redeemscript,&len,script,0,coinaddr,swap->alicecoin->taddr,swap->alicecoin->p2shtype,swap->I.pubAm,swap->I.pubBn); + LP_importaddress(swap->alicecoin->symbol,coinaddr); fprintf(fp,",\"Apayment\":\"%s\"",coinaddr); } if ( rawtx->I.redeemlen > 0 ) diff --git a/iguana/exchanges/LP_swap.c b/iguana/exchanges/LP_swap.c index fb6adf940..e803f48fd 100644 --- a/iguana/exchanges/LP_swap.c +++ b/iguana/exchanges/LP_swap.c @@ -620,9 +620,9 @@ int32_t LP_rawtx_spendscript(struct basilisk_swap *swap,int32_t height,struct ba txfee = LP_MIN_TXFEE; else { - if ( strcmp(rawtx->coin->symbol,swap->bobcoin.symbol) == 0 ) + if ( strcmp(rawtx->coin->symbol,swap->bobcoin->symbol) == 0 ) txfee = swap->I.Btxfee; - else if ( strcmp(rawtx->coin->symbol,swap->alicecoin.symbol) == 0 ) + else if ( strcmp(rawtx->coin->symbol,swap->alicecoin->symbol) == 0 ) txfee = swap->I.Atxfee; else txfee = LP_MIN_TXFEE; } @@ -783,12 +783,12 @@ void LP_bobloop(void *_swap) printf("error bobscripts payment\n"); else { - if ( strcmp(swap->alicecoin.symbol,"BTC") == 0 ) + if ( strcmp(swap->alicecoin->symbol,"BTC") == 0 ) m = 0; else m = swap->I.aliceconfirms; - while ( (n= LP_numconfirms(swap->alicecoin.symbol,swap->alicepayment.I.destaddr,swap->alicepayment.I.signedtxid,0,1)) < m ) // sync with alice + while ( (n= LP_numconfirms(swap->alicecoin->symbol,swap->alicepayment.I.destaddr,swap->alicepayment.I.signedtxid,0,1)) < m ) // sync with alice { - char str[65];printf("%d wait for alicepayment %s numconfs.%d %s %s\n",n,swap->alicepayment.I.destaddr,m,swap->alicecoin.symbol,bits256_str(str,swap->alicepayment.I.signedtxid)); + char str[65];printf("%d wait for alicepayment %s numconfs.%d %s %s\n",n,swap->alicepayment.I.destaddr,m,swap->alicecoin->symbol,bits256_str(str,swap->alicepayment.I.signedtxid)); sleep(10); } if ( LP_swapdata_rawtxsend(swap->N.pair,swap,0x8000,data,maxlen,&swap->bobpayment,0x4000,0) == 0 ) @@ -801,7 +801,7 @@ void LP_bobloop(void *_swap) basilisk_bobpayment_reclaim(swap,swap->I.callduration); if ( swap->N.pair >= 0 ) nn_close(swap->N.pair), swap->N.pair = -1; - LP_swapwait(swap->I.req.requestid,swap->I.req.quoteid,LP_atomic_locktime(swap->bobcoin.symbol,swap->alicecoin.symbol)*2,30); + LP_swapwait(swap->I.req.requestid,swap->I.req.quoteid,LP_atomic_locktime(swap->bobcoin->symbol,swap->alicecoin->symbol)*2,30); } } } @@ -840,12 +840,12 @@ void LP_aliceloop(void *_swap) printf("error sending alicepayment\n"); else { - if ( strcmp(swap->alicecoin.symbol,"BTC") == 0 ) + if ( strcmp(swap->alicecoin->symbol,"BTC") == 0 ) m = 0; else m = swap->I.aliceconfirms; - while ( (n= LP_numconfirms(swap->alicecoin.symbol,swap->alicepayment.I.destaddr,swap->alicepayment.I.signedtxid,0,1)) < m ) + while ( (n= LP_numconfirms(swap->alicecoin->symbol,swap->alicepayment.I.destaddr,swap->alicepayment.I.signedtxid,0,1)) < m ) { - char str[65];printf("%d wait for alicepayment %s numconfs.%d %s %s\n",n,swap->alicepayment.I.destaddr,m,swap->alicecoin.symbol,bits256_str(str,swap->alicepayment.I.signedtxid)); + char str[65];printf("%d wait for alicepayment %s numconfs.%d %s %s\n",n,swap->alicepayment.I.destaddr,m,swap->alicecoin->symbol,bits256_str(str,swap->alicepayment.I.signedtxid)); sleep(10); } swap->sentflag = 1; @@ -853,21 +853,21 @@ void LP_aliceloop(void *_swap) printf("error waiting for bobpayment\n"); else { - while ( (n= LP_numconfirms(swap->bobcoin.symbol,swap->bobpayment.I.destaddr,swap->bobpayment.I.signedtxid,0,1)) < swap->I.bobconfirms ) + while ( (n= LP_numconfirms(swap->bobcoin->symbol,swap->bobpayment.I.destaddr,swap->bobpayment.I.signedtxid,0,1)) < swap->I.bobconfirms ) { - char str[65];printf("%d wait for bobpayment %s numconfs.%d %s %s\n",n,swap->bobpayment.I.destaddr,swap->I.bobconfirms,swap->bobcoin.symbol,bits256_str(str,swap->bobpayment.I.signedtxid)); + char str[65];printf("%d wait for bobpayment %s numconfs.%d %s %s\n",n,swap->bobpayment.I.destaddr,swap->I.bobconfirms,swap->bobcoin->symbol,bits256_str(str,swap->bobpayment.I.signedtxid)); sleep(10); } /*if ( LP_swapdata_rawtxsend(swap->N.pair,swap,0x20000,data,maxlen,&swap->alicespend,0x40000,0) == 0 ) printf("error sending alicespend\n"); - while ( (n= LP_numconfirms(swap->alicecoin.symbol,swap->alicespend.I.destaddr,swap->alicespend.I.signedtxid,0,1)) < swap->I.aliceconfirms ) + while ( (n= LP_numconfirms(swap->alicecoin->symbol,swap->alicespend.I.destaddr,swap->alicespend.I.signedtxid,0,1)) < swap->I.aliceconfirms ) { - char str[65];printf("%d wait for alicespend %s numconfs.%d %s %s\n",n,swap->alicespend.I.destaddr,swap->I.aliceconfirms,swap->bobcoin.symbol,bits256_str(str,swap->alicespend.I.signedtxid)); + char str[65];printf("%d wait for alicespend %s numconfs.%d %s %s\n",n,swap->alicespend.I.destaddr,swap->I.aliceconfirms,swap->bobcoin->symbol,bits256_str(str,swap->alicespend.I.signedtxid)); sleep(LP_SWAPSTEP_TIMEOUT); }*/ if ( swap->N.pair >= 0 ) nn_close(swap->N.pair), swap->N.pair = -1; - LP_swapwait(swap->I.req.requestid,swap->I.req.quoteid,LP_atomic_locktime(swap->bobcoin.symbol,swap->alicecoin.symbol)*2,30); + LP_swapwait(swap->I.req.requestid,swap->I.req.quoteid,LP_atomic_locktime(swap->bobcoin->symbol,swap->alicecoin->symbol)*2,30); } } } @@ -1009,7 +1009,7 @@ struct basilisk_swap *bitcoin_swapinit(bits256 privkey,uint8_t *pubkey33,bits256 printf("bitcoin_swapinit %s Btxfee %.8f rejected\n",swap->I.req.src,dstr(swap->I.Btxfee)); return(0); } - swap->I.putduration = swap->I.callduration = LP_atomic_locktime(swap->bobcoin.symbol,swap->alicecoin.symbol); + swap->I.putduration = swap->I.callduration = LP_atomic_locktime(swap->bobcoin->symbol,swap->alicecoin->symbol); if ( optionduration < 0 ) swap->I.putduration -= optionduration; else if ( optionduration > 0 ) @@ -1058,27 +1058,27 @@ struct basilisk_swap *bitcoin_swapinit(bits256 privkey,uint8_t *pubkey33,bits256 return(0); } if ( (coin= LP_coinfind(swap->I.alicestr)) != 0 ) - swap->alicecoin = *coin; + swap->alicecoin = coin; else { - printf("missing bobcoin.%p or missing alicecoin.%p src.%p dest.%p\n",&swap->bobcoin,&swap->alicecoin,LP_coinfind(swap->I.req.src),LP_coinfind(swap->I.req.dest)); + printf("missing bobcoin->%p or missing alicecoin->%p src.%p dest.%p\n",swap->bobcoin,swap->alicecoin,LP_coinfind(swap->I.req.src),LP_coinfind(swap->I.req.dest)); free(swap); return(0); } if ( (coin= LP_coinfind(swap->I.bobstr)) != 0 ) - swap->bobcoin = *coin; + swap->bobcoin = coin; else { - printf("missing bobcoin.%p or missing alicecoin.%p src.%p dest.%p\n",&swap->bobcoin,&swap->alicecoin,LP_coinfind(swap->I.req.src),LP_coinfind(swap->I.req.dest)); + printf("missing bobcoin->%p or missing alicecoin->%p src.%p dest.%p\n",swap->bobcoin,swap->alicecoin,LP_coinfind(swap->I.req.src),LP_coinfind(swap->I.req.dest)); free(swap); return(0); } - if ( strcmp("BTC",swap->bobcoin.symbol) == 0 ) + if ( strcmp("BTC",swap->bobcoin->symbol) == 0 ) { swap->I.bobconfirms = (1 + sqrt(dstr(swap->I.bobsatoshis) * .1)); swap->I.aliceconfirms = BASILISK_DEFAULT_NUMCONFIRMS; } - else if ( strcmp("BTC",swap->alicecoin.symbol) == 0 ) + else if ( strcmp("BTC",swap->alicecoin->symbol) == 0 ) { swap->I.aliceconfirms = (1 + sqrt(dstr(swap->I.alicesatoshis) * .1)); swap->I.bobconfirms = BASILISK_DEFAULT_NUMCONFIRMS; @@ -1088,17 +1088,17 @@ struct basilisk_swap *bitcoin_swapinit(bits256 privkey,uint8_t *pubkey33,bits256 swap->I.bobconfirms = BASILISK_DEFAULT_NUMCONFIRMS; swap->I.aliceconfirms = BASILISK_DEFAULT_NUMCONFIRMS; } - if ( swap->bobcoin.isassetchain != 0 ) + if ( swap->bobcoin->isassetchain != 0 ) swap->I.bobconfirms = 1; - if ( swap->alicecoin.isassetchain != 0 ) + if ( swap->alicecoin->isassetchain != 0 ) swap->I.aliceconfirms = 1; - if ( swap->bobcoin.userconfirms > 0 ) - swap->I.bobconfirms = swap->bobcoin.userconfirms; - if ( swap->alicecoin.userconfirms > 0 ) - swap->I.aliceconfirms = swap->alicecoin.userconfirms; - if ( (swap->I.bobmaxconfirms= swap->bobcoin.maxconfirms) == 0 ) + if ( swap->bobcoin->userconfirms > 0 ) + swap->I.bobconfirms = swap->bobcoin->userconfirms; + if ( swap->alicecoin->userconfirms > 0 ) + swap->I.aliceconfirms = swap->alicecoin->userconfirms; + if ( (swap->I.bobmaxconfirms= swap->bobcoin->maxconfirms) == 0 ) swap->I.bobmaxconfirms = BASILISK_DEFAULT_MAXCONFIRMS; - if ( (swap->I.alicemaxconfirms= swap->alicecoin.maxconfirms) == 0 ) + if ( (swap->I.alicemaxconfirms= swap->alicecoin->maxconfirms) == 0 ) swap->I.alicemaxconfirms = BASILISK_DEFAULT_MAXCONFIRMS; if ( swap->I.bobconfirms > swap->I.bobmaxconfirms ) swap->I.bobconfirms = swap->I.bobmaxconfirms; @@ -1106,51 +1106,51 @@ struct basilisk_swap *bitcoin_swapinit(bits256 privkey,uint8_t *pubkey33,bits256 swap->I.aliceconfirms = swap->I.alicemaxconfirms; swap->I.bobconfirms *= !swap->I.bobistrusted; swap->I.aliceconfirms *= !swap->I.aliceistrusted; - printf(">>>>>>>>>> jumblrflag.%d <<<<<<<<< use smart address, %.8f bobconfs.%d, %.8f aliceconfs.%d taddr.%d %d\n",jumblrflag,dstr(swap->I.bobsatoshis),swap->I.bobconfirms,dstr(swap->I.alicesatoshis),swap->I.aliceconfirms,swap->bobcoin.taddr,swap->alicecoin.taddr); + printf(">>>>>>>>>> jumblrflag.%d <<<<<<<<< use smart address, %.8f bobconfs.%d, %.8f aliceconfs.%d taddr.%d %d\n",jumblrflag,dstr(swap->I.bobsatoshis),swap->I.bobconfirms,dstr(swap->I.alicesatoshis),swap->I.aliceconfirms,swap->bobcoin->taddr,swap->alicecoin->taddr); if ( swap->I.iambob != 0 ) { - basilisk_rawtx_setparms("myfee",swap->I.req.quoteid,&swap->myfee,&swap->bobcoin,0,0,LP_DEXFEE(swap->I.bobsatoshis) + 0*swap->bobcoin.txfee,0,0,jumblrflag); - basilisk_rawtx_setparms("otherfee",swap->I.req.quoteid,&swap->otherfee,&swap->alicecoin,0,0,LP_DEXFEE(swap->I.alicesatoshis) + 0*swap->alicecoin.txfee,0,0,jumblrflag); + basilisk_rawtx_setparms("myfee",swap->I.req.quoteid,&swap->myfee,swap->bobcoin,0,0,LP_DEXFEE(swap->I.bobsatoshis) + 0*swap->bobcoin->txfee,0,0,jumblrflag); + basilisk_rawtx_setparms("otherfee",swap->I.req.quoteid,&swap->otherfee,swap->alicecoin,0,0,LP_DEXFEE(swap->I.alicesatoshis) + 0*swap->alicecoin->txfee,0,0,jumblrflag); bobpub33 = pubkey33; } else { - basilisk_rawtx_setparms("otherfee",swap->I.req.quoteid,&swap->otherfee,&swap->bobcoin,0,0,LP_DEXFEE(swap->I.bobsatoshis) + 0*swap->bobcoin.txfee,0,0,jumblrflag); - basilisk_rawtx_setparms("myfee",swap->I.req.quoteid,&swap->myfee,&swap->alicecoin,0,0,LP_DEXFEE(swap->I.alicesatoshis) + 0*swap->alicecoin.txfee,0,0,jumblrflag); + basilisk_rawtx_setparms("otherfee",swap->I.req.quoteid,&swap->otherfee,swap->bobcoin,0,0,LP_DEXFEE(swap->I.bobsatoshis) + 0*swap->bobcoin->txfee,0,0,jumblrflag); + basilisk_rawtx_setparms("myfee",swap->I.req.quoteid,&swap->myfee,swap->alicecoin,0,0,LP_DEXFEE(swap->I.alicesatoshis) + 0*swap->alicecoin->txfee,0,0,jumblrflag); alicepub33 = pubkey33; } swap->myfee.I.locktime = swap->I.started + 1; swap->otherfee.I.locktime = swap->I.started + 1; - basilisk_rawtx_setparms("bobdeposit",swap->I.req.quoteid,&swap->bobdeposit,&swap->bobcoin,swap->I.bobconfirms,0,LP_DEPOSITSATOSHIS(swap->I.bobsatoshis) + swap->bobcoin.txfee,4,0,jumblrflag); - basilisk_rawtx_setparms("bobrefund",swap->I.req.quoteid,&swap->bobrefund,&swap->bobcoin,1,4,LP_DEPOSITSATOSHIS(swap->I.bobsatoshis),1,bobpub33,jumblrflag); + basilisk_rawtx_setparms("bobdeposit",swap->I.req.quoteid,&swap->bobdeposit,swap->bobcoin,swap->I.bobconfirms,0,LP_DEPOSITSATOSHIS(swap->I.bobsatoshis) + swap->bobcoin->txfee,4,0,jumblrflag); + basilisk_rawtx_setparms("bobrefund",swap->I.req.quoteid,&swap->bobrefund,swap->bobcoin,1,4,LP_DEPOSITSATOSHIS(swap->I.bobsatoshis),1,bobpub33,jumblrflag); swap->bobrefund.I.suppress_pubkeys = 1; - basilisk_rawtx_setparms("aliceclaim",swap->I.req.quoteid,&swap->aliceclaim,&swap->bobcoin,1,4,LP_DEPOSITSATOSHIS(swap->I.bobsatoshis),1,alicepub33,jumblrflag); + basilisk_rawtx_setparms("aliceclaim",swap->I.req.quoteid,&swap->aliceclaim,swap->bobcoin,1,4,LP_DEPOSITSATOSHIS(swap->I.bobsatoshis),1,alicepub33,jumblrflag); swap->aliceclaim.I.suppress_pubkeys = 1; swap->aliceclaim.I.locktime = swap->I.started + swap->I.putduration+swap->I.callduration + 1; - basilisk_rawtx_setparms("bobpayment",swap->I.req.quoteid,&swap->bobpayment,&swap->bobcoin,swap->I.bobconfirms,0,swap->I.bobsatoshis + swap->bobcoin.txfee,3,0,jumblrflag); - basilisk_rawtx_setparms("alicespend",swap->I.req.quoteid,&swap->alicespend,&swap->bobcoin,swap->I.bobconfirms,3,swap->I.bobsatoshis,1,alicepub33,jumblrflag); + basilisk_rawtx_setparms("bobpayment",swap->I.req.quoteid,&swap->bobpayment,swap->bobcoin,swap->I.bobconfirms,0,swap->I.bobsatoshis + swap->bobcoin->txfee,3,0,jumblrflag); + basilisk_rawtx_setparms("alicespend",swap->I.req.quoteid,&swap->alicespend,swap->bobcoin,swap->I.bobconfirms,3,swap->I.bobsatoshis,1,alicepub33,jumblrflag); swap->alicespend.I.suppress_pubkeys = 1; - basilisk_rawtx_setparms("bobreclaim",swap->I.req.quoteid,&swap->bobreclaim,&swap->bobcoin,swap->I.bobconfirms,3,swap->I.bobsatoshis,1,bobpub33,jumblrflag); + basilisk_rawtx_setparms("bobreclaim",swap->I.req.quoteid,&swap->bobreclaim,swap->bobcoin,swap->I.bobconfirms,3,swap->I.bobsatoshis,1,bobpub33,jumblrflag); swap->bobreclaim.I.suppress_pubkeys = 1; swap->bobreclaim.I.locktime = swap->I.started + swap->I.putduration + 1; - basilisk_rawtx_setparms("alicepayment",swap->I.req.quoteid,&swap->alicepayment,&swap->alicecoin,swap->I.aliceconfirms,0,swap->I.alicesatoshis + swap->alicecoin.txfee,2,0,jumblrflag); - basilisk_rawtx_setparms("bobspend",swap->I.req.quoteid,&swap->bobspend,&swap->alicecoin,swap->I.aliceconfirms,2,swap->I.alicesatoshis,1,bobpub33,jumblrflag); + basilisk_rawtx_setparms("alicepayment",swap->I.req.quoteid,&swap->alicepayment,swap->alicecoin,swap->I.aliceconfirms,0,swap->I.alicesatoshis + swap->alicecoin->txfee,2,0,jumblrflag); + basilisk_rawtx_setparms("bobspend",swap->I.req.quoteid,&swap->bobspend,swap->alicecoin,swap->I.aliceconfirms,2,swap->I.alicesatoshis,1,bobpub33,jumblrflag); swap->bobspend.I.suppress_pubkeys = 1; - basilisk_rawtx_setparms("alicereclaim",swap->I.req.quoteid,&swap->alicereclaim,&swap->alicecoin,swap->I.aliceconfirms,2,swap->I.alicesatoshis,1,alicepub33,jumblrflag); + basilisk_rawtx_setparms("alicereclaim",swap->I.req.quoteid,&swap->alicereclaim,swap->alicecoin,swap->I.aliceconfirms,2,swap->I.alicesatoshis,1,alicepub33,jumblrflag); swap->alicereclaim.I.suppress_pubkeys = 1; swap->bobpayment.utxotxid = qp->txid, swap->bobpayment.utxovout = qp->vout; swap->bobdeposit.utxotxid = qp->txid2, swap->bobdeposit.utxovout = qp->vout2; swap->alicepayment.utxotxid = qp->desttxid, swap->alicepayment.utxovout = qp->destvout; - LP_mark_spent(swap->bobcoin.symbol,qp->txid,qp->vout); - LP_mark_spent(swap->bobcoin.symbol,qp->txid2,qp->vout2); - LP_mark_spent(swap->alicecoin.symbol,qp->desttxid,qp->destvout); + LP_mark_spent(swap->bobcoin->symbol,qp->txid,qp->vout); + LP_mark_spent(swap->bobcoin->symbol,qp->txid2,qp->vout2); + LP_mark_spent(swap->alicecoin->symbol,qp->desttxid,qp->destvout); if ( swap->I.iambob != 0 ) swap->otherfee.utxotxid = qp->feetxid, swap->otherfee.utxovout = qp->feevout; else { swap->myfee.utxotxid = qp->feetxid, swap->myfee.utxovout = qp->feevout; - LP_mark_spent(swap->alicecoin.symbol,qp->feetxid,qp->feevout); + LP_mark_spent(swap->alicecoin->symbol,qp->feetxid,qp->feevout); } char str[65],str2[65],str3[65]; printf("IAMBOB.%d %s %s %s\n",swap->I.iambob,bits256_str(str,qp->txid),bits256_str(str2,qp->txid2),bits256_str(str3,qp->feetxid)); return(swap); diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index 661319305..54c3045c0 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -1230,7 +1230,7 @@ int32_t basilisk_rawtx_gen(void *ctx,char *str,uint32_t swapstarted,uint8_t *pub return(-1); if ( strcmp(coin->smartaddr,vinaddr) != 0 ) { - printf("basilisk_rawtx_gen mismatched vinaddr.%s != %s\n",vinaddr,coin->smartaddr); + printf("basilisk_rawtx_gen mismatched %s vinaddr.%s != (%s)\n",coin->symbol,vinaddr,coin->smartaddr); return(-1); } argjson = cJSON_CreateObject(); @@ -1613,7 +1613,7 @@ int32_t basilisk_bobpayment_reclaim(struct basilisk_swap *swap,int32_t delay) len = basilisk_swapuserdata(userdata,zero,1,swap->I.myprivs[1],swap->bobpayment.redeemscript,swap->bobpayment.I.redeemlen); memcpy(swap->I.userdata_bobreclaim,userdata,len); swap->I.userdata_bobreclaimlen = len; - if ( (retval= basilisk_rawtx_sign(swap->bobcoin.symbol,swap->bobcoin.wiftaddr,swap->bobcoin.taddr,swap->bobcoin.pubtype,swap->bobcoin.p2shtype,swap->bobcoin.isPoS,swap->bobcoin.wiftype,swap,&swap->bobreclaim,&swap->bobpayment,swap->I.myprivs[1],0,userdata,len,1,swap->changermd160,swap->bobpayment.I.destaddr,swap->bobcoin.zcash)) == 0 ) + if ( (retval= basilisk_rawtx_sign(swap->bobcoin->symbol,swap->bobcoin->wiftaddr,swap->bobcoin->taddr,swap->bobcoin->pubtype,swap->bobcoin->p2shtype,swap->bobcoin->isPoS,swap->bobcoin->wiftype,swap,&swap->bobreclaim,&swap->bobpayment,swap->I.myprivs[1],0,userdata,len,1,swap->changermd160,swap->bobpayment.I.destaddr,swap->bobcoin->zcash)) == 0 ) { for (i=0; ibobreclaim.I.datalen; i++) printf("%02x",swap->bobreclaim.txbytes[i]); @@ -1630,7 +1630,7 @@ int32_t basilisk_bobdeposit_refund(struct basilisk_swap *swap,int32_t delay) len = basilisk_swapuserdata(userdata,swap->I.privBn,0,swap->I.myprivs[0],swap->bobdeposit.redeemscript,swap->bobdeposit.I.redeemlen); memcpy(swap->I.userdata_bobrefund,userdata,len); swap->I.userdata_bobrefundlen = len; - if ( (retval= basilisk_rawtx_sign(swap->bobcoin.symbol,swap->bobcoin.wiftaddr,swap->bobcoin.taddr,swap->bobcoin.pubtype,swap->bobcoin.p2shtype,swap->bobcoin.isPoS,swap->bobcoin.wiftype,swap,&swap->bobrefund,&swap->bobdeposit,swap->I.myprivs[0],0,userdata,len,0,swap->changermd160,swap->bobdeposit.I.destaddr,swap->bobcoin.zcash)) == 0 ) + if ( (retval= basilisk_rawtx_sign(swap->bobcoin->symbol,swap->bobcoin->wiftaddr,swap->bobcoin->taddr,swap->bobcoin->pubtype,swap->bobcoin->p2shtype,swap->bobcoin->isPoS,swap->bobcoin->wiftype,swap,&swap->bobrefund,&swap->bobdeposit,swap->I.myprivs[0],0,userdata,len,0,swap->changermd160,swap->bobdeposit.I.destaddr,swap->bobcoin->zcash)) == 0 ) { for (i=0; ibobrefund.I.datalen; i++) printf("%02x",swap->bobrefund.txbytes[i]); @@ -1674,15 +1674,15 @@ void LP_swap_coinaddr(struct iguana_info *coin,char *coinaddr,uint64_t *valuep,u int32_t basilisk_bobscripts_set(struct basilisk_swap *swap,int32_t depositflag,int32_t genflag) { int32_t j; char coinaddr[64],checkaddr[64]; - bitcoin_address(coinaddr,swap->bobcoin.taddr,swap->bobcoin.pubtype,swap->changermd160,20); + bitcoin_address(coinaddr,swap->bobcoin->taddr,swap->bobcoin->pubtype,swap->changermd160,20); if ( genflag != 0 && swap->I.iambob == 0 ) printf("basilisk_bobscripts_set WARNING: alice generating BOB tx\n"); if ( depositflag == 0 ) { swap->bobpayment.I.spendlen = basilisk_bobscript(swap->bobpayment.I.rmd160,swap->bobpayment.redeemscript,&swap->bobpayment.I.redeemlen,swap->bobpayment.spendscript,0,&swap->bobpayment.I.locktime,&swap->bobpayment.I.secretstart,&swap->I,0); - bitcoin_address(swap->bobpayment.p2shaddr,swap->bobcoin.taddr,swap->bobcoin.p2shtype,swap->bobpayment.redeemscript,swap->bobpayment.I.redeemlen); + bitcoin_address(swap->bobpayment.p2shaddr,swap->bobcoin->taddr,swap->bobcoin->p2shtype,swap->bobpayment.redeemscript,swap->bobpayment.I.redeemlen); strcpy(swap->bobpayment.I.destaddr,swap->bobpayment.p2shaddr); - //LP_importaddress(swap->bobcoin.symbol,swap->bobpayment.I.destaddr); + //LP_importaddress(swap->bobcoin->symbol,swap->bobpayment.I.destaddr); //int32_t i; for (i=0; ibobpayment.I.redeemlen; i++) // printf("%02x",swap->bobpayment.redeemscript[i]); //printf(" <- bobpayment redeem %d %s\n",i,swap->bobpayment.I.destaddr); @@ -1703,13 +1703,13 @@ int32_t basilisk_bobscripts_set(struct basilisk_swap *swap,int32_t depositflag,i printf("%02x",swap->bobpayment.redeemscript[j]); printf(" <- redeem.%d\n",swap->bobpayment.I.redeemlen); printf(" <- GENERATED BOB PAYMENT.%d destaddr.(%s)\n",swap->bobpayment.I.datalen,swap->bobpayment.I.destaddr); - LP_swap_coinaddr(&swap->bobcoin,checkaddr,0,swap->bobpayment.txbytes,swap->bobpayment.I.datalen,0); + LP_swap_coinaddr(swap->bobcoin,checkaddr,0,swap->bobpayment.txbytes,swap->bobpayment.I.datalen,0); if ( strcmp(swap->bobpayment.I.destaddr,checkaddr) != 0 ) { printf("BOBPAYMENT REDEEMADDR MISMATCH??? %s != %s\n",swap->bobpayment.I.destaddr,checkaddr); return(-1); } - LP_unspents_mark(swap->bobcoin.symbol,swap->bobpayment.vins); + LP_unspents_mark(swap->bobcoin->symbol,swap->bobpayment.vins); //printf("bobscripts set completed\n"); return(0); } @@ -1718,7 +1718,7 @@ int32_t basilisk_bobscripts_set(struct basilisk_swap *swap,int32_t depositflag,i else { swap->bobdeposit.I.spendlen = basilisk_bobscript(swap->bobdeposit.I.rmd160,swap->bobdeposit.redeemscript,&swap->bobdeposit.I.redeemlen,swap->bobdeposit.spendscript,0,&swap->bobdeposit.I.locktime,&swap->bobdeposit.I.secretstart,&swap->I,1); - bitcoin_address(swap->bobdeposit.p2shaddr,swap->bobcoin.taddr,swap->bobcoin.p2shtype,swap->bobdeposit.redeemscript,swap->bobdeposit.I.redeemlen); + bitcoin_address(swap->bobdeposit.p2shaddr,swap->bobcoin->taddr,swap->bobcoin->p2shtype,swap->bobdeposit.redeemscript,swap->bobdeposit.I.redeemlen); strcpy(swap->bobdeposit.I.destaddr,swap->bobdeposit.p2shaddr); //int32_t i; for (i=0; ibobdeposit.I.redeemlen; i++) // printf("%02x",swap->bobdeposit.redeemscript[i]); @@ -1736,13 +1736,13 @@ int32_t basilisk_bobscripts_set(struct basilisk_swap *swap,int32_t depositflag,i for (j=0; jbobdeposit.I.datalen; j++) printf("%02x",swap->bobdeposit.txbytes[j]); printf(" <- GENERATED BOB DEPOSIT.%d (%s)\n",swap->bobdeposit.I.datalen,swap->bobdeposit.I.destaddr); - LP_swap_coinaddr(&swap->bobcoin,checkaddr,0,swap->bobdeposit.txbytes,swap->bobdeposit.I.datalen,0); + LP_swap_coinaddr(swap->bobcoin,checkaddr,0,swap->bobdeposit.txbytes,swap->bobdeposit.I.datalen,0); if ( strcmp(swap->bobdeposit.I.destaddr,checkaddr) != 0 ) { printf("BOBDEPOSIT REDEEMADDR MISMATCH??? %s != %s\n",swap->bobdeposit.I.destaddr,checkaddr); return(-1); } - LP_unspents_mark(swap->bobcoin.symbol,swap->bobdeposit.vins); + LP_unspents_mark(swap->bobcoin->symbol,swap->bobdeposit.vins); printf("bobscripts set completed\n"); return(0); } @@ -1758,7 +1758,7 @@ int32_t basilisk_alicepayment_spend(struct basilisk_swap *swap,struct basilisk_r { int32_t i,retval; printf("alicepayment_spend\n"); - swap->alicepayment.I.spendlen = basilisk_alicescript(swap->alicepayment.redeemscript,&swap->alicepayment.I.redeemlen,swap->alicepayment.spendscript,0,swap->alicepayment.I.destaddr,swap->alicecoin.p2shtype,swap->I.pubAm,swap->I.pubBn); + swap->alicepayment.I.spendlen = basilisk_alicescript(swap->alicepayment.redeemscript,&swap->alicepayment.I.redeemlen,swap->alicepayment.spendscript,0,swap->alicepayment.I.destaddr,swap->alicecoin->p2shtype,swap->I.pubAm,swap->I.pubBn); printf("alicepayment_spend len.%d\n",swap->alicepayment.I.spendlen); if ( swap->I.iambob == 0 ) { @@ -1770,7 +1770,7 @@ int32_t basilisk_alicepayment_spend(struct basilisk_swap *swap,struct basilisk_r memcpy(swap->I.userdata_bobspend,swap->alicepayment.redeemscript,swap->alicepayment.I.spendlen); swap->I.userdata_bobspendlen = swap->alicepayment.I.spendlen; } - if ( (retval= basilisk_rawtx_sign(swap->alicecoin.symbol,swap->alicecoin.pubtype,swap->alicecoin.p2shtype,swap->alicecoin.isPoS,swap->alicecoin.wiftype,swap,dest,&swap->alicepayment,swap->I.privAm,&swap->I.privBn,0,0,1,swap->changermd160)) == 0 ) + if ( (retval= basilisk_rawtx_sign(swap->alicecoin->symbol,swap->alicecoin->pubtype,swap->alicecoin->p2shtype,swap->alicecoin->isPoS,swap->alicecoin->wiftype,swap,dest,&swap->alicepayment,swap->I.privAm,&swap->I.privBn,0,0,1,swap->changermd160)) == 0 ) { for (i=0; iI.datalen; i++) printf("%02x",dest->txbytes[i]); @@ -1802,26 +1802,26 @@ int32_t basilisk_alicetxs(int32_t pairsock,struct basilisk_swap *swap,uint8_t *d printf("error alice generating payment.%d\n",swap->alicepayment.I.spendlen); else { - bitcoin_address(swap->alicepayment.I.destaddr,swap->alicecoin.taddr,swap->alicecoin.p2shtype,swap->alicepayment.redeemscript,swap->alicepayment.I.redeemlen); - //LP_importaddress(swap->alicecoin.symbol,swap->alicepayment.I.destaddr); + bitcoin_address(swap->alicepayment.I.destaddr,swap->alicecoin->taddr,swap->alicecoin->p2shtype,swap->alicepayment.redeemscript,swap->alicepayment.I.redeemlen); + //LP_importaddress(swap->alicecoin->symbol,swap->alicepayment.I.destaddr); strcpy(swap->alicepayment.p2shaddr,swap->alicepayment.I.destaddr); retval = 0; for (i=0; ialicepayment.I.datalen; i++) printf("%02x",swap->alicepayment.txbytes[i]); printf(" ALICE PAYMENT created.(%s)\n",swap->alicepayment.I.destaddr); - LP_unspents_mark(swap->alicecoin.symbol,swap->alicepayment.vins); - //LP_importaddress(swap->alicecoin.symbol,swap->alicepayment.I.destaddr); + LP_unspents_mark(swap->alicecoin->symbol,swap->alicepayment.vins); + //LP_importaddress(swap->alicecoin->symbol,swap->alicepayment.I.destaddr); //basilisk_txlog(swap,&swap->alicepayment,-1); } if ( swap->myfee.I.datalen == 0 ) { - printf("generate fee %.8f\n",dstr(strcmp(swap->myfee.coin->symbol,"BTC") == 0 ? LP_MIN_TXFEE : swap->myfee.coin->txfee)); - bitcoin_address(coinaddr,swap->alicecoin.taddr,swap->alicecoin.pubtype,swap->changermd160,20); + printf("%s generate fee %.8f from.%s\n",swap->alicecoin->symbol,dstr(strcmp(swap->myfee.coin->symbol,"BTC") == 0 ? LP_MIN_TXFEE : swap->myfee.coin->txfee),swap->alicecoin->smartaddr); + bitcoin_address(coinaddr,swap->alicecoin->taddr,swap->alicecoin->pubtype,swap->changermd160,20); if ( basilisk_rawtx_gen(swap->ctx,"myfee",swap->I.started,swap->persistent_pubkey33,swap->I.iambob,1,&swap->myfee,swap->myfee.I.locktime,swap->myfee.spendscript,swap->myfee.I.spendlen,strcmp(swap->myfee.coin->symbol,"BTC") == 0 ? LP_MIN_TXFEE : swap->myfee.coin->txfee,1,0,swap->persistent_privkey,swap->changermd160,coinaddr) == 0 ) { printf("rawtxsend %s %.8f\n",swap->myfee.coin->symbol,dstr(strcmp(swap->myfee.coin->symbol,"BTC") == 0 ? LP_MIN_TXFEE : swap->myfee.coin->txfee)); swap->I.statebits |= LP_swapdata_rawtxsend(pairsock,swap,0x80,data,maxlen,&swap->myfee,0x40,0); - LP_unspents_mark(swap->I.iambob!=0?swap->bobcoin.symbol:swap->alicecoin.symbol,swap->myfee.vins); + LP_unspents_mark(swap->I.iambob!=0?swap->bobcoin->symbol:swap->alicecoin->symbol,swap->myfee.vins); //basilisk_txlog(swap,&swap->myfee,-1); for (i=0; imyfee.I.datalen; i++) printf("%02x",swap->myfee.txbytes[i]); @@ -1845,7 +1845,7 @@ int32_t basilisk_alicetxs(int32_t pairsock,struct basilisk_swap *swap,uint8_t *d int32_t LP_verify_otherfee(struct basilisk_swap *swap,uint8_t *data,int32_t datalen) { int32_t diff; - if ( LP_rawtx_spendscript(swap,swap->bobcoin.longestchain,&swap->otherfee,0,data,datalen,0) == 0 ) + if ( LP_rawtx_spendscript(swap,swap->bobcoin->longestchain,&swap->otherfee,0,data,datalen,0) == 0 ) { printf("otherfee amount %.8f -> %s vs %s locktime %u vs %u\n",dstr(swap->otherfee.I.amount),swap->otherfee.p2shaddr,swap->otherfee.I.destaddr,swap->otherfee.I.locktime,swap->I.started+1); if ( strcmp(swap->otherfee.I.destaddr,swap->otherfee.p2shaddr) == 0 ) @@ -1864,7 +1864,7 @@ int32_t LP_verify_otherfee(struct basilisk_swap *swap,uint8_t *data,int32_t data int32_t LP_verify_alicespend(struct basilisk_swap *swap,uint8_t *data,int32_t datalen) { - if ( LP_rawtx_spendscript(swap,swap->bobcoin.longestchain,&swap->alicespend,0,data,datalen,0) == 0 ) + if ( LP_rawtx_spendscript(swap,swap->bobcoin->longestchain,&swap->alicespend,0,data,datalen,0) == 0 ) { printf("alicespend amount %.8f -> %s vs %s\n",dstr(swap->alicespend.I.amount),swap->alicespend.p2shaddr,swap->alicespend.I.destaddr); if ( strcmp(swap->alicespend.I.destaddr,swap->alicespend.p2shaddr) == 0 ) @@ -1886,10 +1886,10 @@ int32_t LP_verify_alicespend(struct basilisk_swap *swap,uint8_t *data,int32_t da int32_t LP_verify_bobdeposit(struct basilisk_swap *swap,uint8_t *data,int32_t datalen) { uint8_t userdata[512]; int32_t retval=-1,len = 0; static bits256 zero; - if ( LP_rawtx_spendscript(swap,swap->bobcoin.longestchain,&swap->bobdeposit,0,data,datalen,0) == 0 ) + if ( LP_rawtx_spendscript(swap,swap->bobcoin->longestchain,&swap->bobdeposit,0,data,datalen,0) == 0 ) { swap->aliceclaim.utxovout = 0; - swap->bobdeposit.I.signedtxid = LP_broadcast_tx(swap->bobdeposit.name,swap->bobcoin.symbol,swap->bobdeposit.txbytes,swap->bobdeposit.I.datalen); + swap->bobdeposit.I.signedtxid = LP_broadcast_tx(swap->bobdeposit.name,swap->bobcoin->symbol,swap->bobdeposit.txbytes,swap->bobdeposit.I.datalen); if ( bits256_nonz(swap->bobdeposit.I.signedtxid) != 0 ) swap->depositunconf = 1; else swap->bobdeposit.I.signedtxid = swap->bobdeposit.I.actualtxid; @@ -1897,7 +1897,7 @@ int32_t LP_verify_bobdeposit(struct basilisk_swap *swap,uint8_t *data,int32_t da swap->aliceclaim.utxotxid = swap->bobdeposit.I.signedtxid; memcpy(swap->I.userdata_aliceclaim,userdata,len); swap->I.userdata_aliceclaimlen = len; - bitcoin_address(swap->bobdeposit.p2shaddr,swap->bobcoin.taddr,swap->bobcoin.p2shtype,swap->bobdeposit.redeemscript,swap->bobdeposit.I.redeemlen); + bitcoin_address(swap->bobdeposit.p2shaddr,swap->bobcoin->taddr,swap->bobcoin->p2shtype,swap->bobdeposit.redeemscript,swap->bobdeposit.I.redeemlen); strcpy(swap->bobdeposit.I.destaddr,swap->bobdeposit.p2shaddr); basilisk_dontforget_update(swap,&swap->bobdeposit); //int32_t i; char str[65]; for (i=0; ibobdeposit.I.datalen; i++) @@ -1909,9 +1909,9 @@ int32_t LP_verify_bobdeposit(struct basilisk_swap *swap,uint8_t *data,int32_t da memcpy(swap->aliceclaim.redeemscript,swap->bobdeposit.redeemscript,swap->bobdeposit.I.redeemlen); swap->aliceclaim.I.redeemlen = swap->bobdeposit.I.redeemlen; memcpy(swap->aliceclaim.I.pubkey33,swap->persistent_pubkey33,33); - bitcoin_address(swap->aliceclaim.I.destaddr,swap->alicecoin.taddr,swap->alicecoin.pubtype,swap->persistent_pubkey33,33); + bitcoin_address(swap->aliceclaim.I.destaddr,swap->alicecoin->taddr,swap->alicecoin->pubtype,swap->persistent_pubkey33,33); retval = 0; - if ( (retval= basilisk_rawtx_sign(swap->bobcoin.symbol,swap->bobcoin.wiftaddr,swap->bobcoin.taddr,swap->bobcoin.pubtype,swap->bobcoin.p2shtype,swap->bobcoin.isPoS,swap->bobcoin.wiftype,swap,&swap->aliceclaim,&swap->bobdeposit,swap->I.myprivs[0],0,userdata,len,1,swap->changermd160,swap->bobdeposit.I.destaddr,swap->bobcoin.zcash)) == 0 ) + if ( (retval= basilisk_rawtx_sign(swap->bobcoin->symbol,swap->bobcoin->wiftaddr,swap->bobcoin->taddr,swap->bobcoin->pubtype,swap->bobcoin->p2shtype,swap->bobcoin->isPoS,swap->bobcoin->wiftype,swap,&swap->aliceclaim,&swap->bobdeposit,swap->I.myprivs[0],0,userdata,len,1,swap->changermd160,swap->bobdeposit.I.destaddr,swap->bobcoin->zcash)) == 0 ) { int32_t i; for (i=0; ibobdeposit.I.datalen; i++) printf("%02x",swap->bobdeposit.txbytes[i]); @@ -1920,7 +1920,7 @@ int32_t LP_verify_bobdeposit(struct basilisk_swap *swap,uint8_t *data,int32_t da printf("%02x",swap->aliceclaim.txbytes[i]); printf(" <- aliceclaim\n"); //basilisk_txlog(swap,&swap->aliceclaim,swap->I.putduration+swap->I.callduration); - return(LP_waitmempool(swap->bobcoin.symbol,swap->bobdeposit.I.destaddr,swap->bobdeposit.I.signedtxid,0,60)); + return(LP_waitmempool(swap->bobcoin->symbol,swap->bobdeposit.I.destaddr,swap->bobdeposit.I.signedtxid,0,60)); } else printf("error signing aliceclaim suppress.%d vin.(%s)\n",swap->aliceclaim.I.suppress_pubkeys,swap->bobdeposit.I.destaddr); } printf("error with bobdeposit\n"); @@ -1929,18 +1929,18 @@ int32_t LP_verify_bobdeposit(struct basilisk_swap *swap,uint8_t *data,int32_t da int32_t LP_verify_alicepayment(struct basilisk_swap *swap,uint8_t *data,int32_t datalen) { - if ( LP_rawtx_spendscript(swap,swap->alicecoin.longestchain,&swap->alicepayment,0,data,datalen,0) == 0 ) + if ( LP_rawtx_spendscript(swap,swap->alicecoin->longestchain,&swap->alicepayment,0,data,datalen,0) == 0 ) { swap->bobspend.utxovout = 0; - swap->bobspend.utxotxid = swap->alicepayment.I.signedtxid = LP_broadcast_tx(swap->alicepayment.name,swap->alicecoin.symbol,swap->alicepayment.txbytes,swap->alicepayment.I.datalen); - bitcoin_address(swap->alicepayment.p2shaddr,swap->alicecoin.taddr,swap->alicecoin.p2shtype,swap->alicepayment.redeemscript,swap->alicepayment.I.redeemlen); + swap->bobspend.utxotxid = swap->alicepayment.I.signedtxid = LP_broadcast_tx(swap->alicepayment.name,swap->alicecoin->symbol,swap->alicepayment.txbytes,swap->alicepayment.I.datalen); + bitcoin_address(swap->alicepayment.p2shaddr,swap->alicecoin->taddr,swap->alicecoin->p2shtype,swap->alicepayment.redeemscript,swap->alicepayment.I.redeemlen); strcpy(swap->alicepayment.I.destaddr,swap->alicepayment.p2shaddr); if ( bits256_nonz(swap->alicepayment.I.signedtxid) != 0 ) swap->aliceunconf = 1; basilisk_dontforget_update(swap,&swap->alicepayment); - return(LP_waitmempool(swap->alicecoin.symbol,swap->alicepayment.I.destaddr,swap->alicepayment.I.signedtxid,0,60)); + return(LP_waitmempool(swap->alicecoin->symbol,swap->alicepayment.I.destaddr,swap->alicepayment.I.signedtxid,0,60)); //printf("import alicepayment address.(%s)\n",swap->alicepayment.p2shaddr); - //LP_importaddress(swap->alicecoin.symbol,swap->alicepayment.p2shaddr); + //LP_importaddress(swap->alicecoin->symbol,swap->alicepayment.p2shaddr); return(0); } printf("error validating alicepayment\n"); @@ -1951,7 +1951,7 @@ int32_t LP_verify_bobpayment(struct basilisk_swap *swap,uint8_t *data,int32_t da { uint8_t userdata[512]; int32_t i,retval=-1,len = 0; bits256 revAm; memset(revAm.bytes,0,sizeof(revAm)); - if ( LP_rawtx_spendscript(swap,swap->bobcoin.longestchain,&swap->bobpayment,0,data,datalen,0) == 0 ) + if ( LP_rawtx_spendscript(swap,swap->bobcoin->longestchain,&swap->bobpayment,0,data,datalen,0) == 0 ) { swap->alicespend.utxovout = 0; swap->alicespend.utxotxid = swap->bobpayment.I.signedtxid = LP_broadcast_tx(swap->bobpayment.name,swap->bobpayment.coin->symbol,swap->bobpayment.txbytes,swap->bobpayment.I.datalen); @@ -1960,10 +1960,10 @@ int32_t LP_verify_bobpayment(struct basilisk_swap *swap,uint8_t *data,int32_t da for (i=0; i<32; i++) revAm.bytes[i] = swap->I.privAm.bytes[31-i]; len = basilisk_swapuserdata(userdata,revAm,0,swap->I.myprivs[0],swap->bobpayment.redeemscript,swap->bobpayment.I.redeemlen); - bitcoin_address(swap->bobpayment.p2shaddr,swap->bobcoin.taddr,swap->bobcoin.p2shtype,swap->bobpayment.redeemscript,swap->bobpayment.I.redeemlen); + bitcoin_address(swap->bobpayment.p2shaddr,swap->bobcoin->taddr,swap->bobcoin->p2shtype,swap->bobpayment.redeemscript,swap->bobpayment.I.redeemlen); strcpy(swap->bobpayment.I.destaddr,swap->bobpayment.p2shaddr); basilisk_dontforget_update(swap,&swap->bobpayment); - //LP_importaddress(swap->bobcoin.symbol,swap->bobpayment.I.destaddr); + //LP_importaddress(swap->bobcoin->symbol,swap->bobpayment.I.destaddr); /*for (i=0; ibobpayment.I.datalen; i++) printf("%02x",swap->bobpayment.txbytes[i]); printf(" <- bobpayment.%d\n",swap->bobpayment.I.datalen); @@ -1974,9 +1974,9 @@ int32_t LP_verify_bobpayment(struct basilisk_swap *swap,uint8_t *data,int32_t da swap->I.userdata_alicespendlen = len; retval = 0; memcpy(swap->alicespend.I.pubkey33,swap->persistent_pubkey33,33); - bitcoin_address(swap->alicespend.I.destaddr,swap->bobcoin.taddr,swap->bobcoin.pubtype,swap->persistent_pubkey33,33); + bitcoin_address(swap->alicespend.I.destaddr,swap->bobcoin->taddr,swap->bobcoin->pubtype,swap->persistent_pubkey33,33); //char str[65],str2[65]; printf("bobpaid privAm.(%s) myprivs[0].(%s)\n",bits256_str(str,swap->I.privAm),bits256_str(str2,swap->I.myprivs[0])); - if ( (retval= basilisk_rawtx_sign(swap->bobcoin.symbol,swap->bobcoin.wiftaddr,swap->bobcoin.taddr,swap->bobcoin.pubtype,swap->bobcoin.p2shtype,swap->bobcoin.isPoS,swap->bobcoin.wiftype,swap,&swap->alicespend,&swap->bobpayment,swap->I.myprivs[0],0,userdata,len,1,swap->changermd160,swap->alicepayment.I.destaddr,swap->bobcoin.zcash)) == 0 ) + if ( (retval= basilisk_rawtx_sign(swap->bobcoin->symbol,swap->bobcoin->wiftaddr,swap->bobcoin->taddr,swap->bobcoin->pubtype,swap->bobcoin->p2shtype,swap->bobcoin->isPoS,swap->bobcoin->wiftype,swap,&swap->alicespend,&swap->bobpayment,swap->I.myprivs[0],0,userdata,len,1,swap->changermd160,swap->alicepayment.I.destaddr,swap->bobcoin->zcash)) == 0 ) { /*for (i=0; ibobpayment.I.datalen; i++) printf("%02x",swap->bobpayment.txbytes[i]); @@ -1985,7 +1985,7 @@ int32_t LP_verify_bobpayment(struct basilisk_swap *swap,uint8_t *data,int32_t da printf("%02x",swap->alicespend.txbytes[i]); printf(" <- alicespend\n\n");*/ swap->I.alicespent = 1; - return(LP_waitmempool(swap->bobcoin.symbol,swap->bobpayment.I.destaddr,swap->bobpayment.I.signedtxid,0,60)); + return(LP_waitmempool(swap->bobcoin->symbol,swap->bobpayment.I.destaddr,swap->bobpayment.I.signedtxid,0,60)); } else printf("error signing aliceclaim suppress.%d vin.(%s)\n",swap->alicespend.I.suppress_pubkeys,swap->bobpayment.I.destaddr); } printf("error validating bobpayment\n"); From 90d9f06d4448ac5a7e94323c3a5f719693fecb51 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 01:16:40 +0200 Subject: [PATCH 052/306] 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 12e8dccb0..f65f88370 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -719,7 +719,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; From 262a9b132c23792aead7da4e1cc3ea42965f0fdd Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 01:22:17 +0200 Subject: [PATCH 053/306] Test --- iguana/exchanges/LP_swap.c | 42 +++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/iguana/exchanges/LP_swap.c b/iguana/exchanges/LP_swap.c index e803f48fd..008bdf45f 100644 --- a/iguana/exchanges/LP_swap.c +++ b/iguana/exchanges/LP_swap.c @@ -801,7 +801,7 @@ void LP_bobloop(void *_swap) basilisk_bobpayment_reclaim(swap,swap->I.callduration); if ( swap->N.pair >= 0 ) nn_close(swap->N.pair), swap->N.pair = -1; - LP_swapwait(swap->I.req.requestid,swap->I.req.quoteid,LP_atomic_locktime(swap->bobcoin->symbol,swap->alicecoin->symbol)*2,30); + LP_swapwait(swap->I.req.requestid,swap->I.req.quoteid,LP_atomic_locktime(swap->I.bobstr,swap->I.alicestr)*2,30); } } } @@ -867,7 +867,7 @@ void LP_aliceloop(void *_swap) }*/ if ( swap->N.pair >= 0 ) nn_close(swap->N.pair), swap->N.pair = -1; - LP_swapwait(swap->I.req.requestid,swap->I.req.quoteid,LP_atomic_locktime(swap->bobcoin->symbol,swap->alicecoin->symbol)*2,30); + LP_swapwait(swap->I.req.requestid,swap->I.req.quoteid,LP_atomic_locktime(swap->I.bobstr,swap->I.alicestr)*2,30); } } } @@ -999,6 +999,24 @@ struct basilisk_swap *bitcoin_swapinit(bits256 privkey,uint8_t *pubkey33,bits256 { //FILE *fp; char fname[512]; uint8_t *alicepub33=0,*bobpub33=0; int32_t jumblrflag=-2,x = -1; struct iguana_info *coin; + strcpy(swap->I.bobstr,swap->I.req.src); + strcpy(swap->I.alicestr,swap->I.req.dest); + if ( (coin= LP_coinfind(swap->I.alicestr)) != 0 ) + swap->alicecoin = coin; + else + { + printf("missing bobcoin->%p or missing alicecoin->%p src.%p dest.%p\n",swap->bobcoin,swap->alicecoin,LP_coinfind(swap->I.req.src),LP_coinfind(swap->I.req.dest)); + free(swap); + return(0); + } + if ( (coin= LP_coinfind(swap->I.bobstr)) != 0 ) + swap->bobcoin = coin; + else + { + printf("missing bobcoin->%p or missing alicecoin->%p src.%p dest.%p\n",swap->bobcoin,swap->alicecoin,LP_coinfind(swap->I.req.src),LP_coinfind(swap->I.req.dest)); + free(swap); + return(0); + } if ( (swap->I.Atxfee= qp->desttxfee) < 0 ) { printf("bitcoin_swapinit %s Atxfee %.8f rejected\n",swap->I.req.dest,dstr(swap->I.Atxfee)); @@ -1009,7 +1027,7 @@ struct basilisk_swap *bitcoin_swapinit(bits256 privkey,uint8_t *pubkey33,bits256 printf("bitcoin_swapinit %s Btxfee %.8f rejected\n",swap->I.req.src,dstr(swap->I.Btxfee)); return(0); } - swap->I.putduration = swap->I.callduration = LP_atomic_locktime(swap->bobcoin->symbol,swap->alicecoin->symbol); + swap->I.putduration = swap->I.callduration = LP_atomic_locktime(swap->I.bobstr,swap->I.alicestr); if ( optionduration < 0 ) swap->I.putduration -= optionduration; else if ( optionduration > 0 ) @@ -1028,8 +1046,6 @@ struct basilisk_swap *bitcoin_swapinit(bits256 privkey,uint8_t *pubkey33,bits256 swap->I.bobinsurance = LP_MIN_TXFEE; if ( (swap->I.aliceinsurance= (swap->I.alicesatoshis / INSTANTDEX_INSURANCEDIV)) < LP_MIN_TXFEE ) swap->I.aliceinsurance = LP_MIN_TXFEE; - strcpy(swap->I.bobstr,swap->I.req.src); - strcpy(swap->I.alicestr,swap->I.req.dest); swap->I.started = (uint32_t)time(NULL); swap->I.expiration = swap->I.req.timestamp + swap->I.putduration + swap->I.callduration; OS_randombytes((uint8_t *)&swap->I.choosei,sizeof(swap->I.choosei)); @@ -1057,22 +1073,6 @@ struct basilisk_swap *bitcoin_swapinit(bits256 privkey,uint8_t *pubkey33,bits256 char str[65]; printf("couldnt generate privkeys %d %s\n",x,bits256_str(str,privkey)); return(0); } - if ( (coin= LP_coinfind(swap->I.alicestr)) != 0 ) - swap->alicecoin = coin; - else - { - printf("missing bobcoin->%p or missing alicecoin->%p src.%p dest.%p\n",swap->bobcoin,swap->alicecoin,LP_coinfind(swap->I.req.src),LP_coinfind(swap->I.req.dest)); - free(swap); - return(0); - } - if ( (coin= LP_coinfind(swap->I.bobstr)) != 0 ) - swap->bobcoin = coin; - else - { - printf("missing bobcoin->%p or missing alicecoin->%p src.%p dest.%p\n",swap->bobcoin,swap->alicecoin,LP_coinfind(swap->I.req.src),LP_coinfind(swap->I.req.dest)); - free(swap); - return(0); - } if ( strcmp("BTC",swap->bobcoin->symbol) == 0 ) { swap->I.bobconfirms = (1 + sqrt(dstr(swap->I.bobsatoshis) * .1)); From fa9f638ebec8105b53dd3a94928b1a1e46750273 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 01:46:28 +0200 Subject: [PATCH 054/306] Use decker's condition --- iguana/exchanges/LP_tradebots.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_tradebots.c b/iguana/exchanges/LP_tradebots.c index ce3a6a65a..12d93436c 100644 --- a/iguana/exchanges/LP_tradebots.c +++ b/iguana/exchanges/LP_tradebots.c @@ -481,7 +481,8 @@ char *LP_tradebot_buy(int32_t dispdir,char *base,char *rel,double maxprice,doubl else balance = LP_RTsmartbalance(relcoin); sum = (SATOSHIDEN*relvolume+2*dstr(txfees)) + 3 * ((SATOSHIDEN*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 && balance > sum+2*txfee ) + if ( (dstr(abalance + txfees) < relvolume) || (dstr(balance - abalance) < dstr(balance - abalance + txfees)) ) + //if ( dstr(abalance) < relvolume && balance > sum+2*txfee ) { retjson = cJSON_CreateObject(); jaddstr(retjson,"error","not enough funds"); From 7e70c96a1a7fc7ee1b63e6439f3d1b224d404115 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 01:51:05 +0200 Subject: [PATCH 055/306] Test --- iguana/exchanges/LP_swap.c | 3 ++- iguana/exchanges/LP_transaction.c | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_swap.c b/iguana/exchanges/LP_swap.c index 008bdf45f..c98cc0dd9 100644 --- a/iguana/exchanges/LP_swap.c +++ b/iguana/exchanges/LP_swap.c @@ -969,6 +969,7 @@ void basilisk_rawtx_setparms(char *name,uint32_t quoteid,struct basilisk_rawtx * #endif strcpy(rawtx->name,name); rawtx->coin = coin; + printf("set coin.%s %s -> %s\n",coin->symbol,coin->smartaddr,name); strcpy(rawtx->I.coinstr,coin->symbol); rawtx->I.numconfirms = numconfirms; if ( (rawtx->I.amount= satoshis) < LP_MIN_TXFEE ) @@ -1152,7 +1153,7 @@ struct basilisk_swap *bitcoin_swapinit(bits256 privkey,uint8_t *pubkey33,bits256 swap->myfee.utxotxid = qp->feetxid, swap->myfee.utxovout = qp->feevout; LP_mark_spent(swap->alicecoin->symbol,qp->feetxid,qp->feevout); } - char str[65],str2[65],str3[65]; printf("IAMBOB.%d %s %s %s\n",swap->I.iambob,bits256_str(str,qp->txid),bits256_str(str2,qp->txid2),bits256_str(str3,qp->feetxid)); + char str[65],str2[65],str3[65]; printf("IAMBOB.%d %s %s %s [%s %s]\n",swap->I.iambob,bits256_str(str,qp->txid),bits256_str(str2,qp->txid2),bits256_str(str3,qp->feetxid),swap->bobcoin->symbol,swap->alicecoin->symbol); return(swap); } diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index 54c3045c0..453cd0fd4 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -1230,8 +1230,8 @@ int32_t basilisk_rawtx_gen(void *ctx,char *str,uint32_t swapstarted,uint8_t *pub return(-1); if ( strcmp(coin->smartaddr,vinaddr) != 0 ) { - printf("basilisk_rawtx_gen mismatched %s vinaddr.%s != (%s)\n",coin->symbol,vinaddr,coin->smartaddr); - return(-1); + printf("???????????????????????? basilisk_rawtx_gen mismatched %s vinaddr.%s != (%s)\n",coin->symbol,vinaddr,coin->smartaddr); + //return(-1); } argjson = cJSON_CreateObject(); jaddbits256(argjson,"utxotxid",rawtx->utxotxid); From e1b227ef25cec4998d7d8bf7f85810cdcd3a7f00 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 02:32:32 +0200 Subject: [PATCH 056/306] Test --- iguana/exchanges/LP_include.h | 7 +- iguana/exchanges/LP_remember.c | 20 +- iguana/exchanges/LP_statemachine.c | 18 - iguana/exchanges/LP_swap.c | 130 ++++---- iguana/exchanges/LP_tradebots.c | 2 +- iguana/exchanges/LP_transaction.c | 516 +++++++++++++++-------------- 6 files changed, 354 insertions(+), 339 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index ec9a2eca5..839333523 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -166,7 +166,7 @@ struct basilisk_swap; struct basilisk_rawtxinfo { - char destaddr[64],coinstr[128]; + char destaddr[64]; bits256 txid,signedtxid,actualtxid; int64_t amount,change,inputsum; int32_t redeemlen,datalen,completed,vintype,vouttype,numconfirms,spendlen,secretstart,suppress_pubkeys; @@ -187,10 +187,9 @@ struct basilisk_request struct basilisk_rawtx { - char name[32]; + char name[32],symbol[65]; struct iguana_msgtx msgtx; struct basilisk_rawtxinfo I; - struct iguana_info *coin; char vinstr[8192],p2shaddr[64]; cJSON *vins; bits256 utxotxid; int32_t utxovout; @@ -347,7 +346,7 @@ struct LP_endpoint { int32_t pair; char ipaddr[64]; uint16_t port; }; struct basilisk_swap { - void *ctx; struct iguana_info *bobcoin,*alicecoin; struct LP_utxoinfo *utxo; + void *ctx; struct LP_utxoinfo *utxo; struct LP_endpoint N; void (*balancingtrade)(struct basilisk_swap *swap,int32_t iambob); int32_t subsock,pushsock,connected,aliceunconf,depositunconf,paymentunconf; diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index 0820bf82b..d8b264e7c 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -32,13 +32,15 @@ void basilisk_dontforget_userdata(char *userdataname,FILE *fp,uint8_t *script,in void basilisk_dontforget(struct basilisk_swap *swap,struct basilisk_rawtx *rawtx,int32_t locktime,bits256 triggertxid) { - char zeroes[32],fname[512],str[65],coinaddr[64],secretAmstr[41],secretAm256str[65],secretBnstr[41],secretBn256str[65]; FILE *fp; int32_t i,len; uint8_t redeemscript[256],script[256]; + char zeroes[32],fname[512],str[65],coinaddr[64],secretAmstr[41],secretAm256str[65],secretBnstr[41],secretBn256str[65]; FILE *fp; int32_t i,len; uint8_t redeemscript[256],script[256]; struct iguana_info *bobcoin,*alicecoin; sprintf(fname,"%s/SWAPS/%u-%u.%s",GLOBAL_DBDIR,swap->I.req.requestid,swap->I.req.quoteid,rawtx->name), OS_compatible_path(fname); + bobcoin = LP_coinfind(swap->I.bobstr); + alicecoin = LP_coinfind(swap->I.alicestr); coinaddr[0] = secretAmstr[0] = secretAm256str[0] = secretBnstr[0] = secretBn256str[0] = 0; memset(zeroes,0,sizeof(zeroes)); - if ( rawtx != 0 && (fp= fopen(fname,"wb")) != 0 ) + if ( alicecoin != 0 && bobcoin != 0 && rawtx != 0 && (fp= fopen(fname,"wb")) != 0 ) { - fprintf(fp,"{\"name\":\"%s\",\"coin\":\"%s\"",rawtx->name,rawtx->coin->symbol); + fprintf(fp,"{\"name\":\"%s\",\"coin\":\"%s\"",rawtx->name,rawtx->symbol); if ( rawtx->I.datalen > 0 ) { fprintf(fp,",\"tx\":\""); @@ -47,10 +49,10 @@ void basilisk_dontforget(struct basilisk_swap *swap,struct basilisk_rawtx *rawtx fprintf(fp,"\",\"txid\":\"%s\"",bits256_str(str,bits256_doublesha256(0,rawtx->txbytes,rawtx->I.datalen))); if ( rawtx == &swap->bobdeposit || rawtx == &swap->bobpayment ) { - LP_swap_coinaddr(swap->bobcoin,coinaddr,0,rawtx->txbytes,rawtx->I.datalen,0); + LP_swap_coinaddr(bobcoin,coinaddr,0,rawtx->txbytes,rawtx->I.datalen,0); if ( coinaddr[0] != 0 ) { - LP_importaddress(swap->bobcoin->symbol,coinaddr); + LP_importaddress(swap->I.bobstr,coinaddr); if ( rawtx == &swap->bobdeposit ) safecopy(swap->Bdeposit,coinaddr,sizeof(swap->Bdeposit)); else safecopy(swap->Bpayment,coinaddr,sizeof(swap->Bpayment)); @@ -63,16 +65,16 @@ void basilisk_dontforget(struct basilisk_swap *swap,struct basilisk_rawtx *rawtx fprintf(fp,",\"%s\":\"%s\"","Bpayment",swap->Bpayment); fprintf(fp,",\"expiration\":%u",swap->I.expiration); fprintf(fp,",\"iambob\":%d",swap->I.iambob); - fprintf(fp,",\"bobcoin\":\"%s\"",swap->bobcoin->symbol); - fprintf(fp,",\"alicecoin\":\"%s\"",swap->alicecoin->symbol); + fprintf(fp,",\"bobcoin\":\"%s\"",swap->I.bobstr); + fprintf(fp,",\"alicecoin\":\"%s\"",swap->I.alicestr); fprintf(fp,",\"lock\":%u",locktime); fprintf(fp,",\"amount\":%.8f",dstr(rawtx->I.amount)); if ( bits256_nonz(triggertxid) != 0 ) fprintf(fp,",\"trigger\":\"%s\"",bits256_str(str,triggertxid)); if ( bits256_nonz(swap->I.pubAm) != 0 && bits256_nonz(swap->I.pubBn) != 0 ) { - basilisk_alicescript(redeemscript,&len,script,0,coinaddr,swap->alicecoin->taddr,swap->alicecoin->p2shtype,swap->I.pubAm,swap->I.pubBn); - LP_importaddress(swap->alicecoin->symbol,coinaddr); + basilisk_alicescript(redeemscript,&len,script,0,coinaddr,alicecoin->taddr,alicecoin->p2shtype,swap->I.pubAm,swap->I.pubBn); + LP_importaddress(swap->I.alicestr,coinaddr); fprintf(fp,",\"Apayment\":\"%s\"",coinaddr); } if ( rawtx->I.redeemlen > 0 ) diff --git a/iguana/exchanges/LP_statemachine.c b/iguana/exchanges/LP_statemachine.c index 6bb33ffcc..b267364df 100644 --- a/iguana/exchanges/LP_statemachine.c +++ b/iguana/exchanges/LP_statemachine.c @@ -595,24 +595,6 @@ void basilisk_swap_saveupdate(struct basilisk_swap *swap) } } -/*int32_t basilisk_swap_loadtx(struct basilisk_rawtx *rawtx,FILE *fp,char *bobcoinstr,char *alicecoinstr) - { - if ( fread(rawtx,1,sizeof(*rawtx),fp) == sizeof(*rawtx) ) - { - rawtx->coin = 0; - rawtx->vins = 0; - if ( strcmp(rawtx->I.coinstr,bobcoinstr) == 0 || strcmp(rawtx->I.coinstr,alicecoinstr) == 0 ) - { - rawtx->coin = LP_coinfind(rawtx->I.coinstr); - if ( rawtx->vinstr[0] != 0 ) - rawtx->vins = cJSON_Parse(rawtx->vinstr); - printf("loaded.%s len.%d\n",rawtx->name,rawtx->I.datalen); - return(0); - } - } - return(-1); - }*/ - void basilisk_swap_sendabort(struct basilisk_swap *swap) { uint32_t msgbits = 0; uint8_t buf[sizeof(msgbits) + sizeof(swap->I.req.quoteid) + sizeof(bits256)*2]; int32_t sentbytes,offset=0; diff --git a/iguana/exchanges/LP_swap.c b/iguana/exchanges/LP_swap.c index c98cc0dd9..ce1b725da 100644 --- a/iguana/exchanges/LP_swap.c +++ b/iguana/exchanges/LP_swap.c @@ -556,7 +556,12 @@ struct basilisk_rawtx *LP_swapdata_rawtx(struct basilisk_swap *swap,uint8_t *dat int32_t LP_rawtx_spendscript(struct basilisk_swap *swap,int32_t height,struct basilisk_rawtx *rawtx,int32_t v,uint8_t *recvbuf,int32_t recvlen,int32_t suppress_pubkeys) { - bits256 otherhash,myhash,txid; int64_t txfee,val; int32_t i,offset=0,datalen=0,retval=-1,hexlen,n; uint8_t *data; cJSON *txobj,*skey,*vouts,*vout; char *hexstr,redeemaddr[64],checkaddr[64]; uint32_t quoteid,msgbits; + bits256 otherhash,myhash,txid; int64_t txfee,val; int32_t i,offset=0,datalen=0,retval=-1,hexlen,n; uint8_t *data; cJSON *txobj,*skey,*vouts,*vout; char *hexstr,redeemaddr[64],checkaddr[64]; uint32_t quoteid,msgbits; struct iguana_info *coin; + if ( (coin= LP_coinfind(rawtx->symbol)) == 0 ) + { + printf("LP_rawtx_spendscript couldnt find coin.(%s)\n",rawtx->symbol); + return(-1); + } for (i=0; i<32; i++) otherhash.bytes[i] = recvbuf[offset++]; for (i=0; i<32; i++) @@ -577,9 +582,9 @@ int32_t LP_rawtx_spendscript(struct basilisk_swap *swap,int32_t height,struct ba memcpy(rawtx->redeemscript,&data[datalen],rawtx->I.redeemlen); //for (i=0; iI.redeemlen; i++) // printf("%02x",rawtx->redeemscript[i]); - bitcoin_address(redeemaddr,rawtx->coin->taddr,rawtx->coin->p2shtype,rawtx->redeemscript,rawtx->I.redeemlen); - //printf(" received redeemscript.(%s) %s taddr.%d\n",redeemaddr,rawtx->coin->symbol,rawtx->coin->taddr); - LP_swap_coinaddr(rawtx->coin,checkaddr,0,data,datalen,0); + bitcoin_address(redeemaddr,coin->taddr,coin->p2shtype,rawtx->redeemscript,rawtx->I.redeemlen); + //printf(" received redeemscript.(%s) %s taddr.%d\n",redeemaddr,coin->symbol,coin->taddr); + LP_swap_coinaddr(coin,checkaddr,0,data,datalen,0); if ( strcmp(redeemaddr,checkaddr) != 0 ) { printf("REDEEMADDR MISMATCH??? %s != %s\n",redeemaddr,checkaddr); @@ -609,20 +614,20 @@ int32_t LP_rawtx_spendscript(struct basilisk_swap *swap,int32_t height,struct ba char str[65]; printf("rawtx.%s txid %s\n",rawtx->name,bits256_str(str,txid)); if ( bits256_cmp(txid,rawtx->I.actualtxid) != 0 && bits256_nonz(rawtx->I.actualtxid) == 0 ) rawtx->I.actualtxid = txid; - if ( (txobj= bitcoin_data2json(rawtx->coin->taddr,rawtx->coin->pubtype,rawtx->coin->p2shtype,rawtx->coin->isPoS,height,&rawtx->I.signedtxid,&rawtx->msgtx,rawtx->extraspace,sizeof(rawtx->extraspace),data,datalen,0,suppress_pubkeys,rawtx->coin->zcash)) != 0 ) + if ( (txobj= bitcoin_data2json(coin->taddr,coin->pubtype,coin->p2shtype,coin->isPoS,height,&rawtx->I.signedtxid,&rawtx->msgtx,rawtx->extraspace,sizeof(rawtx->extraspace),data,datalen,0,suppress_pubkeys,coin->zcash)) != 0 ) { rawtx->I.actualtxid = rawtx->I.signedtxid; rawtx->I.locktime = rawtx->msgtx.lock_time; if ( (vouts= jarray(&n,txobj,"vout")) != 0 && v < n ) { vout = jitem(vouts,v); - if ( strcmp("BTC",rawtx->coin->symbol) == 0 && rawtx == &swap->otherfee ) + if ( strcmp("BTC",coin->symbol) == 0 && rawtx == &swap->otherfee ) txfee = LP_MIN_TXFEE; else { - if ( strcmp(rawtx->coin->symbol,swap->bobcoin->symbol) == 0 ) + if ( strcmp(coin->symbol,swap->I.bobstr) == 0 ) txfee = swap->I.Btxfee; - else if ( strcmp(rawtx->coin->symbol,swap->alicecoin->symbol) == 0 ) + else if ( strcmp(coin->symbol,swap->I.alicestr) == 0 ) txfee = swap->I.Atxfee; else txfee = LP_MIN_TXFEE; } @@ -641,9 +646,9 @@ int32_t LP_rawtx_spendscript(struct basilisk_swap *swap,int32_t height,struct ba if ( rawtx == &swap->otherfee ) { char str[65]; - LP_swap_coinaddr(rawtx->coin,rawtx->p2shaddr,0,data,datalen,0); + LP_swap_coinaddr(coin,rawtx->p2shaddr,0,data,datalen,0); printf("got %s txid.%s (%s) -> %s\n",rawtx->name,bits256_str(str,rawtx->I.signedtxid),jprint(txobj,0),rawtx->p2shaddr); - } else bitcoin_address(rawtx->p2shaddr,rawtx->coin->taddr,rawtx->coin->p2shtype,rawtx->spendscript,hexlen); + } else bitcoin_address(rawtx->p2shaddr,coin->taddr,coin->p2shtype,rawtx->spendscript,hexlen); } } else printf("%s satoshis %.8f ERROR.(%s) txfees.[%.8f %.8f: %.8f] amount.%.8f -> %.8f\n",rawtx->name,dstr(j64bits(vout,"satoshis")),jprint(txobj,0),dstr(swap->I.Atxfee),dstr(swap->I.Btxfee),dstr(txfee),dstr(rawtx->I.amount),dstr(rawtx->I.amount)-dstr(txfee)); } @@ -659,7 +664,7 @@ uint32_t LP_swapdata_rawtxsend(int32_t pairsock,struct basilisk_swap *swap,uint3 { if ( bits256_nonz(rawtx->I.signedtxid) != 0 && bits256_nonz(rawtx->I.actualtxid) == 0 ) { - rawtx->I.actualtxid = LP_broadcast_tx(rawtx->name,rawtx->coin->symbol,rawtx->txbytes,rawtx->I.datalen); + rawtx->I.actualtxid = LP_broadcast_tx(rawtx->name,rawtx->symbol,rawtx->txbytes,rawtx->I.datalen); if ( bits256_cmp(rawtx->I.actualtxid,rawtx->I.signedtxid) != 0 ) { char str[65],str2[65]; @@ -687,7 +692,7 @@ uint32_t LP_swapdata_rawtxsend(int32_t pairsock,struct basilisk_swap *swap,uint3 if ( suppress_swapsend == 0 ) { retval = LP_swapsend(pairsock,swap,msgbits,sendbuf,sendlen,nextbits,rawtx->I.crcs); - if ( LP_waitmempool(rawtx->coin->symbol,rawtx->I.destaddr,rawtx->I.signedtxid,0,LP_SWAPSTEP_TIMEOUT*10) < 0 ) + if ( LP_waitmempool(rawtx->symbol,rawtx->I.destaddr,rawtx->I.signedtxid,0,LP_SWAPSTEP_TIMEOUT*10) < 0 ) { char str[65]; printf("failed to find %s %s %s in the mempool?\n",rawtx->name,rawtx->I.destaddr,bits256_str(str,rawtx->I.actualtxid)); retval = -1; @@ -783,12 +788,12 @@ void LP_bobloop(void *_swap) printf("error bobscripts payment\n"); else { - if ( strcmp(swap->alicecoin->symbol,"BTC") == 0 ) + if ( strcmp(swap->I.alicestr,"BTC") == 0 ) m = 0; else m = swap->I.aliceconfirms; - while ( (n= LP_numconfirms(swap->alicecoin->symbol,swap->alicepayment.I.destaddr,swap->alicepayment.I.signedtxid,0,1)) < m ) // sync with alice + while ( (n= LP_numconfirms(swap->I.alicestr,swap->alicepayment.I.destaddr,swap->alicepayment.I.signedtxid,0,1)) < m ) // sync with alice { - char str[65];printf("%d wait for alicepayment %s numconfs.%d %s %s\n",n,swap->alicepayment.I.destaddr,m,swap->alicecoin->symbol,bits256_str(str,swap->alicepayment.I.signedtxid)); + char str[65];printf("%d wait for alicepayment %s numconfs.%d %s %s\n",n,swap->alicepayment.I.destaddr,m,swap->I.alicestr,bits256_str(str,swap->alicepayment.I.signedtxid)); sleep(10); } if ( LP_swapdata_rawtxsend(swap->N.pair,swap,0x8000,data,maxlen,&swap->bobpayment,0x4000,0) == 0 ) @@ -840,12 +845,12 @@ void LP_aliceloop(void *_swap) printf("error sending alicepayment\n"); else { - if ( strcmp(swap->alicecoin->symbol,"BTC") == 0 ) + if ( strcmp(swap->I.alicestr,"BTC") == 0 ) m = 0; else m = swap->I.aliceconfirms; - while ( (n= LP_numconfirms(swap->alicecoin->symbol,swap->alicepayment.I.destaddr,swap->alicepayment.I.signedtxid,0,1)) < m ) + while ( (n= LP_numconfirms(swap->I.alicestr,swap->alicepayment.I.destaddr,swap->alicepayment.I.signedtxid,0,1)) < m ) { - char str[65];printf("%d wait for alicepayment %s numconfs.%d %s %s\n",n,swap->alicepayment.I.destaddr,m,swap->alicecoin->symbol,bits256_str(str,swap->alicepayment.I.signedtxid)); + char str[65];printf("%d wait for alicepayment %s numconfs.%d %s %s\n",n,swap->alicepayment.I.destaddr,m,swap->I.alicestr,bits256_str(str,swap->alicepayment.I.signedtxid)); sleep(10); } swap->sentflag = 1; @@ -853,16 +858,16 @@ void LP_aliceloop(void *_swap) printf("error waiting for bobpayment\n"); else { - while ( (n= LP_numconfirms(swap->bobcoin->symbol,swap->bobpayment.I.destaddr,swap->bobpayment.I.signedtxid,0,1)) < swap->I.bobconfirms ) + while ( (n= LP_numconfirms(swap->I.bobstr,swap->bobpayment.I.destaddr,swap->bobpayment.I.signedtxid,0,1)) < swap->I.bobconfirms ) { - char str[65];printf("%d wait for bobpayment %s numconfs.%d %s %s\n",n,swap->bobpayment.I.destaddr,swap->I.bobconfirms,swap->bobcoin->symbol,bits256_str(str,swap->bobpayment.I.signedtxid)); + char str[65];printf("%d wait for bobpayment %s numconfs.%d %s %s\n",n,swap->bobpayment.I.destaddr,swap->I.bobconfirms,swap->I.bobstr,bits256_str(str,swap->bobpayment.I.signedtxid)); sleep(10); } /*if ( LP_swapdata_rawtxsend(swap->N.pair,swap,0x20000,data,maxlen,&swap->alicespend,0x40000,0) == 0 ) printf("error sending alicespend\n"); - while ( (n= LP_numconfirms(swap->alicecoin->symbol,swap->alicespend.I.destaddr,swap->alicespend.I.signedtxid,0,1)) < swap->I.aliceconfirms ) + while ( (n= LP_numconfirms(swap->I.alicestr,swap->alicespend.I.destaddr,swap->alicespend.I.signedtxid,0,1)) < swap->I.aliceconfirms ) { - char str[65];printf("%d wait for alicespend %s numconfs.%d %s %s\n",n,swap->alicespend.I.destaddr,swap->I.aliceconfirms,swap->bobcoin->symbol,bits256_str(str,swap->alicespend.I.signedtxid)); + char str[65];printf("%d wait for alicespend %s numconfs.%d %s %s\n",n,swap->alicespend.I.destaddr,swap->I.aliceconfirms,swap->I.bobstr,bits256_str(str,swap->alicespend.I.signedtxid)); sleep(LP_SWAPSTEP_TIMEOUT); }*/ if ( swap->N.pair >= 0 ) @@ -968,9 +973,8 @@ void basilisk_rawtx_setparms(char *name,uint32_t quoteid,struct basilisk_rawtx * numconfirms = 0; #endif strcpy(rawtx->name,name); - rawtx->coin = coin; printf("set coin.%s %s -> %s\n",coin->symbol,coin->smartaddr,name); - strcpy(rawtx->I.coinstr,coin->symbol); + strcpy(rawtx->symbol,coin->symbol); rawtx->I.numconfirms = numconfirms; if ( (rawtx->I.amount= satoshis) < LP_MIN_TXFEE ) rawtx->I.amount = LP_MIN_TXFEE; @@ -981,13 +985,13 @@ void basilisk_rawtx_setparms(char *name,uint32_t quoteid,struct basilisk_rawtx * if ( strcmp(coin->symbol,"BTC") == 0 && (quoteid % 10) == 0 ) decode_hex(rawtx->I.rmd160,20,TIERNOLAN_RMD160); else decode_hex(rawtx->I.rmd160,20,INSTANTDEX_RMD160); - bitcoin_address(rawtx->I.destaddr,rawtx->coin->taddr,rawtx->coin->pubtype,rawtx->I.rmd160,20); + bitcoin_address(rawtx->I.destaddr,coin->taddr,coin->pubtype,rawtx->I.rmd160,20); } if ( pubkey33 != 0 ) { memcpy(rawtx->I.pubkey33,pubkey33,33); - bitcoin_address(rawtx->I.destaddr,rawtx->coin->taddr,rawtx->coin->pubtype,rawtx->I.pubkey33,33); - bitcoin_addr2rmd160(rawtx->coin->taddr,&rawtx->I.addrtype,rawtx->I.rmd160,rawtx->I.destaddr); + bitcoin_address(rawtx->I.destaddr,coin->taddr,coin->pubtype,rawtx->I.pubkey33,33); + bitcoin_addr2rmd160(coin->taddr,&rawtx->I.addrtype,rawtx->I.rmd160,rawtx->I.destaddr); } if ( rawtx->I.vouttype <= 1 && rawtx->I.destaddr[0] != 0 ) { @@ -999,22 +1003,18 @@ void basilisk_rawtx_setparms(char *name,uint32_t quoteid,struct basilisk_rawtx * struct basilisk_swap *bitcoin_swapinit(bits256 privkey,uint8_t *pubkey33,bits256 pubkey25519,struct basilisk_swap *swap,int32_t optionduration,uint32_t statebits,struct LP_quoteinfo *qp) { //FILE *fp; char fname[512]; - uint8_t *alicepub33=0,*bobpub33=0; int32_t jumblrflag=-2,x = -1; struct iguana_info *coin; + uint8_t *alicepub33=0,*bobpub33=0; int32_t jumblrflag=-2,x = -1; struct iguana_info *bobcoin,*alicecoin; strcpy(swap->I.bobstr,swap->I.req.src); strcpy(swap->I.alicestr,swap->I.req.dest); - if ( (coin= LP_coinfind(swap->I.alicestr)) != 0 ) - swap->alicecoin = coin; - else + if ( (alicecoin= LP_coinfind(swap->I.alicestr)) == 0 ) { - printf("missing bobcoin->%p or missing alicecoin->%p src.%p dest.%p\n",swap->bobcoin,swap->alicecoin,LP_coinfind(swap->I.req.src),LP_coinfind(swap->I.req.dest)); + printf("missing alicecoin src.%p dest.%p\n",LP_coinfind(swap->I.req.src),LP_coinfind(swap->I.req.dest)); free(swap); return(0); } - if ( (coin= LP_coinfind(swap->I.bobstr)) != 0 ) - swap->bobcoin = coin; - else + if ( (bobcoin= LP_coinfind(swap->I.bobstr)) == 0 ) { - printf("missing bobcoin->%p or missing alicecoin->%p src.%p dest.%p\n",swap->bobcoin,swap->alicecoin,LP_coinfind(swap->I.req.src),LP_coinfind(swap->I.req.dest)); + printf("missing bobcoin src.%p dest.%p\n",LP_coinfind(swap->I.req.src),LP_coinfind(swap->I.req.dest)); free(swap); return(0); } @@ -1074,12 +1074,12 @@ struct basilisk_swap *bitcoin_swapinit(bits256 privkey,uint8_t *pubkey33,bits256 char str[65]; printf("couldnt generate privkeys %d %s\n",x,bits256_str(str,privkey)); return(0); } - if ( strcmp("BTC",swap->bobcoin->symbol) == 0 ) + if ( strcmp("BTC",swap->I.bobstr) == 0 ) { swap->I.bobconfirms = (1 + sqrt(dstr(swap->I.bobsatoshis) * .1)); swap->I.aliceconfirms = BASILISK_DEFAULT_NUMCONFIRMS; } - else if ( strcmp("BTC",swap->alicecoin->symbol) == 0 ) + else if ( strcmp("BTC",swap->I.alicestr) == 0 ) { swap->I.aliceconfirms = (1 + sqrt(dstr(swap->I.alicesatoshis) * .1)); swap->I.bobconfirms = BASILISK_DEFAULT_NUMCONFIRMS; @@ -1089,17 +1089,17 @@ struct basilisk_swap *bitcoin_swapinit(bits256 privkey,uint8_t *pubkey33,bits256 swap->I.bobconfirms = BASILISK_DEFAULT_NUMCONFIRMS; swap->I.aliceconfirms = BASILISK_DEFAULT_NUMCONFIRMS; } - if ( swap->bobcoin->isassetchain != 0 ) + if ( bobcoin->isassetchain != 0 ) swap->I.bobconfirms = 1; - if ( swap->alicecoin->isassetchain != 0 ) + if ( alicecoin->isassetchain != 0 ) swap->I.aliceconfirms = 1; - if ( swap->bobcoin->userconfirms > 0 ) - swap->I.bobconfirms = swap->bobcoin->userconfirms; - if ( swap->alicecoin->userconfirms > 0 ) - swap->I.aliceconfirms = swap->alicecoin->userconfirms; - if ( (swap->I.bobmaxconfirms= swap->bobcoin->maxconfirms) == 0 ) + if ( bobcoin->userconfirms > 0 ) + swap->I.bobconfirms = bobcoin->userconfirms; + if ( alicecoin->userconfirms > 0 ) + swap->I.aliceconfirms = alicecoin->userconfirms; + if ( (swap->I.bobmaxconfirms= bobcoin->maxconfirms) == 0 ) swap->I.bobmaxconfirms = BASILISK_DEFAULT_MAXCONFIRMS; - if ( (swap->I.alicemaxconfirms= swap->alicecoin->maxconfirms) == 0 ) + if ( (swap->I.alicemaxconfirms= alicecoin->maxconfirms) == 0 ) swap->I.alicemaxconfirms = BASILISK_DEFAULT_MAXCONFIRMS; if ( swap->I.bobconfirms > swap->I.bobmaxconfirms ) swap->I.bobconfirms = swap->I.bobmaxconfirms; @@ -1107,53 +1107,53 @@ struct basilisk_swap *bitcoin_swapinit(bits256 privkey,uint8_t *pubkey33,bits256 swap->I.aliceconfirms = swap->I.alicemaxconfirms; swap->I.bobconfirms *= !swap->I.bobistrusted; swap->I.aliceconfirms *= !swap->I.aliceistrusted; - printf(">>>>>>>>>> jumblrflag.%d <<<<<<<<< use smart address, %.8f bobconfs.%d, %.8f aliceconfs.%d taddr.%d %d\n",jumblrflag,dstr(swap->I.bobsatoshis),swap->I.bobconfirms,dstr(swap->I.alicesatoshis),swap->I.aliceconfirms,swap->bobcoin->taddr,swap->alicecoin->taddr); + printf(">>>>>>>>>> jumblrflag.%d <<<<<<<<< use smart address, %.8f bobconfs.%d, %.8f aliceconfs.%d taddr.%d %d\n",jumblrflag,dstr(swap->I.bobsatoshis),swap->I.bobconfirms,dstr(swap->I.alicesatoshis),swap->I.aliceconfirms,bobcoin->taddr,alicecoin->taddr); if ( swap->I.iambob != 0 ) { - basilisk_rawtx_setparms("myfee",swap->I.req.quoteid,&swap->myfee,swap->bobcoin,0,0,LP_DEXFEE(swap->I.bobsatoshis) + 0*swap->bobcoin->txfee,0,0,jumblrflag); - basilisk_rawtx_setparms("otherfee",swap->I.req.quoteid,&swap->otherfee,swap->alicecoin,0,0,LP_DEXFEE(swap->I.alicesatoshis) + 0*swap->alicecoin->txfee,0,0,jumblrflag); + basilisk_rawtx_setparms("myfee",swap->I.req.quoteid,&swap->myfee,bobcoin,0,0,LP_DEXFEE(swap->I.bobsatoshis) + 0*bobcoin->txfee,0,0,jumblrflag); + basilisk_rawtx_setparms("otherfee",swap->I.req.quoteid,&swap->otherfee,alicecoin,0,0,LP_DEXFEE(swap->I.alicesatoshis) + 0*alicecoin->txfee,0,0,jumblrflag); bobpub33 = pubkey33; } else { - basilisk_rawtx_setparms("otherfee",swap->I.req.quoteid,&swap->otherfee,swap->bobcoin,0,0,LP_DEXFEE(swap->I.bobsatoshis) + 0*swap->bobcoin->txfee,0,0,jumblrflag); - basilisk_rawtx_setparms("myfee",swap->I.req.quoteid,&swap->myfee,swap->alicecoin,0,0,LP_DEXFEE(swap->I.alicesatoshis) + 0*swap->alicecoin->txfee,0,0,jumblrflag); + basilisk_rawtx_setparms("otherfee",swap->I.req.quoteid,&swap->otherfee,bobcoin,0,0,LP_DEXFEE(swap->I.bobsatoshis) + 0*bobcoin->txfee,0,0,jumblrflag); + basilisk_rawtx_setparms("myfee",swap->I.req.quoteid,&swap->myfee,alicecoin,0,0,LP_DEXFEE(swap->I.alicesatoshis) + 0*alicecoin->txfee,0,0,jumblrflag); alicepub33 = pubkey33; } swap->myfee.I.locktime = swap->I.started + 1; swap->otherfee.I.locktime = swap->I.started + 1; - basilisk_rawtx_setparms("bobdeposit",swap->I.req.quoteid,&swap->bobdeposit,swap->bobcoin,swap->I.bobconfirms,0,LP_DEPOSITSATOSHIS(swap->I.bobsatoshis) + swap->bobcoin->txfee,4,0,jumblrflag); - basilisk_rawtx_setparms("bobrefund",swap->I.req.quoteid,&swap->bobrefund,swap->bobcoin,1,4,LP_DEPOSITSATOSHIS(swap->I.bobsatoshis),1,bobpub33,jumblrflag); + basilisk_rawtx_setparms("bobdeposit",swap->I.req.quoteid,&swap->bobdeposit,bobcoin,swap->I.bobconfirms,0,LP_DEPOSITSATOSHIS(swap->I.bobsatoshis) + bobcoin->txfee,4,0,jumblrflag); + basilisk_rawtx_setparms("bobrefund",swap->I.req.quoteid,&swap->bobrefund,bobcoin,1,4,LP_DEPOSITSATOSHIS(swap->I.bobsatoshis),1,bobpub33,jumblrflag); swap->bobrefund.I.suppress_pubkeys = 1; - basilisk_rawtx_setparms("aliceclaim",swap->I.req.quoteid,&swap->aliceclaim,swap->bobcoin,1,4,LP_DEPOSITSATOSHIS(swap->I.bobsatoshis),1,alicepub33,jumblrflag); + basilisk_rawtx_setparms("aliceclaim",swap->I.req.quoteid,&swap->aliceclaim,bobcoin,1,4,LP_DEPOSITSATOSHIS(swap->I.bobsatoshis),1,alicepub33,jumblrflag); swap->aliceclaim.I.suppress_pubkeys = 1; swap->aliceclaim.I.locktime = swap->I.started + swap->I.putduration+swap->I.callduration + 1; - basilisk_rawtx_setparms("bobpayment",swap->I.req.quoteid,&swap->bobpayment,swap->bobcoin,swap->I.bobconfirms,0,swap->I.bobsatoshis + swap->bobcoin->txfee,3,0,jumblrflag); - basilisk_rawtx_setparms("alicespend",swap->I.req.quoteid,&swap->alicespend,swap->bobcoin,swap->I.bobconfirms,3,swap->I.bobsatoshis,1,alicepub33,jumblrflag); + basilisk_rawtx_setparms("bobpayment",swap->I.req.quoteid,&swap->bobpayment,bobcoin,swap->I.bobconfirms,0,swap->I.bobsatoshis + bobcoin->txfee,3,0,jumblrflag); + basilisk_rawtx_setparms("alicespend",swap->I.req.quoteid,&swap->alicespend,bobcoin,swap->I.bobconfirms,3,swap->I.bobsatoshis,1,alicepub33,jumblrflag); swap->alicespend.I.suppress_pubkeys = 1; - basilisk_rawtx_setparms("bobreclaim",swap->I.req.quoteid,&swap->bobreclaim,swap->bobcoin,swap->I.bobconfirms,3,swap->I.bobsatoshis,1,bobpub33,jumblrflag); + basilisk_rawtx_setparms("bobreclaim",swap->I.req.quoteid,&swap->bobreclaim,bobcoin,swap->I.bobconfirms,3,swap->I.bobsatoshis,1,bobpub33,jumblrflag); swap->bobreclaim.I.suppress_pubkeys = 1; swap->bobreclaim.I.locktime = swap->I.started + swap->I.putduration + 1; - basilisk_rawtx_setparms("alicepayment",swap->I.req.quoteid,&swap->alicepayment,swap->alicecoin,swap->I.aliceconfirms,0,swap->I.alicesatoshis + swap->alicecoin->txfee,2,0,jumblrflag); - basilisk_rawtx_setparms("bobspend",swap->I.req.quoteid,&swap->bobspend,swap->alicecoin,swap->I.aliceconfirms,2,swap->I.alicesatoshis,1,bobpub33,jumblrflag); + basilisk_rawtx_setparms("alicepayment",swap->I.req.quoteid,&swap->alicepayment,alicecoin,swap->I.aliceconfirms,0,swap->I.alicesatoshis + alicecoin->txfee,2,0,jumblrflag); + basilisk_rawtx_setparms("bobspend",swap->I.req.quoteid,&swap->bobspend,alicecoin,swap->I.aliceconfirms,2,swap->I.alicesatoshis,1,bobpub33,jumblrflag); swap->bobspend.I.suppress_pubkeys = 1; - basilisk_rawtx_setparms("alicereclaim",swap->I.req.quoteid,&swap->alicereclaim,swap->alicecoin,swap->I.aliceconfirms,2,swap->I.alicesatoshis,1,alicepub33,jumblrflag); + basilisk_rawtx_setparms("alicereclaim",swap->I.req.quoteid,&swap->alicereclaim,alicecoin,swap->I.aliceconfirms,2,swap->I.alicesatoshis,1,alicepub33,jumblrflag); swap->alicereclaim.I.suppress_pubkeys = 1; swap->bobpayment.utxotxid = qp->txid, swap->bobpayment.utxovout = qp->vout; swap->bobdeposit.utxotxid = qp->txid2, swap->bobdeposit.utxovout = qp->vout2; swap->alicepayment.utxotxid = qp->desttxid, swap->alicepayment.utxovout = qp->destvout; - LP_mark_spent(swap->bobcoin->symbol,qp->txid,qp->vout); - LP_mark_spent(swap->bobcoin->symbol,qp->txid2,qp->vout2); - LP_mark_spent(swap->alicecoin->symbol,qp->desttxid,qp->destvout); + LP_mark_spent(swap->I.bobstr,qp->txid,qp->vout); + LP_mark_spent(swap->I.bobstr,qp->txid2,qp->vout2); + LP_mark_spent(swap->I.alicestr,qp->desttxid,qp->destvout); if ( swap->I.iambob != 0 ) swap->otherfee.utxotxid = qp->feetxid, swap->otherfee.utxovout = qp->feevout; else { swap->myfee.utxotxid = qp->feetxid, swap->myfee.utxovout = qp->feevout; - LP_mark_spent(swap->alicecoin->symbol,qp->feetxid,qp->feevout); + LP_mark_spent(swap->I.alicestr,qp->feetxid,qp->feevout); } - char str[65],str2[65],str3[65]; printf("IAMBOB.%d %s %s %s [%s %s]\n",swap->I.iambob,bits256_str(str,qp->txid),bits256_str(str2,qp->txid2),bits256_str(str3,qp->feetxid),swap->bobcoin->symbol,swap->alicecoin->symbol); + char str[65],str2[65],str3[65]; printf("IAMBOB.%d %s %s %s [%s %s]\n",swap->I.iambob,bits256_str(str,qp->txid),bits256_str(str2,qp->txid2),bits256_str(str3,qp->feetxid),swap->I.bobstr,swap->I.alicestr); return(swap); } diff --git a/iguana/exchanges/LP_tradebots.c b/iguana/exchanges/LP_tradebots.c index 12d93436c..762a5c6bf 100644 --- a/iguana/exchanges/LP_tradebots.c +++ b/iguana/exchanges/LP_tradebots.c @@ -481,7 +481,7 @@ char *LP_tradebot_buy(int32_t dispdir,char *base,char *rel,double maxprice,doubl else balance = LP_RTsmartbalance(relcoin); sum = (SATOSHIDEN*relvolume+2*dstr(txfees)) + 3 * ((SATOSHIDEN*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 + txfees) < relvolume) || (dstr(balance - abalance) < dstr(balance - abalance + txfees)) ) + if ( (abalance < SATOSHIDEN*relvolume + txfees) || ((balance-abalance) < (uint64_t)(SATOSHIDEN*relvolume)/777 + txfees) ) //if ( dstr(abalance) < relvolume && balance > sum+2*txfee ) { retjson = cJSON_CreateObject(); diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index 453cd0fd4..c2a07a804 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -1226,7 +1226,7 @@ char *LP_withdraw(struct iguana_info *coin,cJSON *argjson) int32_t basilisk_rawtx_gen(void *ctx,char *str,uint32_t swapstarted,uint8_t *pubkey33,int32_t iambob,int32_t lockinputs,struct basilisk_rawtx *rawtx,uint32_t locktime,uint8_t *script,int32_t scriptlen,int64_t txfee,int32_t minconf,int32_t delay,bits256 privkey,uint8_t *changermd160,char *vinaddr) { struct iguana_info *coin; int32_t len,retval=-1; char *retstr,*hexstr; cJSON *argjson,*outputs,*item,*retjson,*obj; - if ( (coin= rawtx->coin) == 0 ) + if ( (coin= LP_coinfind(rawtx->symbol)) == 0 ) return(-1); if ( strcmp(coin->smartaddr,vinaddr) != 0 ) { @@ -1608,36 +1608,44 @@ int32_t basilisk_swapuserdata(uint8_t *userdata,bits256 privkey,int32_t ifpath,b int32_t basilisk_bobpayment_reclaim(struct basilisk_swap *swap,int32_t delay) { - uint8_t userdata[512]; int32_t retval,i,len = 0; static bits256 zero; - //printf("basilisk_bobpayment_reclaim\n"); - len = basilisk_swapuserdata(userdata,zero,1,swap->I.myprivs[1],swap->bobpayment.redeemscript,swap->bobpayment.I.redeemlen); - memcpy(swap->I.userdata_bobreclaim,userdata,len); - swap->I.userdata_bobreclaimlen = len; - if ( (retval= basilisk_rawtx_sign(swap->bobcoin->symbol,swap->bobcoin->wiftaddr,swap->bobcoin->taddr,swap->bobcoin->pubtype,swap->bobcoin->p2shtype,swap->bobcoin->isPoS,swap->bobcoin->wiftype,swap,&swap->bobreclaim,&swap->bobpayment,swap->I.myprivs[1],0,userdata,len,1,swap->changermd160,swap->bobpayment.I.destaddr,swap->bobcoin->zcash)) == 0 ) - { - for (i=0; ibobreclaim.I.datalen; i++) - printf("%02x",swap->bobreclaim.txbytes[i]); - printf(" <- bobreclaim\n"); - //basilisk_txlog(swap,&swap->bobreclaim,delay); - return(retval); - } + static bits256 zero; + uint8_t userdata[512]; int32_t retval,i,len = 0; struct iguana_info *coin; + if ( (coin= LP_coinfind(swap->I.bobstr)) != 0 ) + { + //printf("basilisk_bobpayment_reclaim\n"); + len = basilisk_swapuserdata(userdata,zero,1,swap->I.myprivs[1],swap->bobpayment.redeemscript,swap->bobpayment.I.redeemlen); + memcpy(swap->I.userdata_bobreclaim,userdata,len); + swap->I.userdata_bobreclaimlen = len; + if ( (retval= basilisk_rawtx_sign(coin->symbol,coin->wiftaddr,coin->taddr,coin->pubtype,coin->p2shtype,coin->isPoS,coin->wiftype,swap,&swap->bobreclaim,&swap->bobpayment,swap->I.myprivs[1],0,userdata,len,1,swap->changermd160,swap->bobpayment.I.destaddr,coin->zcash)) == 0 ) + { + for (i=0; ibobreclaim.I.datalen; i++) + printf("%02x",swap->bobreclaim.txbytes[i]); + printf(" <- bobreclaim\n"); + //basilisk_txlog(swap,&swap->bobreclaim,delay); + return(retval); + } + } else printf("basilisk_bobpayment_reclaim cant find (%s)\n",swap->I.bobstr); return(-1); } int32_t basilisk_bobdeposit_refund(struct basilisk_swap *swap,int32_t delay) { - uint8_t userdata[512]; int32_t i,retval,len = 0; char str[65]; - len = basilisk_swapuserdata(userdata,swap->I.privBn,0,swap->I.myprivs[0],swap->bobdeposit.redeemscript,swap->bobdeposit.I.redeemlen); - memcpy(swap->I.userdata_bobrefund,userdata,len); - swap->I.userdata_bobrefundlen = len; - if ( (retval= basilisk_rawtx_sign(swap->bobcoin->symbol,swap->bobcoin->wiftaddr,swap->bobcoin->taddr,swap->bobcoin->pubtype,swap->bobcoin->p2shtype,swap->bobcoin->isPoS,swap->bobcoin->wiftype,swap,&swap->bobrefund,&swap->bobdeposit,swap->I.myprivs[0],0,userdata,len,0,swap->changermd160,swap->bobdeposit.I.destaddr,swap->bobcoin->zcash)) == 0 ) - { - for (i=0; ibobrefund.I.datalen; i++) - printf("%02x",swap->bobrefund.txbytes[i]); - printf(" <- bobrefund.(%s)\n",bits256_str(str,swap->bobrefund.I.txid)); - //basilisk_txlog(swap,&swap->bobrefund,delay); - return(retval); - } + uint8_t userdata[512]; int32_t i,retval,len = 0; char str[65]; struct iguana_info *coin; + if ( (coin= LP_coinfind(swap->I.bobstr)) != 0 ) + { + len = basilisk_swapuserdata(userdata,swap->I.privBn,0,swap->I.myprivs[0],swap->bobdeposit.redeemscript,swap->bobdeposit.I.redeemlen); + memcpy(swap->I.userdata_bobrefund,userdata,len); + swap->I.userdata_bobrefundlen = len; + if ( (retval= basilisk_rawtx_sign(coin->symbol,coin->wiftaddr,coin->taddr,coin->pubtype,coin->p2shtype,coin->isPoS,coin->wiftype,swap,&swap->bobrefund,&swap->bobdeposit,swap->I.myprivs[0],0,userdata,len,0,swap->changermd160,swap->bobdeposit.I.destaddr,coin->zcash)) == 0 ) + { + for (i=0; ibobrefund.I.datalen; i++) + printf("%02x",swap->bobrefund.txbytes[i]); + printf(" <- bobrefund.(%s)\n",bits256_str(str,swap->bobrefund.I.txid)); + //basilisk_txlog(swap,&swap->bobrefund,delay); + return(retval); + } + } else printf("basilisk_bobdeposit_refund cant find (%s)\n",swap->I.bobstr); + return(-1); } @@ -1673,81 +1681,84 @@ void LP_swap_coinaddr(struct iguana_info *coin,char *coinaddr,uint64_t *valuep,u int32_t basilisk_bobscripts_set(struct basilisk_swap *swap,int32_t depositflag,int32_t genflag) { - int32_t j; char coinaddr[64],checkaddr[64]; - bitcoin_address(coinaddr,swap->bobcoin->taddr,swap->bobcoin->pubtype,swap->changermd160,20); - if ( genflag != 0 && swap->I.iambob == 0 ) - printf("basilisk_bobscripts_set WARNING: alice generating BOB tx\n"); - if ( depositflag == 0 ) - { - swap->bobpayment.I.spendlen = basilisk_bobscript(swap->bobpayment.I.rmd160,swap->bobpayment.redeemscript,&swap->bobpayment.I.redeemlen,swap->bobpayment.spendscript,0,&swap->bobpayment.I.locktime,&swap->bobpayment.I.secretstart,&swap->I,0); - bitcoin_address(swap->bobpayment.p2shaddr,swap->bobcoin->taddr,swap->bobcoin->p2shtype,swap->bobpayment.redeemscript,swap->bobpayment.I.redeemlen); - strcpy(swap->bobpayment.I.destaddr,swap->bobpayment.p2shaddr); - //LP_importaddress(swap->bobcoin->symbol,swap->bobpayment.I.destaddr); - //int32_t i; for (i=0; ibobpayment.I.redeemlen; i++) - // printf("%02x",swap->bobpayment.redeemscript[i]); - //printf(" <- bobpayment redeem %d %s\n",i,swap->bobpayment.I.destaddr); - if ( genflag != 0 && bits256_nonz(*(bits256 *)swap->I.secretBn256) != 0 && swap->bobpayment.I.datalen == 0 ) - { - basilisk_rawtx_gen(swap->ctx,"payment",swap->I.started,swap->persistent_pubkey33,1,1,&swap->bobpayment,swap->bobpayment.I.locktime,swap->bobpayment.spendscript,swap->bobpayment.I.spendlen,swap->bobpayment.coin->txfee,1,0,swap->persistent_privkey,swap->changermd160,coinaddr); - if ( swap->bobpayment.I.spendlen == 0 || swap->bobpayment.I.datalen == 0 ) - { - printf("error bob generating %p payment.%d\n",swap->bobpayment.txbytes,swap->bobpayment.I.spendlen); - sleep(DEX_SLEEP); - } - else + int32_t j; char coinaddr[64],checkaddr[64]; struct iguana_info *coin; + if ( (coin= LP_coinfind(swap->I.bobstr)) != 0 ) + { + bitcoin_address(coinaddr,coin->taddr,coin->pubtype,swap->changermd160,20); + if ( genflag != 0 && swap->I.iambob == 0 ) + printf("basilisk_bobscripts_set WARNING: alice generating BOB tx\n"); + if ( depositflag == 0 ) + { + swap->bobpayment.I.spendlen = basilisk_bobscript(swap->bobpayment.I.rmd160,swap->bobpayment.redeemscript,&swap->bobpayment.I.redeemlen,swap->bobpayment.spendscript,0,&swap->bobpayment.I.locktime,&swap->bobpayment.I.secretstart,&swap->I,0); + bitcoin_address(swap->bobpayment.p2shaddr,coin->taddr,coin->p2shtype,swap->bobpayment.redeemscript,swap->bobpayment.I.redeemlen); + strcpy(swap->bobpayment.I.destaddr,swap->bobpayment.p2shaddr); + //LP_importaddress(coin->symbol,swap->bobpayment.I.destaddr); + //int32_t i; for (i=0; ibobpayment.I.redeemlen; i++) + // printf("%02x",swap->bobpayment.redeemscript[i]); + //printf(" <- bobpayment redeem %d %s\n",i,swap->bobpayment.I.destaddr); + if ( genflag != 0 && bits256_nonz(*(bits256 *)swap->I.secretBn256) != 0 && swap->bobpayment.I.datalen == 0 ) { - for (j=0; jbobpayment.I.datalen; j++) - printf("%02x",swap->bobpayment.txbytes[j]); - printf(" <- bobpayment.%d\n",swap->bobpayment.I.datalen); - for (j=0; jbobpayment.I.redeemlen; j++) - printf("%02x",swap->bobpayment.redeemscript[j]); - printf(" <- redeem.%d\n",swap->bobpayment.I.redeemlen); - printf(" <- GENERATED BOB PAYMENT.%d destaddr.(%s)\n",swap->bobpayment.I.datalen,swap->bobpayment.I.destaddr); - LP_swap_coinaddr(swap->bobcoin,checkaddr,0,swap->bobpayment.txbytes,swap->bobpayment.I.datalen,0); - if ( strcmp(swap->bobpayment.I.destaddr,checkaddr) != 0 ) + basilisk_rawtx_gen(swap->ctx,"payment",swap->I.started,swap->persistent_pubkey33,1,1,&swap->bobpayment,swap->bobpayment.I.locktime,swap->bobpayment.spendscript,swap->bobpayment.I.spendlen,coin->txfee,1,0,swap->persistent_privkey,swap->changermd160,coinaddr); + if ( swap->bobpayment.I.spendlen == 0 || swap->bobpayment.I.datalen == 0 ) { - printf("BOBPAYMENT REDEEMADDR MISMATCH??? %s != %s\n",swap->bobpayment.I.destaddr,checkaddr); - return(-1); + printf("error bob generating %p payment.%d\n",swap->bobpayment.txbytes,swap->bobpayment.I.spendlen); + sleep(DEX_SLEEP); + } + else + { + for (j=0; jbobpayment.I.datalen; j++) + printf("%02x",swap->bobpayment.txbytes[j]); + printf(" <- bobpayment.%d\n",swap->bobpayment.I.datalen); + for (j=0; jbobpayment.I.redeemlen; j++) + printf("%02x",swap->bobpayment.redeemscript[j]); + printf(" <- redeem.%d\n",swap->bobpayment.I.redeemlen); + printf(" <- GENERATED BOB PAYMENT.%d destaddr.(%s)\n",swap->bobpayment.I.datalen,swap->bobpayment.I.destaddr); + LP_swap_coinaddr(coin,checkaddr,0,swap->bobpayment.txbytes,swap->bobpayment.I.datalen,0); + if ( strcmp(swap->bobpayment.I.destaddr,checkaddr) != 0 ) + { + printf("BOBPAYMENT REDEEMADDR MISMATCH??? %s != %s\n",swap->bobpayment.I.destaddr,checkaddr); + return(-1); + } + LP_unspents_mark(coin->symbol,swap->bobpayment.vins); + //printf("bobscripts set completed\n"); + return(0); } - LP_unspents_mark(swap->bobcoin->symbol,swap->bobpayment.vins); - //printf("bobscripts set completed\n"); - return(0); } } - } - else - { - swap->bobdeposit.I.spendlen = basilisk_bobscript(swap->bobdeposit.I.rmd160,swap->bobdeposit.redeemscript,&swap->bobdeposit.I.redeemlen,swap->bobdeposit.spendscript,0,&swap->bobdeposit.I.locktime,&swap->bobdeposit.I.secretstart,&swap->I,1); - bitcoin_address(swap->bobdeposit.p2shaddr,swap->bobcoin->taddr,swap->bobcoin->p2shtype,swap->bobdeposit.redeemscript,swap->bobdeposit.I.redeemlen); - strcpy(swap->bobdeposit.I.destaddr,swap->bobdeposit.p2shaddr); - //int32_t i; for (i=0; ibobdeposit.I.redeemlen; i++) - // printf("%02x",swap->bobdeposit.redeemscript[i]); - //printf(" <- bobdeposit redeem %d %s\n",i,swap->bobdeposit.I.destaddr); - if ( genflag != 0 && (swap->bobdeposit.I.datalen == 0 || swap->bobrefund.I.datalen == 0) ) + else { - basilisk_rawtx_gen(swap->ctx,"deposit",swap->I.started,swap->persistent_pubkey33,1,1,&swap->bobdeposit,swap->bobdeposit.I.locktime,swap->bobdeposit.spendscript,swap->bobdeposit.I.spendlen,swap->bobdeposit.coin->txfee,1,0,swap->persistent_privkey,swap->changermd160,coinaddr); - if ( swap->bobdeposit.I.datalen == 0 || swap->bobdeposit.I.spendlen == 0 ) + swap->bobdeposit.I.spendlen = basilisk_bobscript(swap->bobdeposit.I.rmd160,swap->bobdeposit.redeemscript,&swap->bobdeposit.I.redeemlen,swap->bobdeposit.spendscript,0,&swap->bobdeposit.I.locktime,&swap->bobdeposit.I.secretstart,&swap->I,1); + bitcoin_address(swap->bobdeposit.p2shaddr,coin->taddr,coin->p2shtype,swap->bobdeposit.redeemscript,swap->bobdeposit.I.redeemlen); + strcpy(swap->bobdeposit.I.destaddr,swap->bobdeposit.p2shaddr); + //int32_t i; for (i=0; ibobdeposit.I.redeemlen; i++) + // printf("%02x",swap->bobdeposit.redeemscript[i]); + //printf(" <- bobdeposit redeem %d %s\n",i,swap->bobdeposit.I.destaddr); + if ( genflag != 0 && (swap->bobdeposit.I.datalen == 0 || swap->bobrefund.I.datalen == 0) ) { - printf("error bob generating %p deposit.%d\n",swap->bobdeposit.txbytes,swap->bobdeposit.I.spendlen); - sleep(DEX_SLEEP); - } - else - { - for (j=0; jbobdeposit.I.datalen; j++) - printf("%02x",swap->bobdeposit.txbytes[j]); - printf(" <- GENERATED BOB DEPOSIT.%d (%s)\n",swap->bobdeposit.I.datalen,swap->bobdeposit.I.destaddr); - LP_swap_coinaddr(swap->bobcoin,checkaddr,0,swap->bobdeposit.txbytes,swap->bobdeposit.I.datalen,0); - if ( strcmp(swap->bobdeposit.I.destaddr,checkaddr) != 0 ) + basilisk_rawtx_gen(swap->ctx,"deposit",swap->I.started,swap->persistent_pubkey33,1,1,&swap->bobdeposit,swap->bobdeposit.I.locktime,swap->bobdeposit.spendscript,swap->bobdeposit.I.spendlen,coin->txfee,1,0,swap->persistent_privkey,swap->changermd160,coinaddr); + if ( swap->bobdeposit.I.datalen == 0 || swap->bobdeposit.I.spendlen == 0 ) { - printf("BOBDEPOSIT REDEEMADDR MISMATCH??? %s != %s\n",swap->bobdeposit.I.destaddr,checkaddr); - return(-1); + printf("error bob generating %p deposit.%d\n",swap->bobdeposit.txbytes,swap->bobdeposit.I.spendlen); + sleep(DEX_SLEEP); + } + else + { + for (j=0; jbobdeposit.I.datalen; j++) + printf("%02x",swap->bobdeposit.txbytes[j]); + printf(" <- GENERATED BOB DEPOSIT.%d (%s)\n",swap->bobdeposit.I.datalen,swap->bobdeposit.I.destaddr); + LP_swap_coinaddr(coin,checkaddr,0,swap->bobdeposit.txbytes,swap->bobdeposit.I.datalen,0); + if ( strcmp(swap->bobdeposit.I.destaddr,checkaddr) != 0 ) + { + printf("BOBDEPOSIT REDEEMADDR MISMATCH??? %s != %s\n",swap->bobdeposit.I.destaddr,checkaddr); + return(-1); + } + LP_unspents_mark(coin->symbol,swap->bobdeposit.vins); + printf("bobscripts set completed\n"); + return(0); } - LP_unspents_mark(swap->bobcoin->symbol,swap->bobdeposit.vins); - printf("bobscripts set completed\n"); - return(0); } } - } + } else printf("bobscripts set cant find (%s)\n",swap->I.bobstr); return(0); } @@ -1758,7 +1769,7 @@ int32_t basilisk_alicepayment_spend(struct basilisk_swap *swap,struct basilisk_r { int32_t i,retval; printf("alicepayment_spend\n"); - swap->alicepayment.I.spendlen = basilisk_alicescript(swap->alicepayment.redeemscript,&swap->alicepayment.I.redeemlen,swap->alicepayment.spendscript,0,swap->alicepayment.I.destaddr,swap->alicecoin->p2shtype,swap->I.pubAm,swap->I.pubBn); + swap->alicepayment.I.spendlen = basilisk_alicescript(swap->alicepayment.redeemscript,&swap->alicepayment.I.redeemlen,swap->alicepayment.spendscript,0,swap->alicepayment.I.destaddr,coin->p2shtype,swap->I.pubAm,swap->I.pubBn); printf("alicepayment_spend len.%d\n",swap->alicepayment.I.spendlen); if ( swap->I.iambob == 0 ) { @@ -1770,7 +1781,7 @@ int32_t basilisk_alicepayment_spend(struct basilisk_swap *swap,struct basilisk_r memcpy(swap->I.userdata_bobspend,swap->alicepayment.redeemscript,swap->alicepayment.I.spendlen); swap->I.userdata_bobspendlen = swap->alicepayment.I.spendlen; } - if ( (retval= basilisk_rawtx_sign(swap->alicecoin->symbol,swap->alicecoin->pubtype,swap->alicecoin->p2shtype,swap->alicecoin->isPoS,swap->alicecoin->wiftype,swap,dest,&swap->alicepayment,swap->I.privAm,&swap->I.privBn,0,0,1,swap->changermd160)) == 0 ) + if ( (retval= basilisk_rawtx_sign(coin->symbol,coin->pubtype,coin->p2shtype,coin->isPoS,coin->wiftype,swap,dest,&swap->alicepayment,swap->I.privAm,&swap->I.privBn,0,0,1,swap->changermd160)) == 0 ) { for (i=0; iI.datalen; i++) printf("%02x",dest->txbytes[i]); @@ -1795,84 +1806,94 @@ void basilisk_alicepayment(struct basilisk_swap *swap,struct iguana_info *coin,s int32_t basilisk_alicetxs(int32_t pairsock,struct basilisk_swap *swap,uint8_t *data,int32_t maxlen) { - char coinaddr[64]; int32_t i,retval = -1; - if ( swap->alicepayment.I.datalen == 0 ) - basilisk_alicepayment(swap,swap->alicepayment.coin,&swap->alicepayment,swap->I.pubAm,swap->I.pubBn); - if ( swap->alicepayment.I.datalen == 0 || swap->alicepayment.I.spendlen == 0 ) - printf("error alice generating payment.%d\n",swap->alicepayment.I.spendlen); - else + char coinaddr[64]; int32_t i,retval = -1; struct iguana_info *coin; + if ( (coin= LP_coinfind(swap->I.alicestr)) != 0 ) { - bitcoin_address(swap->alicepayment.I.destaddr,swap->alicecoin->taddr,swap->alicecoin->p2shtype,swap->alicepayment.redeemscript,swap->alicepayment.I.redeemlen); - //LP_importaddress(swap->alicecoin->symbol,swap->alicepayment.I.destaddr); - strcpy(swap->alicepayment.p2shaddr,swap->alicepayment.I.destaddr); - retval = 0; - for (i=0; ialicepayment.I.datalen; i++) - printf("%02x",swap->alicepayment.txbytes[i]); - printf(" ALICE PAYMENT created.(%s)\n",swap->alicepayment.I.destaddr); - LP_unspents_mark(swap->alicecoin->symbol,swap->alicepayment.vins); - //LP_importaddress(swap->alicecoin->symbol,swap->alicepayment.I.destaddr); - //basilisk_txlog(swap,&swap->alicepayment,-1); - } - if ( swap->myfee.I.datalen == 0 ) - { - printf("%s generate fee %.8f from.%s\n",swap->alicecoin->symbol,dstr(strcmp(swap->myfee.coin->symbol,"BTC") == 0 ? LP_MIN_TXFEE : swap->myfee.coin->txfee),swap->alicecoin->smartaddr); - bitcoin_address(coinaddr,swap->alicecoin->taddr,swap->alicecoin->pubtype,swap->changermd160,20); - if ( basilisk_rawtx_gen(swap->ctx,"myfee",swap->I.started,swap->persistent_pubkey33,swap->I.iambob,1,&swap->myfee,swap->myfee.I.locktime,swap->myfee.spendscript,swap->myfee.I.spendlen,strcmp(swap->myfee.coin->symbol,"BTC") == 0 ? LP_MIN_TXFEE : swap->myfee.coin->txfee,1,0,swap->persistent_privkey,swap->changermd160,coinaddr) == 0 ) - { - printf("rawtxsend %s %.8f\n",swap->myfee.coin->symbol,dstr(strcmp(swap->myfee.coin->symbol,"BTC") == 0 ? LP_MIN_TXFEE : swap->myfee.coin->txfee)); - swap->I.statebits |= LP_swapdata_rawtxsend(pairsock,swap,0x80,data,maxlen,&swap->myfee,0x40,0); - LP_unspents_mark(swap->I.iambob!=0?swap->bobcoin->symbol:swap->alicecoin->symbol,swap->myfee.vins); - //basilisk_txlog(swap,&swap->myfee,-1); - for (i=0; imyfee.I.datalen; i++) - printf("%02x",swap->myfee.txbytes[i]); - printf(" <- fee state.%x\n",swap->I.statebits); - swap->I.statebits |= 0x40; - } + if ( swap->alicepayment.I.datalen == 0 ) + basilisk_alicepayment(swap,coin,&swap->alicepayment,swap->I.pubAm,swap->I.pubBn); + if ( swap->alicepayment.I.datalen == 0 || swap->alicepayment.I.spendlen == 0 ) + printf("error alice generating payment.%d\n",swap->alicepayment.I.spendlen); else { - printf("error creating myfee\n"); - return(-2); + bitcoin_address(swap->alicepayment.I.destaddr,coin->taddr,coin->p2shtype,swap->alicepayment.redeemscript,swap->alicepayment.I.redeemlen); + //LP_importaddress(coin->symbol,swap->alicepayment.I.destaddr); + strcpy(swap->alicepayment.p2shaddr,swap->alicepayment.I.destaddr); + retval = 0; + for (i=0; ialicepayment.I.datalen; i++) + printf("%02x",swap->alicepayment.txbytes[i]); + printf(" ALICE PAYMENT created.(%s)\n",swap->alicepayment.I.destaddr); + LP_unspents_mark(coin->symbol,swap->alicepayment.vins); + //LP_importaddress(coin->symbol,swap->alicepayment.I.destaddr); + //basilisk_txlog(swap,&swap->alicepayment,-1); } - } - if ( swap->alicepayment.I.datalen != 0 && swap->alicepayment.I.spendlen > 0 && swap->myfee.I.datalen != 0 && swap->myfee.I.spendlen > 0 ) - { - printf("fee sent\n"); - return(0); - } + if ( swap->myfee.I.datalen == 0 ) + { + printf("%s generate fee %.8f from.%s\n",coin->symbol,dstr(strcmp(coin->symbol,"BTC") == 0 ? LP_MIN_TXFEE : coin->txfee),coin->smartaddr); + bitcoin_address(coinaddr,coin->taddr,coin->pubtype,swap->changermd160,20); + if ( basilisk_rawtx_gen(swap->ctx,"myfee",swap->I.started,swap->persistent_pubkey33,swap->I.iambob,1,&swap->myfee,swap->myfee.I.locktime,swap->myfee.spendscript,swap->myfee.I.spendlen,strcmp(coin->symbol,"BTC") == 0 ? LP_MIN_TXFEE : coin->txfee,1,0,swap->persistent_privkey,swap->changermd160,coinaddr) == 0 ) + { + printf("rawtxsend %s %.8f\n",coin->symbol,dstr(strcmp(coin->symbol,"BTC") == 0 ? LP_MIN_TXFEE : coin->txfee)); + swap->I.statebits |= LP_swapdata_rawtxsend(pairsock,swap,0x80,data,maxlen,&swap->myfee,0x40,0); + LP_unspents_mark(swap->I.iambob!=0?coin->symbol:coin->symbol,swap->myfee.vins); + //basilisk_txlog(swap,&swap->myfee,-1); + for (i=0; imyfee.I.datalen; i++) + printf("%02x",swap->myfee.txbytes[i]); + printf(" <- fee state.%x\n",swap->I.statebits); + swap->I.statebits |= 0x40; + } + else + { + printf("error creating myfee\n"); + return(-2); + } + } + if ( swap->alicepayment.I.datalen != 0 && swap->alicepayment.I.spendlen > 0 && swap->myfee.I.datalen != 0 && swap->myfee.I.spendlen > 0 ) + { + printf("fee sent\n"); + return(0); + } + } else printf("basilisk alicetx cant find (%s)\n",swap->I.alicestr); return(-1); } int32_t LP_verify_otherfee(struct basilisk_swap *swap,uint8_t *data,int32_t datalen) { - int32_t diff; - if ( LP_rawtx_spendscript(swap,swap->bobcoin->longestchain,&swap->otherfee,0,data,datalen,0) == 0 ) - { - printf("otherfee amount %.8f -> %s vs %s locktime %u vs %u\n",dstr(swap->otherfee.I.amount),swap->otherfee.p2shaddr,swap->otherfee.I.destaddr,swap->otherfee.I.locktime,swap->I.started+1); - if ( strcmp(swap->otherfee.I.destaddr,swap->otherfee.p2shaddr) == 0 ) - { - diff = swap->otherfee.I.locktime - (swap->I.started+1); - if ( diff < 0 ) - diff = -diff; - if ( diff < 10 ) - printf("dexfee verified\n"); - else printf("locktime mismatch in otherfee, reject %u vs %u\n",swap->otherfee.I.locktime,swap->I.started+1); - return(0); - } else printf("destaddress mismatch in other fee, reject (%s) vs (%s)\n",swap->otherfee.I.destaddr,swap->otherfee.p2shaddr); - } + int32_t diff; struct iguana_info *coin; + if ( (coin= LP_coinfind(swap->I.iambob != 0 ? swap->I.alicestr : swap->I.bobstr)) != 0 ) + { + if ( LP_rawtx_spendscript(swap,coin->longestchain,&swap->otherfee,0,data,datalen,0) == 0 ) + { + printf("otherfee amount %.8f -> %s vs %s locktime %u vs %u\n",dstr(swap->otherfee.I.amount),swap->otherfee.p2shaddr,swap->otherfee.I.destaddr,swap->otherfee.I.locktime,swap->I.started+1); + if ( strcmp(swap->otherfee.I.destaddr,swap->otherfee.p2shaddr) == 0 ) + { + diff = swap->otherfee.I.locktime - (swap->I.started+1); + if ( diff < 0 ) + diff = -diff; + if ( diff < 10 ) + printf("dexfee verified\n"); + else printf("locktime mismatch in otherfee, reject %u vs %u\n",swap->otherfee.I.locktime,swap->I.started+1); + return(0); + } else printf("destaddress mismatch in other fee, reject (%s) vs (%s)\n",swap->otherfee.I.destaddr,swap->otherfee.p2shaddr); + } + } else printf("cant find other coin iambob.%d\n",swap->I.iambob); return(-1); } int32_t LP_verify_alicespend(struct basilisk_swap *swap,uint8_t *data,int32_t datalen) { - if ( LP_rawtx_spendscript(swap,swap->bobcoin->longestchain,&swap->alicespend,0,data,datalen,0) == 0 ) + struct iguana_info *coin; + if ( (coin= LP_coinfind(swap->I.alicestr)) != 0 ) { - printf("alicespend amount %.8f -> %s vs %s\n",dstr(swap->alicespend.I.amount),swap->alicespend.p2shaddr,swap->alicespend.I.destaddr); - if ( strcmp(swap->alicespend.I.destaddr,swap->alicespend.p2shaddr) == 0 ) + if ( LP_rawtx_spendscript(swap,coin->longestchain,&swap->alicespend,0,data,datalen,0) == 0 ) { - printf("alicespend verified\n"); - return(0); + printf("alicespend amount %.8f -> %s vs %s\n",dstr(swap->alicespend.I.amount),swap->alicespend.p2shaddr,swap->alicespend.I.destaddr); + if ( strcmp(swap->alicespend.I.destaddr,swap->alicespend.p2shaddr) == 0 ) + { + printf("alicespend verified\n"); + return(0); + } } - } + } else printf("verify alicespend cant find (%s)\n",swap->I.alicestr); return(-1); } @@ -1885,109 +1906,120 @@ int32_t LP_verify_alicespend(struct basilisk_swap *swap,uint8_t *data,int32_t da int32_t LP_verify_bobdeposit(struct basilisk_swap *swap,uint8_t *data,int32_t datalen) { - uint8_t userdata[512]; int32_t retval=-1,len = 0; static bits256 zero; - if ( LP_rawtx_spendscript(swap,swap->bobcoin->longestchain,&swap->bobdeposit,0,data,datalen,0) == 0 ) - { - swap->aliceclaim.utxovout = 0; - swap->bobdeposit.I.signedtxid = LP_broadcast_tx(swap->bobdeposit.name,swap->bobcoin->symbol,swap->bobdeposit.txbytes,swap->bobdeposit.I.datalen); - if ( bits256_nonz(swap->bobdeposit.I.signedtxid) != 0 ) - swap->depositunconf = 1; - else swap->bobdeposit.I.signedtxid = swap->bobdeposit.I.actualtxid; - len = basilisk_swapuserdata(userdata,zero,1,swap->I.myprivs[0],swap->bobdeposit.redeemscript,swap->bobdeposit.I.redeemlen); - swap->aliceclaim.utxotxid = swap->bobdeposit.I.signedtxid; - memcpy(swap->I.userdata_aliceclaim,userdata,len); - swap->I.userdata_aliceclaimlen = len; - bitcoin_address(swap->bobdeposit.p2shaddr,swap->bobcoin->taddr,swap->bobcoin->p2shtype,swap->bobdeposit.redeemscript,swap->bobdeposit.I.redeemlen); - strcpy(swap->bobdeposit.I.destaddr,swap->bobdeposit.p2shaddr); - basilisk_dontforget_update(swap,&swap->bobdeposit); - //int32_t i; char str[65]; for (i=0; ibobdeposit.I.datalen; i++) - // printf("%02x",swap->bobdeposit.txbytes[i]); - //printf(" <- bobdeposit.%d %s\n",swap->bobdeposit.I.datalen,bits256_str(str,swap->bobdeposit.I.signedtxid)); - //for (i=0; ibobdeposit.I.redeemlen; i++) - // printf("%02x",swap->bobdeposit.redeemscript[i]); - //printf(" <- bobdeposit redeem %d %s suppress.%d\n",i,swap->bobdeposit.I.destaddr,swap->aliceclaim.I.suppress_pubkeys); - memcpy(swap->aliceclaim.redeemscript,swap->bobdeposit.redeemscript,swap->bobdeposit.I.redeemlen); - swap->aliceclaim.I.redeemlen = swap->bobdeposit.I.redeemlen; - memcpy(swap->aliceclaim.I.pubkey33,swap->persistent_pubkey33,33); - bitcoin_address(swap->aliceclaim.I.destaddr,swap->alicecoin->taddr,swap->alicecoin->pubtype,swap->persistent_pubkey33,33); - retval = 0; - if ( (retval= basilisk_rawtx_sign(swap->bobcoin->symbol,swap->bobcoin->wiftaddr,swap->bobcoin->taddr,swap->bobcoin->pubtype,swap->bobcoin->p2shtype,swap->bobcoin->isPoS,swap->bobcoin->wiftype,swap,&swap->aliceclaim,&swap->bobdeposit,swap->I.myprivs[0],0,userdata,len,1,swap->changermd160,swap->bobdeposit.I.destaddr,swap->bobcoin->zcash)) == 0 ) - { - int32_t i; for (i=0; ibobdeposit.I.datalen; i++) - printf("%02x",swap->bobdeposit.txbytes[i]); - printf(" <- bobdeposit\n"); - for (i=0; ialiceclaim.I.datalen; i++) - printf("%02x",swap->aliceclaim.txbytes[i]); - printf(" <- aliceclaim\n"); - //basilisk_txlog(swap,&swap->aliceclaim,swap->I.putduration+swap->I.callduration); - return(LP_waitmempool(swap->bobcoin->symbol,swap->bobdeposit.I.destaddr,swap->bobdeposit.I.signedtxid,0,60)); - } else printf("error signing aliceclaim suppress.%d vin.(%s)\n",swap->aliceclaim.I.suppress_pubkeys,swap->bobdeposit.I.destaddr); - } + static bits256 zero; + uint8_t userdata[512]; int32_t retval=-1,len = 0; struct iguana_info *coin; + if ( (coin= LP_coinfind(swap->I.bobstr)) != 0 ) + { + if ( LP_rawtx_spendscript(swap,coin->longestchain,&swap->bobdeposit,0,data,datalen,0) == 0 ) + { + swap->aliceclaim.utxovout = 0; + swap->bobdeposit.I.signedtxid = LP_broadcast_tx(swap->bobdeposit.name,coin->symbol,swap->bobdeposit.txbytes,swap->bobdeposit.I.datalen); + if ( bits256_nonz(swap->bobdeposit.I.signedtxid) != 0 ) + swap->depositunconf = 1; + else swap->bobdeposit.I.signedtxid = swap->bobdeposit.I.actualtxid; + len = basilisk_swapuserdata(userdata,zero,1,swap->I.myprivs[0],swap->bobdeposit.redeemscript,swap->bobdeposit.I.redeemlen); + swap->aliceclaim.utxotxid = swap->bobdeposit.I.signedtxid; + memcpy(swap->I.userdata_aliceclaim,userdata,len); + swap->I.userdata_aliceclaimlen = len; + bitcoin_address(swap->bobdeposit.p2shaddr,coin->taddr,coin->p2shtype,swap->bobdeposit.redeemscript,swap->bobdeposit.I.redeemlen); + strcpy(swap->bobdeposit.I.destaddr,swap->bobdeposit.p2shaddr); + basilisk_dontforget_update(swap,&swap->bobdeposit); + //int32_t i; char str[65]; for (i=0; ibobdeposit.I.datalen; i++) + // printf("%02x",swap->bobdeposit.txbytes[i]); + //printf(" <- bobdeposit.%d %s\n",swap->bobdeposit.I.datalen,bits256_str(str,swap->bobdeposit.I.signedtxid)); + //for (i=0; ibobdeposit.I.redeemlen; i++) + // printf("%02x",swap->bobdeposit.redeemscript[i]); + //printf(" <- bobdeposit redeem %d %s suppress.%d\n",i,swap->bobdeposit.I.destaddr,swap->aliceclaim.I.suppress_pubkeys); + memcpy(swap->aliceclaim.redeemscript,swap->bobdeposit.redeemscript,swap->bobdeposit.I.redeemlen); + swap->aliceclaim.I.redeemlen = swap->bobdeposit.I.redeemlen; + memcpy(swap->aliceclaim.I.pubkey33,swap->persistent_pubkey33,33); + bitcoin_address(swap->aliceclaim.I.destaddr,coin->taddr,coin->pubtype,swap->persistent_pubkey33,33); + retval = 0; + if ( (retval= basilisk_rawtx_sign(coin->symbol,coin->wiftaddr,coin->taddr,coin->pubtype,coin->p2shtype,coin->isPoS,coin->wiftype,swap,&swap->aliceclaim,&swap->bobdeposit,swap->I.myprivs[0],0,userdata,len,1,swap->changermd160,swap->bobdeposit.I.destaddr,coin->zcash)) == 0 ) + { + int32_t i; for (i=0; ibobdeposit.I.datalen; i++) + printf("%02x",swap->bobdeposit.txbytes[i]); + printf(" <- bobdeposit\n"); + for (i=0; ialiceclaim.I.datalen; i++) + printf("%02x",swap->aliceclaim.txbytes[i]); + printf(" <- aliceclaim\n"); + //basilisk_txlog(swap,&swap->aliceclaim,swap->I.putduration+swap->I.callduration); + return(LP_waitmempool(coin->symbol,swap->bobdeposit.I.destaddr,swap->bobdeposit.I.signedtxid,0,60)); + } else printf("error signing aliceclaim suppress.%d vin.(%s)\n",swap->aliceclaim.I.suppress_pubkeys,swap->bobdeposit.I.destaddr); + } + } else printf("verify bob depositcant find bob coin (%s)\n",swap->I.bobstr); printf("error with bobdeposit\n"); return(retval); } int32_t LP_verify_alicepayment(struct basilisk_swap *swap,uint8_t *data,int32_t datalen) { - if ( LP_rawtx_spendscript(swap,swap->alicecoin->longestchain,&swap->alicepayment,0,data,datalen,0) == 0 ) - { - swap->bobspend.utxovout = 0; - swap->bobspend.utxotxid = swap->alicepayment.I.signedtxid = LP_broadcast_tx(swap->alicepayment.name,swap->alicecoin->symbol,swap->alicepayment.txbytes,swap->alicepayment.I.datalen); - bitcoin_address(swap->alicepayment.p2shaddr,swap->alicecoin->taddr,swap->alicecoin->p2shtype,swap->alicepayment.redeemscript,swap->alicepayment.I.redeemlen); - strcpy(swap->alicepayment.I.destaddr,swap->alicepayment.p2shaddr); - if ( bits256_nonz(swap->alicepayment.I.signedtxid) != 0 ) - swap->aliceunconf = 1; - basilisk_dontforget_update(swap,&swap->alicepayment); - return(LP_waitmempool(swap->alicecoin->symbol,swap->alicepayment.I.destaddr,swap->alicepayment.I.signedtxid,0,60)); - //printf("import alicepayment address.(%s)\n",swap->alicepayment.p2shaddr); - //LP_importaddress(swap->alicecoin->symbol,swap->alicepayment.p2shaddr); - return(0); - } + struct iguana_info *coin; + if ( (coin= LP_coinfind(swap->I.alicestr)) != 0 ) + { + if ( LP_rawtx_spendscript(swap,coin->longestchain,&swap->alicepayment,0,data,datalen,0) == 0 ) + { + swap->bobspend.utxovout = 0; + swap->bobspend.utxotxid = swap->alicepayment.I.signedtxid = LP_broadcast_tx(swap->alicepayment.name,coin->symbol,swap->alicepayment.txbytes,swap->alicepayment.I.datalen); + bitcoin_address(swap->alicepayment.p2shaddr,coin->taddr,coin->p2shtype,swap->alicepayment.redeemscript,swap->alicepayment.I.redeemlen); + strcpy(swap->alicepayment.I.destaddr,swap->alicepayment.p2shaddr); + if ( bits256_nonz(swap->alicepayment.I.signedtxid) != 0 ) + swap->aliceunconf = 1; + basilisk_dontforget_update(swap,&swap->alicepayment); + return(LP_waitmempool(coin->symbol,swap->alicepayment.I.destaddr,swap->alicepayment.I.signedtxid,0,60)); + //printf("import alicepayment address.(%s)\n",swap->alicepayment.p2shaddr); + //LP_importaddress(coin->symbol,swap->alicepayment.p2shaddr); + return(0); + } + } else printf("verify alicepayment couldnt find coin.(%s)\n",swap->I.alicestr); printf("error validating alicepayment\n"); return(-1); } int32_t LP_verify_bobpayment(struct basilisk_swap *swap,uint8_t *data,int32_t datalen) { - uint8_t userdata[512]; int32_t i,retval=-1,len = 0; bits256 revAm; - memset(revAm.bytes,0,sizeof(revAm)); - if ( LP_rawtx_spendscript(swap,swap->bobcoin->longestchain,&swap->bobpayment,0,data,datalen,0) == 0 ) - { - swap->alicespend.utxovout = 0; - swap->alicespend.utxotxid = swap->bobpayment.I.signedtxid = LP_broadcast_tx(swap->bobpayment.name,swap->bobpayment.coin->symbol,swap->bobpayment.txbytes,swap->bobpayment.I.datalen); - if ( bits256_nonz(swap->bobpayment.I.signedtxid) != 0 ) - swap->paymentunconf = 1; - for (i=0; i<32; i++) - revAm.bytes[i] = swap->I.privAm.bytes[31-i]; - len = basilisk_swapuserdata(userdata,revAm,0,swap->I.myprivs[0],swap->bobpayment.redeemscript,swap->bobpayment.I.redeemlen); - bitcoin_address(swap->bobpayment.p2shaddr,swap->bobcoin->taddr,swap->bobcoin->p2shtype,swap->bobpayment.redeemscript,swap->bobpayment.I.redeemlen); - strcpy(swap->bobpayment.I.destaddr,swap->bobpayment.p2shaddr); - basilisk_dontforget_update(swap,&swap->bobpayment); - //LP_importaddress(swap->bobcoin->symbol,swap->bobpayment.I.destaddr); - /*for (i=0; ibobpayment.I.datalen; i++) - printf("%02x",swap->bobpayment.txbytes[i]); - printf(" <- bobpayment.%d\n",swap->bobpayment.I.datalen); - for (i=0; ibobpayment.I.redeemlen; i++) - printf("%02x",swap->bobpayment.redeemscript[i]); - printf(" <- bobpayment redeem %d %s %s\n",i,swap->bobpayment.I.destaddr,bits256_str(str,swap->bobpayment.I.signedtxid));*/ - memcpy(swap->I.userdata_alicespend,userdata,len); - swap->I.userdata_alicespendlen = len; - retval = 0; - memcpy(swap->alicespend.I.pubkey33,swap->persistent_pubkey33,33); - bitcoin_address(swap->alicespend.I.destaddr,swap->bobcoin->taddr,swap->bobcoin->pubtype,swap->persistent_pubkey33,33); - //char str[65],str2[65]; printf("bobpaid privAm.(%s) myprivs[0].(%s)\n",bits256_str(str,swap->I.privAm),bits256_str(str2,swap->I.myprivs[0])); - if ( (retval= basilisk_rawtx_sign(swap->bobcoin->symbol,swap->bobcoin->wiftaddr,swap->bobcoin->taddr,swap->bobcoin->pubtype,swap->bobcoin->p2shtype,swap->bobcoin->isPoS,swap->bobcoin->wiftype,swap,&swap->alicespend,&swap->bobpayment,swap->I.myprivs[0],0,userdata,len,1,swap->changermd160,swap->alicepayment.I.destaddr,swap->bobcoin->zcash)) == 0 ) + uint8_t userdata[512]; int32_t i,retval=-1,len = 0; bits256 revAm; struct iguana_info *coin; + if ( (coin= LP_coinfind(swap->I.bobstr)) != 0 ) + { + memset(revAm.bytes,0,sizeof(revAm)); + if ( LP_rawtx_spendscript(swap,coin->longestchain,&swap->bobpayment,0,data,datalen,0) == 0 ) { + swap->alicespend.utxovout = 0; + swap->alicespend.utxotxid = swap->bobpayment.I.signedtxid = LP_broadcast_tx(swap->bobpayment.name,coin->symbol,swap->bobpayment.txbytes,swap->bobpayment.I.datalen); + if ( bits256_nonz(swap->bobpayment.I.signedtxid) != 0 ) + swap->paymentunconf = 1; + for (i=0; i<32; i++) + revAm.bytes[i] = swap->I.privAm.bytes[31-i]; + len = basilisk_swapuserdata(userdata,revAm,0,swap->I.myprivs[0],swap->bobpayment.redeemscript,swap->bobpayment.I.redeemlen); + bitcoin_address(swap->bobpayment.p2shaddr,coin->taddr,coin->p2shtype,swap->bobpayment.redeemscript,swap->bobpayment.I.redeemlen); + strcpy(swap->bobpayment.I.destaddr,swap->bobpayment.p2shaddr); + basilisk_dontforget_update(swap,&swap->bobpayment); + //LP_importaddress(coin->symbol,swap->bobpayment.I.destaddr); /*for (i=0; ibobpayment.I.datalen; i++) - printf("%02x",swap->bobpayment.txbytes[i]); - printf(" <- bobpayment\n"); - for (i=0; ialicespend.I.datalen; i++) - printf("%02x",swap->alicespend.txbytes[i]); - printf(" <- alicespend\n\n");*/ - swap->I.alicespent = 1; - return(LP_waitmempool(swap->bobcoin->symbol,swap->bobpayment.I.destaddr,swap->bobpayment.I.signedtxid,0,60)); - } else printf("error signing aliceclaim suppress.%d vin.(%s)\n",swap->alicespend.I.suppress_pubkeys,swap->bobpayment.I.destaddr); - } + printf("%02x",swap->bobpayment.txbytes[i]); + printf(" <- bobpayment.%d\n",swap->bobpayment.I.datalen); + for (i=0; ibobpayment.I.redeemlen; i++) + printf("%02x",swap->bobpayment.redeemscript[i]); + printf(" <- bobpayment redeem %d %s %s\n",i,swap->bobpayment.I.destaddr,bits256_str(str,swap->bobpayment.I.signedtxid));*/ + memcpy(swap->I.userdata_alicespend,userdata,len); + swap->I.userdata_alicespendlen = len; + retval = 0; + memcpy(swap->alicespend.I.pubkey33,swap->persistent_pubkey33,33); + bitcoin_address(swap->alicespend.I.destaddr,coin->taddr,coin->pubtype,swap->persistent_pubkey33,33); + //char str[65],str2[65]; printf("bobpaid privAm.(%s) myprivs[0].(%s)\n",bits256_str(str,swap->I.privAm),bits256_str(str2,swap->I.myprivs[0])); + if ( (retval= basilisk_rawtx_sign(coin->symbol,coin->wiftaddr,coin->taddr,coin->pubtype,coin->p2shtype,coin->isPoS,coin->wiftype,swap,&swap->alicespend,&swap->bobpayment,swap->I.myprivs[0],0,userdata,len,1,swap->changermd160,swap->alicepayment.I.destaddr,coin->zcash)) == 0 ) + { + /*for (i=0; ibobpayment.I.datalen; i++) + printf("%02x",swap->bobpayment.txbytes[i]); + printf(" <- bobpayment\n"); + for (i=0; ialicespend.I.datalen; i++) + printf("%02x",swap->alicespend.txbytes[i]); + printf(" <- alicespend\n\n");*/ + swap->I.alicespent = 1; + return(LP_waitmempool(coin->symbol,swap->bobpayment.I.destaddr,swap->bobpayment.I.signedtxid,0,60)); + } else printf("error signing aliceclaim suppress.%d vin.(%s)\n",swap->alicespend.I.suppress_pubkeys,swap->bobpayment.I.destaddr); + } + } else printf("verify bobpayment cant find (%s)\n",swap->I.bobstr); printf("error validating bobpayment\n"); return(-1); } From 574014c366ce041e09487bab4416a7913d0d379c Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 02:43:17 +0200 Subject: [PATCH 057/306] Test --- iguana/exchanges/LP_nativeDEX.c | 2 +- iguana/exchanges/LP_ordermatch.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 430b104dd..497aebe75 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -133,7 +133,7 @@ char GLOBAL_DBDIR[] = { "DB" }; char LP_myipaddr[64],LP_publicaddr[64],USERHOME[512] = { "/root" }; char LP_gui[16] = { "cli" }; -char *default_LPnodes[] = { "5.9.253.195", "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", +char *default_LPnodes[] = { "5.9.253.195", "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", //"24.54.206.138", "173.212.225.176", "136.243.45.140", "107.72.162.127", "72.50.16.86", "51.15.202.191", "173.228.198.88", "51.15.203.171", "51.15.86.136", "51.15.94.249", "51.15.80.18", "51.15.91.40", "51.15.54.2", "51.15.86.31", "51.15.82.29", "51.15.89.155", };//"5.9.253.204" }; // diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index f65f88370..4f99f2298 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -158,6 +158,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 ) { + //alice not eligible 0.36893923 -> dest 0.55020000 1.49130251 (0.61732249 0.00104324) 14b8b74808d2d34a70e5eddd1cad47d855858f8b23cac802576d4d37b5f8af8f/v1 abec6e76169bcb738235ca67fab02cc55390f39e422aa71f1badf8747c290cc4/v1 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); } From 6e73032283844d668b7e0f78d08fee596c85f3d3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 02:45:42 +0200 Subject: [PATCH 058/306] Test --- iguana/exchanges/LP_transaction.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index c2a07a804..82120368d 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -1230,8 +1230,8 @@ int32_t basilisk_rawtx_gen(void *ctx,char *str,uint32_t swapstarted,uint8_t *pub return(-1); if ( strcmp(coin->smartaddr,vinaddr) != 0 ) { - printf("???????????????????????? basilisk_rawtx_gen mismatched %s vinaddr.%s != (%s)\n",coin->symbol,vinaddr,coin->smartaddr); - //return(-1); + printf("???????????????????????? basilisk_rawtx_gen mismatched %s %s vinaddr.%s != (%s)\n",rawtx->symbol,coin->symbol,vinaddr,coin->smartaddr); + return(-1); } argjson = cJSON_CreateObject(); jaddbits256(argjson,"utxotxid",rawtx->utxotxid); From 08d4dc192b55a7d38949fdf22874704efae85409 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 02:49:43 +0200 Subject: [PATCH 059/306] Test --- iguana/exchanges/LP_commands.c | 2 +- iguana/exchanges/LP_nativeDEX.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 3aca6ee1c..41df9bd17 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -486,7 +486,7 @@ bot_resume(botid)\n\ { ptr->privkeydepth = 0; LP_address(ptr,ptr->smartaddr); - if ( jint(argjson,"reset") != 0 ) + if ( 0 && jint(argjson,"reset") != 0 ) { LP_address_utxo_reset(ptr); LP_passphrase_init(jstr(argjson,"passphrase"),G.gui); diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 497aebe75..bd0bb193a 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -518,6 +518,8 @@ void LP_coinsloop(void *_coins) continue; } } + if ( coin->smartaddr[0] == 0 ) + printf("%s has no smartaddress??\n",coin->symbol); memset(&zero,0,sizeof(zero)); if ( coin->inactive != 0 ) continue; From d7a48f542cecb8b99702779660a57ff5cafb13ec Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 03:00:37 +0200 Subject: [PATCH 060/306] Test --- iguana/exchanges/LP_bitcoin.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iguana/exchanges/LP_bitcoin.c b/iguana/exchanges/LP_bitcoin.c index 373af373b..8eaeafd86 100644 --- a/iguana/exchanges/LP_bitcoin.c +++ b/iguana/exchanges/LP_bitcoin.c @@ -3198,6 +3198,7 @@ cJSON *iguana_voutjson(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,struct igu jadd(json,"scriptPubKey",skey); } } + free(vp); return(json); } From 7432c82dc5c4521ff80c7ac11113c435ef4461ae Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 03:05:38 +0200 Subject: [PATCH 061/306] Test --- iguana/exchanges/LP_transaction.c | 2 +- iguana/exchanges/LP_utxo.c | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index 82120368d..6f54db403 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -910,7 +910,7 @@ int32_t LP_vins_select(void *ctx,struct iguana_info *coin,int64_t *totalp,int64_ printf("have utxotxid but wasnt found up.%p\n",up); if ( up == 0 ) { - value = LP_txvalue(coin->smartaddr,coin->symbol,utxotxid,utxovout); + value = LP_txvalue(0,coin->symbol,utxotxid,utxovout); LP_address_utxoadd("withdraw",coin,coin->smartaddr,utxotxid,utxovout,value,1,-1); printf("added after not finding\n"); } diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index bfd1103f3..5d4b5b482 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -765,13 +765,12 @@ uint64_t LP_txvalue(char *coinaddr,char *symbol,bits256 txid,int32_t vout) } else if ( coin->electrum == 0 ) { - uint64_t value; char _coinaddr[64]; + uint64_t value; if ( (txobj= LP_gettxout(coin->symbol,coinaddr,txid,vout)) != 0 ) { value = LP_value_extract(txobj,0);//SATOSHIDEN * (jdouble(txobj,"value") + jdouble(txobj,"interest")); - if ( coinaddr == 0 ) - coinaddr = _coinaddr; - LP_destaddr(coinaddr,txobj); + if ( coinaddr != 0 ) + LP_destaddr(coinaddr,txobj); //printf("pruned node? LP_txvalue couldnt find %s tx %s, but gettxout %.8f\n",coin->symbol,bits256_str(str,txid),dstr(value)); if ( value != 0 ) { From cea1ddfe59664030786be3851404dddd0dbbcadf Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 03:24:54 +0200 Subject: [PATCH 062/306] Test --- iguana/exchanges/LP_bitcoin.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_bitcoin.c b/iguana/exchanges/LP_bitcoin.c index 8eaeafd86..a86473d61 100644 --- a/iguana/exchanges/LP_bitcoin.c +++ b/iguana/exchanges/LP_bitcoin.c @@ -3331,7 +3331,7 @@ int32_t iguana_rwjoinsplit(int32_t rwflag,uint8_t *serialized,struct iguana_msgj int32_t iguana_rwmsgtx(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t isPoS,int32_t height,int32_t rwflag,cJSON *json,uint8_t *serialized,int32_t maxsize,struct iguana_msgtx *msg,bits256 *txidp,char *vpnstr,uint8_t *extraspace,int32_t extralen,cJSON *vins,int32_t suppress_pubkeys,int32_t zcash) { - int32_t i,n,len = 0,extraused=0; uint32_t seglen; uint8_t segwitflag=0,spendscript[IGUANA_MAXSCRIPTSIZE],*txstart = serialized,*sigser=0; char txidstr[65]; cJSON *vinarray=0,*voutarray=0; bits256 sigtxid; + int32_t i,n,len = 0,extraused=0; uint32_t seglen,tmp,segitems; uint8_t segwitflag=0,spendscript[IGUANA_MAXSCRIPTSIZE],*txstart = serialized,*sigser=0; char txidstr[65]; cJSON *vinarray=0,*voutarray=0; bits256 sigtxid; len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->version),&msg->version); if ( json != 0 ) @@ -3441,10 +3441,18 @@ int32_t iguana_rwmsgtx(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t is printf("unsupported rwflag.%d when segwitflag\n",rwflag); else { - len += iguana_rwvarint32(rwflag,&serialized[len],&seglen); - printf("witness len.%d sum %d vs max.%d\n",seglen,seglen+len,maxsize); - if ( seglen+len < maxsize ) - len += maxsize; + len += iguana_rwvarint32(rwflag,&serialized[len],&segitems); + printf("witness segitems.%d sum %d vs max.%d\n",segitems,len,maxsize); + for (i=0; i= maxsize ) + { + printf("i.%d of segitems.%d overflowed %d+%d >= max.%d\n",i,segitems,len,tmp,maxsize); + break; + } else len += tmp; + } } } len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->lock_time),&msg->lock_time); From cfacf467cabe9a1fc5360d15ec87e99cb589a776 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 03:38:11 +0200 Subject: [PATCH 063/306] Test --- iguana/exchanges/LP_bitcoin.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/iguana/exchanges/LP_bitcoin.c b/iguana/exchanges/LP_bitcoin.c index a86473d61..7d945ebb2 100644 --- a/iguana/exchanges/LP_bitcoin.c +++ b/iguana/exchanges/LP_bitcoin.c @@ -3331,7 +3331,7 @@ int32_t iguana_rwjoinsplit(int32_t rwflag,uint8_t *serialized,struct iguana_msgj int32_t iguana_rwmsgtx(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t isPoS,int32_t height,int32_t rwflag,cJSON *json,uint8_t *serialized,int32_t maxsize,struct iguana_msgtx *msg,bits256 *txidp,char *vpnstr,uint8_t *extraspace,int32_t extralen,cJSON *vins,int32_t suppress_pubkeys,int32_t zcash) { - int32_t i,n,len = 0,extraused=0; uint32_t seglen,tmp,segitems; uint8_t segwitflag=0,spendscript[IGUANA_MAXSCRIPTSIZE],*txstart = serialized,*sigser=0; char txidstr[65]; cJSON *vinarray=0,*voutarray=0; bits256 sigtxid; + int32_t i,j,n,len = 0,extraused=0; uint32_t tmp,segitems; uint8_t segwitflag=0,spendscript[IGUANA_MAXSCRIPTSIZE],*txstart = serialized,*sigser=0; char txidstr[65]; cJSON *vinarray=0,*voutarray=0; bits256 sigtxid; len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->version),&msg->version); if ( json != 0 ) @@ -3441,18 +3441,23 @@ int32_t iguana_rwmsgtx(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t is printf("unsupported rwflag.%d when segwitflag\n",rwflag); else { - len += iguana_rwvarint32(rwflag,&serialized[len],&segitems); - printf("witness segitems.%d sum %d vs max.%d\n",segitems,len,maxsize); - for (i=0; itx_in; i++) { - len += iguana_rwvarint32(rwflag,&serialized[len],&tmp); - printf("%d ",tmp); - if ( len+tmp >= maxsize ) + len += iguana_rwvarint32(rwflag,&serialized[len],&segitems); + printf("vini.%d (%d:",i,segitems); + for (j=0; j= max.%d\n",i,segitems,len,tmp,maxsize); - break; - } else len += tmp; + len += iguana_rwvarint32(rwflag,&serialized[len],&tmp); + printf(" %d",tmp); + if ( len+tmp >= maxsize ) + { + printf("vini.%d of %d, j.%d of segitems.%d overflowed %d+%d >= max.%d\n",i,msg->tx_in,j,segitems,len,tmp,maxsize); + break; + } else len += tmp; + } + printf("), "); } + printf("witness sum %d vs max.%d\n",len,maxsize); } } len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->lock_time),&msg->lock_time); From 142b72804e238182766746e05345a0fed738ffa0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 03:46:41 +0200 Subject: [PATCH 064/306] Test --- iguana/exchanges/LP_bitcoin.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_bitcoin.c b/iguana/exchanges/LP_bitcoin.c index 7d945ebb2..772e4aa34 100644 --- a/iguana/exchanges/LP_bitcoin.c +++ b/iguana/exchanges/LP_bitcoin.c @@ -3457,7 +3457,8 @@ int32_t iguana_rwmsgtx(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t is } printf("), "); } - printf("witness sum %d vs max.%d\n",len,maxsize); + bits256 txid = bits256_doublesha256(0,serialized,len+sizeof(msg->lock_time)); + char str[65]; printf("witness sum %d vs max.%d txid %s\n",len,maxsize,bits256_str(str,txid)); } } len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->lock_time),&msg->lock_time); From b1de4ec3032e19fcf3219c8db3bc899d2fe0234c Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 03:54:00 +0200 Subject: [PATCH 065/306] Test --- iguana/exchanges/LP_bitcoin.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_bitcoin.c b/iguana/exchanges/LP_bitcoin.c index 772e4aa34..657672b64 100644 --- a/iguana/exchanges/LP_bitcoin.c +++ b/iguana/exchanges/LP_bitcoin.c @@ -3331,7 +3331,7 @@ int32_t iguana_rwjoinsplit(int32_t rwflag,uint8_t *serialized,struct iguana_msgj int32_t iguana_rwmsgtx(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t isPoS,int32_t height,int32_t rwflag,cJSON *json,uint8_t *serialized,int32_t maxsize,struct iguana_msgtx *msg,bits256 *txidp,char *vpnstr,uint8_t *extraspace,int32_t extralen,cJSON *vins,int32_t suppress_pubkeys,int32_t zcash) { - int32_t i,j,n,len = 0,extraused=0; uint32_t tmp,segitems; uint8_t segwitflag=0,spendscript[IGUANA_MAXSCRIPTSIZE],*txstart = serialized,*sigser=0; char txidstr[65]; cJSON *vinarray=0,*voutarray=0; bits256 sigtxid; + int32_t i,j,n,segtxlen,len = 0,extraused=0; uint32_t tmp,segitems; uint8_t *segtx,segwitflag=0,spendscript[IGUANA_MAXSCRIPTSIZE],*txstart = serialized,*sigser=0; char txidstr[65]; cJSON *vinarray=0,*voutarray=0; bits256 sigtxid; len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->version),&msg->version); if ( json != 0 ) @@ -3436,6 +3436,11 @@ int32_t iguana_rwmsgtx(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t is } if ( segwitflag != 0 ) { + segtxlen = len - 2 + sizeof(msg->lock_time); + segtx = malloc(segtxlen); + memcpy(segtx,serialized,sizeof(int32_t)); + memcpy(&segtx[sizeof(int32_t)],&serialized[sizeof(int32_t)+2],len-2-sizeof(int32_t)); + printf("tx_out %d, tx_in %d %02x %02x %02x\n",msg->tx_out,msg->tx_in,serialized[len],serialized[len+1],serialized[len+2]); if ( rwflag != 0 ) printf("unsupported rwflag.%d when segwitflag\n",rwflag); @@ -3457,7 +3462,8 @@ int32_t iguana_rwmsgtx(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t is } printf("), "); } - bits256 txid = bits256_doublesha256(0,serialized,len+sizeof(msg->lock_time)); + memcpy(&segtx[segtxlen-sizeof(int32_t)],&serialized[len],sizeof(int32_t)); + bits256 txid = bits256_doublesha256(0,segtx,segtxlen); char str[65]; printf("witness sum %d vs max.%d txid %s\n",len,maxsize,bits256_str(str,txid)); } } From 825115c4a28e06d2c3a435845b032e6c01b2af6d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 03:56:32 +0200 Subject: [PATCH 066/306] Test --- iguana/exchanges/LP_bitcoin.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/iguana/exchanges/LP_bitcoin.c b/iguana/exchanges/LP_bitcoin.c index 657672b64..97ca24817 100644 --- a/iguana/exchanges/LP_bitcoin.c +++ b/iguana/exchanges/LP_bitcoin.c @@ -3449,22 +3449,22 @@ int32_t iguana_rwmsgtx(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t is for (i=0; itx_in; i++) { len += iguana_rwvarint32(rwflag,&serialized[len],&segitems); - printf("vini.%d (%d:",i,segitems); + //printf("vini.%d (%d:",i,segitems); for (j=0; j= maxsize ) { printf("vini.%d of %d, j.%d of segitems.%d overflowed %d+%d >= max.%d\n",i,msg->tx_in,j,segitems,len,tmp,maxsize); break; } else len += tmp; } - printf("), "); + //printf("), "); } memcpy(&segtx[segtxlen-sizeof(int32_t)],&serialized[len],sizeof(int32_t)); - bits256 txid = bits256_doublesha256(0,segtx,segtxlen); - char str[65]; printf("witness sum %d vs max.%d txid %s\n",len,maxsize,bits256_str(str,txid)); + *txidp = bits256_doublesha256(0,segtx,segtxlen); + //char str[65]; printf("witness sum %d vs max.%d txid %s\n",len,maxsize,bits256_str(str,txid)); } } len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->lock_time),&msg->lock_time); @@ -3519,7 +3519,8 @@ int32_t iguana_rwmsgtx(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t is jadd(json,"vout",voutarray); jaddnum(json,"numvouts",msg->tx_out); } - *txidp = bits256_doublesha256(txidstr,txstart,len); + if ( segwitflag == 0 ) + *txidp = bits256_doublesha256(txidstr,txstart,len); if ( json != 0 ) { jaddnum(json,"locktime",msg->lock_time); From a2d3150dd5d64a43faeea07845878613326616d3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 03:58:27 +0200 Subject: [PATCH 067/306] Test --- iguana/exchanges/LP_bitcoin.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_bitcoin.c b/iguana/exchanges/LP_bitcoin.c index 97ca24817..0c8e9abc6 100644 --- a/iguana/exchanges/LP_bitcoin.c +++ b/iguana/exchanges/LP_bitcoin.c @@ -3364,7 +3364,7 @@ int32_t iguana_rwmsgtx(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t is if ( serialized[len] == 0x00 && (segwitflag= serialized[len+1]) == 0x01 ) { len += 2; - printf("SEGWIT transaction\n"); + //printf("SEGWIT transaction\n"); } } len += iguana_rwvarint32(rwflag,&serialized[len],&msg->tx_in); @@ -3441,7 +3441,7 @@ int32_t iguana_rwmsgtx(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t is memcpy(segtx,serialized,sizeof(int32_t)); memcpy(&segtx[sizeof(int32_t)],&serialized[sizeof(int32_t)+2],len-2-sizeof(int32_t)); - printf("tx_out %d, tx_in %d %02x %02x %02x\n",msg->tx_out,msg->tx_in,serialized[len],serialized[len+1],serialized[len+2]); + //printf("tx_out %d, tx_in %d %02x %02x %02x\n",msg->tx_out,msg->tx_in,serialized[len],serialized[len+1],serialized[len+2]); if ( rwflag != 0 ) printf("unsupported rwflag.%d when segwitflag\n",rwflag); else From e480e2d7e38b2ac99dd8d8f493f078580fe36aed Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 04:04:44 +0200 Subject: [PATCH 068/306] Test --- iguana/exchanges/LP_commands.c | 2 +- iguana/exchanges/LP_nativeDEX.c | 16 +--------------- iguana/exchanges/LP_transaction.c | 7 +++++-- 3 files changed, 7 insertions(+), 18 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 41df9bd17..3aca6ee1c 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -486,7 +486,7 @@ bot_resume(botid)\n\ { ptr->privkeydepth = 0; LP_address(ptr,ptr->smartaddr); - if ( 0 && jint(argjson,"reset") != 0 ) + if ( jint(argjson,"reset") != 0 ) { LP_address_utxo_reset(ptr); LP_passphrase_init(jstr(argjson,"passphrase"),G.gui); diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index bd0bb193a..123c461be 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -19,26 +19,12 @@ // marketmaker // // alice waiting for bestprice -// regen inventory -// previously, it used to show amount, kmd equiv, perc // bot safe to exit? // // BCH signing +// previously, it used to show amount, kmd equiv, perc // dPoW security -> 4: KMD notarized, 5: BTC notarized, after next notary elections // bigendian architectures need to use little endian for sighash calcs -//BTC LP_transaction_fromdata mismatched txid f78c80e831c02c89c0888e7d4438287030238e09e33f88da6df4dc84b949959b vs 1390f386f5997607e646be9c93f30018aa68ea971790b92b7b06e892656f0769 -//failed blockchain.transaction.get BTC f78c80e831c02c89c0888e7d4438287030238e09e33f88da6df4dc84b949959b -//02000000000101242344292f9117c8318adb84f7991239361da2ff0a15ad2106d402945072cc110a0000001716001470eb5212b558cfc10b31f0849ef88ecf17097ac1ffffffff0c4a8321000000000017a914baed1c79cc6325333d5013b44dc17e8256bf5b718704bf3c000000000017a914255cf2809a1f42569c5c47c71e6234aac35a800f873099f400000000001976a914049877b81a8d6d8592919b75b9bcb4182f7c52cd88acb907e200000000001976a9140614fc114940e867210b09cc900db14d8bc58d2b88ac40771b00000000001976a9148cadbb1d7002d22d60e38ca238678d00f04ed22988ac002d3101000000001976a9140d05714431cf478846cea1435f9eabae9ad5c65388acc0f280010000000017a914c17a70c74154fc53263652aaca26c8d71683f1ba87aa2a4e00000000001976a914feea6b867954b1072962083233796d47e4c1665e88ace0e1de02000000001976a91445b71fbb02df53be5563257b77780b9afcc55bdc88acf6fe6700000000001976a91492332f8ff3b26e3ce2666afa5fee2e45308225af88ace74c1500000000001976a914fc7580f1ce24b2c85c80b2c8e641592b9bbf974588ac081ad000000000001976a9145e61c81c9b3ac55bf90ab00240023e8ddaf43e1788ac02483045022100a74be4e00585637c6792eeff9279508f09163db525f8b16c03e57283d12b0a6a022042cc061d70e78e9260ff30635db4f4e0b317831a8cb1f30473a25b93b4d1b4fb01210238288b60e8c50785809a69517ae3ca2fe3e407cac8b5868c5fb3803c233dfbcc00000000 data2json n.219 vs len.586 - - -//BTC LP_transaction_fromdata mismatched txid ae7af65215554964b7af01babb58fce10fc51d9812ced07ee4a62a1ffe10c0bb vs 051ef4f75898b511dd3aebd687d5a5bdb004226d811aaf13e64be741dbe81ff2 -//failed blockchain.transaction.get BTC ae7af65215554964b7af01babb58fce10fc51d9812ced07ee4a62a1ffe10c0bb -//errortxobj.({"version":1}) -//010000000001010c590740b0c558f75b64cc0d00b0533ff951e403d993b866a87c7c52981388a60300000017160014cd2b7646f9931c85bb9d4d353b652c76b40aff84ffffffff0240420f000000000017a914239ae54cd403a91b084d3244e7e423f05c25ec268728fe28010000000017a914b96e21dd6e11bb67479f9072df55881e7fb17f788702473044022076e4c1cfba0dab889598efdfdcbc7a1046cc0eecfb8fec379994d559143d271c02206b16d9a0e3c425434d1b793d61e1e491f269abc7e7d3af52d95f6a26c1c2aa0d0121037f88a6ccdd608645024b05f408324550cf6fa1c74e3d7c1f94a1e9b57369d10600000000 data2json n.-1 vs len.247 - - -//ScriptSig: PUSHDATA(34)[002072d8f7debd607b94c95ced6cff38265ed99c7c1ee58b67d0a3f3ed43b6d9a977] -//Witness: 040047304402206f23bb2dd06bc70d78312e27d53954420d0defbda7ad638718b9dc2c1efb93100220270f79bfb3230194d2e625875073799f6f07d96d5bce43b19cfe6be9957d95540148304502210081842f5987009e65f1d7de6140433da541b9da52ed211e87e1ae6fc25260d7680220798de97c682541d7b26b0795b19994f045f3ef4f433c55da0b5f1506ddeec413014752210305345798069ac85285628732485a3ce7e96b85696ed7da72287f6eae3b275363210268aace9c841b8d61fe3532981c8b25e235690003916c5a90c23a708e5d8f929752ae #include struct LP_millistats diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index 6f54db403..8431e90fb 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -1082,8 +1082,11 @@ char *LP_createrawtransaction(cJSON **txobjp,int32_t *numvinsp,struct iguana_inf memset(utxos,0,sizeof(utxos)); if ( (numutxos= LP_address_utxo_ptrs(coin,0,utxos,max,ap,coin->smartaddr)) <= 0 ) { - printf("LP_createrawtransaction: address_utxo_ptrs %d, error\n",numutxos); - //return(0); + if ( bits256_nonz(utxotxid) == 0 ) + { + printf("LP_createrawtransaction: address_utxo_ptrs %d, error\n",numutxos); + return(0); + } } char str[65]; for (i=0; i Date: Tue, 14 Nov 2017 04:07:33 +0200 Subject: [PATCH 069/306] Test --- iguana/exchanges/LP_ordermatch.c | 7 ++++--- iguana/exchanges/LP_transaction.c | 12 ++++++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 4f99f2298..d2b7b9e79 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -844,7 +844,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); + //printf("price %.8f qprice %.8f\n",price,qprice); if ( recalc == 0 ) { value = LP_txvalue(tmp,Q.srccoin,Q.txid,Q.vout); @@ -941,14 +941,15 @@ 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,ask,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)); sleep(1); bits256 zero; memset(zero.bytes,0,sizeof(zero)); - LP_reserved_msg(1,Q.srccoin,Q.destcoin,zero,msg); + //LP_reserved_msg(1,Q.srccoin,Q.destcoin,zero,msg); + LP_reserved_msg(0,Q.srccoin,Q.destcoin,zero,msg); //LP_broadcast_message(LP_mypubsock,Q.srccoin,Q.destcoin,Q.desthash,jprint(retjson,0)); free_json(retjson); return(retval); diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index 8431e90fb..6e4642f3e 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -907,12 +907,12 @@ int32_t LP_vins_select(void *ctx,struct iguana_info *coin,int64_t *totalp,int64_ if ( bits256_nonz(utxotxid) != 0 && numpre == 0 ) { up = LP_address_utxofind(coin,coin->smartaddr,utxotxid,utxovout); - printf("have utxotxid but wasnt found up.%p\n",up); + //printf("have utxotxid but wasnt found up.%p\n",up); if ( up == 0 ) { value = LP_txvalue(0,coin->symbol,utxotxid,utxovout); LP_address_utxoadd("withdraw",coin,coin->smartaddr,utxotxid,utxovout,value,1,-1); - printf("added after not finding\n"); + //printf("added after not finding\n"); } if ( (up= LP_address_utxofind(coin,coin->smartaddr,utxotxid,utxovout)) != 0 ) preselected[numpre++] = up; @@ -978,7 +978,7 @@ int32_t LP_vins_select(void *ctx,struct iguana_info *coin,int64_t *totalp,int64_ char str[65]; printf("%s/%d %.8f interest %.8f -> sum %.8f\n",bits256_str(str,up->U.txid),up->U.vout,dstr(up->U.value),dstr(interest),dstr(interestsum)); } } - printf("numunspents.%d vini.%d value %.8f, total %.8f remains %.8f interest %.8f sum %.8f %s/v%d\n",numunspents,n,dstr(up->U.value),dstr(total),dstr(remains),dstr(interest),dstr(interestsum),bits256_str(str,up->U.txid),up->U.vout); + //printf("numunspents.%d vini.%d value %.8f, total %.8f remains %.8f interest %.8f sum %.8f %s/v%d\n",numunspents,n,dstr(up->U.value),dstr(total),dstr(remains),dstr(interest),dstr(interestsum),bits256_str(str,up->U.txid),up->U.vout); vp = &V[n++]; vp->N = vp->M = 1; vp->signers[0].privkey = privkey; @@ -1088,9 +1088,9 @@ char *LP_createrawtransaction(cJSON **txobjp,int32_t *numvinsp,struct iguana_inf return(0); } } - char str[65]; - for (i=0; iU.txid),utxos[i]->U.vout,dstr(utxos[i]->U.value)); + //char str[65]; + //for (i=0; iU.txid),utxos[i]->U.vout,dstr(utxos[i]->U.value)); ignore_cltverr = 0; suppress_pubkeys = 1; From 3c1fc577da6cc1cdb256ffcb17a4b00478958536 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 04:17:12 +0200 Subject: [PATCH 070/306] Test --- iguana/exchanges/LP_ordermatch.c | 10 +++++----- iguana/exchanges/LP_stats.c | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index d2b7b9e79..86ca8afc4 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -34,7 +34,7 @@ double LP_bob_competition(int32_t *counterp,uint64_t aliceid,double price,int32_ { if ( now > Bob_competition[i].starttime+LP_AUTOTRADE_TIMEOUT ) { - //printf("aliceid.%llx expired\n",(long long)aliceid); + //printf("aliceid.%llu expired\n",(long long)aliceid); Bob_competition[i].bestprice = 0.; Bob_competition[i].starttime = now; Bob_competition[i].counter = 0; @@ -42,7 +42,7 @@ double LP_bob_competition(int32_t *counterp,uint64_t aliceid,double price,int32_ 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.%llu <- bestprice %.8f\n",(long long)aliceid,price); } Bob_competition[i].counter += counter; *counterp = Bob_competition[i].counter; @@ -58,7 +58,7 @@ double LP_bob_competition(int32_t *counterp,uint64_t aliceid,double price,int32_ Bob_competition[firsti].aliceid = aliceid; Bob_competition[firsti].bestprice = price; *counterp = counter; - //printf("Bob competition aliceid.%llx %.8f\n",(long long)aliceid,price); + //printf("Bob competition aliceid.%llu %.8f\n",(long long)aliceid,price); return(price); } @@ -720,7 +720,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: received %12s aliceid.%22llu %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; @@ -732,7 +732,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, if ( strcmp(method,"reserved") == 0 ) { bestprice = LP_bob_competition(&counter,aliceid,qprice,1); - //printf("aliceid.%llx price %.8f -> bestprice %.8f\n",(long long)aliceid,qprice,bestprice); + //printf("aliceid.%llu price %.8f -> bestprice %.8f\n",(long long)aliceid,qprice,bestprice); if ( LP_Alicemaxprice == 0. ) return(retval); if ( bits256_nonz(LP_Alicedestpubkey) != 0 ) diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index 853ce8bd0..40569f027 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -209,7 +209,7 @@ int32_t LP_swapstats_update(struct LP_swapstats *sp,struct LP_quoteinfo *qp,cJSO else { if ( requestid == sp->Q.R.requestid && quoteid == sp->Q.R.quoteid ) - printf("mismatched tradestatus aliceid.%016llx b%s/%s r%s/%s r%u/%u q%u/%u %.8f/%.8f -> %.8f/%.8f\n",(long long)sp->aliceid,base,sp->Q.srccoin,rel,sp->Q.destcoin,requestid,sp->Q.R.requestid,quoteid,sp->Q.R.quoteid,dstr(satoshis+2*sp->Q.txfee),dstr(sp->Q.satoshis),dstr(destsatoshis+2*sp->Q.desttxfee),dstr(sp->Q.destsatoshis)); + printf("mismatched tradestatus aliceid.%22llu b%s/%s r%s/%s r%u/%u q%u/%u %.8f/%.8f -> %.8f/%.8f\n",(long long)sp->aliceid,base,sp->Q.srccoin,rel,sp->Q.destcoin,requestid,sp->Q.R.requestid,quoteid,sp->Q.R.quoteid,dstr(satoshis+2*sp->Q.txfee),dstr(sp->Q.satoshis),dstr(destsatoshis+2*sp->Q.desttxfee),dstr(sp->Q.destsatoshis)); return(-1); } From 7e6479b0a23a418100cb5446ffa81921e31473c0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 04:27:04 +0200 Subject: [PATCH 071/306] 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 86ca8afc4..da83aeb26 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -863,7 +863,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, price += (r * range) / 100.; bestprice = LP_bob_competition(&counter,aliceid,price,0); printf(">>>>>>>>>>>>> price %.8f qprice %.8f r.%d range %.8f -> %.8f, bestprice %.8f counter.%d\n",ask,qprice,r,range,price,bestprice,counter); - if ( counter > 2 || price > bestprice*1.1 ) + if ( counter > 10 )//2 || price > bestprice*1.1 ) 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)); @@ -948,8 +948,8 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, sleep(1); bits256 zero; memset(zero.bytes,0,sizeof(zero)); - //LP_reserved_msg(1,Q.srccoin,Q.destcoin,zero,msg); - LP_reserved_msg(0,Q.srccoin,Q.destcoin,zero,msg); + LP_reserved_msg(1,Q.srccoin,Q.destcoin,zero,msg); + //LP_reserved_msg(0,Q.srccoin,Q.destcoin,zero,msg); //LP_broadcast_message(LP_mypubsock,Q.srccoin,Q.destcoin,Q.desthash,jprint(retjson,0)); free_json(retjson); return(retval); From 0902ea2c030085a407a734591d4ad33f158cdf47 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 04:36:27 +0200 Subject: [PATCH 072/306] 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 da83aeb26..95278302d 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -801,7 +801,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 vs qprice %.8f\n",Q.srccoin,Q.destcoin,price,qprice); 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)); @@ -891,7 +891,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); } } @@ -941,7 +941,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,ask,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 7d9fdd77eb5d6b70162800aea98222410ddc0df7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 04:42:07 +0200 Subject: [PATCH 073/306] 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 95278302d..88171d831 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -863,7 +863,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, price += (r * range) / 100.; bestprice = LP_bob_competition(&counter,aliceid,price,0); printf(">>>>>>>>>>>>> price %.8f qprice %.8f r.%d range %.8f -> %.8f, bestprice %.8f counter.%d\n",ask,qprice,r,range,price,bestprice,counter); - if ( counter > 10 )//2 || price > bestprice*1.1 ) + if ( counter > 5 || price > bestprice*1.1 ) 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)); From b695221cb19237c232e851d0a672af8d62e6d84e Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 04:49:26 +0200 Subject: [PATCH 074/306] 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 5d4b5b482..3257f6096 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -189,7 +189,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 && (iambob == 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 e8e6fd263330dac03fae301b582f9bf7760ce210 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 04:50:58 +0200 Subject: [PATCH 075/306] Test --- iguana/exchanges/LP_commands.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 3aca6ee1c..56ed047e4 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -484,10 +484,10 @@ bot_resume(botid)\n\ struct iguana_info *ptr; if ( (ptr= LP_coinfind(coin)) != 0 ) { - ptr->privkeydepth = 0; LP_address(ptr,ptr->smartaddr); if ( jint(argjson,"reset") != 0 ) { + ptr->privkeydepth = 0; LP_address_utxo_reset(ptr); LP_passphrase_init(jstr(argjson,"passphrase"),G.gui); } From 818fceb3e260082a097a1faa3b2e24cdc508cb5b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 13:20:24 +0200 Subject: [PATCH 076/306] Test --- iguana/exchanges/LP_bitcoin.c | 3 ++- iguana/exchanges/LP_nativeDEX.c | 2 +- iguana/exchanges/LP_ordermatch.c | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_bitcoin.c b/iguana/exchanges/LP_bitcoin.c index 0c8e9abc6..a9aa5751b 100644 --- a/iguana/exchanges/LP_bitcoin.c +++ b/iguana/exchanges/LP_bitcoin.c @@ -3331,7 +3331,7 @@ int32_t iguana_rwjoinsplit(int32_t rwflag,uint8_t *serialized,struct iguana_msgj int32_t iguana_rwmsgtx(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t isPoS,int32_t height,int32_t rwflag,cJSON *json,uint8_t *serialized,int32_t maxsize,struct iguana_msgtx *msg,bits256 *txidp,char *vpnstr,uint8_t *extraspace,int32_t extralen,cJSON *vins,int32_t suppress_pubkeys,int32_t zcash) { - int32_t i,j,n,segtxlen,len = 0,extraused=0; uint32_t tmp,segitems; uint8_t *segtx,segwitflag=0,spendscript[IGUANA_MAXSCRIPTSIZE],*txstart = serialized,*sigser=0; char txidstr[65]; cJSON *vinarray=0,*voutarray=0; bits256 sigtxid; + int32_t i,j,n,segtxlen,len = 0,extraused=0; uint32_t tmp,segitems; uint8_t *segtx=0,segwitflag=0,spendscript[IGUANA_MAXSCRIPTSIZE],*txstart = serialized,*sigser=0; char txidstr[65]; cJSON *vinarray=0,*voutarray=0; bits256 sigtxid; len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->version),&msg->version); if ( json != 0 ) @@ -3464,6 +3464,7 @@ int32_t iguana_rwmsgtx(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t is } memcpy(&segtx[segtxlen-sizeof(int32_t)],&serialized[len],sizeof(int32_t)); *txidp = bits256_doublesha256(0,segtx,segtxlen); + free(segtx); //char str[65]; printf("witness sum %d vs max.%d txid %s\n",len,maxsize,bits256_str(str,txid)); } } diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 123c461be..455845d77 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -13,11 +13,11 @@ * Removal or modification of this copyright notice is prohibited. * * * ******************************************************************************/ - // // LP_nativeDEX.c // marketmaker // +// single utxo allocations, reject result, latency // alice waiting for bestprice // bot safe to exit? // diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 88171d831..7f7e946c1 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -891,7 +891,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, } else { - printf("cant find utxopair\n"); + printf("cant find utxopair %s/%s\n",Q.srccoin,Q.destcoin); return(retval); } } From c7d175dac94a82a86be3a85248827c806bafdfb7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 18:39:22 +0200 Subject: [PATCH 077/306] Dynamic inventory --- iguana/exchanges/LP_cache.c | 4 +- iguana/exchanges/LP_include.h | 15 +- iguana/exchanges/LP_nativeDEX.c | 3 +- iguana/exchanges/LP_ordermatch.c | 320 +++++++++++++++--------------- iguana/exchanges/LP_signatures.c | 11 +- iguana/exchanges/LP_socket.c | 6 +- iguana/exchanges/LP_swap.c | 12 +- iguana/exchanges/LP_transaction.c | 39 +--- iguana/exchanges/LP_utxo.c | 206 +++++++++++++++---- iguana/exchanges/LP_utxos.c | 52 +++-- 10 files changed, 405 insertions(+), 263 deletions(-) diff --git a/iguana/exchanges/LP_cache.c b/iguana/exchanges/LP_cache.c index 65140dc2c..a08828966 100644 --- a/iguana/exchanges/LP_cache.c +++ b/iguana/exchanges/LP_cache.c @@ -58,7 +58,7 @@ struct LP_transaction *LP_create_transaction(struct iguana_info *coin,bits256 tx tx->outpoints[i].interest = SATOSHIDEN * jdouble(vout,"interest"); LP_destaddr(tx->outpoints[i].coinaddr,vout); //printf("from transaction init %s %s %s/v%d <- %.8f\n",coin->symbol,tx->outpoints[i].coinaddr,bits256_str(str,txid),i,dstr(tx->outpoints[i].value)); - LP_address_utxoadd("LP_create_transaction",coin,tx->outpoints[i].coinaddr,txid,i,tx->outpoints[i].value,height,-1); + LP_address_utxoadd((uint32_t)time(NULL),"LP_create_transaction",coin,tx->outpoints[i].coinaddr,txid,i,tx->outpoints[i].value,height,-1); } for (i=0; ioutpoints[spentvout].spendtxid = txid; tx->outpoints[spentvout].spendvini = i; tx->outpoints[spentvout].spendheight = height > 0 ? height : 1; - LP_address_utxoadd("LP_transactioninit iter1",coin,tx->outpoints[spentvout].coinaddr,spenttxid,spentvout,tx->outpoints[spentvout].value,-1,height>0?height:1); + LP_address_utxoadd((uint32_t)time(NULL),"LP_transactioninit iter1",coin,tx->outpoints[spentvout].coinaddr,spenttxid,spentvout,tx->outpoints[spentvout].value,-1,height>0?height:1); if ( 0 && strcmp(coin->symbol,"REVS") == 0 ) printf("spend %s %s/v%d at ht.%d\n",coin->symbol,bits256_str(str,tx->txid),spentvout,height); } diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 839333523..c24ad9bf4 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 "14336" +#define LP_BUILD_NUMBER "14414" #ifdef FROM_JS #include @@ -43,7 +43,8 @@ void emscripten_usleep(int32_t x); // returns immediate, no sense for sleeping #define LP_MAXVINS 64 #define LP_HTTP_TIMEOUT 3 // 1 is too small due to edge cases of time(NULL) -#define LP_AUTOTRADE_TIMEOUT 60 +#define LP_AUTOTRADE_TIMEOUT 30 +#define LP_RESERVETIME (LP_AUTOTRADE_TIMEOUT * 2) #define ELECTRUM_TIMEOUT 7 #define LP_ELECTRUM_KEEPALIVE 60 #define LP_ELECTRUM_MAXERRORS 777 @@ -103,7 +104,6 @@ void emscripten_usleep(int32_t x); // returns immediate, no sense for sleeping #define LP_RPCPORT 7783 #define LP_PROPAGATION_SLACK 100 // txid ordering is not enforced, so getting extra recent txid -#define LP_RESERVETIME 60 #define LP_AVETXSIZE 256 #define LP_CACHEDURATION 60 #define BASILISK_DEFAULT_NUMCONFIRMS 1 @@ -288,7 +288,7 @@ struct LP_utxobob { struct _LP_utxoinfo utxo,deposit; }; struct LP_utxoalice { struct _LP_utxoinfo utxo,fee; }; -struct LP_utxoswap { bits256 otherpubkey; void *swap; uint64_t satoshis; }; +struct LP_utxoswap { bits256 otherpubkey; uint64_t satoshis; }; struct LP_utxoinfo { @@ -308,6 +308,7 @@ struct LP_address_utxo struct LP_address_utxo *next,*prev; struct _LP_utxoinfo U; int32_t SPV,spendheight; + uint32_t timestamp; }; struct LP_address @@ -346,7 +347,7 @@ struct LP_endpoint { int32_t pair; char ipaddr[64]; uint16_t port; }; struct basilisk_swap { - void *ctx; struct LP_utxoinfo *utxo; + void *ctx; //struct LP_utxoinfo *utxo; struct LP_endpoint N; void (*balancingtrade)(struct basilisk_swap *swap,int32_t iambob); int32_t subsock,pushsock,connected,aliceunconf,depositunconf,paymentunconf; @@ -410,7 +411,7 @@ uint64_t LP_value_extract(cJSON *obj,int32_t addinterest); int32_t LP_swap_getcoinaddr(char *symbol,char *coinaddr,bits256 txid,int32_t vout); char *LP_command_process(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,uint8_t *data,int32_t datalen); int64_t LP_komodo_interest(bits256 txid,int64_t value); -void LP_availableset(struct LP_utxoinfo *utxo); +void LP_availableset(bits256 txid,int32_t vout); int32_t LP_iseligible(uint64_t *valp,uint64_t *val2p,int32_t iambob,char *symbol,bits256 txid,int32_t vout,uint64_t satoshis,bits256 txid2,int32_t vout2); int32_t LP_pullsock_check(void *ctx,char **retstrp,char *myipaddr,int32_t pubsock,int32_t pullsock); void LP_unspents_cache(char *symbol,char *addr,char *arraystr,int32_t updatedflag); @@ -452,7 +453,7 @@ int32_t LP_txheight(struct iguana_info *coin,bits256 txid); int32_t LP_numpeers(); char *basilisk_swapentry(uint32_t requestid,uint32_t quoteid); uint64_t LP_KMDvalue(struct iguana_info *coin,uint64_t balance); -int32_t LP_address_utxoadd(char *debug,struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout,uint64_t value,int32_t height,int32_t spendheight); +int32_t LP_address_utxoadd(uint32_t timestamp,char *debug,struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout,uint64_t value,int32_t height,int32_t spendheight); void LP_smartutxos_push(struct iguana_info *coin); void LP_cacheptrs_init(struct iguana_info *coin); cJSON *LP_address_utxos(struct iguana_info *coin,char *coinaddr,int32_t electrumret); diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 455845d77..713e8e7de 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -78,7 +78,7 @@ void LP_millistats_update(struct LP_millistats *mp) } #include "LP_include.h" -portable_mutex_t LP_peermutex,LP_UTXOmutex,LP_utxomutex,LP_commandmutex,LP_cachemutex,LP_swaplistmutex,LP_forwardmutex,LP_pubkeymutex,LP_networkmutex,LP_psockmutex,LP_coinmutex,LP_messagemutex,LP_portfoliomutex,LP_electrummutex,LP_butxomutex,LP_reservedmutex,LP_nanorecvsmutex,LP_tradebotsmutex,LP_gcmutex; +portable_mutex_t LP_peermutex,LP_UTXOmutex,LP_utxomutex,LP_commandmutex,LP_cachemutex,LP_swaplistmutex,LP_forwardmutex,LP_pubkeymutex,LP_networkmutex,LP_psockmutex,LP_coinmutex,LP_messagemutex,LP_portfoliomutex,LP_electrummutex,LP_butxomutex,LP_reservedmutex,LP_nanorecvsmutex,LP_tradebotsmutex,LP_gcmutex,LP_inusemutex; int32_t LP_canbind; char *Broadcaststr,*Reserved_msgs[2][1000]; int32_t num_Reserved_msgs[2],max_Reserved_msgs[2]; @@ -923,6 +923,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu portable_mutex_init(&LP_networkmutex); portable_mutex_init(&LP_gcmutex); portable_mutex_init(&LP_forwardmutex); + portable_mutex_init(&LP_inusemutex); portable_mutex_init(&LP_psockmutex); portable_mutex_init(&LP_coinmutex); portable_mutex_init(&LP_pubkeymutex); diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 7f7e946c1..0ef73ab65 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -290,7 +290,7 @@ int32_t LP_nearest_utxovalue(struct iguana_info *coin,char *coinaddr,struct LP_a //printf("nearest i.%d target %.8f val %.8f dist %.8f mindist %.8f mini.%d spent.%d\n",i,dstr(targetval),dstr(up->U.value),dstr(dist),dstr(mindist),mini,up->spendheight); if ( up->spendheight <= 0 ) { - if ( dist >= 0 && dist < mindist ) //(coin->electrum == 0 || up->SPV > 0) && + if ( dist >= 0 && dist < mindist ) { //printf("(%.8f %.8f %.8f).%d ",dstr(up->U.value),dstr(dist),dstr(mindist),mini); mini = i; @@ -303,6 +303,55 @@ int32_t LP_nearest_utxovalue(struct iguana_info *coin,char *coinaddr,struct LP_a return(mini); } +void LP_butxo_set(struct LP_utxoinfo *butxo,struct iguana_info *coin,struct LP_address_utxo *up,struct LP_address_utxo *up2,int64_t satoshis) +{ + butxo->pubkey = G.LP_mypub25519; + safecopy(butxo->coin,coin->symbol,sizeof(butxo->coin)); + safecopy(butxo->coinaddr,coin->smartaddr,sizeof(butxo->coinaddr)); + butxo->payment.txid = up->U.txid; + butxo->payment.vout = up->U.vout; + butxo->payment.value = up->U.value; + butxo->iambob = 1; + butxo->deposit.txid = up2->U.txid; + butxo->deposit.vout = up2->U.vout; + butxo->deposit.value = up2->U.value; + butxo->S.satoshis = satoshis; +} + +void LP_abutxo_set(struct LP_utxoinfo *autxo,struct LP_utxoinfo *butxo,struct LP_quoteinfo *qp) +{ + if ( butxo != 0 ) + { + memset(butxo,0,sizeof(*butxo)); + butxo->pubkey = qp->srchash; + safecopy(butxo->coin,qp->srccoin,sizeof(butxo->coin)); + safecopy(butxo->coinaddr,qp->coinaddr,sizeof(butxo->coinaddr)); + butxo->payment.txid = qp->txid; + butxo->payment.vout = qp->vout; + //butxo->payment.value = qp->value; + butxo->iambob = 1; + butxo->deposit.txid = qp->txid2; + butxo->deposit.vout = qp->vout2; + //butxo->deposit.value = up2->U.value; + butxo->S.satoshis = qp->satoshis; + } + if ( autxo != 0 ) + { + memset(autxo,0,sizeof(*autxo)); + autxo->pubkey = qp->desthash; + safecopy(autxo->coin,qp->destcoin,sizeof(autxo->coin)); + safecopy(autxo->coinaddr,qp->destaddr,sizeof(autxo->coinaddr)); + autxo->payment.txid = qp->desttxid; + autxo->payment.vout = qp->destvout; + //autxo->payment.value = qp->value; + autxo->iambob = 0; + autxo->fee.txid = qp->feetxid; + autxo->fee.vout = qp->feevout; + //autxo->deposit.value = up2->U.value; + autxo->S.satoshis = qp->destsatoshis; + } +} + 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); @@ -311,9 +360,10 @@ uint64_t LP_basesatoshis(double relvolume,double price,uint64_t txfee,uint64_t d else return(0); } -struct LP_utxoinfo *LP_address_utxopair(int32_t iambob,struct LP_address_utxo **utxos,int32_t max,struct iguana_info *coin,char *coinaddr,uint64_t txfee,double relvolume,double price,uint64_t desttxfee) +struct LP_utxoinfo *LP_address_myutxopair(struct LP_utxoinfo *butxo,int32_t iambob,struct LP_address_utxo **utxos,int32_t max,struct iguana_info *coin,char *coinaddr,uint64_t txfee,double relvolume,double price,uint64_t desttxfee) { - struct LP_address *ap; uint64_t targetval,targetval2; int32_t m,mini; struct LP_address_utxo *up,*up2; struct LP_utxoinfo *utxo = 0;//,*utmp; + struct LP_address *ap; uint64_t targetval,targetval2; int32_t m,mini; struct LP_address_utxo *up,*up2; + memset(butxo,0,sizeof(*butxo)); targetval = LP_basesatoshis(relvolume,price,txfee,desttxfee); targetval2 = (targetval / 8) * 9 + 2*txfee; if ( coin != 0 && (ap= LP_addressfind(coin,coinaddr)) != 0 ) @@ -340,12 +390,13 @@ struct LP_utxoinfo *LP_address_utxopair(int32_t iambob,struct LP_address_utxo ** { if ( up != 0 && (up2= utxos[mini]) != 0 ) { - if ( (utxo= LP_utxoadd(1,coin->symbol,up->U.txid,up->U.vout,up->U.value,up2->U.txid,up2->U.vout,up2->U.value,coinaddr,ap->pubkey,G.gui,0,targetval)) != 0 ) + /*if ( (utxo= LP_utxoadd(1,coin->symbol,up->U.txid,up->U.vout,up->U.value,up2->U.txid,up2->U.vout,up2->U.value,coinaddr,ap->pubkey,G.gui,0,targetval)) != 0 ) { utxo->S.satoshis = targetval; char str[65],str2[65]; printf("butxo.%p targetval %.8f, found val %.8f %s | targetval2 %.8f val2 %.8f %s\n",utxo,dstr(targetval),dstr(up->U.value),bits256_str(str,utxo->payment.txid),dstr(targetval2),dstr(up2->U.value),bits256_str(str2,utxo->deposit.txid)); - return(utxo); - } + return(butxo); + }*/ + LP_butxo_set(butxo,coin,up,up2,targetval); } } //else printf("cant find targetval2 %.8f\n",dstr(targetval2)); } //else printf("failed ratio test %.8f\n",(double)up->U.value/targetval); @@ -353,64 +404,21 @@ struct LP_utxoinfo *LP_address_utxopair(int32_t iambob,struct LP_address_utxo ** printf("targetval %.8f mini.%d\n",dstr(targetval),mini); } //else printf("no %s utxos pass LP_address_utxo_ptrs filter\n",coinaddr); } else printf("couldnt find %s %s\n",coin->symbol,coinaddr); - /*HASH_ITER(hh,G.LP_utxoinfos[iambob],utxo,utmp) - { - if ( LP_isavailable(utxo) != 0 && utxo->payment.value >= targetval && targetval >= utxo->payment.value/2 && utxo->deposit.value >= targetval2 ) - { - utxo->S.satoshis = targetval; - printf("backup method found utxo!\n"); - return(utxo); - } - }*/ return(0); } -void LP_abutxo_set(struct LP_utxoinfo *autxo,struct LP_utxoinfo *butxo,struct LP_quoteinfo *qp) -{ - if ( butxo != 0 ) - { - memset(butxo,0,sizeof(*butxo)); - butxo->pubkey = qp->srchash; - safecopy(butxo->coin,qp->srccoin,sizeof(butxo->coin)); - safecopy(butxo->coinaddr,qp->coinaddr,sizeof(butxo->coinaddr)); - butxo->payment.txid = qp->txid; - butxo->payment.vout = qp->vout; - //butxo->payment.value = qp->value; - butxo->iambob = 1; - butxo->deposit.txid = qp->txid2; - butxo->deposit.vout = qp->vout2; - //butxo->deposit.value = up2->U.value; - butxo->S.satoshis = qp->satoshis; - } - if ( autxo != 0 ) - { - memset(autxo,0,sizeof(*autxo)); - autxo->pubkey = qp->desthash; - safecopy(autxo->coin,qp->destcoin,sizeof(autxo->coin)); - safecopy(autxo->coinaddr,qp->destaddr,sizeof(autxo->coinaddr)); - autxo->payment.txid = qp->desttxid; - autxo->payment.vout = qp->destvout; - //autxo->payment.value = qp->value; - autxo->iambob = 0; - autxo->fee.txid = qp->feetxid; - autxo->fee.vout = qp->feevout; - //autxo->deposit.value = up2->U.value; - autxo->S.satoshis = qp->destsatoshis; - } -} - -int32_t LP_connectstartbob(void *ctx,int32_t pubsock,struct LP_utxoinfo *utxo,cJSON *argjson,char *base,char *rel,double price,struct LP_quoteinfo *qp) +int32_t LP_connectstartbob(void *ctx,int32_t pubsock,cJSON *argjson,char *base,char *rel,double price,struct LP_quoteinfo *qp) { char pairstr[512]; cJSON *retjson; bits256 privkey; int32_t pair=-1,retval = -1,DEXselector = 0; struct basilisk_swap *swap; struct iguana_info *coin; printf("LP_connectstartbob.(%s) with.(%s) %s\n",LP_myipaddr,jprint(argjson,0),LP_myipaddr); qp->quotetime = (uint32_t)time(NULL); - if ( (coin= LP_coinfind(utxo->coin)) == 0 ) + if ( (coin= LP_coinfind(qp->srccoin)) == 0 ) { - printf("cant find coin.%s\n",utxo->coin); + printf("cant find coin.%s\n",qp->srccoin); return(-1); } - privkey = LP_privkey(utxo->coinaddr,coin->taddr); - if ( bits256_nonz(privkey) != 0 && bits256_cmp(G.LP_mypub25519,qp->srchash) == 0 ) //qp->quotetime >= qp->timestamp-3 && qp->quotetime <= utxo->T.swappending && + privkey = LP_privkey(coin->smartaddr,coin->taddr); + if ( bits256_nonz(privkey) != 0 && bits256_cmp(G.LP_mypub25519,qp->srchash) == 0 ) { LP_requestinit(&qp->R,qp->srchash,qp->desthash,base,qp->satoshis-qp->txfee,rel,qp->destsatoshis-qp->desttxfee,qp->timestamp,qp->quotetime,DEXselector); if ( (swap= LP_swapinit(1,0,privkey,&qp->R,qp)) == 0 ) @@ -421,45 +429,37 @@ int32_t LP_connectstartbob(void *ctx,int32_t pubsock,struct LP_utxoinfo *utxo,cJ if ( (pair= LP_nanobind(ctx,pairstr)) >= 0 ) { swap->N.pair = pair; - utxo->S.swap = swap; - swap->utxo = utxo; + //utxo->S.swap = swap; + //swap->utxo = utxo; if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_bobloop,(void *)swap) == 0 ) { retjson = LP_quotejson(qp); jaddstr(retjson,"method","connected"); jaddstr(retjson,"pair",pairstr); - //jaddnum(retjson,"requestid",qp->R.requestid); - //jaddnum(retjson,"quoteid",qp->R.quoteid); - // LP_addsig - char str[65]; printf("BOB pubsock.%d binds to %d (%s)\n",pubsock,pair,bits256_str(str,utxo->S.otherpubkey)); - LP_reserved_msg(1,base,rel,utxo->S.otherpubkey,jprint(retjson,0)); + char str[65]; printf("BOB pubsock.%d binds to %d (%s)\n",pubsock,pair,bits256_str(str,qp->desthash)); + LP_reserved_msg(1,base,rel,qp->desthash,jprint(retjson,0)); sleep(1); bits256 zero; memset(zero.bytes,0,sizeof(zero)); LP_reserved_msg(1,base,rel,zero,jprint(retjson,0)); - //LP_broadcast_message(LP_mypubsock,qp->srccoin,qp->destcoin,qp->desthash,jprint(retjson,0)); free_json(retjson); retval = 0; } else printf("error launching swaploop\n"); } else printf("couldnt bind to any port %s\n",pairstr); } - else - { - printf("dest %.8f vs required %.8f (%d %d %d %d %d)\n",dstr(qp->destsatoshis),dstr(price*(utxo->S.satoshis-qp->txfee)),bits256_nonz(privkey) != 0 ,qp->timestamp == utxo->T.swappending-LP_RESERVETIME,qp->quotetime >= qp->timestamp-3,qp->quotetime < utxo->T.swappending,bits256_cmp(G.LP_mypub25519,qp->srchash) == 0); - } if ( retval < 0 ) { if ( pair >= 0 ) nn_close(pair); - LP_availableset(utxo); - } else LP_unavailableset(utxo,utxo->S.otherpubkey); - //LP_butxo_swapfields(utxo); + LP_availableset(qp->txid,qp->vout); + LP_availableset(qp->txid2,qp->vout2); + } return(retval); } 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,bits256 destpubkey) { - 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; + struct LP_utxoinfo *aliceutxo; double price; if ( (aliceutxo= LP_utxopairfind(0,qp->desttxid,qp->destvout,qp->feetxid,qp->feevout)) == 0 ) { char str[65],str2[65]; printf("dest.(%s)/v%d fee.(%s)/v%d\n",bits256_str(str,qp->desttxid),qp->destvout,bits256_str(str2,qp->feetxid),qp->feevout); @@ -491,15 +491,20 @@ int32_t LP_quotecmp(struct LP_quoteinfo *qp,struct LP_quoteinfo *qp2) else return(-1); } +void LP_alicequery_clear() +{ + memset(&LP_Alicequery,0,sizeof(LP_Alicequery)); + memset(&LP_Alicedestpubkey,0,sizeof(LP_Alicedestpubkey)); + LP_Alicemaxprice = 0.; + Alice_expiration = 0; +} + int32_t LP_alice_eligible() { if ( Alice_expiration != 0 && time(NULL) > Alice_expiration ) { printf("time expired for Alice_request\n"); - memset(&LP_Alicequery,0,sizeof(LP_Alicequery)); - memset(&LP_Alicedestpubkey,0,sizeof(LP_Alicedestpubkey)); - LP_Alicemaxprice = 0.; - Alice_expiration = 0; + LP_alicequery_clear(); } return(Alice_expiration == 0 || time(NULL) < Alice_expiration); } @@ -513,10 +518,7 @@ void LP_reserved(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo if ( LP_pricevalid(price) > 0 && maxprice > SMALLVAL && price <= maxprice*1.005 ) { qp->tradeid = LP_Alicequery.tradeid; - memset(&LP_Alicequery,0,sizeof(LP_Alicequery)); - memset(&LP_Alicedestpubkey,0,sizeof(LP_Alicedestpubkey)); - LP_Alicemaxprice = 0.; - Alice_expiration = 0; + LP_alicequery_clear(); printf("send CONNECT\n"); LP_query(ctx,myipaddr,mypubsock,"connect",qp); } else printf("LP_reserved price %.8f vs maxprice %.8f\n",price,maxprice*1.005); @@ -543,19 +545,20 @@ char *LP_connectedalice(cJSON *argjson) // alice LP_aliceid(Q.tradeid,Q.aliceid,"error2",0,0); return(clonestr("{\"error\":\"cant find autxo\"}")); } - if ( autxo->S.swap != 0 ) + /*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\"}")); - } + }*/ LP_aliceid(Q.tradeid,Q.aliceid,"connected",Q.R.requestid,Q.R.quoteid); butxo = &B; memset(butxo,0,sizeof(*butxo)); LP_abutxo_set(0,butxo,&Q); if ( (qprice= LP_quote_validate(autxo,butxo,&Q,0)) <= SMALLVAL ) { - LP_availableset(autxo); + LP_availableset(Q.desttxid,Q.vout); + LP_availableset(Q.feetxid,Q.feevout); LP_aliceid(Q.tradeid,Q.aliceid,"error4",0,0); printf("quote validate error %.0f\n",qprice); return(clonestr("{\"error\":\"quote validation error\"}")); @@ -563,7 +566,8 @@ 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); - LP_availableset(autxo); + LP_availableset(Q.desttxid,Q.vout); + LP_availableset(Q.feetxid,Q.feevout); LP_aliceid(Q.tradeid,Q.aliceid,"error5",0,0); return(clonestr("{\"error\":\"no price set\"}")); } @@ -582,7 +586,8 @@ char *LP_connectedalice(cJSON *argjson) // alice if ( (swap= LP_swapinit(0,0,Q.privkey,&Q.R,&Q)) == 0 ) { jaddstr(retjson,"error","couldnt swapinit"); - LP_availableset(autxo); + LP_availableset(Q.desttxid,Q.vout); + LP_availableset(Q.feetxid,Q.feevout); LP_aliceid(Q.tradeid,Q.aliceid,"error7",Q.R.requestid,Q.R.quoteid); return(jprint(retjson,1)); } @@ -598,8 +603,8 @@ char *LP_connectedalice(cJSON *argjson) // alice //nn_setsockopt(pairsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout)); swap->tradeid = Q.tradeid; swap->N.pair = pairsock; - autxo->S.swap = swap; - swap->utxo = autxo; + //autxo->S.swap = swap; + //swap->utxo = autxo; LP_aliceid(Q.tradeid,Q.aliceid,"started",Q.R.requestid,Q.R.quoteid); printf("alice pairstr.(%s) pairsock.%d\n",pairstr,pairsock); if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_aliceloop,(void *)swap) == 0 ) @@ -622,12 +627,16 @@ char *LP_connectedalice(cJSON *argjson) // alice } printf("connected result.(%s)\n",jprint(retjson,0)); if ( jobj(retjson,"error") != 0 ) - LP_availableset(autxo); + { + LP_availableset(Q.desttxid,Q.vout); + LP_availableset(Q.feetxid,Q.feevout); + } return(jprint(retjson,1)); } else { - LP_availableset(autxo); + LP_availableset(Q.desttxid,Q.vout); + LP_availableset(Q.feetxid,Q.feevout); LP_aliceid(Q.tradeid,Q.aliceid,"error11",0,0); printf("no privkey found coin.%s %s taddr.%u\n",Q.destcoin,Q.destaddr,coin->taddr); return(clonestr("{\"error\",\"no privkey\"}")); @@ -636,7 +645,7 @@ char *LP_connectedalice(cJSON *argjson) // alice int32_t LP_listunspent_both(char *symbol,char *coinaddr,int32_t fullflag) { - int32_t i,v,numconfs,height,n=0; uint64_t value; bits256 txid; char buf[512]; cJSON *array,*item; struct iguana_info *coin = LP_coinfind(symbol); + int32_t i,v,numconfs,height,n=0; uint64_t value; bits256 txid; char buf[512]; cJSON *array,*item; uint32_t now; struct iguana_info *coin = LP_coinfind(symbol); if ( coin != 0 )//&& (IAMLP != 0 || coin->inactive == 0) ) { if ( coin->electrum != 0 || LP_address_ismine(symbol,coinaddr) <= 0 ) @@ -657,6 +666,7 @@ int32_t LP_listunspent_both(char *symbol,char *coinaddr,int32_t fullflag) { if ( (n= cJSON_GetArraySize(array)) > 0 ) { + now = (uint32_t)time(NULL); for (i=0; icoinaddr,coin->smartaddr) != 0 || bits256_nonz(butxo->payment.txid) == 0 || bits256_nonz(butxo->deposit.txid) == 0 ) + char str[65]; + if ( bits256_nonz(Q.srchash) == 0 || bits256_cmp(Q.srchash,G.LP_mypub25519) == 0 ) + { + qprice = (double)Q.destsatoshis / Q.satoshis; + strcpy(Q.gui,G.gui); + strcpy(Q.coinaddr,coin->smartaddr); + strcpy(butxo->coinaddr,coin->smartaddr); + Q.srchash = G.LP_mypub25519; + memset(&Q.txid,0,sizeof(Q.txid)); + memset(&Q.txid2,0,sizeof(Q.txid2)); + Q.vout = Q.vout2 = -1; + } else return(retval); + /*if ( bits256_nonz(Q.srchash) == 0 || 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); @@ -855,7 +875,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, 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); + } else return(retval);*/ if ( qprice > price ) { r = (rand() % 100); @@ -863,45 +883,33 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, price += (r * range) / 100.; bestprice = LP_bob_competition(&counter,aliceid,price,0); printf(">>>>>>>>>>>>> price %.8f qprice %.8f r.%d range %.8f -> %.8f, bestprice %.8f counter.%d\n",ask,qprice,r,range,price,bestprice,counter); - if ( counter > 5 || price > bestprice*1.1 ) + if ( counter > 5 || price > bestprice*1.1 ) // skip if late or bad price 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 ) + LP_RTmetrics_update(Q.srccoin,Q.destcoin); + if ( LP_RTmetrics_blacklisted(Q.desthash) >= 0 ) { - LP_RTmetrics_update(Q.srccoin,Q.destcoin); - if ( LP_RTmetrics_blacklisted(Q.desthash) >= 0 ) - { - printf("request from blacklisted %s, ignore\n",bits256_str(str,Q.desthash)); - return(retval); - } - 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 ) - { - strcpy(Q.gui,G.gui); - strcpy(Q.coinaddr,coin->smartaddr); - Q.srchash = G.LP_mypub25519; - Q.txid = butxo->payment.txid; - Q.vout = butxo->payment.vout; - Q.txid2 = butxo->deposit.txid; - Q.vout2 = butxo->deposit.vout; - Q.satoshis = butxo->S.satoshis; - printf("found %.8f -> %.8f newprice %.8f vs ask %.8f += %.8f qprice %.8f\n",dstr(Q.satoshis),dstr(Q.destsatoshis),(double)Q.destsatoshis/Q.satoshis,ask,price,qprice); - //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 - { - printf("cant find utxopair %s/%s\n",Q.srccoin,Q.destcoin); - return(retval); - } + printf("request from blacklisted %s, ignore\n",bits256_str(str,Q.desthash)); + return(retval); } - } - else // "connect" - { - if ( bits256_cmp(G.LP_mypub25519,Q.srchash) == 0 && bits256_cmp(G.LP_mypub25519,Q.desthash) != 0 ) + LP_address_utxo_reset(coin); + if ( (butxo= LP_address_myutxopair(butxo,1,utxos,max,LP_coinfind(Q.srccoin),Q.coinaddr,Q.txfee,dstr(Q.destsatoshis),price,Q.desttxfee)) != 0 ) { - butxo = LP_utxopairfind(1,Q.txid,Q.vout,Q.txid2,Q.vout2); // better work! - } else return(retval); + strcpy(Q.gui,G.gui); + strcpy(Q.coinaddr,coin->smartaddr); + Q.srchash = G.LP_mypub25519; + Q.txid = butxo->payment.txid; + Q.vout = butxo->payment.vout; + Q.txid2 = butxo->deposit.txid; + Q.vout2 = butxo->deposit.vout; + Q.satoshis = butxo->S.satoshis; + printf("found %.8f -> %.8f newprice %.8f vs ask %.8f += %.8f qprice %.8f\n",dstr(Q.satoshis),dstr(Q.destsatoshis),(double)Q.destsatoshis/Q.satoshis,ask,price,qprice); + } + else + { + printf("cant find utxopair aliceid.%llu %s/%s\n",(long long)aliceid,Q.srccoin,Q.destcoin); + return(retval); + } } if ( strcmp(Q.coinaddr,coin->smartaddr) != 0 ) { @@ -923,55 +931,46 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, 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)); - if ( butxo->S.swap == 0 && time(NULL) > butxo->T.swappending ) - butxo->T.swappending = 0; + char str[65],str2[65]; printf("(%s/v%d %s/v%d) TRADECOMMAND.(%s)\n",bits256_str(str,Q.txid),Q.vout,bits256_str(str2,Q.txid2),Q.vout2,jprint(argjson,0)); if ( strcmp(method,"request") == 0 ) // bob needs apayment + fee tx's { - if ( LP_isavailable(butxo) > 0 ) + if ( LP_allocated(Q.txid,Q.vout) == 0 && LP_allocated(Q.txid2,Q.vout2) == 0 ) { - autxo->T.swappending = butxo->T.swappending = Q.timestamp + LP_RESERVETIME; retjson = LP_quotejson(&Q); - butxo->S.otherpubkey = jbits256(argjson,"desthash"); - LP_unavailableset(butxo,butxo->S.otherpubkey); - jaddnum(retjson,"quotetime",juint(argjson,"quotetime")); - jaddnum(retjson,"pending",butxo->T.swappending); - jaddbits256(retjson,"desthash",butxo->S.otherpubkey); - jaddbits256(retjson,"pubkey",butxo->S.otherpubkey); + LP_unavailableset(Q.txid,Q.vout,Q.timestamp + LP_RESERVETIME,Q.desthash); + LP_unavailableset(Q.txid2,Q.vout2,Q.timestamp + LP_RESERVETIME,Q.desthash); + jaddnum(retjson,"quotetime",Q.quotetime); + jaddnum(retjson,"pending",Q.timestamp + LP_RESERVETIME); + jaddbits256(retjson,"desthash",Q.desthash); 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,ask,msg); - // LP_addsig - //msg2 = clonestr(msg); - LP_reserved_msg(1,Q.srccoin,Q.destcoin,butxo->S.otherpubkey,clonestr(msg)); + printf("return after queued RESERVED: set swappending.%u accept qprice %.8f, min %.8f\n(%s)\n",Q.timestamp + LP_RESERVETIME,qprice,ask,msg); + LP_reserved_msg(1,Q.srccoin,Q.destcoin,Q.desthash,clonestr(msg)); sleep(1); bits256 zero; memset(zero.bytes,0,sizeof(zero)); LP_reserved_msg(1,Q.srccoin,Q.destcoin,zero,msg); - //LP_reserved_msg(0,Q.srccoin,Q.destcoin,zero,msg); - //LP_broadcast_message(LP_mypubsock,Q.srccoin,Q.destcoin,Q.desthash,jprint(retjson,0)); free_json(retjson); + butxo->T.lasttime = (uint32_t)time(NULL); return(retval); - } else printf("warning swappending.%u swap.%p\n",butxo->T.swappending,butxo->S.swap); + } else printf("request processing selected ineligible utxos?\n"); } else if ( strcmp(method,"connect") == 0 ) // bob { retval = 4; - if ( butxo->S.swap == 0 && butxo->T.swappending != 0 ) + if ( bits256_cmp(G.LP_mypub25519,Q.srchash) != 0 || bits256_cmp(G.LP_mypub25519,Q.desthash) == 0 ) + return(retval); + else if ( LP_reservation_check(Q.txid,Q.vout,Q.desthash) == 0 && LP_reservation_check(Q.txid2,Q.vout2,Q.desthash) == 0 ) { - // validate SPV alice - LP_connectstartbob(ctx,pubsock,butxo,argjson,Q.srccoin,Q.destcoin,qprice,&Q); - //LP_butxo_swapfields_set(butxo); + LP_connectstartbob(ctx,pubsock,argjson,Q.srccoin,Q.destcoin,qprice,&Q); return(retval); - } - else printf("pend.%u swap %p when connect came in (%s)\n",butxo->T.swappending,butxo->S.swap,jprint(argjson,0)); + } else printf("connect message from non-reserved (%s)\n",jprint(argjson,0)); } - //LP_butxo_swapfields_set(butxo); } return(retval); } +#ifdef oldway struct LP_utxoinfo *LP_ordermatch_iter(struct LP_address_utxo **utxos,int32_t max,double *ordermatchpricep,int64_t *bestsatoshisp,int64_t *bestdestsatoshisp,struct iguana_info *basecoin,char *coinaddr,uint64_t asatoshis,double price,uint64_t txfee,uint64_t desttxfee,bits256 pubkey,char *gui) { uint64_t basesatoshis; struct LP_utxoinfo *bestutxo; @@ -1076,10 +1075,11 @@ struct LP_utxoinfo *LP_buyutxo(double *ordermatchpricep,int64_t *bestsatoshisp,i LP_mypriceset(&changed,autxo->coin,base,1. / *ordermatchpricep); return(bestutxo); } +#endif 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,B,*bestutxo = 0; double qprice,ordermatchprice=0.; struct LP_quoteinfo Q; bits256 pubkeys[100]; + uint64_t desttxfee,txfee; uint32_t lastnonce; int64_t bestsatoshis=0,destsatoshis; struct iguana_info *basecoin,*relcoin; struct LP_utxoinfo *autxo,B; struct LP_quoteinfo Q; bits256 pubkeys[100]; basecoin = LP_coinfind(base); relcoin = LP_coinfind(rel); if ( gui == 0 ) @@ -1111,12 +1111,7 @@ char *LP_autobuy(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel } if ( time(NULL) < Alice_expiration ) return(clonestr("{\"error\":\"only one pending request at a time\"}")); - else - { - Alice_expiration = 0; - memset(&LP_Alicequery,0,sizeof(LP_Alicequery)); - LP_Alicemaxprice = 0.; - } + else LP_alicequery_clear(); if ( maxprice <= 0. || relvolume <= 0. || LP_priceinfofind(base) == 0 || LP_priceinfofind(rel) == 0 ) return(clonestr("{\"error\":\"invalid parameter\"}")); if ( strcmp("BTC",rel) == 0 ) @@ -1155,7 +1150,7 @@ char *LP_autobuy(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel int32_t changed; LP_mypriceset(&changed,autxo->coin,base,1. / maxprice); return(LP_trade(ctx,myipaddr,mypubsock,&Q,maxprice,timeout,duration,tradeid,destpubkey)); - +#ifdef oldway LP_RTmetrics_update(base,rel); while ( 1 ) { @@ -1197,6 +1192,7 @@ char *LP_autobuy(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel return(LP_trade(ctx,myipaddr,mypubsock,&Q,maxprice,timeout,duration,tradeid,destpubkey)); } return(clonestr("{\"error\":\"cant get here\"}")); +#endif } diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index 6b5643bb6..fee4a1189 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -658,7 +658,7 @@ char *LP_uitem_recv(cJSON *argjson) { //char str[65]; printf("uitem %s %s %s/v%d %.8f ht.%d\n",symbol,coinaddr,bits256_str(str,txid),vout,dstr(value),height); if ( strcmp(coin->smartaddr,coinaddr) != 0 ) - LP_address_utxoadd("LP_uitem_recv",coin,coinaddr,txid,vout,value,height,-1); + LP_address_utxoadd((uint32_t)time(NULL),"LP_uitem_recv",coin,coinaddr,txid,vout,value,height,-1); //else printf("ignore external uitem %s %s\n",symbol,coin->smartaddr); } return(clonestr("{\"result\":\"success\"}")); @@ -676,11 +676,14 @@ void LP_listunspent_query(char *symbol,char *coinaddr) void LP_query(void *ctx,char *myipaddr,int32_t mypubsock,char *method,struct LP_quoteinfo *qp) { - cJSON *reqjson; bits256 zero; char *msg,*msg2; int32_t flag = 0; struct LP_utxoinfo *utxo; + cJSON *reqjson; bits256 zero; char *msg,*msg2; int32_t flag = 0; if ( strcmp(method,"request") == 0 ) { - if ( (utxo= LP_utxofind(0,qp->desttxid,qp->destvout)) != 0 && LP_ismine(utxo) > 0 && LP_isavailable(utxo) > 0 ) - LP_unavailableset(utxo,qp->srchash); + if ( LP_allocated(qp->desttxid,qp->destvout) == 0 && LP_allocated(qp->feetxid,qp->feevout) == 0 ) + { + LP_unavailableset(qp->desttxid,qp->destvout,qp->timestamp+LP_AUTOTRADE_TIMEOUT,qp->srchash); + LP_unavailableset(qp->feetxid,qp->feevout,qp->timestamp+LP_AUTOTRADE_TIMEOUT,qp->srchash); + } else { printf("couldnt find my txid to make request\n"); diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index f345e9ab6..870543904 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -303,7 +303,7 @@ int32_t electrum_process_array(struct iguana_info *coin,struct electrum_info *ep else { //printf("external unspent has no gettxout\n"); - flag += LP_address_utxoadd("electrum process",coin,coinaddr,txid,v,value,0,1); + flag += LP_address_utxoadd((uint32_t)time(NULL),"electrum process",coin,coinaddr,txid,v,value,0,1); } } else @@ -345,7 +345,7 @@ int32_t electrum_process_array(struct iguana_info *coin,struct electrum_info *ep if ( tx->height > 0 ) { //printf("from electrum_process_array\n"); - flag += LP_address_utxoadd("electrum process2",coin,coinaddr,txid,v,value,tx->height,-1); + flag += LP_address_utxoadd((uint32_t)time(NULL),"electrum process2",coin,coinaddr,txid,v,value,tx->height,-1); } //printf("v.%d numvouts.%d %.8f (%s)\n",v,tx->numvouts,dstr(tx->outpoints[jint(item,"tx_pos")].value),jprint(item,0)); } //else printf("cant find tx\n"); @@ -544,7 +544,7 @@ cJSON *electrum_address_gethistory(char *symbol,struct electrum_info *ep,cJSON * if ( tx->height > 0 && tx->height != height ) printf("update %s height.%d <- %d\n",bits256_str(str,txid),tx->height,height); tx->height = height; - LP_address_utxoadd("electrum history",coin,addr,txid,0,0,height,-1); + LP_address_utxoadd((uint32_t)time(NULL),"electrum history",coin,addr,txid,0,0,height,-1); } } } diff --git a/iguana/exchanges/LP_swap.c b/iguana/exchanges/LP_swap.c index ce1b725da..03d08d69e 100644 --- a/iguana/exchanges/LP_swap.c +++ b/iguana/exchanges/LP_swap.c @@ -120,11 +120,21 @@ void basilisk_rawtx_purge(struct basilisk_rawtx *rawtx) void basilisk_swap_finished(struct basilisk_swap *swap) { int32_t i; - if ( swap->utxo != 0 && swap->sentflag == 0 ) + /*if ( swap->utxo != 0 && swap->sentflag == 0 ) { LP_availableset(swap->utxo); swap->utxo = 0; //LP_butxo_swapfields_set(swap->utxo); + }*/ + if ( swap->I.iambob != 0 ) + { + LP_availableset(swap->bobdeposit.utxotxid,swap->bobdeposit.utxovout); + LP_availableset(swap->bobpayment.utxotxid,swap->bobpayment.utxovout); + } + else + { + LP_availableset(swap->alicepayment.utxotxid,swap->alicepayment.utxovout); + LP_availableset(swap->myfee.utxotxid,swap->myfee.utxovout); } swap->I.finished = (uint32_t)time(NULL); // save to permanent storage diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index 6e4642f3e..4d9ee5fe1 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -911,7 +911,7 @@ int32_t LP_vins_select(void *ctx,struct iguana_info *coin,int64_t *totalp,int64_ if ( up == 0 ) { value = LP_txvalue(0,coin->symbol,utxotxid,utxovout); - LP_address_utxoadd("withdraw",coin,coin->smartaddr,utxotxid,utxovout,value,1,-1); + LP_address_utxoadd((uint32_t)time(NULL),"withdraw",coin,coin->smartaddr,utxotxid,utxovout,value,1,-1); //printf("added after not finding\n"); } if ( (up= LP_address_utxofind(coin,coin->smartaddr,utxotxid,utxovout)) != 0 ) @@ -999,36 +999,6 @@ int32_t LP_vins_select(void *ctx,struct iguana_info *coin,int64_t *totalp,int64_ return(n); } -struct LP_address *LP_address_utxo_reset(struct iguana_info *coin) -{ - struct LP_address *ap; int32_t i,n; cJSON *array,*item; int64_t value; bits256 txid; int32_t vout,height; - LP_listunspent_issue(coin->symbol,coin->smartaddr,2); - if ( (ap= LP_addressfind(coin,coin->smartaddr)) == 0 ) - { - printf("LP_createrawtransaction: cant find address data\n"); - return(0); - } - if ( (array= LP_listunspent(coin->symbol,coin->smartaddr)) != 0 ) - { - ap->utxos = 0; - if ( (n= cJSON_GetArraySize(array)) > 0 ) - { - for (i=0; ismartaddr,txid,vout,value,height,-1); - } - } - free_json(array); - } - return(ap); -} - char *LP_createrawtransaction(cJSON **txobjp,int32_t *numvinsp,struct iguana_info *coin,struct vin_info *V,int32_t max,bits256 privkey,cJSON *outputs,cJSON *vins,cJSON *privkeys,int64_t txfee,bits256 utxotxid,int32_t utxovout,uint32_t locktime) { static void *ctx; @@ -1077,7 +1047,12 @@ char *LP_createrawtransaction(cJSON **txobjp,int32_t *numvinsp,struct iguana_inf return(0); } } - if ( (ap= LP_address_utxo_reset(coin)) == 0 ) + if ( bits256_nonz(utxotxid) == 0 ) + { + if ( (ap= LP_address_utxo_reset(coin)) == 0 ) + return(0); + } + else if ( (ap= LP_address(coin,coin->smartaddr)) == 0 ) return(0); memset(utxos,0,sizeof(utxos)); if ( (numutxos= LP_address_utxo_ptrs(coin,0,utxos,max,ap,coin->smartaddr)) <= 0 ) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 3257f6096..f8fab79a7 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -18,6 +18,124 @@ // marketmaker // + +struct LP_inuse_info +{ + bits256 txid,otherpub; + uint32_t expiration; + int32_t vout,ind; +} LP_inuse[1024]; +int32_t LP_numinuse; + +struct LP_inuse_info *_LP_inuse_find(bits256 txid,int32_t vout) +{ + int32_t i; + if ( bits256_nonz(txid) != 0 ) + { + for (i=0; iind; + *lp = LP_inuse[--LP_numinuse]; + lp->ind = ind; + memset(&LP_inuse[LP_numinuse],0,sizeof(struct LP_inuse_info)); + for (ind=0; indtxid = txid; + lp->vout = vout; + lp->expiration = expiration; + lp->otherpub = otherpub; + lp->ind = LP_numinuse++; + } + else + { + if ( bits256_nonz(otherpub) != 0 ) + lp->otherpub = otherpub; + if ( expiration > lp->expiration || expiration == 0 ) + lp->expiration = expiration; + } + return(lp); + } else printf("_LP_inuse_add [%d] overflow\n",LP_numinuse); + return(0); +} + +int32_t LP_reservation_check(bits256 txid,int32_t vout,bits256 pubkey) +{ + struct LP_inuse_info *lp; int32_t retval = -1; + if ( bits256_nonz(pubkey) != 0 ) + { + portable_mutex_lock(&LP_inusemutex); + if ( (lp= _LP_inuse_find(txid,vout)) != 0 ) + { + if ( bits256_cmp(lp->otherpub,pubkey) == 0 ) + retval = 0; + } + portable_mutex_unlock(&LP_inusemutex); + } + return(retval); +} + +uint32_t LP_allocated(bits256 txid,int32_t vout) +{ + struct LP_inuse_info *lp; uint32_t now,duration = 0; + now = (uint32_t)time(NULL); + portable_mutex_lock(&LP_inusemutex); + if ( (lp= _LP_inuse_find(txid,vout)) != 0 ) + { + if ( lp->expiration != 0 && now < lp->expiration ) + duration = (lp->expiration - now); + } + portable_mutex_unlock(&LP_inusemutex); + return(duration); +} + +void LP_unavailableset(bits256 txid,int32_t vout,uint32_t expiration,bits256 otherpub) +{ + portable_mutex_lock(&LP_inusemutex); + _LP_inuse_add(expiration,otherpub,txid,vout); + portable_mutex_unlock(&LP_inusemutex); +} + +void LP_availableset(bits256 txid,int32_t vout) +{ + portable_mutex_lock(&LP_inusemutex); + _LP_inuse_delete(txid,vout); + portable_mutex_unlock(&LP_inusemutex); +} + +int32_t LP_isavailable(struct LP_utxoinfo *utxo) +{ + struct _LP_utxoinfo u; + u = (utxo->iambob != 0) ? utxo->deposit : utxo->fee; + if ( LP_allocated(utxo->payment.txid,utxo->payment.vout) == 0 && LP_allocated(u.txid,u.vout) == 0 ) + return(1); + else return(0); +} + uint64_t LP_value_extract(cJSON *obj,int32_t addinterest) { double val = 0.; uint64_t value = 0; int32_t electrumflag; @@ -116,36 +234,9 @@ int32_t LP_address_minmax(uint64_t *balancep,uint64_t *minp,uint64_t *maxp,struc return(n); } -struct LP_utxoinfo *LP_allocated(bits256 txid,int32_t vout) -{ - struct LP_utxoinfo *utxo; - if ( (utxo= _LP_utxofind(0,txid,vout)) != 0 && LP_isavailable(utxo) == 0 ) - { - //char str[65]; printf("%s/v%d not available\n",bits256_str(str,txid),vout); - return(utxo); - } - if ( (utxo= _LP_utxo2find(0,txid,vout)) != 0 && LP_isavailable(utxo) == 0 ) - { - //char str[65]; printf("%s/v%d not available2\n",bits256_str(str,txid),vout); - return(utxo); - } - if ( (utxo= _LP_utxofind(1,txid,vout)) != 0 && LP_isavailable(utxo) == 0 ) - { - //char str[65]; printf("%s/v%d not available\n",bits256_str(str,txid),vout); - return(utxo); - } - if ( (utxo= _LP_utxo2find(1,txid,vout)) != 0 && LP_isavailable(utxo) == 0 ) - { - //char str[65]; printf("%s/v%d not available2\n",bits256_str(str,txid),vout); - return(utxo); - } - return(0); -} - int32_t LP_address_utxo_ptrs(struct iguana_info *coin,int32_t iambob,struct LP_address_utxo **utxos,int32_t max,struct LP_address *ap,char *coinaddr) { struct LP_address_utxo *up,*tmp; struct LP_transaction *tx; cJSON *txout; int32_t n = 0; - //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); @@ -189,7 +280,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 )//&& (iambob == 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 ) { utxos[n++] = up; if ( n >= max ) @@ -239,7 +330,7 @@ void LP_mark_spent(char *symbol,bits256 txid,int32_t vout) } } -int32_t LP_address_utxoadd(char *debug,struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout,uint64_t value,int32_t height,int32_t spendheight) +int32_t LP_address_utxoadd(uint32_t timestamp,char *debug,struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout,uint64_t value,int32_t height,int32_t spendheight) { struct LP_address *ap; cJSON *txobj; struct LP_transaction *tx; struct LP_address_utxo *up,*tmp; int32_t flag,retval = 0; //char str[65]; if ( coin == 0 ) @@ -262,6 +353,7 @@ int32_t LP_address_utxoadd(char *debug,struct iguana_info *coin,char *coinaddr,b up->spendheight = spendheight, flag |= 4; if ( value != 0 && up->U.value == 0 && up->U.value != value ) up->U.value = value, flag |= 8; + up->timestamp = timestamp; //printf("found >>>>>>>>>> %s %s %s/v%d ht.%d %.8f\n",coin->symbol,coinaddr,bits256_str(str,txid),vout,height,dstr(value)); break; } @@ -282,21 +374,61 @@ int32_t LP_address_utxoadd(char *debug,struct iguana_info *coin,char *coinaddr,b up->U.height = height; up->U.value = value; up->spendheight = spendheight; - portable_mutex_lock(&coin->addrmutex); - DL_APPEND(ap->utxos,up); - portable_mutex_unlock(&coin->addrmutex); + up->timestamp = timestamp; retval = 1; if ( (tx= LP_transactionfind(coin,txid)) != 0 && tx->SPV > 0 ) { up->SPV = tx->SPV; //printf("%s ADD UTXO >> %s %s %s/v%d ht.%d %.8f\n",debug,coin->symbol,coinaddr,bits256_str(str,txid),vout,height,dstr(value)); } + portable_mutex_lock(&coin->addrmutex); + DL_APPEND(ap->utxos,up); + portable_mutex_unlock(&coin->addrmutex); } } // else printf("cant get ap %s %s\n",coin->symbol,coinaddr); //printf("done %s add addr.%s ht.%d\n",coin->symbol,coinaddr,height); return(retval); } +struct LP_address *LP_address_utxo_reset(struct iguana_info *coin) +{ + struct LP_address *ap; struct LP_address_utxo *up,*tmp; int32_t i,n,vout,height; cJSON *array,*item; int64_t value; bits256 txid; uint32_t now; + LP_listunspent_issue(coin->symbol,coin->smartaddr,2); + if ( (ap= LP_addressfind(coin,coin->smartaddr)) == 0 ) + { + printf("LP_createrawtransaction: cant find address data\n"); + return(0); + } + if ( (array= LP_listunspent(coin->symbol,coin->smartaddr)) != 0 ) + { + //ap->utxos = 0; + now = (uint32_t)time(NULL); + if ( (n= cJSON_GetArraySize(array)) > 0 ) + { + for (i=0; ismartaddr,txid,vout,value,height,-1); + } + } + free_json(array); + DL_FOREACH_SAFE(ap->utxos,up,tmp) + { + if ( up->timestamp < now ) + { + char str[65]; printf("purge %s/v%d as it wasnt in listunspent\n",bits256_str(str,up->U.txid),up->U.vout); + up->spendheight = 1; + } + } + } + return(ap); +} + cJSON *LP_address_item(struct iguana_info *coin,struct LP_address_utxo *up,int32_t electrumret) { cJSON *item = cJSON_CreateObject(); @@ -422,7 +554,7 @@ cJSON *LP_address_balance(struct iguana_info *coin,char *coinaddr,int32_t electr int32_t LP_unspents_array(struct iguana_info *coin,char *coinaddr,cJSON *array) { - int32_t i,n,v,ht,errs,height,count=0; uint64_t value,val; cJSON *item,*txobj; bits256 txid; + int32_t i,n,v,errs,height,count=0; uint64_t value,val; cJSON *item,*txobj; bits256 txid; if ( (n= cJSON_GetArraySize(array)) <= 0 ) return(0); //printf("%s %s LP_unspents.(%s)\n",coin->symbol,coinaddr,jprint(array,0)); @@ -442,7 +574,7 @@ int32_t LP_unspents_array(struct iguana_info *coin,char *coinaddr,cJSON *array) char str[65]; printf("REJECT %s %s/v%d value.%llu vs %llu (%s)\n",coin->symbol,bits256_str(str,txid),v,(long long)value,(long long)val,jprint(txobj,0)); errs++; } - ht = LP_txheight(coin,txid); + //ht = LP_txheight(coin,txid); //if ( coin->height != 0 ) // ht = LP_getheight(coin) - jint(txobj,"confirmations") + 1; //else ht = 0; @@ -456,7 +588,7 @@ int32_t LP_unspents_array(struct iguana_info *coin,char *coinaddr,cJSON *array) if ( errs == 0 ) { //printf("from LP_unspents_array\n"); - LP_address_utxoadd("LP_unspents_array",coin,coinaddr,txid,v,val,height,-1); + LP_address_utxoadd((uint32_t)time(NULL),"LP_unspents_array",coin,coinaddr,txid,v,val,height,-1); count++; } } @@ -580,7 +712,7 @@ cJSON *LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter,cJS tx->outpoints[i].interest = SATOSHIDEN * jdouble(vout,"interest"); LP_destaddr(tx->outpoints[i].coinaddr,vout); //printf("from transaction init %s %s %s/v%d <- %.8f\n",coin->symbol,tx->outpoints[i].coinaddr,bits256_str(str,txid),i,dstr(tx->outpoints[i].value)); - LP_address_utxoadd("LP_transactioninit iter0",coin,tx->outpoints[i].coinaddr,txid,i,tx->outpoints[i].value,height,-1); + LP_address_utxoadd((uint32_t)time(NULL),"LP_transactioninit iter0",coin,tx->outpoints[i].coinaddr,txid,i,tx->outpoints[i].value,height,-1); } //printf("numvouts.%d\n",numvouts); } @@ -602,7 +734,7 @@ cJSON *LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter,cJS tx->outpoints[spentvout].spendtxid = txid; tx->outpoints[spentvout].spendvini = i; tx->outpoints[spentvout].spendheight = height > 0 ? height : 1; - LP_address_utxoadd("LP_transactioninit iter1",coin,tx->outpoints[spentvout].coinaddr,spenttxid,spentvout,tx->outpoints[spentvout].value,-1,height>0?height:1); + LP_address_utxoadd((uint32_t)time(NULL),"LP_transactioninit iter1",coin,tx->outpoints[spentvout].coinaddr,spenttxid,spentvout,tx->outpoints[spentvout].value,-1,height>0?height:1); if ( 0 && strcmp(coin->symbol,"REVS") == 0 ) printf("spend %s %s/v%d at ht.%d\n",coin->symbol,bits256_str(str,tx->txid),spentvout,height); } diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index b24c47ff3..c09e7e6c4 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -19,8 +19,6 @@ // - - int32_t LP_ismine(struct LP_utxoinfo *utxo) { if ( utxo != 0 && bits256_cmp(utxo->pubkey,G.LP_mypub25519) == 0 ) @@ -28,15 +26,6 @@ int32_t LP_ismine(struct LP_utxoinfo *utxo) else return(0); } -int32_t LP_isavailable(struct LP_utxoinfo *utxo) -{ - if ( time(NULL) > utxo->T.swappending ) - utxo->T.swappending = 0; - if ( utxo != 0 && utxo->T.swappending == 0 && utxo->S.swap == 0 ) - return(1); - else return(0); -} - int32_t LP_isunspent(struct LP_utxoinfo *utxo) { struct LP_address_utxo *up; struct _LP_utxoinfo u; struct iguana_info *coin; @@ -88,6 +77,41 @@ int32_t LP_utxoaddptrs(struct LP_utxoinfo *ptrs[],int32_t n,struct LP_utxoinfo * return(n); } +/*uint32_t LP_allocated(bits256 txid,int32_t vout) +{ + struct LP_utxoinfo *utxo; + if ( (utxo= _LP_utxofind(0,txid,vout)) != 0 && LP_isavailable(utxo) == 0 ) + { + //char str[65]; printf("%s/v%d not available\n",bits256_str(str,txid),vout); + return(utxo); + } + if ( (utxo= _LP_utxo2find(0,txid,vout)) != 0 && LP_isavailable(utxo) == 0 ) + { + //char str[65]; printf("%s/v%d not available2\n",bits256_str(str,txid),vout); + return(utxo); + } + if ( (utxo= _LP_utxofind(1,txid,vout)) != 0 && LP_isavailable(utxo) == 0 ) + { + //char str[65]; printf("%s/v%d not available\n",bits256_str(str,txid),vout); + return(utxo); + } + if ( (utxo= _LP_utxo2find(1,txid,vout)) != 0 && LP_isavailable(utxo) == 0 ) + { + //char str[65]; printf("%s/v%d not available2\n",bits256_str(str,txid),vout); + return(utxo); + } + return(0); +} + +int32_t LP_isavailable(struct LP_utxoinfo *utxo) +{ + if ( time(NULL) > utxo->T.swappending ) + utxo->T.swappending = 0; + if ( utxo != 0 && utxo->T.swappending == 0 && utxo->S.swap == 0 ) + return(1); + else return(0); +} + int32_t LP_utxocollisions(struct LP_utxoinfo *ptrs[],struct LP_utxoinfo *refutxo) { int32_t iambob,n = 0; struct LP_utxoinfo *utxo; struct _LP_utxoinfo u; @@ -170,6 +194,7 @@ void LP_availableset(struct LP_utxoinfo *utxo) } } } +*/ cJSON *LP_inventoryjson(cJSON *item,struct LP_utxoinfo *utxo) { @@ -208,8 +233,8 @@ cJSON *LP_inventoryjson(cJSON *item,struct LP_utxoinfo *utxo) if ( bits256_nonz(utxo->S.otherpubkey) != 0 ) jaddbits256(item,"srchash",utxo->S.otherpubkey); } - if ( utxo->S.swap != 0 ) - jaddstr(item,"swap","in progress"); + //if ( utxo->S.swap != 0 ) + // jaddstr(item,"swap","in progress"); if ( utxo->T.spentflag != 0 ) jaddnum(item,"spent",utxo->T.spentflag); jaddnum(item,"session",utxo->T.sessionid); @@ -235,7 +260,6 @@ struct LP_utxoinfo *LP_utxo_bestfit(char *symbol,uint64_t destsatoshis) printf("LP_utxo_bestfit error symbol.%p %.8f\n",symbol,dstr(destsatoshis)); return(0); } - // jl777 remove mempool HASH_ITER(hh,G.LP_utxoinfos[iambob],utxo,tmp) { if ( strcmp(symbol,utxo->coin) != 0 ) From bf6c9969aea363188daaf2d58b421a7bbfbf0158 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 18:45:41 +0200 Subject: [PATCH 078/306] Test --- iguana/exchanges/LP_utxo.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index f8fab79a7..481250689 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -419,11 +419,12 @@ struct LP_address *LP_address_utxo_reset(struct iguana_info *coin) free_json(array); DL_FOREACH_SAFE(ap->utxos,up,tmp) { - if ( up->timestamp < now ) + char str[65]; + if ( up->timestamp < now && up->spendheight <= 0 ) { - char str[65]; printf("purge %s/v%d as it wasnt in listunspent\n",bits256_str(str,up->U.txid),up->U.vout); + printf("purge %s/v%d as it wasnt in listunspent\n",bits256_str(str,up->U.txid),up->U.vout); up->spendheight = 1; - } + } else printf("%s/v%d %.8f avail\n",bits256_str(str,up->U.txid),up->U.vout,dstr(up->U.value)); } } return(ap); From 2173fc7abb41073e3f48b73b5384641802228111 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 18:47:15 +0200 Subject: [PATCH 079/306] Test --- iguana/exchanges/LP_ordermatch.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 0ef73ab65..0dcf2bdeb 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -911,6 +911,11 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, return(retval); } } + else if ( strcmp(method,"connect") == 0 ) + { + if ( bits256_cmp(G.LP_mypub25519,Q.srchash) != 0 || bits256_cmp(G.LP_mypub25519,Q.desthash) == 0 ) + return(retval); + } if ( strcmp(Q.coinaddr,coin->smartaddr) != 0 ) { printf("bob is patching Q.coinaddr %s mismatch != %s\n",Q.coinaddr,coin->smartaddr); @@ -958,9 +963,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, else if ( strcmp(method,"connect") == 0 ) // bob { retval = 4; - if ( bits256_cmp(G.LP_mypub25519,Q.srchash) != 0 || bits256_cmp(G.LP_mypub25519,Q.desthash) == 0 ) - return(retval); - else if ( LP_reservation_check(Q.txid,Q.vout,Q.desthash) == 0 && LP_reservation_check(Q.txid2,Q.vout2,Q.desthash) == 0 ) + if ( LP_reservation_check(Q.txid,Q.vout,Q.desthash) == 0 && LP_reservation_check(Q.txid2,Q.vout2,Q.desthash) == 0 ) { LP_connectstartbob(ctx,pubsock,argjson,Q.srccoin,Q.destcoin,qprice,&Q); return(retval); From 5b3d32166247efac6dd283c09552428c248fbc45 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 18:52:54 +0200 Subject: [PATCH 080/306] Test --- iguana/exchanges/LP_utxo.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 481250689..c43d2e02c 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -393,10 +393,11 @@ int32_t LP_address_utxoadd(uint32_t timestamp,char *debug,struct iguana_info *co struct LP_address *LP_address_utxo_reset(struct iguana_info *coin) { struct LP_address *ap; struct LP_address_utxo *up,*tmp; int32_t i,n,vout,height; cJSON *array,*item; int64_t value; bits256 txid; uint32_t now; + LP_address(coin,coin->smartaddr); LP_listunspent_issue(coin->symbol,coin->smartaddr,2); if ( (ap= LP_addressfind(coin,coin->smartaddr)) == 0 ) { - printf("LP_createrawtransaction: cant find address data\n"); + printf("LP_address_utxo_reset: cant find address data\n"); return(0); } if ( (array= LP_listunspent(coin->symbol,coin->smartaddr)) != 0 ) From 9b896d4d4a4c8ee4616d351c60095403f9ded856 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 18:56:03 +0200 Subject: [PATCH 081/306] Test --- iguana/exchanges/LP_utxo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index c43d2e02c..715c103a8 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -354,7 +354,7 @@ int32_t LP_address_utxoadd(uint32_t timestamp,char *debug,struct iguana_info *co if ( value != 0 && up->U.value == 0 && up->U.value != value ) up->U.value = value, flag |= 8; up->timestamp = timestamp; -//printf("found >>>>>>>>>> %s %s %s/v%d ht.%d %.8f\n",coin->symbol,coinaddr,bits256_str(str,txid),vout,height,dstr(value)); + char str[65]; printf("found >>>>>>>>>> %s %s %s/v%d ht.%d %.8f\n",coin->symbol,coinaddr,bits256_str(str,txid),vout,height,dstr(value)); break; } } @@ -379,8 +379,8 @@ int32_t LP_address_utxoadd(uint32_t timestamp,char *debug,struct iguana_info *co if ( (tx= LP_transactionfind(coin,txid)) != 0 && tx->SPV > 0 ) { up->SPV = tx->SPV; - //printf("%s ADD UTXO >> %s %s %s/v%d ht.%d %.8f\n",debug,coin->symbol,coinaddr,bits256_str(str,txid),vout,height,dstr(value)); } + char str[65]; printf("%s ADD UTXO >> %s %s %s/v%d ht.%d %.8f\n",debug,coin->symbol,coinaddr,bits256_str(str,txid),vout,height,dstr(value)); portable_mutex_lock(&coin->addrmutex); DL_APPEND(ap->utxos,up); portable_mutex_unlock(&coin->addrmutex); From d2314e8a25c1f63f788f2c9c7060cbf90f17fe97 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 19:02:03 +0200 Subject: [PATCH 082/306] Test --- iguana/exchanges/LP_utxo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 715c103a8..8d35d9ea5 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -354,7 +354,7 @@ int32_t LP_address_utxoadd(uint32_t timestamp,char *debug,struct iguana_info *co if ( value != 0 && up->U.value == 0 && up->U.value != value ) up->U.value = value, flag |= 8; up->timestamp = timestamp; - char str[65]; printf("found >>>>>>>>>> %s %s %s/v%d ht.%d %.8f\n",coin->symbol,coinaddr,bits256_str(str,txid),vout,height,dstr(value)); + //char str[65]; printf("found >>>>>>>>>> %s %s %s/v%d ht.%d %.8f\n",coin->symbol,coinaddr,bits256_str(str,txid),vout,height,dstr(value)); break; } } @@ -379,8 +379,8 @@ int32_t LP_address_utxoadd(uint32_t timestamp,char *debug,struct iguana_info *co if ( (tx= LP_transactionfind(coin,txid)) != 0 && tx->SPV > 0 ) { up->SPV = tx->SPV; + //char str[65]; printf("%s ADD UTXO >> %s %s %s/v%d ht.%d %.8f\n",debug,coin->symbol,coinaddr,bits256_str(str,txid),vout,height,dstr(value)); } - char str[65]; printf("%s ADD UTXO >> %s %s %s/v%d ht.%d %.8f\n",debug,coin->symbol,coinaddr,bits256_str(str,txid),vout,height,dstr(value)); portable_mutex_lock(&coin->addrmutex); DL_APPEND(ap->utxos,up); portable_mutex_unlock(&coin->addrmutex); From 12408f15db8c2367fd96273ab05b72b607593d45 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 19:07:32 +0200 Subject: [PATCH 083/306] 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 0dcf2bdeb..1b8103090 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -370,7 +370,7 @@ struct LP_utxoinfo *LP_address_myutxopair(struct LP_utxoinfo *butxo,int32_t iamb { if ( (m= LP_address_utxo_ptrs(coin,iambob,utxos,max,ap,coinaddr)) > 1 ) { - if ( 0 ) + if ( 1 ) { int32_t i; for (i=0; i targetval2 %.8f, ratio %.2f\n",mini,dstr(up->U.value),dstr(targetval),dstr(targetval2),(double)up->U.value/targetval); +printf("found mini.%d %.8f for targetval %.8f -> targetval2 %.8f, ratio %.2f\n",mini,dstr(up->U.value),dstr(targetval),dstr(targetval2),(double)up->U.value/targetval); if ( (double)up->U.value/targetval < LP_MINVOL-1 ) { @@ -397,6 +397,7 @@ struct LP_utxoinfo *LP_address_myutxopair(struct LP_utxoinfo *butxo,int32_t iamb return(butxo); }*/ LP_butxo_set(butxo,coin,up,up2,targetval); + return(butxo); } } //else printf("cant find targetval2 %.8f\n",dstr(targetval2)); } //else printf("failed ratio test %.8f\n",(double)up->U.value/targetval); From accfa2bc627d35f1eda979f7886300be1cf4e33a Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 19:15:34 +0200 Subject: [PATCH 084/306] 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 8d35d9ea5..268a6362c 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -349,7 +349,7 @@ int32_t LP_address_utxoadd(uint32_t timestamp,char *debug,struct iguana_info *co flag = 1; if ( height > 0 && up->U.height != height ) up->U.height = height, flag |= 2; - if ( spendheight > 0 && up->spendheight != spendheight ) + if ( up->spendheight != spendheight ) up->spendheight = spendheight, flag |= 4; if ( value != 0 && up->U.value == 0 && up->U.value != value ) up->U.value = value, flag |= 8; From a286a2339316c4a92d6858b65c7a7213fdc081ca Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 19:22:48 +0200 Subject: [PATCH 085/306] Test --- iguana/exchanges/LP_include.h | 2 +- iguana/exchanges/LP_utxo.c | 25 +++++++++++-------------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index c24ad9bf4..1b0394f95 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -308,7 +308,7 @@ struct LP_address_utxo struct LP_address_utxo *next,*prev; struct _LP_utxoinfo U; int32_t SPV,spendheight; - uint32_t timestamp; + //uint32_t timestamp; }; struct LP_address diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 268a6362c..007178e94 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -243,7 +243,7 @@ int32_t LP_address_utxo_ptrs(struct iguana_info *coin,int32_t iambob,struct LP_a portable_mutex_lock(&LP_utxomutex); DL_FOREACH_SAFE(ap->utxos,up,tmp) { - //char str[65]; printf("LP_address_utxo_ptrs %s n.%d %.8f %s v%d spendheight.%d allocated.%p\n",ap->coinaddr,n,dstr(up->U.value),bits256_str(str,up->U.txid),up->U.vout,up->spendheight,LP_allocated(up->U.txid,up->U.vout)); + char str[65]; printf("LP_address_utxo_ptrs %s n.%d %.8f %s v%d spendheight.%d allocated.%d\n",ap->coinaddr,n,dstr(up->U.value),bits256_str(str,up->U.txid),up->U.vout,up->spendheight,LP_allocated(up->U.txid,up->U.vout)); if ( up->spendheight <= 0 && LP_RTmetrics_avoidtxid(up->U.txid) < 0 ) { if ( coin->electrum == 0 ) @@ -349,11 +349,11 @@ int32_t LP_address_utxoadd(uint32_t timestamp,char *debug,struct iguana_info *co flag = 1; if ( height > 0 && up->U.height != height ) up->U.height = height, flag |= 2; - if ( up->spendheight != spendheight ) + if ( spendheight > 0 && up->spendheight != spendheight ) up->spendheight = spendheight, flag |= 4; if ( value != 0 && up->U.value == 0 && up->U.value != value ) up->U.value = value, flag |= 8; - up->timestamp = timestamp; + //up->timestamp = timestamp; //char str[65]; printf("found >>>>>>>>>> %s %s %s/v%d ht.%d %.8f\n",coin->symbol,coinaddr,bits256_str(str,txid),vout,height,dstr(value)); break; } @@ -374,7 +374,7 @@ int32_t LP_address_utxoadd(uint32_t timestamp,char *debug,struct iguana_info *co up->U.height = height; up->U.value = value; up->spendheight = spendheight; - up->timestamp = timestamp; + //up->timestamp = timestamp; retval = 1; if ( (tx= LP_transactionfind(coin,txid)) != 0 && tx->SPV > 0 ) { @@ -402,7 +402,13 @@ struct LP_address *LP_address_utxo_reset(struct iguana_info *coin) } if ( (array= LP_listunspent(coin->symbol,coin->smartaddr)) != 0 ) { - //ap->utxos = 0; + DL_FOREACH_SAFE(ap->utxos,up,tmp) + { + portable_mutex_lock(&coin->addrmutex); + DL_DELETE(ap->utxos,up); + portable_mutex_unlock(&coin->addrmutex); + free(up); + } now = (uint32_t)time(NULL); if ( (n= cJSON_GetArraySize(array)) > 0 ) { @@ -418,15 +424,6 @@ struct LP_address *LP_address_utxo_reset(struct iguana_info *coin) } } free_json(array); - DL_FOREACH_SAFE(ap->utxos,up,tmp) - { - char str[65]; - if ( up->timestamp < now && up->spendheight <= 0 ) - { - printf("purge %s/v%d as it wasnt in listunspent\n",bits256_str(str,up->U.txid),up->U.vout); - up->spendheight = 1; - } else printf("%s/v%d %.8f avail\n",bits256_str(str,up->U.txid),up->U.vout,dstr(up->U.value)); - } } return(ap); } From 1be8574932fdfc0df0de45e7dbf4aca5f04d0a20 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 19:28:32 +0200 Subject: [PATCH 086/306] Test --- iguana/exchanges/LP_utxo.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 007178e94..7d36a9eab 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -252,7 +252,7 @@ int32_t LP_address_utxo_ptrs(struct iguana_info *coin,int32_t iambob,struct LP_a { if ( LP_value_extract(txout,0) == 0 ) { - //printf("LP_address_utxo_ptrs skip zero value %s/v%d\n",bits256_str(str,up->U.txid),up->U.vout); + printf("LP_address_utxo_ptrs skip zero value %s/v%d\n",bits256_str(str,up->U.txid),up->U.vout); free_json(txout); up->spendheight = 1; if ( (tx= LP_transactionfind(coin,up->U.txid)) != 0 && up->U.vout < tx->numvouts ) @@ -263,7 +263,7 @@ int32_t LP_address_utxo_ptrs(struct iguana_info *coin,int32_t iambob,struct LP_a } else { - //printf("LP_address_utxo_ptrs skips %s %s payment %s/v%d is spent\n",coin->symbol,coinaddr,bits256_str(str,up->U.txid),up->U.vout); + printf("LP_address_utxo_ptrs skips %s %s payment %s/v%d is spent\n",coin->symbol,coinaddr,bits256_str(str,up->U.txid),up->U.vout); up->spendheight = 1; if ( (tx= LP_transactionfind(coin,up->U.txid)) != 0 && up->U.vout < tx->numvouts ) tx->outpoints[up->U.vout].spendheight = 1; @@ -274,7 +274,7 @@ int32_t LP_address_utxo_ptrs(struct iguana_info *coin,int32_t iambob,struct LP_a { if ( up->SPV < 0 || up->U.height == 0 ) { -//printf("LP_address_utxo_ptrs skips %s/v%u due to SPV.%d ht.%d\n",bits256_str(str,up->U.txid),up->U.vout,up->SPV,up->U.height); +printf("LP_address_utxo_ptrs skips %s/v%u due to SPV.%d ht.%d\n",bits256_str(str,up->U.txid),up->U.vout,up->SPV,up->U.height); if ( (tx= LP_transactionfind(coin,up->U.txid)) != 0 && up->U.vout < tx->numvouts ) tx->outpoints[up->U.vout].spendheight = 1; continue; @@ -285,7 +285,7 @@ int32_t LP_address_utxo_ptrs(struct iguana_info *coin,int32_t iambob,struct LP_a utxos[n++] = up; if ( n >= max ) break; - } + } else printf("LP_allocated skip\n"); } else { @@ -422,6 +422,7 @@ struct LP_address *LP_address_utxo_reset(struct iguana_info *coin) height = jint(item,"height"); LP_address_utxoadd(now,"withdraw",coin,coin->smartaddr,txid,vout,value,height,-1); } + printf("added %d from listunspents\n",n); } free_json(array); } From 58896cc3b8be5fcbaf53e0b23a77dade8671a1b7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 19:32:45 +0200 Subject: [PATCH 087/306] Test --- iguana/exchanges/LP_ordermatch.c | 4 ++-- iguana/exchanges/LP_utxo.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 1b8103090..1c8524d06 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -366,7 +366,7 @@ struct LP_utxoinfo *LP_address_myutxopair(struct LP_utxoinfo *butxo,int32_t iamb memset(butxo,0,sizeof(*butxo)); targetval = LP_basesatoshis(relvolume,price,txfee,desttxfee); targetval2 = (targetval / 8) * 9 + 2*txfee; - if ( coin != 0 && (ap= LP_addressfind(coin,coinaddr)) != 0 ) + if ( coin != 0 && (ap= LP_address(coin,coinaddr)) != 0 ) { if ( (m= LP_address_utxo_ptrs(coin,iambob,utxos,max,ap,coinaddr)) > 1 ) { @@ -403,7 +403,7 @@ printf("found mini.%d %.8f for targetval %.8f -> targetval2 %.8f, ratio %.2f\n", } //else printf("failed ratio test %.8f\n",(double)up->U.value/targetval); } else if ( targetval != 0 && mini >= 0 ) printf("targetval %.8f mini.%d\n",dstr(targetval),mini); - } //else printf("no %s utxos pass LP_address_utxo_ptrs filter\n",coinaddr); + } else printf("no %s utxos pass LP_address_utxo_ptrs filter\n",coinaddr); } else printf("couldnt find %s %s\n",coin->symbol,coinaddr); return(0); } diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 7d36a9eab..b63ee8673 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -239,8 +239,8 @@ int32_t LP_address_utxo_ptrs(struct iguana_info *coin,int32_t iambob,struct LP_a struct LP_address_utxo *up,*tmp; struct LP_transaction *tx; cJSON *txout; int32_t n = 0; 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); + //LP_listunspent_issue(coin->symbol,coin->smartaddr,2); + //portable_mutex_lock(&LP_utxomutex); DL_FOREACH_SAFE(ap->utxos,up,tmp) { char str[65]; printf("LP_address_utxo_ptrs %s n.%d %.8f %s v%d spendheight.%d allocated.%d\n",ap->coinaddr,n,dstr(up->U.value),bits256_str(str,up->U.txid),up->U.vout,up->spendheight,LP_allocated(up->U.txid,up->U.vout)); @@ -293,8 +293,8 @@ printf("LP_address_utxo_ptrs skips %s/v%u due to SPV.%d ht.%d\n",bits256_str(str tx->outpoints[up->U.vout].spendheight = 1; } } - portable_mutex_unlock(&LP_utxomutex); - //printf("return n.%d\n",n); + //portable_mutex_unlock(&LP_utxomutex); + printf("return n.%d for %s %s\n",n,coin->symbol,coinaddr); return(n); } From e15152011322a7c1006e288c6064c939232388cd Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 19:36:21 +0200 Subject: [PATCH 088/306] Test --- iguana/exchanges/LP_utxo.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index b63ee8673..250e5c1c2 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -364,7 +364,7 @@ int32_t LP_address_utxoadd(uint32_t timestamp,char *debug,struct iguana_info *co { if ( (txobj= LP_gettxout(coin->symbol,coinaddr,txid,vout)) == 0 ) { - //printf("prevent utxoadd since gettxout %s %s %s/v%d missing\n",coin->symbol,coinaddr,bits256_str(str,txid),vout); + char str[65]; printf("prevent utxoadd since gettxout %s %s %s/v%d missing\n",coin->symbol,coinaddr,bits256_str(str,txid),vout); return(0); } else free_json(txobj); } @@ -379,8 +379,10 @@ int32_t LP_address_utxoadd(uint32_t timestamp,char *debug,struct iguana_info *co if ( (tx= LP_transactionfind(coin,txid)) != 0 && tx->SPV > 0 ) { up->SPV = tx->SPV; - //char str[65]; printf("%s ADD UTXO >> %s %s %s/v%d ht.%d %.8f\n",debug,coin->symbol,coinaddr,bits256_str(str,txid),vout,height,dstr(value)); } + char str[65]; + if ( strcmp(coin->smartaddr,coinaddr) == 0 && strcmp("KMD",coin->symbol) == 0 ) + printf("%s ADD UTXO >> %s %s %s/v%d ht.%d %.8f\n",debug,coin->symbol,coinaddr,bits256_str(str,txid),vout,height,dstr(value)); portable_mutex_lock(&coin->addrmutex); DL_APPEND(ap->utxos,up); portable_mutex_unlock(&coin->addrmutex); From 4057fd6f59ecf4a68d014a0ba1337fac3b20753f Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 19:41:20 +0200 Subject: [PATCH 089/306] 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 250e5c1c2..1d0770e44 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -414,6 +414,7 @@ struct LP_address *LP_address_utxo_reset(struct iguana_info *coin) now = (uint32_t)time(NULL); if ( (n= cJSON_GetArraySize(array)) > 0 ) { + char str[65]; for (i=0; ismartaddr,txid,vout,value,height,-1); + if ( (up= LP_address_utxofind(coin,coin->smartaddr,txid,vout)) == 0 ) + printf("couldnt find just added %s/%d ht.%d %.8f\n",bits256_str(str,txid),vout,height,dstr(value)); } printf("added %d from listunspents\n",n); } From f0063628c38e000cc7ef0aba9826768644206e6b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 19:44:44 +0200 Subject: [PATCH 090/306] Test --- iguana/exchanges/LP_utxo.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 1d0770e44..c695ffae6 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -419,10 +419,20 @@ struct LP_address *LP_address_utxo_reset(struct iguana_info *coin) { //{"tx_hash":"38d1b7c73015e1b1d6cb7fc314cae402a635b7d7ea294970ab857df8777a66f4","tx_pos":0,"height":577975,"value":238700} item = jitem(array,i); - txid = jbits256(item,"tx_hash"); - vout = juint(item,"tx_pos"); - value = j64bits(item,"value"); - height = jint(item,"height"); + if ( coin->electrum != 0 ) + { + txid = jbits256(item,"tx_hash"); + vout = juint(item,"tx_pos"); + value = j64bits(item,"value"); + height = jint(item,"height"); + } + else + { + txid = jbits256(item,"txid"); + vout = juint(item,"vout"); + value = LP_value_extract(item,0); + height = LP_txheight(coin,txid); + } LP_address_utxoadd(now,"withdraw",coin,coin->smartaddr,txid,vout,value,height,-1); if ( (up= LP_address_utxofind(coin,coin->smartaddr,txid,vout)) == 0 ) printf("couldnt find just added %s/%d ht.%d %.8f\n",bits256_str(str,txid),vout,height,dstr(value)); From c569b02a464982e328742698712e9892d4148d9c Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 19:50:34 +0200 Subject: [PATCH 091/306] Test --- iguana/exchanges/LP_utxo.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index c695ffae6..85d7df5ed 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -364,7 +364,7 @@ int32_t LP_address_utxoadd(uint32_t timestamp,char *debug,struct iguana_info *co { if ( (txobj= LP_gettxout(coin->symbol,coinaddr,txid,vout)) == 0 ) { - char str[65]; printf("prevent utxoadd since gettxout %s %s %s/v%d missing\n",coin->symbol,coinaddr,bits256_str(str,txid),vout); + //char str[65]; printf("prevent utxoadd since gettxout %s %s %s/v%d missing\n",coin->symbol,coinaddr,bits256_str(str,txid),vout); return(0); } else free_json(txobj); } @@ -381,7 +381,7 @@ int32_t LP_address_utxoadd(uint32_t timestamp,char *debug,struct iguana_info *co up->SPV = tx->SPV; } char str[65]; - if ( strcmp(coin->smartaddr,coinaddr) == 0 && strcmp("KMD",coin->symbol) == 0 ) + if ( 0 && strcmp(coin->smartaddr,coinaddr) == 0 && strcmp("KMD",coin->symbol) == 0 ) printf("%s ADD UTXO >> %s %s %s/v%d ht.%d %.8f\n",debug,coin->symbol,coinaddr,bits256_str(str,txid),vout,height,dstr(value)); portable_mutex_lock(&coin->addrmutex); DL_APPEND(ap->utxos,up); @@ -492,7 +492,10 @@ cJSON *LP_address_utxos(struct iguana_info *coin,char *coinaddr,int32_t electrum } if ( up->spendheight <= 0 && up->U.value != 0 ) { - if ( coin->electrum == 0 || up->SPV > 0 ) + char str[65]; + if ( LP_allocated(up->U.txid,up->U.vout) != 0 ) + printf("%s %s/v%d allocated\n",coin->symbol,bits256_str(str,up->U.txid),up->U.vout); + else if ( coin->electrum == 0 || up->SPV > 0 ) { jaddi(array,LP_address_item(coin,up,electrumret)); n++; From 383adfe215b06060b56fcb30d0117dc6cfd0bf1c Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 20:06:45 +0200 Subject: [PATCH 092/306] Test --- iguana/exchanges/LP_utxo.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 85d7df5ed..0fe71aa4e 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -243,7 +243,7 @@ int32_t LP_address_utxo_ptrs(struct iguana_info *coin,int32_t iambob,struct LP_a //portable_mutex_lock(&LP_utxomutex); DL_FOREACH_SAFE(ap->utxos,up,tmp) { - char str[65]; printf("LP_address_utxo_ptrs %s n.%d %.8f %s v%d spendheight.%d allocated.%d\n",ap->coinaddr,n,dstr(up->U.value),bits256_str(str,up->U.txid),up->U.vout,up->spendheight,LP_allocated(up->U.txid,up->U.vout)); + //char str[65]; printf("LP_address_utxo_ptrs %s n.%d %.8f %s v%d spendheight.%d allocated.%d\n",ap->coinaddr,n,dstr(up->U.value),bits256_str(str,up->U.txid),up->U.vout,up->spendheight,LP_allocated(up->U.txid,up->U.vout)); if ( up->spendheight <= 0 && LP_RTmetrics_avoidtxid(up->U.txid) < 0 ) { if ( coin->electrum == 0 ) @@ -252,7 +252,7 @@ int32_t LP_address_utxo_ptrs(struct iguana_info *coin,int32_t iambob,struct LP_a { if ( LP_value_extract(txout,0) == 0 ) { - printf("LP_address_utxo_ptrs skip zero value %s/v%d\n",bits256_str(str,up->U.txid),up->U.vout); + //printf("LP_address_utxo_ptrs skip zero value %s/v%d\n",bits256_str(str,up->U.txid),up->U.vout); free_json(txout); up->spendheight = 1; if ( (tx= LP_transactionfind(coin,up->U.txid)) != 0 && up->U.vout < tx->numvouts ) @@ -263,7 +263,7 @@ int32_t LP_address_utxo_ptrs(struct iguana_info *coin,int32_t iambob,struct LP_a } else { - printf("LP_address_utxo_ptrs skips %s %s payment %s/v%d is spent\n",coin->symbol,coinaddr,bits256_str(str,up->U.txid),up->U.vout); + //printf("LP_address_utxo_ptrs skips %s %s payment %s/v%d is spent\n",coin->symbol,coinaddr,bits256_str(str,up->U.txid),up->U.vout); up->spendheight = 1; if ( (tx= LP_transactionfind(coin,up->U.txid)) != 0 && up->U.vout < tx->numvouts ) tx->outpoints[up->U.vout].spendheight = 1; @@ -274,7 +274,7 @@ int32_t LP_address_utxo_ptrs(struct iguana_info *coin,int32_t iambob,struct LP_a { if ( up->SPV < 0 || up->U.height == 0 ) { -printf("LP_address_utxo_ptrs skips %s/v%u due to SPV.%d ht.%d\n",bits256_str(str,up->U.txid),up->U.vout,up->SPV,up->U.height); +//printf("LP_address_utxo_ptrs skips %s/v%u due to SPV.%d ht.%d\n",bits256_str(str,up->U.txid),up->U.vout,up->SPV,up->U.height); if ( (tx= LP_transactionfind(coin,up->U.txid)) != 0 && up->U.vout < tx->numvouts ) tx->outpoints[up->U.vout].spendheight = 1; continue; From 434c96cd41b1e6d5d2f1531af202be2faeb17ed9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 21:02:34 +0200 Subject: [PATCH 093/306] Test --- iguana/exchanges/LP_ordermatch.c | 4 ++-- iguana/exchanges/LP_socket.c | 4 ++-- iguana/exchanges/LP_utxos.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 1c8524d06..a27dc1078 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -404,7 +404,7 @@ printf("found mini.%d %.8f for targetval %.8f -> targetval2 %.8f, ratio %.2f\n", } else if ( targetval != 0 && mini >= 0 ) printf("targetval %.8f mini.%d\n",dstr(targetval),mini); } else printf("no %s utxos pass LP_address_utxo_ptrs filter\n",coinaddr); - } else printf("couldnt find %s %s\n",coin->symbol,coinaddr); + } else printf("address_myutxopair couldnt find %s %s\n",coin->symbol,coinaddr); return(0); } @@ -812,7 +812,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, return(retval); } price = ask; - printf("MYPRICE %s/%s %.8f vs qprice %.8f\n",Q.srccoin,Q.destcoin,price,qprice); + //printf("MYPRICE %s/%s %.8f vs qprice %.8f\n",Q.srccoin,Q.destcoin,price,qprice); 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)); diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 870543904..e50e648d4 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -578,8 +578,8 @@ cJSON *electrum_address_listunspent(char *symbol,struct electrum_info *ep,cJSON cJSON *retjson=0; char *retstr; struct LP_address *ap; struct iguana_info *coin; int32_t updatedflag,height,usecache=1; if ( (coin= LP_coinfind(symbol)) == 0 ) return(0); - //if ( strcmp(addr,INSTANTDEX_KMD) == 0 ) - // return(cJSON_Parse("[]")); + if ( strcmp(addr,INSTANTDEX_KMD) == 0 ) + return(cJSON_Parse("[]")); if ( ep == 0 || ep->heightp == 0 ) height = coin->longestchain; else height = *(ep->heightp); diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index c09e7e6c4..2816dd303 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -516,7 +516,7 @@ cJSON *LP_inventory(char *symbol) { //if ( utxo->T.spentflag == 0 ) // utxo->T.spentflag = (uint32_t)time(NULL); - printf("%s %s ineligible %.8f %.8f\n",utxo->coin,bits256_str(str,u.txid),dstr(val),dstr(val2)); + //printf("%s %s ineligible %.8f %.8f\n",utxo->coin,bits256_str(str,u.txid),dstr(val),dstr(val2)); continue; } //if ( iambob != 0 ) From 437501f854783fe1a5995a4ed8c9a8593f646a53 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 21:55:30 +0200 Subject: [PATCH 094/306] Test --- iguana/exchanges/LP_nativeDEX.c | 1 + iguana/exchanges/LP_network.c | 15 ++++++- iguana/exchanges/LP_ordermatch.c | 64 ++++++++++++------------------ iguana/exchanges/LP_statemachine.c | 35 ++++++++++++++++ iguana/exchanges/LP_utxo.c | 7 +++- 5 files changed, 81 insertions(+), 41 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 713e8e7de..64687dedc 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -87,6 +87,7 @@ struct LP_forwardinfo *LP_forwardinfos; struct iguana_info *LP_coins; struct LP_pubkeyinfo *LP_pubkeyinfos; struct rpcrequest_info *LP_garbage_collector; +struct LP_address_utxo *LP_garbage_collector2; //uint32_t LP_deadman_switch; diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index 101313348..49cefa778 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -267,7 +267,7 @@ int32_t LP_peerindsock(int32_t *peerindp) void gc_loop(void *arg) { - struct rpcrequest_info *req,*rtmp; int32_t flag = 0; + uint32_t now; struct LP_address_utxo *up,*utmp; struct rpcrequest_info *req,*rtmp; int32_t flag = 0; strcpy(LP_gcloop_stats.name,"gc_loop"); LP_gcloop_stats.threshold = 1100.; while ( 1 ) @@ -282,6 +282,19 @@ void gc_loop(void *arg) free(req); flag++; } + now = (uint32_t)time(NULL); + DL_FOREACH_SAFE(LP_garbage_collector2,up,utmp) + { + if ( (uint32_t)up->spendheight > now-120 ) + printf("recent gc2 %u lag.%d\n",up->spendheight,now-up->spendheight); + else + { + DL_DELETE(LP_garbage_collector2,up); + char str[65]; printf("garbage collect %s/v%d\n",bits256_str(str,up->U.txid),up->U.vout); + free(up); + } + flag++; + } portable_mutex_unlock(&LP_gcmutex); if ( 0 && flag != 0 ) printf("gc_loop.%d\n",flag); diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index a27dc1078..c897f55f5 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -275,7 +275,7 @@ int32_t LP_nanobind(void *ctx,char *pairstr) int32_t LP_nearest_utxovalue(struct iguana_info *coin,char *coinaddr,struct LP_address_utxo **utxos,int32_t n,uint64_t targetval) { - int32_t i,mini = -1; struct LP_address_utxo *up; struct electrum_info *backupep=0,*ep; int64_t dist; uint64_t mindist = (1LL << 60); + int32_t i,replacei,bestheight,mini = -1; struct LP_address_utxo *up,*bestup; struct electrum_info *backupep=0,*ep; int64_t dist,bestdist; uint64_t mindist = (1LL << 60); if ( (ep= coin->electrum) != 0 ) { if ( (backupep= ep->prev) == 0 ) @@ -299,6 +299,29 @@ int32_t LP_nearest_utxovalue(struct iguana_info *coin,char *coinaddr,struct LP_a } } } + if ( mini >= 0 && (bestup= utxos[mini]) != 0 ) + { + bestdist = (bestup->U.value - targetval); + replacei = -1; + bestheight = bestup->U.height; + for (i=0; iU.value - targetval); + if ( dist > 0 && (double)dist/bestdist < 1.1 && up->U.height < bestheight ) + { + replacei = i; + bestheight = up->U.height; + } + } + } + if ( replacei >= 0 ) + { + printf("REPLACE bestdist %.8f height %d with dist %.8f height %d\n",dstr(bestdist),bestup->U.height,dstr(utxos[replacei]->U.value - targetval),utxos[replacei]->U.height); + return(replacei); + } + } //printf("return mini.%d\n",mini); return(mini); } @@ -370,7 +393,7 @@ struct LP_utxoinfo *LP_address_myutxopair(struct LP_utxoinfo *butxo,int32_t iamb { if ( (m= LP_address_utxo_ptrs(coin,iambob,utxos,max,ap,coinaddr)) > 1 ) { - if ( 1 ) + if ( 0 ) { int32_t i; for (i=0; i targetval2 %.8f, ratio %.2f\n",mini,dstr(up->U.value),dstr(targetval),dstr(targetval2),(double)up->U.value/targetval); +//printf("found mini.%d %.8f for targetval %.8f -> targetval2 %.8f, ratio %.2f\n",mini,dstr(up->U.value),dstr(targetval),dstr(targetval2),(double)up->U.value/targetval); if ( (double)up->U.value/targetval < LP_MINVOL-1 ) { @@ -842,41 +865,6 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, memset(&Q.txid2,0,sizeof(Q.txid2)); Q.vout = Q.vout2 = -1; } else return(retval); - /*if ( bits256_nonz(Q.srchash) == 0 || 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); - Q.srchash = G.LP_mypub25519; - memset(&Q.txid,0,sizeof(Q.txid)); - memset(&Q.txid2,0,sizeof(Q.txid2)); - Q.vout = Q.vout2 = -1; - recalc = 1; - } - else if ( (qprice= LP_quote_validate(autxo,butxo,&Q,1)) < SMALLVAL ) - recalc = 1; - else if ( price < qprice ) - { - char tmp[64]; - if ( bits256_nonz(Q.txid) != 0 ) - LP_utxos_remove(Q.txid,Q.vout); - else recalc = 1; - 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); - value2 = LP_txvalue(tmp,Q.srccoin,Q.txid2,Q.vout2); - //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 ) - recalc = 1; - } - } else return(retval);*/ if ( qprice > price ) { r = (rand() % 100); diff --git a/iguana/exchanges/LP_statemachine.c b/iguana/exchanges/LP_statemachine.c index b267364df..3c32b8cad 100644 --- a/iguana/exchanges/LP_statemachine.c +++ b/iguana/exchanges/LP_statemachine.c @@ -1704,6 +1704,41 @@ int32_t bitcoin_coinptrs(bits256 pubkey,struct iguana_info **bobcoinp,struct igu } portable_mutex_unlock(&myinfo->DEX_swapmutex); }*/ +/*if ( bits256_nonz(Q.srchash) == 0 || 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); + Q.srchash = G.LP_mypub25519; + memset(&Q.txid,0,sizeof(Q.txid)); + memset(&Q.txid2,0,sizeof(Q.txid2)); + Q.vout = Q.vout2 = -1; + recalc = 1; + } + else if ( (qprice= LP_quote_validate(autxo,butxo,&Q,1)) < SMALLVAL ) + recalc = 1; + else if ( price < qprice ) + { + char tmp[64]; + if ( bits256_nonz(Q.txid) != 0 ) + LP_utxos_remove(Q.txid,Q.vout); + else recalc = 1; + 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); + value2 = LP_txvalue(tmp,Q.srccoin,Q.txid2,Q.vout2); + //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 ) + recalc = 1; + } + } else return(retval);*/ /*int32_t LP_priceping(int32_t pubsock,struct LP_utxoinfo *utxo,char *rel,double origprice) { diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 0fe71aa4e..a89fc0cfe 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -409,8 +409,11 @@ struct LP_address *LP_address_utxo_reset(struct iguana_info *coin) portable_mutex_lock(&coin->addrmutex); DL_DELETE(ap->utxos,up); portable_mutex_unlock(&coin->addrmutex); - free(up); - } + portable_mutex_lock(&LP_gcmutex); + up->spendheight = (int32_t)time(NULL); + DL_APPEND(LP_garbage_collector2,up); + portable_mutex_unlock(&LP_gcmutex); + } now = (uint32_t)time(NULL); if ( (n= cJSON_GetArraySize(array)) > 0 ) { From b93cf95bd9133837decadadf80146706ff96a021 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 21:59:35 +0200 Subject: [PATCH 095/306] Test --- iguana/exchanges/LP_network.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index 49cefa778..63bfcdb44 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -285,9 +285,7 @@ void gc_loop(void *arg) now = (uint32_t)time(NULL); DL_FOREACH_SAFE(LP_garbage_collector2,up,utmp) { - if ( (uint32_t)up->spendheight > now-120 ) - printf("recent gc2 %u lag.%d\n",up->spendheight,now-up->spendheight); - else + if ( now > (uint32_t)up->spendheight+120 ) { DL_DELETE(LP_garbage_collector2,up); char str[65]; printf("garbage collect %s/v%d\n",bits256_str(str,up->U.txid),up->U.vout); @@ -298,7 +296,7 @@ void gc_loop(void *arg) portable_mutex_unlock(&LP_gcmutex); if ( 0 && flag != 0 ) printf("gc_loop.%d\n",flag); - sleep(1); + sleep(10); } } From 1e994506be3119545197a684997e618df75f4f5e Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 22:00:09 +0200 Subject: [PATCH 096/306] Test --- iguana/exchanges/LP_network.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index 63bfcdb44..dd6713e6d 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -288,7 +288,7 @@ void gc_loop(void *arg) if ( now > (uint32_t)up->spendheight+120 ) { DL_DELETE(LP_garbage_collector2,up); - char str[65]; printf("garbage collect %s/v%d\n",bits256_str(str,up->U.txid),up->U.vout); + char str[65]; printf("garbage collect %s/v%d lag.%d\n",bits256_str(str,up->U.txid),up->U.vout,now-up->spendheight); free(up); } flag++; From 2dd9f64d536430e1c508c5991dca4ed9717ca2ce Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 22:05:11 +0200 Subject: [PATCH 097/306] Test --- iguana/exchanges/LP_include.h | 2 +- iguana/exchanges/LP_network.c | 2 +- iguana/exchanges/LP_ordermatch.c | 8 ++++---- iguana/exchanges/LP_utxo.c | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 1b0394f95..b7dd79e03 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -82,7 +82,7 @@ void emscripten_usleep(int32_t x); // returns immediate, no sense for sleeping #define LP_SWAPSTEP_TIMEOUT 30 #define LP_MIN_TXFEE 10000 #define LP_MINVOL 20 -#define LP_MINCLIENTVOL 1000 +#define LP_MINCLIENTVOL 100 #define LP_MINSIZE_TXFEEMULT 10 #define LP_REQUIRED_TXFEE 0.8 diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index dd6713e6d..8fedbc1ab 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -269,7 +269,7 @@ void gc_loop(void *arg) { uint32_t now; struct LP_address_utxo *up,*utmp; struct rpcrequest_info *req,*rtmp; int32_t flag = 0; strcpy(LP_gcloop_stats.name,"gc_loop"); - LP_gcloop_stats.threshold = 1100.; + LP_gcloop_stats.threshold = 11000.; while ( 1 ) { flag = 0; diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index c897f55f5..3dd21d90c 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -393,7 +393,7 @@ struct LP_utxoinfo *LP_address_myutxopair(struct LP_utxoinfo *butxo,int32_t iamb { if ( (m= LP_address_utxo_ptrs(coin,iambob,utxos,max,ap,coinaddr)) > 1 ) { - if ( 0 ) + if ( 1 ) { int32_t i; for (i=0; iU.value/targetval); + } else printf("cant find targetval2 %.8f\n",dstr(targetval2)); + } else printf("failed ratio test %.8f\n",(double)up->U.value/targetval); } else if ( targetval != 0 && mini >= 0 ) printf("targetval %.8f mini.%d\n",dstr(targetval),mini); } else printf("no %s utxos pass LP_address_utxo_ptrs filter\n",coinaddr); @@ -896,7 +896,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, } else { - printf("cant find utxopair aliceid.%llu %s/%s\n",(long long)aliceid,Q.srccoin,Q.destcoin); + printf("cant find utxopair aliceid.%llu %s/%s %.8f -> relvol %.8f\n",(long long)aliceid,Q.srccoin,Q.destcoin,dstr(Q.satoshis),dstr(Q.destsatoshis)); return(retval); } } diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index a89fc0cfe..2bd6ebdcd 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -294,7 +294,7 @@ int32_t LP_address_utxo_ptrs(struct iguana_info *coin,int32_t iambob,struct LP_a } } //portable_mutex_unlock(&LP_utxomutex); - printf("return n.%d for %s %s\n",n,coin->symbol,coinaddr); + //printf("return n.%d for %s %s\n",n,coin->symbol,coinaddr); return(n); } @@ -440,7 +440,7 @@ struct LP_address *LP_address_utxo_reset(struct iguana_info *coin) if ( (up= LP_address_utxofind(coin,coin->smartaddr,txid,vout)) == 0 ) printf("couldnt find just added %s/%d ht.%d %.8f\n",bits256_str(str,txid),vout,height,dstr(value)); } - printf("added %d from listunspents\n",n); + //printf("added %d from listunspents\n",n); } free_json(array); } From 63b0fe14e423b677f772bfdddf5dd0cc7c499dc2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 22:05:41 +0200 Subject: [PATCH 098/306] test --- iguana/exchanges/LP_network.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index 8fedbc1ab..4b33a4717 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -288,7 +288,7 @@ void gc_loop(void *arg) if ( now > (uint32_t)up->spendheight+120 ) { DL_DELETE(LP_garbage_collector2,up); - char str[65]; printf("garbage collect %s/v%d lag.%d\n",bits256_str(str,up->U.txid),up->U.vout,now-up->spendheight); + //char str[65]; printf("garbage collect %s/v%d lag.%d\n",bits256_str(str,up->U.txid),up->U.vout,now-up->spendheight); free(up); } flag++; From a619fe39bd5c42ef299bb982acfcc8ddb8908fdb Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 22:19:56 +0200 Subject: [PATCH 099/306] Test --- iguana/exchanges/LP_ordermatch.c | 16 ++++++++++------ iguana/exchanges/LP_utxo.c | 4 ++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 3dd21d90c..1066284da 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -309,10 +309,13 @@ int32_t LP_nearest_utxovalue(struct iguana_info *coin,char *coinaddr,struct LP_a if ( i != mini && (up= utxos[i]) != 0 ) { dist = (up->U.value - targetval); - if ( dist > 0 && (double)dist/bestdist < 1.1 && up->U.height < bestheight ) + if ( dist > 0 && up->U.height < bestheight ) { - replacei = i; - bestheight = up->U.height; + if ( (double)dist/bestdist < 1.1 ) + { + replacei = i; + bestheight = up->U.height; + } else printf("almost ratio %.3f dist %.8f vs best %.8f, ht %d vs best ht %d\n",(double)dist/bestdist,dstr(dist),dstr(bestdist),up->U.height,bestheight); } } } @@ -397,8 +400,9 @@ struct LP_utxoinfo *LP_address_myutxopair(struct LP_utxoinfo *butxo,int32_t iamb { int32_t i; for (i=0; iU.value)); - printf("targetval %.8f vol %.8f price %.8f txfee %.8f %s\n",dstr(targetval),relvolume,price,dstr(txfee),coinaddr); + if ( utxos[i]->U.value >= targetval ) + printf("%.8f ",dstr(utxos[i]->U.value)); + printf("targetval %.8f vol %.8f price %.8f txfee %.8f %s %s\n",dstr(targetval),relvolume,price,dstr(txfee),coin->symbol,coinaddr); } mini = -1; if ( targetval != 0 && (mini= LP_nearest_utxovalue(coin,coinaddr,utxos,m,targetval)) >= 0 ) @@ -896,7 +900,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, } else { - printf("cant find utxopair aliceid.%llu %s/%s %.8f -> relvol %.8f\n",(long long)aliceid,Q.srccoin,Q.destcoin,dstr(Q.satoshis),dstr(Q.destsatoshis)); + printf("cant find utxopair aliceid.%llu %s/%s %.8f -> relvol %.8f\n",(long long)aliceid,Q.srccoin,Q.destcoin,dstr(LP_basesatoshis(dstr(Q.destsatoshis),price,Q.txfee,Q.desttxfee)),dstr(Q.destsatoshis)); return(retval); } } diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 2bd6ebdcd..0f2aee2c3 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -52,7 +52,7 @@ int32_t _LP_inuse_delete(bits256 txid,int32_t vout) if ( LP_inuse[ind].ind != ind ) printf("ind.%d of %d: mismatched ind.%d\n",ind,LP_numinuse,LP_inuse[ind].ind); } - char str[65]; printf("_LP_inuse_delete cant find %s/v%d\n",bits256_str(str,txid),vout); + //char str[65]; printf("_LP_inuse_delete cant find %s/v%d\n",bits256_str(str,txid),vout); return(-1); } @@ -285,7 +285,7 @@ int32_t LP_address_utxo_ptrs(struct iguana_info *coin,int32_t iambob,struct LP_a utxos[n++] = up; if ( n >= max ) break; - } else printf("LP_allocated skip\n"); + } //else printf("LP_allocated skip\n"); } else { From 47490054aa33f130594d6cb5a136a928e641fb7a Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 22:25:33 +0200 Subject: [PATCH 100/306] Test --- iguana/exchanges/LP_ordermatch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 1066284da..b9bb28e29 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -311,11 +311,11 @@ int32_t LP_nearest_utxovalue(struct iguana_info *coin,char *coinaddr,struct LP_a dist = (up->U.value - targetval); if ( dist > 0 && up->U.height < bestheight ) { - if ( (double)dist/bestdist < 1.1 ) + if ( (double)dist/bestdist < sqrt(bestheight - up->U.height) ) { replacei = i; bestheight = up->U.height; - } else printf("almost ratio %.3f dist %.8f vs best %.8f, ht %d vs best ht %d\n",(double)dist/bestdist,dstr(dist),dstr(bestdist),up->U.height,bestheight); + } //else printf("almost ratio %.3f dist %.8f vs best %.8f, ht %d vs best ht %d\n",(double)dist/bestdist,dstr(dist),dstr(bestdist),up->U.height,bestheight); } } } From 1a0e13355c5e6a53a01029c355a22094f6be207f Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 22:57:52 +0200 Subject: [PATCH 101/306] Test --- iguana/exchanges/LP_ordermatch.c | 2 +- iguana/exchanges/LP_rpc.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index b9bb28e29..a8c061359 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -543,7 +543,7 @@ void LP_reserved(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo if ( LP_alice_eligible() > 0 && LP_quotecmp(qp,&LP_Alicequery) == 0 ) { price = LP_pricecache(qp,qp->srccoin,qp->destcoin,qp->txid,qp->vout); - if ( LP_pricevalid(price) > 0 && maxprice > SMALLVAL && price <= maxprice*1.005 ) + if ( LP_pricevalid(price) > 0 && maxprice > SMALLVAL && price <= maxprice ) { qp->tradeid = LP_Alicequery.tradeid; LP_alicequery_clear(); diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 30789efe7..2a66c9b94 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -544,7 +544,7 @@ cJSON *LP_gettxout(char *symbol,char *coinaddr,bits256 txid,int32_t vout) return(retjson); } } - printf("couldnt find %s (%s) %s/v%d\n",symbol,coinaddr,bits256_str(str,txid),vout); + //printf("couldnt find %s (%s) %s/v%d\n",symbol,coinaddr,bits256_str(str,txid),vout); return(cJSON_Parse("{\"error\":\"couldnt get tx\"}")); } } From 3cb25a8c237b5dac0f8372f25a347f55c9f8267b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 23:18:21 +0200 Subject: [PATCH 102/306] Test --- iguana/exchanges/LP_nativeDEX.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 64687dedc..4b33908b8 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -17,8 +17,10 @@ // LP_nativeDEX.c // marketmaker // -// single utxo allocations, reject result, latency +// single utxo allocations alice, reject result, latency // alice waiting for bestprice +//if ( G.LP_pendingswaps != 0 ) +//return(-1); // bot safe to exit? // // BCH signing @@ -1054,37 +1056,37 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu printf("error launching gc_loop for port.%u\n",myport); exit(-1); } - if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)prices_loop,ctx) != 0 ) + if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)prices_loop,ctx) != 0 ) { printf("error launching prices_loop for port.%u\n",myport); exit(-1); } - if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_coinsloop,(void *)"") != 0 ) + if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_coinsloop,(void *)"") != 0 ) { printf("error launching LP_coinsloop for port.%u\n",myport); exit(-1); } - if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_coinsloop,(void *)"BTC") != 0 ) + if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_coinsloop,(void *)"BTC") != 0 ) { printf("error launching BTC LP_coinsloop for port.%u\n",myport); exit(-1); } - if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_coinsloop,(void *)"KMD") != 0 ) + if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_coinsloop,(void *)"KMD") != 0 ) { printf("error launching KMD LP_coinsloop for port.%u\n",myport); exit(-1); } - if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_pubkeysloop,(void *)myipaddr) != 0 ) + if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_pubkeysloop,(void *)myipaddr) != 0 ) { printf("error launching LP_pubkeysloop for ctx.%p\n",ctx); exit(-1); } - if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_privkeysloop,(void *)myipaddr) != 0 ) + if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_privkeysloop,(void *)myipaddr) != 0 ) { printf("error launching LP_privkeysloop for ctx.%p\n",ctx); exit(-1); } - if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_swapsloop,(void *)myipaddr) != 0 ) + if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_swapsloop,(void *)myipaddr) != 0 ) { printf("error launching LP_swapsloop for port.%u\n",myport); exit(-1); From 8c07a90770936fa667c3250611138b7f5d37ed03 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 23:21:55 +0200 Subject: [PATCH 103/306] Test --- iguana/exchanges/LP_nativeDEX.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 4b33908b8..7510f368c 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1020,7 +1020,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu printf("error launching LP_psockloop for (%s)\n",myipaddr); exit(-1); } - if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_reserved_msgs,(void *)myipaddr) != 0 ) + if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_reserved_msgs,(void *)myipaddr) != 0 ) { printf("error launching LP_reserved_msgs for (%s)\n",myipaddr); exit(-1); @@ -1030,13 +1030,13 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu printf("error launching utxosQ_loop for (%s)\n",myipaddr); exit(-1); } - if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)stats_rpcloop,(void *)&myport) != 0 ) + if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)stats_rpcloop,(void *)&myport) != 0 ) { printf("error launching stats rpcloop for port.%u\n",myport); exit(-1); } uint16_t myport2 = myport-1; - if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)stats_rpcloop,(void *)&myport2) != 0 ) + if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)stats_rpcloop,(void *)&myport2) != 0 ) { printf("error launching stats rpcloop for port.%u\n",myport); exit(-1); From 823e972eda4df41c9a4a467877ad76feedda2898 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 23:24:13 +0200 Subject: [PATCH 104/306] Test --- iguana/exchanges/LP_nativeDEX.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 7510f368c..259053f1a 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1025,7 +1025,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu printf("error launching LP_reserved_msgs for (%s)\n",myipaddr); exit(-1); } - if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)utxosQ_loop,(void *)myipaddr) != 0 ) + if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)utxosQ_loop,(void *)myipaddr) != 0 ) { printf("error launching utxosQ_loop for (%s)\n",myipaddr); exit(-1); @@ -1046,12 +1046,12 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu printf("error launching command_rpcloop for port.%u\n",myport); exit(-1); } - if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)queue_loop,(void *)myipaddr) != 0 ) + if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)queue_loop,(void *)myipaddr) != 0 ) { printf("error launching queue_loop for port.%u\n",myport); exit(-1); } - if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)gc_loop,(void *)myipaddr) != 0 ) + if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)gc_loop,(void *)myipaddr) != 0 ) { printf("error launching gc_loop for port.%u\n",myport); exit(-1); From bbd790bf5582e4965de7968aa4164e1371937dff Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 23:25:51 +0200 Subject: [PATCH 105/306] 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 259053f1a..6108a2f87 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1101,7 +1101,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu //fprintf(stderr,"."); sleep(3); } - if ( LP_mainloop_iter(ctx,myipaddr,mypeer,pubsock,pushaddr,myport) != 0 ) + if ( 0 && LP_mainloop_iter(ctx,myipaddr,mypeer,pubsock,pushaddr,myport) != 0 ) nonz++; if ( nonz == 0 ) usleep(1000); From 17ff863160d9684ab167a69fded6f3444a53084f Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 23:27:11 +0200 Subject: [PATCH 106/306] 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 6108a2f87..431500f4b 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1041,7 +1041,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu printf("error launching stats rpcloop for port.%u\n",myport); exit(-1); } - if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)command_rpcloop,(void *)myipaddr) != 0 ) + if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)command_rpcloop,(void *)myipaddr) != 0 ) { printf("error launching command_rpcloop for port.%u\n",myport); exit(-1); From 7df0dbc54070b20302f099b52ba639a9ded2f901 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 23:29:50 +0200 Subject: [PATCH 107/306] Test --- iguana/exchanges/LP_nativeDEX.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 431500f4b..3703437f6 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1020,23 +1020,23 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu printf("error launching LP_psockloop for (%s)\n",myipaddr); exit(-1); } - if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_reserved_msgs,(void *)myipaddr) != 0 ) + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_reserved_msgs,(void *)myipaddr) != 0 ) { printf("error launching LP_reserved_msgs for (%s)\n",myipaddr); exit(-1); } - if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)utxosQ_loop,(void *)myipaddr) != 0 ) + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)utxosQ_loop,(void *)myipaddr) != 0 ) { printf("error launching utxosQ_loop for (%s)\n",myipaddr); exit(-1); } - if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)stats_rpcloop,(void *)&myport) != 0 ) + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)stats_rpcloop,(void *)&myport) != 0 ) { printf("error launching stats rpcloop for port.%u\n",myport); exit(-1); } uint16_t myport2 = myport-1; - if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)stats_rpcloop,(void *)&myport2) != 0 ) + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)stats_rpcloop,(void *)&myport2) != 0 ) { printf("error launching stats rpcloop for port.%u\n",myport); exit(-1); @@ -1046,47 +1046,47 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu printf("error launching command_rpcloop for port.%u\n",myport); exit(-1); } - if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)queue_loop,(void *)myipaddr) != 0 ) + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)queue_loop,(void *)myipaddr) != 0 ) { printf("error launching queue_loop for port.%u\n",myport); exit(-1); } - if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)gc_loop,(void *)myipaddr) != 0 ) + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)gc_loop,(void *)myipaddr) != 0 ) { printf("error launching gc_loop for port.%u\n",myport); exit(-1); } - if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)prices_loop,ctx) != 0 ) + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)prices_loop,ctx) != 0 ) { printf("error launching prices_loop for port.%u\n",myport); exit(-1); } - if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_coinsloop,(void *)"") != 0 ) + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_coinsloop,(void *)"") != 0 ) { printf("error launching LP_coinsloop for port.%u\n",myport); exit(-1); } - if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_coinsloop,(void *)"BTC") != 0 ) + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_coinsloop,(void *)"BTC") != 0 ) { printf("error launching BTC LP_coinsloop for port.%u\n",myport); exit(-1); } - if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_coinsloop,(void *)"KMD") != 0 ) + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_coinsloop,(void *)"KMD") != 0 ) { printf("error launching KMD LP_coinsloop for port.%u\n",myport); exit(-1); } - if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_pubkeysloop,(void *)myipaddr) != 0 ) + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_pubkeysloop,(void *)myipaddr) != 0 ) { printf("error launching LP_pubkeysloop for ctx.%p\n",ctx); exit(-1); } - if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_privkeysloop,(void *)myipaddr) != 0 ) + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_privkeysloop,(void *)myipaddr) != 0 ) { printf("error launching LP_privkeysloop for ctx.%p\n",ctx); exit(-1); } - if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_swapsloop,(void *)myipaddr) != 0 ) + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_swapsloop,(void *)myipaddr) != 0 ) { printf("error launching LP_swapsloop for port.%u\n",myport); exit(-1); @@ -1101,7 +1101,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu //fprintf(stderr,"."); sleep(3); } - if ( 0 && LP_mainloop_iter(ctx,myipaddr,mypeer,pubsock,pushaddr,myport) != 0 ) + if ( LP_mainloop_iter(ctx,myipaddr,mypeer,pubsock,pushaddr,myport) != 0 ) nonz++; if ( nonz == 0 ) usleep(1000); From 2e867f10f4a15a98d50786902ee68b0cb49e03a0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 23:34:27 +0200 Subject: [PATCH 108/306] 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 3703437f6..7e876b432 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -364,7 +364,7 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int } else validreq = 1; recvlen -= sizeof(bits256); } - if ( validreq != 0 ) + if ( 0 && validreq != 0 ) { if ( (retstr= LP_process_message(ctx,typestr,myipaddr,pubsock,ptr,recvlen,sock)) != 0 ) free(retstr); @@ -1041,7 +1041,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu printf("error launching stats rpcloop for port.%u\n",myport); exit(-1); } - if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)command_rpcloop,(void *)myipaddr) != 0 ) + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)command_rpcloop,(void *)myipaddr) != 0 ) { printf("error launching command_rpcloop for port.%u\n",myport); exit(-1); From c71b1ad57081979b0f5b62d72d3b995f2c84be6f Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 23:37:12 +0200 Subject: [PATCH 109/306] 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 7e876b432..ae1894ea9 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -356,7 +356,7 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int } } int32_t validreq = 0; - if ( strlen((char *)ptr)+sizeof(bits256) <= recvlen ) + if ( 0 && strlen((char *)ptr)+sizeof(bits256) <= recvlen ) { if ( LP_magic_check(ptr,recvlen,remoteaddr) <= 0 ) { From 40c3173ec20ad82c1e1181362d17a74da469932a Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 23:40:05 +0200 Subject: [PATCH 110/306] Test --- iguana/exchanges/LP_nativeDEX.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index ae1894ea9..4f82d0c4a 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -338,6 +338,7 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int pfd.events = NN_POLLIN; if ( nn_poll(&pfd,1,1) != 1 ) break; + ptr = 0; if ( (recvlen= nn_recv(sock,&ptr,NN_MSG,0)) > 0 ) { methodstr[0] = 0; @@ -387,9 +388,9 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int free(str); } } - if ( ptr != 0 ) - nn_freemsg(ptr), ptr = 0; } + if ( ptr != 0 ) + nn_freemsg(ptr), ptr = 0; } } return(nonz); From 9006c80202870a7eadbfd1bc6a62f45956db5f84 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 23:44:00 +0200 Subject: [PATCH 111/306] Test --- iguana/exchanges/LP_network.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index 4b33a4717..f45f5142d 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -574,12 +574,19 @@ void LP_psockloop(void *_ptr) // printouts seem to be needed for forwarding to w else if ( (pfds[n].revents & POLLIN) != 0 ) { printf("publicsock.%d %s has pollin\n",ptr->publicsock,ptr->publicaddr); + buf = 0; if ( (size= nn_recv(ptr->publicsock,&buf,NN_MSG,0)) > 0 ) { ptr->lasttime = now; sendsock = ptr->sendsock; break; } + else if ( buf != 0 ) + { + nn_freemsg(buf); + buf = 0; + size = 0; + } } } n++; @@ -606,12 +613,12 @@ void LP_psockloop(void *_ptr) // printouts seem to be needed for forwarding to w sendsock = ptr->publicsock; break; } - else - { - nn_freemsg(buf); - buf = 0; - size = 0; - } + } + if ( buf != 0 ) + { + nn_freemsg(buf); + buf = 0; + size = 0; } } } From 67a4e5191f995a8e690340b2e2c58f7d7694d080 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 23:45:58 +0200 Subject: [PATCH 112/306] 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 4f82d0c4a..75e236dac 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -357,7 +357,7 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int } } int32_t validreq = 0; - if ( 0 && strlen((char *)ptr)+sizeof(bits256) <= recvlen ) + if ( strlen((char *)ptr)+sizeof(bits256) <= recvlen ) { if ( LP_magic_check(ptr,recvlen,remoteaddr) <= 0 ) { @@ -365,7 +365,7 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int } else validreq = 1; recvlen -= sizeof(bits256); } - if ( 0 && validreq != 0 ) + if ( validreq != 0 ) { if ( (retstr= LP_process_message(ctx,typestr,myipaddr,pubsock,ptr,recvlen,sock)) != 0 ) free(retstr); From 3bb38b13bc1e8c259c78d488baef5ee529af625d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 23:48:07 +0200 Subject: [PATCH 113/306] 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 75e236dac..98f4cc927 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -365,7 +365,7 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int } else validreq = 1; recvlen -= sizeof(bits256); } - if ( validreq != 0 ) + if ( 0 && validreq != 0 ) { if ( (retstr= LP_process_message(ctx,typestr,myipaddr,pubsock,ptr,recvlen,sock)) != 0 ) free(retstr); From 83a6006d7e5bd687f63e9b3e1521244839dac090 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Nov 2017 23:58:00 +0200 Subject: [PATCH 114/306] Test --- iguana/exchanges/LP_nativeDEX.c | 5 +++-- iguana/exchanges/LP_ordermatch.c | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 98f4cc927..c5c34b353 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -315,8 +315,9 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock, } //printf("%.3f %s LP_command_process\n",OS_milliseconds()-millis,jstr(argjson,"method")); } - free_json(argjson); } + if ( argjson != 0 ) + free_json(argjson); } } //else printf("DUPLICATE.(%s)\n",(char *)ptr); portable_mutex_unlock(&LP_commandmutex); @@ -365,7 +366,7 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int } else validreq = 1; recvlen -= sizeof(bits256); } - if ( 0 && validreq != 0 ) + if ( validreq != 0 ) { if ( (retstr= LP_process_message(ctx,typestr,myipaddr,pubsock,ptr,recvlen,sock)) != 0 ) free(retstr); diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index a8c061359..0ab6faca0 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -799,7 +799,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, return(retval); } LP_aliceid(Q.tradeid,Q.aliceid,"reserved",0,0); - printf("alice %s received RESERVED.(%s)\n",bits256_str(str,G.LP_mypub25519),jprint(argjson,0)); + //printf("alice %s received RESERVED.(%s)\n",bits256_str(str,G.LP_mypub25519),jprint(argjson,0)); if ( (retstr= LP_quotereceived(argjson)) != 0 ) free(retstr); LP_reserved(ctx,myipaddr,pubsock,&Q); @@ -929,7 +929,9 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, 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("(%s/v%d %s/v%d) TRADECOMMAND.(%s)\n",bits256_str(str,Q.txid),Q.vout,bits256_str(str2,Q.txid2),Q.vout2,jprint(argjson,0)); + char *astr = jprint(argjson,0); + char str[65],str2[65]; printf("(%s/v%d %s/v%d) TRADECOMMAND.(%s)\n",bits256_str(str,Q.txid),Q.vout,bits256_str(str2,Q.txid2),Q.vout2,astr); + free(astr); if ( strcmp(method,"request") == 0 ) // bob needs apayment + fee tx's { if ( LP_allocated(Q.txid,Q.vout) == 0 && LP_allocated(Q.txid2,Q.vout2) == 0 ) From 0eb9fd4328fb9aa2ee4453484f09846ca5f40c3c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 00:02:11 +0200 Subject: [PATCH 115/306] Test --- iguana/exchanges/LP_transaction.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index 4d9ee5fe1..4df4b3895 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -1047,13 +1047,13 @@ char *LP_createrawtransaction(cJSON **txobjp,int32_t *numvinsp,struct iguana_inf return(0); } } - if ( bits256_nonz(utxotxid) == 0 ) + //if ( bits256_nonz(utxotxid) == 0 ) { if ( (ap= LP_address_utxo_reset(coin)) == 0 ) return(0); } - else if ( (ap= LP_address(coin,coin->smartaddr)) == 0 ) - return(0); + //else if ( (ap= LP_address(coin,coin->smartaddr)) == 0 ) + // return(0); memset(utxos,0,sizeof(utxos)); if ( (numutxos= LP_address_utxo_ptrs(coin,0,utxos,max,ap,coin->smartaddr)) <= 0 ) { From 1775a5dbea16212762b4991659b86b716649717e Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 00:15:18 +0200 Subject: [PATCH 116/306] 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 c5c34b353..d17299573 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -310,7 +310,7 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock, } else { - if ( (retstr= LP_command_process(ctx,myipaddr,pubsock,argjson,&((uint8_t *)ptr)[len],recvlen - len)) != 0 ) + if ( 0 && (retstr= LP_command_process(ctx,myipaddr,pubsock,argjson,&((uint8_t *)ptr)[len],recvlen - len)) != 0 ) { } //printf("%.3f %s LP_command_process\n",OS_milliseconds()-millis,jstr(argjson,"method")); From c871feeb8b57c7d7c6802c840b69da6967767a22 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 00:19:55 +0200 Subject: [PATCH 117/306] Test --- iguana/exchanges/LP_nativeDEX.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index d17299573..87360c470 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -179,18 +179,15 @@ char *LP_command_process(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson char *retstr=0; if ( jobj(argjson,"result") != 0 || jobj(argjson,"error") != 0 ) return(0); - //double millis = OS_milliseconds(); if ( LP_tradecommand(ctx,myipaddr,pubsock,argjson,data,datalen) <= 0 ) { - if ( (retstr= stats_JSON(ctx,myipaddr,pubsock,argjson,"127.0.0.1",0)) != 0 ) + if ( 0 && (retstr= stats_JSON(ctx,myipaddr,pubsock,argjson,"127.0.0.1",0)) != 0 ) { //printf("%s PULL.[%d]-> (%s)\n",myipaddr != 0 ? myipaddr : "127.0.0.1",datalen,retstr); //if ( pubsock >= 0 ) //strncmp("{\"error\":",retstr,strlen("{\"error\":")) != 0 && //LP_send(pubsock,retstr,(int32_t)strlen(retstr)+1,0); } } //else printf("finished tradecommand (%s)\n",jprint(argjson,0)); - //if ( OS_milliseconds()-millis > 100 ) - // printf("%.3f %s\n",OS_milliseconds()-millis,jprint(argjson,0)); return(retstr); } @@ -310,7 +307,7 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock, } else { - if ( 0 && (retstr= LP_command_process(ctx,myipaddr,pubsock,argjson,&((uint8_t *)ptr)[len],recvlen - len)) != 0 ) + if ( (retstr= LP_command_process(ctx,myipaddr,pubsock,argjson,&((uint8_t *)ptr)[len],recvlen - len)) != 0 ) { } //printf("%.3f %s LP_command_process\n",OS_milliseconds()-millis,jstr(argjson,"method")); From 1fca97e9e6437a0e6207f8399471cb42e1a0a7f6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 00:21:16 +0200 Subject: [PATCH 118/306] 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 87360c470..5969f11a1 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -181,7 +181,7 @@ char *LP_command_process(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson return(0); if ( LP_tradecommand(ctx,myipaddr,pubsock,argjson,data,datalen) <= 0 ) { - if ( 0 && (retstr= stats_JSON(ctx,myipaddr,pubsock,argjson,"127.0.0.1",0)) != 0 ) + if ( (retstr= stats_JSON(ctx,myipaddr,pubsock,argjson,"127.0.0.1",0)) != 0 ) { //printf("%s PULL.[%d]-> (%s)\n",myipaddr != 0 ? myipaddr : "127.0.0.1",datalen,retstr); //if ( pubsock >= 0 ) //strncmp("{\"error\":",retstr,strlen("{\"error\":")) != 0 && From dc5149ed0deceafd3855086ad56a6c057578852b Mon Sep 17 00:00:00 2001 From: DeckerSU Date: Wed, 15 Nov 2017 04:56:35 +0400 Subject: [PATCH 119/306] added q/a in script use faq --- iguana/dexscripts.win32/how_to_use.md | 12 +++++++++--- iguana/dexscripts.win32/images/conemu_jq.png | Bin 0 -> 31836 bytes 2 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 iguana/dexscripts.win32/images/conemu_jq.png diff --git a/iguana/dexscripts.win32/how_to_use.md b/iguana/dexscripts.win32/how_to_use.md index 29fdcc537..5d1488885 100644 --- a/iguana/dexscripts.win32/how_to_use.md +++ b/iguana/dexscripts.win32/how_to_use.md @@ -1,15 +1,15 @@ ## DexScripts for Windows. How to use? ## -**1. ** Before start you should put scripts and following binaries into one folder: +**1.** Before start you should put scripts and following binaries into one folder: - curl.exe (required for all scripts) - marketmaker.exe - libcurl.dll (required to run marketmaker) - nanomsg.dll (required to run marketmaker) -**2. ** Don't forget to put `coins.json` file into a same folder. This file is available it this repo. +**2.** Don't forget to put `coins.json` file into a same folder. This file is available it this repo. -**3. ** Type your passphrase into passphrase file in this folder (you should create file with name `passphrase` and without extension) and run `1-client.cmd`. This will run marketmaker. Next step is to obtain userpass needed for other scripts, you can simply copy and paste it from marketmaker output on startup into userpass file. +**3.** Type your passphrase into passphrase file in this folder (you should create file with name `passphrase` and without extension) and run `1-client.cmd`. This will run marketmaker. Next step is to obtain userpass needed for other scripts, you can simply copy and paste it from marketmaker output on startup into userpass file. ![](./images/userpass.png) @@ -42,3 +42,9 @@ And nothing works. **A.** Before run `1-client.cmd` make sure in Task Manager that you haven't already running `marketmaker.exe`. If have - kill this process via Task Manager or via command line command `taskkill /f /im taskkill.exe` . +**Q.** How can i pretty print JSON answers of marketmaker? +**A.** You can get best results with 2 tools - [conemu](https://conemu.github.io/) and [jq](https://stedolan.github.io/jq/), conemu supports ANSI X3.64 and Xterm 256 colors and jq allow you to pretty-print json output with colors, like this: + +![](./images/conemu_jq.png) + +Also i'm always recommend to install [Far Manager](https://www.farmanager.com/index.php?l=en) - this is powerful console file manager for Windows, like Midnight Commander in *nix. \ No newline at end of file diff --git a/iguana/dexscripts.win32/images/conemu_jq.png b/iguana/dexscripts.win32/images/conemu_jq.png new file mode 100644 index 0000000000000000000000000000000000000000..e8eeaf523849b859d5b9a396090f3a3b59e4137b GIT binary patch literal 31836 zcmbrm2T)UM+lCuNK)Og1X#&zgP((T?MMQc>DG?BmE+D-M(xo@)2qL}r8mdTFdJnya z&_aL^I4kbGzrFYO|7Yeub7tZ&6G>QEYrXe#KiB=d2~|^(CnmT<00M!C6`sp#fI!#c zfqx=5t^vXh4$eMEq89kOT|5>`K2t6qnv3P|4EbY zZ9X***KO4h(%85Zi@OBr)C{-m?M!8EEPci=*ot7Qmu%EXz!5;Jb7ARSHk!8MyBq6ny2UL7ZMU8-MOeND;xj%c5`S*$StA(A9i4{A>h z3E^nxcOxewW4(=Q&&-^C{r~i$<&mZ&uqZ-`3>>>;ODc2u*=JIZdE?qMhK(|z<@;81P$+RlCRbM+Sf~AHM@=LHcn`+*i$SVz_?h{m#KN@EtZtX7fk7W zYwnGQm%_yzPmiB1B8Zdm^MYo>+g4W~rX- z(|RnCGGV5vd3X<)oNH!|z7VuXwc87YTym=w!}Gl5tPtZT{c5Nf6tXBrjtv1*nV>CF zmAVhxDHHIp_qa;#BvoE^k9B=2${0UP?hB!&3_~A}MlN3lSvUFQ6Xylb_-eB{S8`Wb zskUi~WNJ%7mL9&ekM~%v>SwY=w$6VcucQELKqS5hzU(?G>3x`>%buQzV|Er946hGP zH_Lmg5}137%BkEGyKm!4FYj_Ly7Vw-oi6LE3RQ#5Wg3^hkwMm5eDjW(wg+ob2W=KG zewrkbSFP;ND2CY^R!P4R%TVVsvhNJGke@YuJ#s5VR_%cJe_iShgPCj2MJS!mWb%?u zx>QkCXsx;XuWcJPFH@$ydr$)6a8|`r6E$Legprqy1KP*A;`7`q0{08I4q|p}3oYhei-c z&kZ}F4%izZ-_Jt7E~zI=dpRg}#9Y^N99gvk~SOOKRKP=mcQ zL?sIKJLei|COx;8C9cVBc zPt&K{(LJ<=W(6c9{m>RXy>E0#87t9Z1SP6~C$GaCSYf{L-U^xZM*+uz?!}tmT~6I8 zXj<{$kEWl#YyQQaSaoz(zS8rhudc>9#z>tZ7h}59eAbF+%cZbWs^KZ~^4al}PdEt0 zt7odhY+25b2h~R}0v)B$YF84^T$*BR*{%C=KV8NDkSQ>NP){c8d^BC|TsYXkc-HyBDu+kz`vA!sY>d>7@|x0UVmx)-*S z&UIx*4gM-cPCdJ7!`#kXXsznBBQCnxi1%WnqaEQC zt|P{aVhuVK(H1A^k0hj^yt*DzL5v!%x9@!;l)8qLB@`XYgxWTh@UxlP79>THEuGKP zzJuc33ZA*#hIeTcNj;W`Y_7Zo;vahq{z0lGr6xtGpnFS%GVz6NR^u%wnjZDVzRx>z zeA2s#<*Pc66dK>M$@r!f%4Y{pbO`t){#JmBIvSh8vBsserw19=6>@I)49BVY@)4kq zXCr4W3&)`sDvv?&V+b5^N$y)VR|y%`DZ8yJ(dhXbvalms%l?_Y3D=)UWH0Ju;9-sq z(#_)~`6QkPZp|L8%QMpgyL~&_pA%}Z6kD|t5uuNO&L4(uDn?ah9znkDNnif#PW<5E z#MhMyz1#`D_rxIUc3jZl?43g6*5x~v4th$6_Kf1mE332et(91n%(4huVrBi=l=Jf= zo^R*p6(3ByH#d`%jfwXK!6lb%6;4fQ7Nx?&pnxQjYR1~@`Hc0MlC$Vy^t;R{$sisW ziRMq;=L;yYm-aT&`f*i|XI|Qp4=rua!p&6Uj$6dqWPi4y@qL<>vL;%+xa=dUAm3}i zzh%#}wtNGb-wI}RrhcbjswEtR$~{@bYlphu>VwObWLm*aQ4(C^nZ-g#hVn-u+#d=S zMq$a+*XS5)Rv4AeUPNLS^CIwm&TZWJLj1n9z}tsq(7GuP&wBgXSf-D#w&~2MXBLhQ zk!@|fO7#_`-}!+StB-i@k;_?CtM<@UtmsB^Gwnv<>|NZM5yC|Cj|h0%;mS3+1^AxJ zg~McKkM7trh4dqt;E^g(2R8L{1=)wsjuI+ou^8-*m(X76_SOrk{$#9QDV6o&3?TUm zA*sxvBdW}=VlcIu95!09hpT=)ki|_?I+jL*xOes~SN*9-w_oubD0v!pMzFJGahQt+8q;KHD2s&Ra9>|z^!MyC&5 zM~d`k{K6cT?H-YV4fiotkE`+K0u-fdqQLCjTOK*jxOF&un#Y&F)}Wcsoa69_B9X^3 zOL1`=CG9~sI-^l$`Esix?hC=0FpnYKO2p?nx@`yGwnu7rn8e-+u79Z6;3NCAC%M^A zK`}=@t+O~SO7PNsFgYqG=gucH^n3_Q=z_1{K?69$NaT&Lk_j6@KR(Zqdc{E|+Xp1b zp`j;vwA&{j`qo@ zF}h7KoFK0+HMnwD#2{nTG6Dhqc(Xwxi*1wrej7C6cG|`lh2zVj zPzc)5kTk^iS!L=VWl)gpMIn94+I4ts?Sg1OB|HBwA4_YQ!TNeh=)>MpA_Honj8Dk3 z$^@R=aINWX>tenj9T&Q9j4H-e8}idWX9h9-ts8xbB3h+zk@ttsUTmjXES_2IB64P2 zT5$2%c8w)TY>AWl&aEZyZ|!mxPfKljCzq!2$u?vzPwJCP-a@`|F{6>bLigQ==Fnd` zX3+-oUZogHv6b}R**+jD%rx4l8rEFj3&%$sy(vgTlGwaEMtfVX4%ykEZmiqa>UAmq z;7j!vW=!PH%{qUYLcE4}Yy*&L|rRR{nHSw7Bx3WcS+Z%GUNH zdB^^w5ewzk&5W6i2l>MVy8IfabY~IZrRrkO1&pRzDLd3$<{5tLNz&oJxzYIWX59Cj z>R|(r?swE^z~^YA!bF@rsWt;xseLG{Wgvkr7&x>aBb;{zm4TOhMbGH1G`MmQb1GUA z&4C@qx5I{+0lUzd0_ny~);RHYPzgljJkRQKZLsvC5_AQb70qsu+)L zhCRd3B{yL2o-E+NX^0AY@P2APM&Lt3JX@}0bX!-W&*Abzo_LRm5C*}BJerrc)}o{G zUP+A)S>!aBUoEl%2mgIcjHzFFFV7ptRO(pSQkkmT9s5<>+P+L2_wf6y6}pV0dtULw zPN07~xA&$pM(&Z2%bpjQb7pf=^k&kB2=VcD5QS8f)!H`ty>Da+kEX^5i_`&kv(CfW z=ByQ^Zzw*vWBf&Xwee=Q*xAPhS7zU&D3W(YTcDi9JUg<(%b)2U91}CY}+n)BB z!$D$D0JI*dBEBWK5#;w})QG(Wica5__{k4?V2#3sHTAq{8Wc<@5%)|Z@{gDdx?JOLI-BSPHsLnr@5$MTsXQH`^`hD zi3GIZjw2&sR}r^~)+G-{7);8FF5Hy2Ij?WJ6 zRbxv82s)R7ryoY5bRp8HMyL{|EMmkm@_wWfHKRi2uiswg>?PWb2z z$K8H?wW6tnRD{8Uq}`htuGVnjv5kbZo}|?+78OM4_gmc{wbM@W{P&i@#0OV>LSkzK zqCC0pl-oiN=N!%Y#Yr$7Q}WP7`_yvlWWKPW)AR3W#`A9}eJ|c!rHjv< zh1+C5`TQ+3$b;_1Hs&V&cFq`~dq1r}z=(7zSWn4f&>h}}yJ=7$hxK~JGbmAkyTe(0 zd}yPWkrDe$(Bwr==n32OWY!u(aD|Gdrx7%RCjhm=wsA&MGT}p~#BM}(A|)AU3Spxo z=iudjs(;<0;rq$~c%j@KkXxnjX@Qr!hEJQ)%uAsySX+`GtV5;*@*SajYIJfjrLs<3 zJPG|XZ-q-1g$=HXPz?CreKu1M=Un5H0TVIh`)vrR<8S3H#nuEDehkr6YqeO<_H@aA zC1yIhQtH_lG_y{4hDA$?5XN|Ac9PF^f(Eha*j&={&}dYdbl$i!f`KEEjqa^d3wcJ& zky>OPm|&wyn9gul?3b}Stm#b>{MYiqaqJJnpAKxQjWcQzj2+GyT|dGi_354ia*RLe z69JgWkGt?UE>+V`r236(S{jpeyKWW5K84+7{I4dQ7S>Y+Vah$GwYkgC*VpHbCd4i`h6IlAw??aO3Ng=1S>RZ#HhNLIGjw% zT1c<=MFzMXpw*9{J3Bo-BfKm+X5-Sb;-$)h$4fMR>;b0+cWcK$oEHX z3M}vdM=|W4A(&%WkNf_}hm+34at6GdhF)OBSF7KNlytF6I#SZ?QT1VXsv{xECA|Z& zk|I1}+q)Pihha`Nmos$t#+qBQxSNmF}P-q0|I@sgze#x8&U_;30m&9`d`wA}fK&O3K z7k!wzASE$UBslbym#*>GePr@Y$Q6OQX-mm;pHT<6N8sN@9Oj=4XX6-e`*uY+(Jkkg z$okYXjP@0jzf7?S8BQo!P@CklDwQ$NSZ_<06+bME?+Kkey78lT=F^vOvX|7GLLO-} z&7uDM69rOv&K_&A>RLa4fvdn5a4k4ij%SPObYG0sTH8m7=Jdbo=zW}{W;X+bRJG3? ztJGXX(UBSVeZ_u_LWET8D$P>!=~>H<^R03Bz;hp@kPZck^a&GOYwDb_c7@KsU2E9M zSJ*~{A`QRi`op^OCf$w3Ya9UE5qhaMv(Xr5m5;_A7~gXYw@&-{*6yK1>pix+BJ?pA zwSN?(DWA4g0*9%qo9CR7A2J!bJ|4%4F*aLWu~_d0w{n*BX1n?7o*|jVGL#b|1S=2T zxT4uyrCFpw3anSq6Fup|d|E zI{yJ+J$VHLzk~tjz1fMfsJqth0UsM0jJxJj7#eUH<(x8ebbj)Nh5{n)?!y<_8tGk( zf{d)t?OX=?cdpAmIx!ju%6GTu%t12Z7 z`X>(RAe4%`qjM!j?|HGbtS)pd=3<|8QeBuOlgjo62U6zgVUxr5@=BJ=t}ZzwxxUS* zLR*|#zK-}x^)S&j4`sgg;j`j%UjqvP=cXYF(s%hRZMf8(ZNCWq3g}RX;!CY{=dQ}> zEf9xq(>9n)_t`u&-O<1D>f51;@0*u;l7aK`H;R3SX*)RD_xt`|!R%^(4%PeP$z9}N z61CNK^?o#OAqXTiq%gcqGpIX9I9E^Da$a_!u_|j8c-;Y?WV(!P-{FSLLZ`4OqckjP z=8SxO2()i_@w6aQlF(YlOg;QLozV2R783s#4bY<(OXBxlDB&NTA^M%y3^g`(p@{N% zS9+J1T-Ay~hm@LM-4lXi*i{WGHlm*E2WVwKK-fvL^kXGy8t;^~i$Kp~r~+3&Z-j*6 zBS}em!?mIU`rr@V9Jok+oMOyRlQL#jRdBa#t}MvuvX|-+MU-Yd=fpAW7kYMDZzd$P zibyW(PE$ciY=pjQICp1l=|=(w^Ca}}jQ9!B0uDW+CDq6K1keZ{r8vsW{Im(#P1k_o<0rc9(D4nCci&dwpmSH{qgJq_bx8{ zgK5~xYta%rt9<>7=%g`(wpI5V$-=c?T9ww2CQ=T-Xo`E~4RM-#z{`#@=Y(vs-_bb& zZlL`0xIE{-4u&H-ccb$1(MlgV-RUW<6)BwY;u%5O!M=#bin9@p1H&!WXrbjJTGqlEC62+8O_P)e_f>_v&aH2Lu-m82p(*!zBf7(Bh_{rJcwC)uET91X2X69#-Ug~Ty_W2 z?%DC+!+>Pm4rr@d)S>!mi8wRHcPaV5a;M_wT-T3S*JV)n7!^>#PfB|TxEVtncW-pA z;yS25Qs!%S_t{NZ-{$;uDQ+ip_IHFn(0i*+uR7Np~-EiXmLo!{x>MQ**8rx8!9Vib!+2jCm6cX+ye;INXi{9BER_Kg}4EO0`Xgz z+hc~dF3IRIrPnSe<0j2m%BPWdyqpRxAvf2T&>zwiODl`X=lTYJq9g+HytN*tj^!n< z8{ecHfvf3u+bR`xLX_-(`{eg28b>8xOj4h%tcU&FQ(DF9GZWv?ez&pI$GUqxA5;(i zWoaR@d~vjs>9)o@{G=4N!{;o~^Y{-ubegMwBA)ijz5WLZFhPZez9!8NbNeBvI>AS_ zw$_d(lb~N-3-?EQo&wiP4JA?f740U*=)Z-Ll@FIhMkBWq7+jDdm&>j<&L&;%9`=*~ zEif-AZY@lKC;B``r}X@c*(2ay--Zy#oRS5TLm4n6{GSr2gX{2=Bg3+i-w%jr27H4a zP)!O=qyC)8s}0D8k0e=9DJK2m2W-Lr&(Q0W?*78X)n$M+#-DYI49~15UBWhVZ@YX1 zh>(A$vD5#E$p-rTk+my16Qz?A!+bV`ny$bvazy)*7|12;`8UvAox$zBCCO^{Fb8;- zyWwzXXz;RO!~WA8@EO#*J^z`-72kEUpN$UKLXmb%QZq9%6LcK4)C#?lO1*tZ0 z&;oA}&&vlm6m#Ko9qgIn%(0IRQkZkmMi4Z}s1(7pV<@=<h4 z`t!409MAw3C*S^s+*BjA;Gb{w7XdV_Ijhc|I6kW)86%h#z-n&xc07+c4J$8gejq^! zdJPfxaQcZLc_|Wrlq^?o`OA<(8f{?z97n@*jMy4Y8ZN6 z2TyFM14a7>cvk3KT=8vIyA!~X9VDQsOGyoe<)P|hlBZGg_KH`&`_S9&>vaYbm%~W$ z2oC#6RT1DmDSK<^UZh{sqFxSWXc7JVRfte5l1*a!6=)>v&gceTlnZIthnIPo8RgSh z_qMDJ*ZS*#vr(e}rR_4$vG8QbfOgi6ey|R^F5yzv4)u6IZE%*+QhK8K?j2vPRFZ$= zjEfA66!~b}=H#wPtDUSC{);Zf|znYL>VJxGgEDO&FWC>){rtlqPpa63}5);T`AaZKvLO z)S&3Vuok~7w==q78LnUmY65u4m)|d0em&*InTP1U82SWKHCKhCAkW>M8$qB{l{1xR znic#~D}r|zr!b3R=LjY37A&QB?VS|?=!S=lq6?)&=dt3h(fQ|^7iVeM!_e;;#XoCl zv%ErWd*lK2fQT~81snm#<#XV^X6rlSO|=%$pv~TuX~?pASg`JgKFohVZR_i?Gn2v+ z(J=er%v$x?LxHcNhv)2$MJhim68NTGnFl`mvK>99wK%=b&7L_!d=Y7o|KzV(0Iy-^ zWE9brKqTpj3GKcY9qGi~Zf%QIs{K}rdvg+%B?gy7&`TkbJ-KcYxMK~hFad>FR2hEb zZg>&|#a0)7BP(02^@))(M^?+JwV(Mt91XeZ24Z{)a^QHC4+?kVCY5oO9y*efb>9jQ z3e4UZt@ALM$79ZhHrM}N@3PzfTipMPU?EjyO(%KMGWx5~hE96e!t(0UOlg*UH|jZd zEhLHnxy`{TtVghZon2_{=wk@Sfbgt%WUg&DUaACP)h=iEIryh#T;Dv66pqA#_Xm65 z_`bE~O8@%_fnoHgMoMxiz@qu!pem+V$E_+Iwm2z0EZt2a&e&5Y<3 z_lu{_uwjfzti%OEOEcbmq8}YINtKgECbn#g^q)6;Wb?#VZQ8GJ(|4RaGbkFcZ6<46 zJZ5yfZg#!e^k-=LfX7$yeo&`-s!RtOxBZBaQtYc%o)L<0mlMb6w5Y7sPzuI@WXHLR zJX3WPvZ0=qaXUc|Vyv4D1{a!8){v_#`M6lCm?NDTah#~LwbA5Pgy6@Z3 zpLfrLR1XdbXY-SjpD7(OMRR<;JN=WQ+6$#`!BGfRysHCuwU?5ZW1XtE z?KRU$v=-5D)rh8`n+r#k5>~?CENe`AN{TUU>B3zb@^Zr#U+?n1S-zCnUAShsd4=5LBkZ=Bp$_Qh7NnDQZ@8`m0Ug?T_lqrIzdzlO?@r?}`wOl+Dv@gN^ zQ{og6nyQ<}>dj;=o`jbZ;X_6jbR3)^-neeFPElSfv#0KCYCC-VEx6ap$y(cAuYS>O zv=e!78;`cMYv+09?c!F$ItxBO!Pckq{nf~yu1~lSniGp>pD5_NyLhc9Pba2ZaipZ; zx36o0Bbw8rQL3^OtPe;R+}xX%3dsG?4c_M3g%lT5Hehk*uqy;t&qWQG5vy(a$7E$u z-^Cl_)6n-dz`C{!jRI^7ozo1V_1eE-hFP-3y zuBnBiwsla`n+39pi~{m9S+u8k0I5OeuMBQ+$U2=~6E)KINtpe_&=q~pRd0tWT$%~* z25Xv^FKN@!{%NAU#f6P-Jk{~qt_DjTKl3FY4j$5k^g^W=d&2HJ9we)Z8Z=USjj!3G z$vb>QW7gOEYSwTj(svfxa}I8{6S_$zC+CF=zbIx2=6BQ?I86rXRsj~283JZt;k3Rs zte)bucxH5??R(vUa7g%y#qbA<)7nXd(?bmq^4)0~w)Igo7xXQaOWDhZxO>n?t;1b- z9%W7NuvtXKgHfT7`#l0m5Usa!MSX-%YBgJXL|w2nSovQWMloI|JfHe>&nY|W)SBWt!4*v=*sDW9W51b{4e!)Gh7NiietR~pgc47lb_R2*F=}G z?Ss3kn#=9}F3+N}`Mzf- z9LrpjHJkE$em+ua@BGNExalA@HZY9$i(&OI+Ar%~Npi2b-ZK*foHif&2tDw&7A#r5ppaM;4S91ADp2mwOzH)u31lH z)YcytFUcQ|E0_K4Y4PtKuodT0)_fb5cOXt|BfyMLsUjHoU0xZ=0dX&3X+pJKT9Kp+ zJt$h!xGH{o)gIxY`&1sVNANmKQ^X}v(0MJssIF`x(ot%Bhn!4ZJVa+d!-?lwxC+nL z!Pg5FH)CvxRKUdNG&AoIc>o{6O$0(Q38QXX;&I#MD**B)uCIrlpFemFjET%`m6`%0 zOMaF`d9Suk8>|LnZ;Sj|_-dbQ&}asXf53{WbLLbbv#iY7pTl+bU0jq6a6sbcCdVOwo0L-Z|Ye1kOHco2rvJP+r{|l`^W)5c;2Ii@w1gwXb8t%m(P@V zL%Ge#PTZ)jOBcy)~=Lq3Z+YskGUNd$&$jv?L`Hw}F zrn4t?g5pKeV6`pgz344PYszFsoKgLOC)Ph}8L1`0-QJctorEtrVaC{M6A%MU=)3vH zaUmhgYP$i*{#jzxbPzvs^xd;BlEeW{sgYmvNTgyqs?b{{*4B}mqx`oI!?IIywmSCX z7JEim0V!@JbkVg}sR%-+>R8iTCDg*{xTb^!7H_rhPs-={Blm)0|b%B@m#ie+DyX&>w zwXV&3jKHVhYZ#yxg%L#C+O{}T!J7Oi%WKE1Uv&Y4i?wWdG$wS~+`86aU}#PXjk%92 zC{>5u^DK26OkD~eD;P24Fa&n~fpKFKD7*{`S`Kn8tVF+m>xpR)WPc~tp1@}*wdvA~ z+JZ;|PF?BZy1nsyWO}&E&NV;z+N7!E`x0@y#j_Po4y)G4&u1MM16=J{C;WBP8^dMg z0`BCXds~Av(pl%R-V#73xq%Fv@Ycp*)U~poJ89tALl0Qn%{&>-ns~!=)0h8_qH}<& zH{5+gORsrWom3GNK<7yoJ{^Fk;TJ*6-v267XdGVP)N<^2q7}HuyhAC(3z_n5FmSjd5wBP+|fjJ(8 zK~3`TVg3_74@R zyT=?B3Y~|Yu9Qke^)%APKerlkeR=)cH#X+5**rTg z$a_4Kwb?n{t(Vf@tqrMj&y9BS>#3c4fwbd=^P#f)Lar9rw&`+4eJg60SEwUx zHa;Z8OOD%ZScK|>96QyB`K^ar&+E^D!A)^&#U|4$2Bu6vQKw{rkqyowr?qR}N_@79Y;{}c6D|Qhx{3%TtVkFW8GaCvtKn&gw&YxfUdzpWp43Wj4?cyS|Ms0Gbd-E$^!b#~)5DYA zE%~Q)E1bt$q*U_PP8i!-8Fn&BE?17~E@4eiR>Yq4D_1vvwc%!8PZ7en}x1V z>6IhK-D=1kuK-zNUVdHMkVWcqIq44z&r>;ooNSyVYZp{fBm!qc2oH-#iHNsPAdKsW zDpgSCbKTjKJY-PrBQro}G7cBL0aS9Q%ghzj*vDpZMF~9e8t&!`0m=1wnegx;fL3W+ zY2*kcOF!n?-u-;;Q&%(=34Z1j0ZB6l8by)^t%pYCg5nCcgZWm2`+Z#BRGhS2SEJcm z>WUlVRVXT%?8cu>lzkssEu0{7?e+SksiUvIEy%moENDax4d!w0 z=4F!zNK_hI$-tI=iz`kk+_#AUb_&c%w?<37Z`9*W5GErFl;5>T9iA5#!2ZqZr}qwaNxJOpX?(DM;vure0r1ugN+x{gC5D(jJ&A^QOr2J z0uR6kIQoz!+ZSh)E^PMK{O+}gboyRLOih}?JiL9t(KXmN$sM65p3@R1GSK*mF*RUT z^mmT4cX8Kqd$%0kRs+R2lehBe+>YGJ51}qzV}OGzT2UkcX3%*xZI0YMm0>3t2;y%1 zrAqwO&MKDVtpW*?254{tC3_-jfXlVTb+llvBi%$9<&{ju`&9fc!-b90bms)~mZhb8 zgACQR@omqRRYb8a5Wi}OmhOM8G4Tev>6)C0O#jHs6tv!}`y+;@+fv(=C2XB}N!RG_ z0x0d7O@I)ZZ7dC5c|!?HMV8`m1!P0nzOqu)NQj2N_Xl7@RfrZS6eKcR$H{jjZ<4h* zEL(Kk!N9V>|7B2~ykxOuOUo|7JsnrU!^v*EV3ArN${)kE7HaM)(jkG8_`GX+Jw_7~ zg+i?xZaJ_%ENS{qT&Ar?vF%wB{?JX~m7DnQdDLE^+-kS*yw+y)>)M?>?`cILibQ`V z=Ipos?N)M2g6=G3jfxfo7Vq}?sQg}qk=}#I0SGl_K z))VML#YE6IqHo0=bMU$rjzmr#7D@K!oWt`tPR-Q*_9&cc+P(-UuI)p5syH`<_&;@q zl@HJvbwDP$N|Wy>NtwY+F;YVb{+&ip(YIkhhw}r*$HPie8jn$kUQ70ouvY?MhZ|o7 z2ci}ydezyxIEu#g(Pa-ZzLqIxLd0iaO<}sP)N_gq^mG^UM^(dNKl);H#!?v8)9(nI zUk7y(>;UVb;EUY@(L_vE^C8(4%YFYbCP+9PtaxyRAnZG&Cxtl=U5bO+er}mOK#3|A6VFY7o3&=eB*_uOTxirqM|0s^&FHn&IpP!g#D$p%c$#>HuCHSZ@uF0Wv;ZFG_#>dvKfAsM6P(Xpi3z`h| zfg3(Q99`a^=%ceVB-b=9(T*A~c0+h+akK6x7OPN$UXOCNH_e%yk2mi?RCdD8(rM(* zTD8-pARR-i${>JjS)4{?F#tf}^y=D*80m4`o$tMEX5(@K*!3~(e+N^iOr+Y2al&QfM z@()MntNP|Uw~i(=rj8zdbu4qa7~*oZHTgrj%zjJPC3_dv4YS&YU1RH*=WL1na>A9Z1-!W zV3IVWBtYuGnsJ(J3*;iQPye<5hwW9nCvdP_N20{B$Ln*2nu=6Rq~RCEg%fj!ISSmC zECy(b<9s(p%eE7w`WM%PZ;P)v{SC>@X#l(Z%U*if&^?c`X8YI}-w$|ee9l)@gBx_= zZQ106mI9?X1D$s7&bPxdACTxuWwwC)MDDKPWI*&R%d(*udt5P9T8>+`rnpfy-P9z0 zFw){*VEs~aI;G%#X@Z&rpL;~4&fFl&U) z^vp_f6*%*~83NZ2N533xE` z^G&tB3$#Evp#}=actC#Tc0EJgF;woWMv=<$Bbvb$x%oC2*qoi^I{efVgR({~nl3Sh zrP06NE(vb`w0Xeyf^dSH?U_^R_kg4+juT$O9q_X6IEw@s8QQ$d!(GcYkw4}=BDF?z zJmJ>+KxSuO3A&6H(8TrpBR5>eH`hjQK0G**=`u5S1VWz5sXtiHU1IBgyp}xhpsBN7 zZFHgXwXdh?-wf9vj`6w0_~Mf`03z{Z0?|Uhn=ZhB4CwB9=epkxfxeU0PVy&nU%O0& z`&vE&9>zZA39oN#8}I$u-RQEBbo;jWTTlMk!0ms)*V5j*tI|$vLqs}pP;P`|pS`Ha5oWCk@*bMSs=NA`y7`K;VSNqz! zypu<(#vJr+@Ud&l*hB6|1lqwMEPNmQV!)q56pjFTq0LZ&vrCJ4!ZxiJOF(z`P z`cP048nU2Qkx~8(>o+99p>61wbf16Ic8^7f>{sficCknpXSc`VnQ$xdIetZkDs(&a z4UlVbknp?pREV`y>|p`7d(PA_CT7cy{?}%^|MCzCo(M`~LwD8gpo42|L|ob<;97aN`$-}#?Lxq=sG8FL*)T%h?I$(Xu&sgRg0m z30N2f8(lqe;MOl~b)^XeAja#{-f_P5H+%}*8Gjf99$wudzLJPLKmY1G)-28_j;Btq zSx+wN(_WY0517~AuhVY>4jPwq0we=uXAOsmvzM*MTtHhFVj^XeVW9V~YHvq!?fDwNs__*hdn<~~%vZFsxNL}HcD z=`^EbMLB7yVn`ziByp0h9SB? z;(TVEDS?dBEp{eFeLRIpRq)&I49$@92k5orCY=Gd&_>%#OT9g|#{L{C_n$mh6v7VZ z{H+6u=F#e+uOeoDnEl=SM_P7N8WJ_@nEJY-CAht)LdgZWqL&-az#iT&@uVMp^A)tW zv@e1;vCgC|iN#CUG`VQsyvxR%y@siz;TXNaR8po3ppt5PYc)w|7F-?|xlj70Pf#C; z0oF=pZu!q3Epc@EwL~YH`p2sk&Z$-$(jb4;J$%q?WYnuBBVT9nv3V9uGre2Z97m|{ zM2L09FO2I;&q@CEaA`V*X7bqaOv|Yakmf@Bzf(2cH_CDvFCJbS5~&(~jU=%Ymayfn zWySWa7(^fPZ4$kwy!<=+8aPytl?_4Um{7$3UUr;~p&`$2p}6f2^ZpLKV(|YB z10l;w7fO1-96@&0zgE?sTUY^CE0o?>@~~|5u7dqgiD=Cmhr`#bTZ0YSC76e#V&%sI z?;9Rk%~6kDqfq%j`I?eHW2_$p3;*$~SNjCN)sZ2;;2|If*iaw`z6+4`Yb&QG@?SBr z*uf$scg)!HMa3oc`x!vlP`1NO^OQiE-N6JD)uDhA>df!-Q>~Sh^P^Q$Tf8zYD<9q0-PIkRK*~ zI-~&V?6=`e=PaG64E)74SlsAHQDuS}EJ@xT_th8KTyM~Sy8f(6-yw8}ibKxhz%H-` z!ycmq>##-nWAe{I(V-~P3Qt0>pxq6hE~It27#>S)8&Ju~aF|ZWCvDKtEvm1R^% z4cvnZbFD9_a9b$>9@_)4x;b7|Rlxq~S)Zf^fT-Als5EO7K+%~zL{c%OwJ=pUaoH^*g??z8t65OaQ$rV2ohRS7 z7IOdG|Ew}CsBq7c17I@qrd0KgzG69(dRzaevCeguC-PWdL3vK42lv!@k$Vh@l)Lcl z&H7PrdVY?o7JQM5IRFaOVu=Yxprl`T(z}nIN|G~fw#2$gdXk8D*0q#o#>G^wdeaJg zp#HLk*$1sbjn}!ZC{n_=?rMH2-rM5!mv@v=bfIM^Zf`GPYL@$Hs{gQ+G`^a)?Ju@Q zI%x;^pHwc%vSyfS({Oh4gSzdHr$@^_rtwqftqDX`R&~;ESTTFJMG!Gr^KngNjRwWP z$(MwnA9KCH0`VQxEo9wqVw~Gb<|*r6*!T3C2FUG?sDA*m>mb36CZ21Wt^m~p0l_bN zR`aBHhYg#JrU7Wz_;KN zAnaB7lfeE)tGL&+hJVvA5U|C#Fv>9M9UQ1<833XB4+GxGQypaG!RxNK3_Sq%V_ zxUB=$2nP@cuw%DkTxCa}ZM?|hkFma;9zV>6uHPuVV$BYiZM>zdq^mdko(oCeW3&C` zcr1B(R>qouv?K*$4&QqPYSxiOi*5bl6f!81Sh61WjRp+6@C=x^TBQ6D? z+y7n?Q6ONQQz=qV>CM0As(Y7r3ZASiUO?l!C{F-}M2h~RXX8Uv%sQ}P!QGpU6GZ!a zYKk5R69T4!Ztu2-1Dp#QtEZ|*PEyk9dKfAp(4r>hi8$;ZYp%Hi`m-SYCkbr?In!80nivzjm7b{0_um-A;}gA(!b;> z&jD=sn`T2GU`WGLCAY%np8sBPJP3BgN0nXG`pw_1>%mCF*U~bLaN-%)&IT-IW{;dM zQMX|*3PA?qiS*)CU8s1CS}xGMDEpm(S|uKL!vcA3yrds9AVRm7CVs2|HE47TKakJv)o8%iJ8DYvmT8BlenxB?1GU zkY(|J(e5O>yH3_BYW5FPFj0)p_kKIfS^Hz(*zw0qnZPm=PI^z zkMv3|V!c8n=YSm?7&K->?mK4btQm>=u<$0|cCYATH~K!%Aq<8f${R$t2=tt^xQBSi zZABB9h=ylyGZz|h57z6-E{Z$SGm2n8r!r?PVhNMPOJUWmpOKAG3~7IQT%1zj{{g`k z8$MG7kIr`KvX=g-=k7Oc$nu&)sG6iG)ih&LV~KoZ;`dcn4IV9P2B*< ztS&T;0Xydpv)hg_yO>#%e(k>{XWs|XY0%eC_%@Oc9c{xq|!_Ka0c^86tJfiN(Hw9|4Gf)tnBIO2vvdS-3H5b^!d1Fa*2>42Z zOGDCG@1wHYzc<1?>IS|d0GL#^wyBxs-nkFJM)~TX!Fie%2JfXI+;tk6XQq2Dpu_f6 zpvNWeHE98g)m~{J2w}#Z(YTGmkRwUoi4U(T+LP+$i>i8O@P#WeSB6PkX4FWE>lmCq zN#LO1Q58KS;Nf%=n5b!8`K&AvpCKyX>G@W9>5F#8H?8x6_i2VF2)(QK`;3`*F}c-$ z^Y_(m%$|Faa7z$~|8FdoJo+hwqtE0l4Uh!mF}7}Xcy34F|H$jccUTmBuh*$WigqI( zTOlU=tfR_i7C5H(qKxR3Mp6Um<>MHfc|ibe-#SW?Z^G+#xnRAIz5nB+a$ok4Z6Nfi zkOcWjh6v)4Z{s$8untu6Y&Cu2lQb-@C@HR}Z^EjPDvjwx;0<=qC(!GC&Iw?p$jqB? z#m6=R-!s8~bpJP+GXr>O$?MUW=jW^J-R8I!!~+I4K$@d~S|GoXJ5lBsfeegi}$-fQ$Z|q3F3=DlK6tGcPlk zf+(sGm`>18+6}sThOr+}K-egp_n^2vx^v6j^g4VecwxAF`oBoLqEqZGGWCz$*83`e zOle#wj+P#RX)yNt>78#>a2h_(&dx6qMr**Tw^v&D7V}I|hQZte1C4M|6bzCwzI6>`Bg%Sx_sa1c|1~%Y=#tO8 znOYUie{WGKc0@ zXMNwe5cBENfQh-8AqwcuZjxx(68iV-Dou+>h;p7I)M4No!wc2)y;1Sv^Tkq)J#L1Jr8r5ReK5l|3B zQd+>FLt-fDl*^hd)21ze@#Gss6hpJqd zXL?G|s|6sLHZiacH`gA$O5_*@yd$hpr(aco=)x+#Xe8o-Yk`?@P#M%{o{1MEMrb8{5v-ggb2 zbuk6c*V@iG>1JvN{(`wZ5P5@lSR|>2uzN`AVg*j19GIAF_%kX zVlwU=f3o`VKj<~a;dQcM_#3^F5KI|$iopMOgFw)YTIYQbkay$9`pEitS|Ps5Qfk^_ zC&cNZ%a?Ib`OcGH4T9I=_A4Pz`sr$fAG^LhWG=`uQff6W%pqPn`*%r}tt{?Gc|wu* zT8>X1VhCzvaZq9rWKqMs{=<-b_Jh7Mu@1TFs>Dl{LTPrEvqwBLcY05^2a0(lDC|oy zfrbCp$mAlq!unw1%Xh-WE_IvgP(@&lByKL+{+p+RX~;llr7P`*Tjz778=MIXm= zjp#qm6?eb_1G(a6I-kZcLvHNVXrt-7x2`Z?*#xEjhd&`73UnEiCCb;AlZlCK zrvupePnnY#FMrb&dMO|>=lNJQYe&z^yVvJ~yCoDg!ja3GxmqO#^Bs@Bu{VK&0v2=~ zy{79&OZsj!Ibv6H-_fjfu&qbvYm`}9DX$$C7|}?bIQ#(`8uwipfWwjjGkFJS`jReS zS!M2)g08-I8m^KBdtrMO>FLy-G zdz`~-b17)=ycLL&TR~-Dk5HO=*1JH{iuL)IL5DSZ#>&@m*gy11yFcb9`zPmsGxi~h zgwzrfU@rTJ?2rQI#i+q%T{S$>ar)ZR&QK{)lnLFVAQ_kOu3cW|t?9TS6O|PFw3Es^RxwgF)}aAPSqg!E;d zYqdkqj`vFUzi<;0zLyb#!c6B(&c?R*(5~w(jtwgG&^bwrUj=}HQxga)QT+5ZkpM?N z;E_$rfSS{D0cAptmuUC?KKK*bjT@EKKyG?uV^|Hyn;VRifal8PdSWf`@%7BFYOHPI zfB^EAjqR@^$?~!9|)*^1H~#SX^MwK5aPPKIz0~wqr>#x<3KWS`__$200 zn{th=3#J<&D%mcM9Y!9{HDW4fRkJR{ASYat7Z!;>O}v=sBPp3c=Js**iL+K-kBGa- zhImE!u1zi?zP+n>cf=wyNLBFC^{ibw>gG{@W+h_EebN;+aU|)1{jHM307mOO(wn+v z+mrZjp1HW~OoiTeZWN^g?lgQq!HTAAxCN$%d{gGYR~ccSZylQTqIl~-8WMe}q_RHv zqk;u8=GpcxXeH&{Ttt!z1^YgXvJrvpbCB^KZ>*Ygkk*h=os!3=Ow#UBGBbY*`7`MAn6N>=> zmn9PtO0R@u>MpG~><)kMwGX|Ufw|B?t+_UA>rbv;O|@qpPa`?ZH)=%d96-02J6~x* zmkZ&b`6;OO=x4L=+x^Xr@Uc&&m}hfXCUmC5mCw9SM z#^V!iaxEA0+bEA$V?chSEE?W)I31WO9X;WHXhW+i56oT?m!P_b?IE&5 zcBZ3IsK(9S{0<8j+c6B4UXwZAMRUoaLc;I!8M(^nOyX(OnGuOcSA zcGEUts)F|AzM=9;)KW77M&{WbJ|*Jj(?l!gKp3{RC$G#sYk92Ylb`bt2al({@7S8NMy}ph<5+mLl=2Q0h`aFrsLh}URZVfcx-6SqbdLOrNYJo{cbJ6wXXMbP%*^u)L4LtHKmy*kFar){Ck5)<AByL+SZG^cI8 zmz~JimJb{@pSSSzmGZD2b!eX@;(fE7KU&62#1h;Nv>?9pz8*(aMEO{6=8&L7_S8fB zbd%3kQI|ufSm-r?Ecya)4;Fc6d2kIf3ft1}6z3x~N9+@^~lluFo@ zwrk&bTq^isaZyqGB+)d1^^86PeiUT79yI4ryK?5yLGw^?{m^`)zqKMZbgA=aY%NQ| z?(0{6Q;B0&lyZ>Zv_|iah1X!+>>@bLH+lbw>rZSJYygOR|X>rOF!o(tow7I8qMU&0Qqj-OD4sMOu>~Q15kBlp& zwcIX(@;j(Jv{~PLzQS-z3acftQl+^o38fo1ELdC!(d*WV#gj}u*3nV+wz`D*CavoA z>sPfsqjSe6nvfbX)JY50V*;`0+b28ylY80m&Xrl+_lJ=$JMbq4VAK@C8D3D21^2zs ziJ5>eC!lh~Qs=Hs*hyL`f8o&m3L~+Rt!19j)L8?ks}xEW>7S!-Vx_*g^hj(KhmHf+ zp!orYb}m9v;Wu=Jh+Y*D7cz3|69)}U-&WJ7#)F~wysi)9g_IHQK9%cSGhDOl$2%%h zC`Bd|#?2#4%=L@!POUb!8&T7)k6TxgMyr>ix4cv==NgU0J~R&)Z~8qLcP1t2cxn-{ zJ&Q5YmR1>DY6iWa2la9p$)mz^-?(pc z;||>3ly|m#wPW#ifC378dJE>=FcqjSRn1I(AZmQ12vV-CuV(38a zEjB=XT6|l6jhBF-2hc==l~l&?c3|KtHFvsd%1(VOJ2MS6DWdqhx@jZ2JXk7l!Y-Lgl2EIXM9+`cTEA z6PB>mFLp(x#UY9Bod*Pl=J`W*vm>x~*@cac&GS0M&krrpMLl?_<^6AX`|d{APe63m z!lTqu++YLnv+7kFy97J=iwB;wfqi=7NBtwu#ERJI0aqHkXStkgFLNMTBbC-VBdtW! zU)~6jtaz~}IJ48j=4v6Er9A4Uw7e7_0f-LOex?N)z)S zv)3er_^UN({jQ7%f2o|LDmYz1N_MuigoqpC7lwnt114 z*a^HQh-H~XQ!cCs>8zX7$pG!lo@dfNb3@kD3S%eWd(fL!VJ9kMdh_?Z!EIxW@FD~F zuXso+pkn8lFN*pDY5|M>hB;^B7^7ZZbyoq`A$k^H=@_Z0@4~#9zcglNHM0I8E+MT$ zQf479lcV3@*-jH#1}&b2v;P>oW!lR7aW*bg$hQJ7j(4MTo&KmaOin7R4XR6!A@-#h z8b}TPiIWlSwNouMJDQ$6C+B`tR_^dCG`LyuZ(V%;us}7JR;UX4(^TT;k`wk9Yq;S0 zb|am*+Cw9%Tgf~0nGt);U*}lS~eMdcsRW+KF+1cQNyz3qCXxQ+Ko~z%L zHg))z8pdxm&X%CMzd8AX3Ho|@wW@n4;e<|4WN06aUp$xa$iI4i+4t^S*(D%&q=4KF zF`icr^y1Z?e;_8dgcsrbxyTal=G@x$a>!2t@`S~5@{ieH@JUBU4voIz;-DP zGRq*J?-iS1ozjYkvp^oL;-HMU_1ZVC9B3YlThJLgpB^{wG}H^tIoc4nV{llxEps3a zJ~fbvF#;@GSu5RRcSnfy6gFQG5sdLTItr-B5X>4m*`eJYEuhT8O@n4-OXHRJk3T|h z>w#-sWpqLa+b?1e4f^QNs&_As3!7RcvAAyS;x%$y2$#|nzkRUn`odzx%Ibhwm2AG`luWGswSby+AA%G>)it3W1tAq$vBatDEeM)yR6s}ZUi5F!6^sdc2hZ?n3#n% zHT@dcuWb3*z*L96YB1NesGX?L4#S%~h+x!U^IPHTNJ_FYk!1I482 z4FYl)%}bL7)>hHoD1&U*m%|+2W-qHihg||4t`u)xo5OQO&`o|BFKv)kxARiY6NH-!Xwj@(OCq+-QW_P%&t(c%2eKOkS~ZY)qzAYjgg*J+Z+u zA6Z;F!Kbmmh1V`cvitKun6ZrT90r(ep2opY1hA%rJZX|wR1#zeEKC(t+h$Ix2*N# zs;!Q>*P7Ue)Np#3n`=`A1Y$@QZ`evp%o6E}7LZ9>$v{?eII?rR$a?2ir~ZM%W1H;_ z1v%6mq8>k^s1wJ|9&EFm`IJAYXJMfVC4lp;8gZCs?&uKSy^nVdo0)Qe|kK+_l) zoI$y5Xq_;;bdm9qLjEj6g>&>D!Zf$QV#0;Etm#;KlBon=PeqCMZ%R}u9(UB(gAa2+ zZGTJN?osr5H~w2zv*_e1nJ}HqeOnk7=rs&ZaY8WL){XJ;1Z{OzT`YJ) zVX>lwJ8f>r#c7(tocmfak4q>fal7L+i;cAYZWESeuy)D8+2H{R0kfGD| z7(VrMTdNy9x-Hxm)O=$;!JJRdb@wG^tuPm+&YUmOYfxgmQ7a6gOB<_1jRZCa%4L?B`=$ z*H&=!|JhAUrNnS0aQA17k;Aj6b~_J(l?EE* zy0xN0qzRWfs=|k7Ynf=iNlov)iR4gWX^Y%}GAVulOQ&oE)2`Ns0D7n^h5t5XIT-h@ z`?j^-`n#Ps)#fCVBws(<_T{Lt$=%tLMI1NP?9IO(6WBS*bV4MNR~_tnanBA>wnKG8 zk8j=zvH?$7;Fn)}MZ$IZ$Z5}6*`lgQkE$OAjTgE26bke=?@H;OK&|J)94Q0l*(6VK zEC4rt=J#)IOnw)5j>#7zfKuP{=^lwmdV}5?*tKMhje+yxpP#IFonr-fqE~8$XKmRt z;1y~5l#m)Hjlu1kGCR~Np}UHhkcr(gv}U7Z5Ie3*s4d5ox1q|aGJz^yhLBf}7?g7p zrfU}qgRvj3Ej?Qa@p1lcz_7ak47()075t{z#Vkj^(E~TD5vB2wp7pS{^6;th@U~Jm z$I!#Lcm4JwF;}oCLYJg~LIm@N#|KJo%TV?2|Iz<;X2+}LD{5M)hba(#8Uvo&Sp(IgcOX~4X{Qhd zWX#ota+nslp$Z|;p{<4Kr0^{d={nkDkMAW(TXwmJ=szJKCh=od129I2_>>BIe|n-m zc4+51!rtkQz1Oh(v;$YEx|geQO)y@EHzZSKNGJ2gQat7?m8_gZ-bs_4Jb7?|NzNeq zaF5_`BHgl-OevFdd4M@Anr?L6;fuVKCpIN^s0rpO0ft-j_gkSU6lb*z{g7+Zv{&RA z&SsBZoDGK{TnqbXiUB8g#SKrJgRl1Q$tpI+pTNk?v`%_|RPr?l@wYIMPOsYaw0=R#Iek;b1hxS!3|K9;_#|DYDP9KOvyJxTgf^! z9lP71&b|+262oUlHI<+J8zFlHY+h(BJUaT389p@*aZ=`~8$Y{q{CM`T#D-NgLyGu% z$Lq#>U%5};$ak)6#8pl5xFE((a+@Zs)ji>ln;V-8&aOsYlt6f%{f*f3(Kmkv>kkz2u5hY4dZGN zv0OFmCYw2O8)dm&b!|LTyiIp-cL?gb#r09%3itLTj)nZGz&dwDQfBK_2)|V#>08uU zcJ&rBp0l$WQ=-h#{WO~x_4x-$Q~pNaWJ7{|6J9E;F0l1oNhfOi5jV0b;gX(FQ2fz? z+LB{i~L@F5{sFh;ECN)@3Ul+m_)jg>hjWPsx0 z2Z=V|caS=iUcDM+u;AAJn8eeGoAQz9Q6yI8BTs29Ai&EeXKaiJu0|bBUaTV4g>M#o ztJa1KL%f^zju@CJ>`P84CafdH#8@^vzbA++9~f{Cbht=^lh1yTD9*`O=ks};c~oAi zGojiGUKDjKY!f8$4<{|6kU)U2>h@h1Y7w-ntdzM&}037jXe}vOel3JvRYox>MMMvDMT>G-m+v zr2pb+X>{|z>#Ne`XPQmm)Fi)j<`Otb z)l8Hf$l>rCWs!c~&!0T?<*2gT*!sNkLA-MIpcchvNh!dw=Su7D=(zbv;iviUHwP%y z+UG{9+;@rP(GJBL*Qg62H-C#>r+$Ho&d!N|yvYu6cc0rJV92OvwNluXQJc#ydfg!a zk>s!*a21@{H{-#IxE8Xc@Z9pu7%bks?b+wW{Y$?t{<$K9&Cn_Tq?`v-s=dwxgX=pl zq?v6n9j~idFd(3J&$<&gJx$P0yxDCl(GbEZVyAO&r#+ncs(j1Vc>RLJcgjol-#Uf8 z0Xu5N^Qxq*nuPn8mPUHsCD0(-jbm3gK6w!d>JUeyHgPP_fH0HpFl6F5D@z`;z3=Ig z-PPczrSvXwarCu}fR3{K`b31in@|P-0!(rNN9*}V?^&i*6U=u~RDd62!Q2wTC$#$! zIoqe*ZiahPcavcmtxUaSyO883*9oe}2Wzb32gk!jVwOf5#Rr-HT%jF7Eao+6z$!7^ zxNsstW6aF$m#*Y5dY3OK^74n^H)1#h0sxz=R&@P*9jYBu34>*L1)#$#geYFCTFEbb zD$joXFa%#wBn$l*V1*;*@Y?wgp;{J21{u9j6MM(UHdef|7!Y7@#SMbb-voZ_=N!_l zIi-~)9#{335q5Qp^xHqinTO}}^8Ta7!#mfvVQ;=M4!P+VU5MzHKbO z0k&M?OaS}n*q8U0BKvPU@b_O%`y@9^OHNlk52#}|%VJ7DbZZ;@fh@8Fmw_*ug|a?q zHNsE56r`SvRrO|@QQ9;`Hhk0dGz=oVPOxcPX}0`|1;q%ucNqg4_M$$6l}zPzm|xaIx`aMmL)iW*4D(vzeS5H8nHoIMQZo6` zZz-7*;j9w~b8x>k06&i!Z3Xl@>^AEN&hkm}_>OIb2CUHeDTi%Lr4^Z+^|xzFPtiwA z`$lu#8Z`4)j-XLEjX*~)dTTm)d%GXu{rn(M4eySjUps#^XU_z>_^LscioEKNp0z@B z^;i4=SPgov;(xi5(GMh%|A}Pk%jv*9!J)$s-$PrCk2*`BO}~Fd<3vJv7JGSO;Vi@v zte60zCto9+hv#tFOk}n_j%~aO8on`szYWyy2;V#PJZkw4@m~ATfCe~d_FeP`;>#nA zbZ%>R9$eH0uWMn&KOf-GE%g_~6{`M4sS+f;Vl$-9sfYM0ahnxRRb_MJop}lnaRxAQ z?^X`#f(V2}-Z_$gVC5!YWW}n59i|L(uV4hTJ>%_%5)onofnN5fp^cUa>0 zQU!bpef6%sJVs`1ZGe)L3rTXUHnWzrBl9tS0av^SFB1#kCg=nc+Wh6kK#Y$D_$Mto z*Mx5KOGNZy0EQ!}B)As-fG1NiW)PhaR-RUwja+XC_E>+$19@2k@Es|(oCvGlq;DQh z^nYKXf(eOI)_0LwWen~O^FxPuJ%>OmAnwT$K+2`y)u&Qj*#Vf+S>9?QqmUXyuLbcS z)ypJL&^!g?4`?4)zyP_0{~-#FG3$WFF7uUUZPq=xoR$ThT*Qwmo7!kRfvt4zy*680 z*-nsK6sbdd6qVoHf~}Orb+ep&yLfW?Gr%d7fIxPQ+~) z3n91+B+?DOJsg9nG5>;~ZGJbsJmO#E`{NZF)LP<~7wyBl7Ty&ppaS&rn$YsW_XLio zh7L}2DargZ3UG^sHnn@nK&P5^vEmOdG2_i#;>eY7u7fc;Lib8=$40v=No6{iPwf)QOyh znI}u4lD_-F8U>OMU11()RVBwb;GeHEz$1KF$wMMC1p$nRZyu}r45f9AIE2-Crg^L0 zcKk67Park>{iMBVft)j0K*(r@4P?y;3-S}}0cW1ey5YjC#dov>+1<%md6wdUWE?MD z9EkGs(jJJU8jRGgvdXmYoAdda&^w^a`QxRwnw_?@^?c1jNeQ+7d&&gfXY_=YPksQP@yU}KDaFx3!z(lboWnTLfzWa@|5!&>gJ9gU?n@w zm_V$!o7LsG)&Pdcwb=wHd1B5{4Ma#GEQO*vZ?3mRlz#9zYT)x#uk}5=Q9rpB#3D9S z=Vbhm0-d$+b2hYS>2@XA(%)jWf(^ItXnw>7OZihn)G$yB3k@BbHW`Ioca3@8w9H7` z1@D}1pwFTm177W*GszwCM0;+2>K}mGaTjl~2P#D{&&cVdB^@^}t&t5r#Y4(LD7RuR z<@XL7qv_vxWK2G??Alz1us&;ROqp(lQH#pXQV5o4$fk!&s7nv2@}rtl7E1Qm%1Rsx-vp z!21wel5clIzUnF9sfjxe1V}2}Y6WjhexA2Q>^?cF zx@5>Z-yYjD#?howUacsI0omkDe}2_AyC);{=T3V;w8cxrs1){yzg#5M8dhFP7UAmY zWxx229V?W&pIjv4-Iz-uhU#X=*okqYQ~Vwc_7pWgGVMjNgS2;_&n%)>!N*Bf*wLI3 z{Ac;3=VT?>HS<)s-#;r?WH^Zy2j#zKFu!W3)!0 zh=YdYRwwf$N+5S@Cjp#xDw#zF_5(;RxEdI9x0gR3yg8%$wdu4cHc`VeaQk^z;b60T z$0bNeCXdo(HE0O;F;Zn|Im^+hKTF6_waC7qo-A3g_{H$j2n#~@kIVC2&3$w5RmL!$ ztcnSw+3cuD@AwpY60c_Vt)fEez-Z(nQ&${}=yBYS4bl4`om-|hU$15+trT)`yYq(y zXf3SVz9prdzXr=dC!F5inS;OFeQDu|n#9)yWmSAP(jFLOJWz~c`^b{2XNyM{JYGYvWG zP6LiRQ>EsNv8`8`CMXI0m-9ca{BP$!rSMm|(ez-pfxMa-V^@L(RTa8=23NN=H>g2L zkm>pOAY$c0=@W)z$2+^iYY)N`5DFWzhKxg(_bNvWZGy1>kz*htD6Jc6$lQzkK6~#I zw**V~*^J+*dg-fx7aa{w=U@7z%Iax?9{sE!_BSER{;RO#BV3V41uS>02)iWGVC0DY z*Dr7Nir2q%M{9-*;HMOS|2CPXcB{}2JqKnI&os80WU=B?L+rT)1i7VINiTM;BotgM z`v0+g_RPt!pgg}yIVwsRJlc}&MeIk)mr9^k-RFo)g9gx-j=uy1p+A zTmL6~a{lk|>2Qc+NO21vw8{_~z*gEVuXb`S! zqRMrrOoaS+QFv3p1mjWjmoLw5@UxU&m+(;$`AHg@DwGvZR9GZF%%u~b+jE6?=?Ti8 zQQ`mAhqtb6O|MA5tN9E2_U<>FE5AY$Gmj15d1Q1twtK}Z-yz#OeJ~PRP|C5sXi9l= zW!sk+{(;r%jLJ5nii6%nztH;=u=}Q?EPDM+N%@q@ob7cv;dZOhd$S@<5IxW7as%1Y z=X;OG$M4%4?_2YE|FL`u*n#Df*Lv8^3`)bA>xX@cf$ZbV7>#*-tlY4wyZ+y}R~eZI zKw7A^l)sg#DbgpYrQuQ+YH{nR)RUIR-Of5}Zkwdb42*99HXx&&?^vr6+_MN^J>xAj zSu5kbyA%|>rTgg1`;yr>T7E%9bgJ-Q!qajAO4&14;~|?o&4%&^E>G!n7!ZrL-NnD( z=4CKgaI7hrqcxFi#s1y>w6g9-42ijFc$fEpE73OKCbFT!=gE_>Ug9ZvT zUUsoYh4Jg^Z@|ia3)2TM#)o@8LJ{mfkx1-6NT%lS78pu;YtP?oM#6z<3JP6Tvp&nG zyy*)w2W-gq+P@iKD91yQRl(pOlT2)?eWmBTgL`*Vh$WVZC0Yw+>}H6!0U5pfvh(16 z0`i7JS+;r&Y>w(A7tW)Z-q*6p&+`aZVJ7GrWG;aBVYdy*GLUNcu}wxjQ~*`T^JS5f4p1u@%Dlei zcuf-v@H%^{a{>IfZ2NluFR_dMa_4Sl_);?5 zDW$Ya?k5Jn2)dZ~Z$D|vq{VG}VZQn_on1;6NYG@-N{vm=V}_|}krT@q%I8Gj$XSTt z%`bn%uA;|BS@dBF_&jIX9vaUAO{ppUd!GC+P;959Un?itn%@^IiUD=#V(-;we0bVg za7B)rRBMpyO&jyPKsyFJ(K6mF(Ronz^NE8N`elSaxy~K+-+KP{u?#kmC>ylSWgl`o zYBLxDC-OX4#Dr7@YZ!ue z$OxuAdz7}j^Z5Z`c`Ny{?XPcO`Ae++b%_73(Ej_pry`fn(hhnr@y38}4Tn4vmlMl* IqWAj$0BxH_7ytkO literal 0 HcmV?d00001 From af80a8ed2ff70c3994a7ef29db82ab43902fb4a7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 11:40:24 +0200 Subject: [PATCH 120/306] mark as spent LP_withdraw --- iguana/exchanges/LP_nativeDEX.c | 5 ++++- iguana/exchanges/LP_transaction.c | 1 + iguana/exchanges/LP_utxo.c | 6 +++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 5969f11a1..6232d159b 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -17,7 +17,10 @@ // LP_nativeDEX.c // marketmaker // -// single utxo allocations alice, reject result, latency +// single utxo allocations alice +// gc cJSON +// more retries for swap sendrawtransaction +// pbca26 unfinished swaps // alice waiting for bestprice //if ( G.LP_pendingswaps != 0 ) //return(-1); diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index 4df4b3895..098d2cb84 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -987,6 +987,7 @@ int32_t LP_vins_select(void *ctx,struct iguana_info *coin,int64_t *totalp,int64_ vp->suppress_pubkeys = suppress_pubkeys; vp->ignore_cltverr = ignore_cltverr; jaddi(vins,LP_inputjson(up->U.txid,up->U.vout,spendscriptstr)); + LP_unavailableset(up->U.txid,up->U.vout,(uint32_t)time(NULL)+600,G.LP_mypub25519); if ( remains <= 0 && i >= numpre-1 ) break; if ( numunspents < 0 ) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 0f2aee2c3..f8b4d7fac 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -59,7 +59,11 @@ int32_t _LP_inuse_delete(bits256 txid,int32_t vout) struct LP_inuse_info *_LP_inuse_add(uint32_t expiration,bits256 otherpub,bits256 txid,int32_t vout) { struct LP_inuse_info *lp; - if ( bits256_nonz(txid) != 0 && LP_numinuse < sizeof(LP_inuse)/sizeof(*LP_inuse) ) + if ( LP_numinuse >= sizeof(LP_inuse)/sizeof(*LP_inuse) ) + { + + } + if ( bits256_nonz(txid) != 0 && ) { if ( (lp= _LP_inuse_find(txid,vout)) == 0 ) { From 57fd772dfc465dca44cf40e50afe2cb278d25a70 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 11:45:41 +0200 Subject: [PATCH 121/306] Test --- iguana/exchanges/LP_utxo.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index f8b4d7fac..6e49013b0 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -58,12 +58,32 @@ int32_t _LP_inuse_delete(bits256 txid,int32_t vout) struct LP_inuse_info *_LP_inuse_add(uint32_t expiration,bits256 otherpub,bits256 txid,int32_t vout) { - struct LP_inuse_info *lp; + struct LP_inuse_info *lp; int32_t i,n,oldesti; uint32_t now,oldest; if ( LP_numinuse >= sizeof(LP_inuse)/sizeof(*LP_inuse) ) { - + now = (uint32_t)time(NULL); + n = 0; + oldesti = -1; + oldest = 0; + for (i=0; i lp->expiration ) + _LP_inuse_delete(lp->txid,lp->vout), n++; + else if ( oldest == 0 || lp->expiration < oldest ) + { + oldest = lp->expiration; + oldesti = i; + } + } + if ( n == 0 ) + { + printf("_LP_inuse_add out of slots error, pick oldesti %d\n",oldesti); + lp = &LP_inuse[oldesti]; + _LP_inuse_delete(lp->txid,lp->vout); + } else printf("expired %d inuse slots\n",n); } - if ( bits256_nonz(txid) != 0 && ) + if ( bits256_nonz(txid) != 0 ) { if ( (lp= _LP_inuse_find(txid,vout)) == 0 ) { From cb09859e0e8975f2b736628cfa0140cf242fd77c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 11:59:39 +0200 Subject: [PATCH 122/306] 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 098d2cb84..3f6ff3e43 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -1020,7 +1020,7 @@ char *LP_createrawtransaction(cJSON **txobjp,int32_t *numvinsp,struct iguana_inf } if ( coin->numutxos < LP_MINDESIRED_UTXOS ) dustcombine = 0; - else if ( coin->numutxos >= LP_MINDESIRED_UTXOS ) + else if ( coin->numutxos >= LP_MAXDESIRED_UTXOS ) dustcombine = 2; else dustcombine = 1; amount = txfee; From be324b6c5fabb94c86a462d9e3fdec26e1b877c5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 12:17:10 +0200 Subject: [PATCH 123/306] Test --- iguana/exchanges/LP_include.h | 4 ++-- iguana/exchanges/LP_nativeDEX.c | 9 ++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index b7dd79e03..5e530f9c1 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -53,8 +53,8 @@ void emscripten_usleep(int32_t x); // returns immediate, no sense for sleeping #define LP_MIN_PEERS 8 #define LP_MAX_PEERS 32 -#define LP_MAXDESIRED_UTXOS 128 -#define LP_MINDESIRED_UTXOS 32 +#define LP_MAXDESIRED_UTXOS (IAMLP != 0 ? 128 : 64) +#define LP_MINDESIRED_UTXOS (IAMLP != 0 ? 32 : 16) #define LP_DUSTCOMBINE_THRESHOLD 1000000 // RTmetrics diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 6232d159b..ae5fa57a7 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -17,16 +17,15 @@ // LP_nativeDEX.c // marketmaker // -// single utxo allocations alice // gc cJSON -// more retries for swap sendrawtransaction +// more retries for swap sendrawtransaction? // pbca26 unfinished swaps -// alice waiting for bestprice -//if ( G.LP_pendingswaps != 0 ) -//return(-1); +// if ( G.LP_pendingswaps != 0 ) return(-1); // bot safe to exit? // // BCH signing +// single utxo allocations alice +// alice waiting for bestprice // previously, it used to show amount, kmd equiv, perc // dPoW security -> 4: KMD notarized, 5: BTC notarized, after next notary elections // bigendian architectures need to use little endian for sighash calcs From 48ffd56a48f7843f33eb5c043a41d04da7b608b4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 13:04:17 +0200 Subject: [PATCH 124/306] Test --- crypto777/cJSON.c | 33 ++++++++++++++++++++++++++++++--- iguana/exchanges/mm.c | 1 + 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/crypto777/cJSON.c b/crypto777/cJSON.c index 8bce48b19..9674910b8 100755 --- a/crypto777/cJSON.c +++ b/crypto777/cJSON.c @@ -578,8 +578,6 @@ cJSON *cJSON_CreateFalse(void) {cJSON *item=cJSON_New_Item();if(item)item->t cJSON *cJSON_CreateBool(int32_t b) {cJSON *item=cJSON_New_Item();if(item)item->type=b?cJSON_True:cJSON_False;return item;} cJSON *cJSON_CreateNumber(double num) {cJSON *item=cJSON_New_Item();if(item){item->type=cJSON_Number;item->valuedouble=num;item->valueint=(int64_t)num;}return item;} cJSON *cJSON_CreateString(const char *string) {cJSON *item=cJSON_New_Item();if(item){item->type=cJSON_String;item->valuestring=cJSON_strdup(string);}return item;} -cJSON *cJSON_CreateArray(void) {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_Array;return item;} -cJSON *cJSON_CreateObject(void) {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_Object;return item;} /* Create Arrays: */ cJSON *cJSON_CreateIntArray(int64_t *numbers,int32_t count) {int32_t i;cJSON *n=0,*p=0,*a=cJSON_CreateArray();for(i=0;a && ichild=n;else suffix_object(p,n);p=n;}return a;} @@ -1129,4 +1127,33 @@ cJSON *addrs_jsonarray(uint64_t *addrs,int32_t num) return(array); } -void free_json(cJSON *json) { if ( json != 0 ) cJSON_Delete(json); } +cJSON *cJSON_CreateArray(void) +{ + cJSON *item = cJSON_New_Item(); + if ( item ) + item->type = cJSON_Array; +#ifdef CJSON_GARBAGECOLLECTION + cJSON_register(item); +#endif + return(item); +} + +cJSON *cJSON_CreateObject(void) +{ + cJSON *item = cJSON_New_Item(); + if ( item ) + item->type = cJSON_Object; +#ifdef CJSON_GARBAGECOLLECTION + cJSON_register(item); +#endif + return item; +} + +void free_json(cJSON *json) +{ +#ifdef CJSON_GARBAGECOLLECTION + cJSON_unregister(item); +#endif + if ( json != 0 ) + cJSON_Delete(json); +} diff --git a/iguana/exchanges/mm.c b/iguana/exchanges/mm.c index 1d2a1bd5e..8ce073d1f 100644 --- a/iguana/exchanges/mm.c +++ b/iguana/exchanges/mm.c @@ -24,6 +24,7 @@ void PNACL_message(char *arg,...) } #define FROM_MARKETMAKER +#define CJSON_GARBAGECOLLECTION #include #include #ifndef NATIVE_WINDOWS From 7e999953c64612ea58110f01b0aa123621781814 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 13:16:29 +0200 Subject: [PATCH 125/306] Test --- crypto777/cJSON.c | 2 +- iguana/m_mm | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crypto777/cJSON.c b/crypto777/cJSON.c index 9674910b8..404931fcf 100755 --- a/crypto777/cJSON.c +++ b/crypto777/cJSON.c @@ -1144,7 +1144,7 @@ cJSON *cJSON_CreateObject(void) if ( item ) item->type = cJSON_Object; #ifdef CJSON_GARBAGECOLLECTION - cJSON_register(item); + cJSON_register(item); fff #endif return item; } diff --git a/iguana/m_mm b/iguana/m_mm index b5ba405ca..3905b5d84 100755 --- a/iguana/m_mm +++ b/iguana/m_mm @@ -1,3 +1,3 @@ cd secp256k1; ./m_unix; cd .. cd ../crypto777; ./m_LP; cd ../iguana -gcc -g -o marketmaker -I../crypto777 exchanges/mm.c mini-gmp.c secp256k1.o ../agents/libcrypto777.a -lnanomsg -lcurl -lpthread -lm +gcc -DFROM_MARKETMAKER -g -o marketmaker -I../crypto777 exchanges/mm.c ../crypto777/cJSON.c mini-gmp.c secp256k1.o ../agents/libcrypto777.a -lnanomsg -lcurl -lpthread -lm From 32191a3f60704664049426d0242e0bf5753a36c2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 13:26:24 +0200 Subject: [PATCH 126/306] Test --- crypto777/cJSON.c | 2 ++ iguana/exchanges/mm.c | 3 +++ 2 files changed, 5 insertions(+) diff --git a/crypto777/cJSON.c b/crypto777/cJSON.c index 404931fcf..a9bb74dd7 100755 --- a/crypto777/cJSON.c +++ b/crypto777/cJSON.c @@ -25,6 +25,8 @@ /* JSON parser in C. */ #include +#define CJSON_GARBAGECOLLECTION + #include "../includes/cJSON.h" #ifndef DBL_EPSILON diff --git a/iguana/exchanges/mm.c b/iguana/exchanges/mm.c index 8ce073d1f..56498394a 100644 --- a/iguana/exchanges/mm.c +++ b/iguana/exchanges/mm.c @@ -23,7 +23,10 @@ void PNACL_message(char *arg,...) { } +#ifndef FROM_MARKETMAKER #define FROM_MARKETMAKER +#endif + #define CJSON_GARBAGECOLLECTION #include #include From 3df1acbc3b4bd1470d291f8c36c21d3a29477032 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 13:28:05 +0200 Subject: [PATCH 127/306] Test --- crypto777/cJSON.c | 2 -- iguana/exchanges/mm.c | 5 +++-- iguana/m_mm | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/crypto777/cJSON.c b/crypto777/cJSON.c index a9bb74dd7..404931fcf 100755 --- a/crypto777/cJSON.c +++ b/crypto777/cJSON.c @@ -25,8 +25,6 @@ /* JSON parser in C. */ #include -#define CJSON_GARBAGECOLLECTION - #include "../includes/cJSON.h" #ifndef DBL_EPSILON diff --git a/iguana/exchanges/mm.c b/iguana/exchanges/mm.c index 56498394a..e20b1dcb6 100644 --- a/iguana/exchanges/mm.c +++ b/iguana/exchanges/mm.c @@ -23,11 +23,12 @@ void PNACL_message(char *arg,...) { } -#ifndef FROM_MARKETMAKER #define FROM_MARKETMAKER -#endif +#ifndef CJSON_GARBAGECOLLECTION #define CJSON_GARBAGECOLLECTION +#endif + #include #include #ifndef NATIVE_WINDOWS diff --git a/iguana/m_mm b/iguana/m_mm index 3905b5d84..0609d842c 100755 --- a/iguana/m_mm +++ b/iguana/m_mm @@ -1,3 +1,3 @@ cd secp256k1; ./m_unix; cd .. cd ../crypto777; ./m_LP; cd ../iguana -gcc -DFROM_MARKETMAKER -g -o marketmaker -I../crypto777 exchanges/mm.c ../crypto777/cJSON.c mini-gmp.c secp256k1.o ../agents/libcrypto777.a -lnanomsg -lcurl -lpthread -lm +gcc -DCJSON_GARBAGECOLLECTION -g -o marketmaker -I../crypto777 exchanges/mm.c ../crypto777/cJSON.c mini-gmp.c secp256k1.o ../agents/libcrypto777.a -lnanomsg -lcurl -lpthread -lm From 62ff96b246815feebf2e2d55e39f75d96cec226b Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 13:29:15 +0200 Subject: [PATCH 128/306] Test --- crypto777/cJSON.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crypto777/cJSON.c b/crypto777/cJSON.c index 404931fcf..9674910b8 100755 --- a/crypto777/cJSON.c +++ b/crypto777/cJSON.c @@ -1144,7 +1144,7 @@ cJSON *cJSON_CreateObject(void) if ( item ) item->type = cJSON_Object; #ifdef CJSON_GARBAGECOLLECTION - cJSON_register(item); fff + cJSON_register(item); #endif return item; } From 21b83eaf5fc3d5e978d247524c46dd2745834c15 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 13:31:20 +0200 Subject: [PATCH 129/306] Test --- includes/cJSON.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/includes/cJSON.h b/includes/cJSON.h index 77e0752e6..cd8e6d00f 100755 --- a/includes/cJSON.h +++ b/includes/cJSON.h @@ -218,6 +218,8 @@ extern "C" char *nxt64str2(uint64_t nxt64bits); cJSON *addrs_jsonarray(uint64_t *addrs,int32_t num); int32_t myatoi(char *str,int32_t range); + void cJSON_register(cJSON *item); + void cJSON_unregister(cJSON *item); char *stringifyM(char *str); #define replace_backslashquotes unstringify From fc1c161db6650d8cd989ae00d742596606d1116d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 13:47:36 +0200 Subject: [PATCH 130/306] Test --- iguana/exchanges/LP_nativeDEX.c | 3 ++- iguana/exchanges/LP_utxo.c | 36 +++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index ae5fa57a7..c7ba59d0b 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -82,7 +82,7 @@ void LP_millistats_update(struct LP_millistats *mp) } #include "LP_include.h" -portable_mutex_t LP_peermutex,LP_UTXOmutex,LP_utxomutex,LP_commandmutex,LP_cachemutex,LP_swaplistmutex,LP_forwardmutex,LP_pubkeymutex,LP_networkmutex,LP_psockmutex,LP_coinmutex,LP_messagemutex,LP_portfoliomutex,LP_electrummutex,LP_butxomutex,LP_reservedmutex,LP_nanorecvsmutex,LP_tradebotsmutex,LP_gcmutex,LP_inusemutex; +portable_mutex_t LP_peermutex,LP_UTXOmutex,LP_utxomutex,LP_commandmutex,LP_cachemutex,LP_swaplistmutex,LP_forwardmutex,LP_pubkeymutex,LP_networkmutex,LP_psockmutex,LP_coinmutex,LP_messagemutex,LP_portfoliomutex,LP_electrummutex,LP_butxomutex,LP_reservedmutex,LP_nanorecvsmutex,LP_tradebotsmutex,LP_gcmutex,LP_inusemutex,LP_cJSONmutex; int32_t LP_canbind; char *Broadcaststr,*Reserved_msgs[2][1000]; int32_t num_Reserved_msgs[2],max_Reserved_msgs[2]; @@ -938,6 +938,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu portable_mutex_init(&LP_reservedmutex); portable_mutex_init(&LP_nanorecvsmutex); portable_mutex_init(&LP_tradebotsmutex); + portable_mutex_init(&LP_cJSONmutex); myipaddr = clonestr("127.0.0.1"); #ifndef _WIN32 #ifndef FROM_JS diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 6e49013b0..cdfff09a1 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -27,6 +27,42 @@ struct LP_inuse_info } LP_inuse[1024]; int32_t LP_numinuse; +struct cJSON_list +{ + struct cJSON_list *next,*prev; + cJSON *item; + uint32_t timestamp; +} *LP_cJSONlist; + +void cJSON_register(cJSON *item) +{ + struct cJSON_list *ptr; + ptr = calloc(1,sizeof(*ptr)); + ptr->timestamp = (uint32_t)time(NULL); + ptr->item = item; + portable_mutex_lock(&LP_cJSONmutex); + DL_APPEND(LP_cJSONlist,ptr); + portable_mutex_unlock(&LP_cJSONmutex); +} + +void cJSON_unregister(cJSON *item) +{ + struct cJSON_list *ptr,*tmp; + DL_FOREACH_SAFE(LP_cJSONlist,ptr,tmp) + { + if ( ptr->item == item ) + break; + ptr = 0; + } + if ( ptr != 0 ) + { + portable_mutex_lock(&LP_cJSONmutex); + DL_DELETE(LP_cJSONlist,ptr); + free(ptr); + portable_mutex_unlock(&LP_cJSONmutex); + } +} + struct LP_inuse_info *_LP_inuse_find(bits256 txid,int32_t vout) { int32_t i; From 5770810c609ab69de70d92bebe61a202bf8fcb5f Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 13:48:38 +0200 Subject: [PATCH 131/306] Test --- crypto777/cJSON.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crypto777/cJSON.c b/crypto777/cJSON.c index 9674910b8..28f02bafc 100755 --- a/crypto777/cJSON.c +++ b/crypto777/cJSON.c @@ -1149,11 +1149,11 @@ cJSON *cJSON_CreateObject(void) return item; } -void free_json(cJSON *json) +void free_json(cJSON *item) { #ifdef CJSON_GARBAGECOLLECTION cJSON_unregister(item); #endif if ( json != 0 ) - cJSON_Delete(json); + cJSON_Delete(item); } From b86d13d6b503774c2c54b4c83c02560396b71f1c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 13:49:30 +0200 Subject: [PATCH 132/306] Test --- crypto777/cJSON.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crypto777/cJSON.c b/crypto777/cJSON.c index 28f02bafc..555fdf29c 100755 --- a/crypto777/cJSON.c +++ b/crypto777/cJSON.c @@ -1154,6 +1154,6 @@ void free_json(cJSON *item) #ifdef CJSON_GARBAGECOLLECTION cJSON_unregister(item); #endif - if ( json != 0 ) + if ( item != 0 ) cJSON_Delete(item); } From 2d23ba8dd6bf0d45f5bd5c8cb32d4498b354aa26 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 14:15:08 +0200 Subject: [PATCH 133/306] Test --- iguana/exchanges/LP_utxo.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index cdfff09a1..6d22d3faf 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -45,9 +45,25 @@ void cJSON_register(cJSON *item) portable_mutex_unlock(&LP_cJSONmutex); } +char *mbstr(char *str,double n); void cJSON_unregister(cJSON *item) { - struct cJSON_list *ptr,*tmp; + static uint32_t lasttime; + char *tmpstr,str[65]; int32_t n; uint64_t total; struct cJSON_list *ptr,*tmp; + if ( time(NULL) > lasttime+600 ) + { + n = 0; + total = 0; + DL_FOREACH_SAFE(LP_cJSONlist,ptr,tmp) + { + tmpstr = jprint(ptr->item,0); + total += strlen(tmpstr); + free(tmpstr); + n++; + } + printf("total %d cJSON pending %s\n",n,mbstr(str,total)); + lasttime = (uint32_t)time(NULL); + } DL_FOREACH_SAFE(LP_cJSONlist,ptr,tmp) { if ( ptr->item == item ) @@ -60,7 +76,7 @@ void cJSON_unregister(cJSON *item) DL_DELETE(LP_cJSONlist,ptr); free(ptr); portable_mutex_unlock(&LP_cJSONmutex); - } + } else printf("cJSON_unregister of unknown %p\n",item); } struct LP_inuse_info *_LP_inuse_find(bits256 txid,int32_t vout) From 19634a3c9afa042ef0b92574c8f608ed3a55770a Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 14:18:04 +0200 Subject: [PATCH 134/306] Test --- iguana/exchanges/LP_utxo.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 6d22d3faf..e36afaff5 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -72,11 +72,12 @@ void cJSON_unregister(cJSON *item) } if ( ptr != 0 ) { + printf("found %p\n",item); portable_mutex_lock(&LP_cJSONmutex); DL_DELETE(LP_cJSONlist,ptr); free(ptr); portable_mutex_unlock(&LP_cJSONmutex); - } else printf("cJSON_unregister of unknown %p\n",item); + } //else printf("cJSON_unregister of unknown %p\n",item); } struct LP_inuse_info *_LP_inuse_find(bits256 txid,int32_t vout) From ce6caefbed81964237feb6d8715a6ca8dfc41b78 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 14:24:45 +0200 Subject: [PATCH 135/306] Test --- iguana/exchanges/LP_utxo.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index e36afaff5..a807f2fcc 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -37,6 +37,7 @@ struct cJSON_list void cJSON_register(cJSON *item) { struct cJSON_list *ptr; + printf(" register %p\n",item); ptr = calloc(1,sizeof(*ptr)); ptr->timestamp = (uint32_t)time(NULL); ptr->item = item; @@ -50,6 +51,7 @@ void cJSON_unregister(cJSON *item) { static uint32_t lasttime; char *tmpstr,str[65]; int32_t n; uint64_t total; struct cJSON_list *ptr,*tmp; + printf("unregister %p\n",item); if ( time(NULL) > lasttime+600 ) { n = 0; From 240d250f68c28d0cfe50022e381918f472870639 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 14:34:25 +0200 Subject: [PATCH 136/306] Test --- iguana/exchanges/LP_utxo.c | 2 +- iguana/exchanges/invreset | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index a807f2fcc..ce9c0f4ca 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -52,7 +52,7 @@ void cJSON_unregister(cJSON *item) static uint32_t lasttime; char *tmpstr,str[65]; int32_t n; uint64_t total; struct cJSON_list *ptr,*tmp; printf("unregister %p\n",item); - if ( time(NULL) > lasttime+600 ) + if ( time(NULL) > lasttime+6 ) { n = 0; total = 0; diff --git a/iguana/exchanges/invreset b/iguana/exchanges/invreset index f0b1c79e3..0304c7503 100755 --- a/iguana/exchanges/invreset +++ b/iguana/exchanges/invreset @@ -1,3 +1,4 @@ +#!/bin/bash source userpass source passphrase curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"inventory\",\"coin\":\"KMD\",\"reset\":1,\"passphrase\":\"$passphrase\"}" From d70d5c835db1c4661513f8b3c9b2280154c09b23 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 14:41:16 +0200 Subject: [PATCH 137/306] Test --- iguana/exchanges/LP_utxo.c | 13 ++++++------- includes/cJSON.h | 1 + 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index ce9c0f4ca..a329aaef5 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -31,16 +31,17 @@ struct cJSON_list { struct cJSON_list *next,*prev; cJSON *item; - uint32_t timestamp; + uint32_t timestamp,cjsonid; } *LP_cJSONlist; void cJSON_register(cJSON *item) { struct cJSON_list *ptr; - printf(" register %p\n",item); ptr = calloc(1,sizeof(*ptr)); ptr->timestamp = (uint32_t)time(NULL); ptr->item = item; + item->cjsonid = rand(); + ptr->cjsonid = item->cjsonid; portable_mutex_lock(&LP_cJSONmutex); DL_APPEND(LP_cJSONlist,ptr); portable_mutex_unlock(&LP_cJSONmutex); @@ -51,8 +52,7 @@ void cJSON_unregister(cJSON *item) { static uint32_t lasttime; char *tmpstr,str[65]; int32_t n; uint64_t total; struct cJSON_list *ptr,*tmp; - printf("unregister %p\n",item); - if ( time(NULL) > lasttime+6 ) + //if ( time(NULL) > lasttime+6 ) { n = 0; total = 0; @@ -68,18 +68,17 @@ void cJSON_unregister(cJSON *item) } DL_FOREACH_SAFE(LP_cJSONlist,ptr,tmp) { - if ( ptr->item == item ) + if ( ptr->cjsonid == item->cjsonid )//ptr->item == item ) break; ptr = 0; } if ( ptr != 0 ) { - printf("found %p\n",item); portable_mutex_lock(&LP_cJSONmutex); DL_DELETE(LP_cJSONlist,ptr); free(ptr); portable_mutex_unlock(&LP_cJSONmutex); - } //else printf("cJSON_unregister of unknown %p\n",item); + } else printf("cJSON_unregister of unknown %p\n",item); } struct LP_inuse_info *_LP_inuse_find(bits256 txid,int32_t vout) diff --git a/includes/cJSON.h b/includes/cJSON.h index cd8e6d00f..3ecdadc69 100755 --- a/includes/cJSON.h +++ b/includes/cJSON.h @@ -73,6 +73,7 @@ extern "C" double valuedouble; /* The item's number, if type==cJSON_Number */ char *string; /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */ + uint32_t cjsonid; } cJSON; typedef struct cJSON_Hooks { From 006fcdaea0a39052d5ff699b02cb3ea0fcff5639 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 14:42:32 +0200 Subject: [PATCH 138/306] 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 a329aaef5..8a54d97ae 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -78,7 +78,7 @@ void cJSON_unregister(cJSON *item) DL_DELETE(LP_cJSONlist,ptr); free(ptr); portable_mutex_unlock(&LP_cJSONmutex); - } else printf("cJSON_unregister of unknown %p\n",item); + } else printf("cJSON_unregister of unknown %p %u\n",item,item->cjsonid); } struct LP_inuse_info *_LP_inuse_find(bits256 txid,int32_t vout) From 5e851f41eadad9b2f13beca5ef25db937970b535 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 14:46:40 +0200 Subject: [PATCH 139/306] Test --- iguana/exchanges/LP_utxo.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 8a54d97ae..d785ca933 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -58,9 +58,11 @@ void cJSON_unregister(cJSON *item) total = 0; DL_FOREACH_SAFE(LP_cJSONlist,ptr,tmp) { - tmpstr = jprint(ptr->item,0); - total += strlen(tmpstr); - free(tmpstr); + if ( (tmpstr= jprint(ptr->item,0)) != 0 ) + { + total += strlen(tmpstr); + free(tmpstr); + } n++; } printf("total %d cJSON pending %s\n",n,mbstr(str,total)); From 86e4295c24ea27dfd2528426d565f0f158bca475 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 14:50:28 +0200 Subject: [PATCH 140/306] Test --- crypto777/bitcoind_RPC.c | 2 +- iguana/exchanges/LP_utxo.c | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/crypto777/bitcoind_RPC.c b/crypto777/bitcoind_RPC.c index 4f0a9cdd4..98c7e7eb0 100755 --- a/crypto777/bitcoind_RPC.c +++ b/crypto777/bitcoind_RPC.c @@ -56,7 +56,7 @@ char *post_process_bitcoind_RPC(char *debugstr,char *command,char *rpcstr,char * char *retstr = 0; cJSON *json,*result,*error; #ifdef FROM_MARKETMAKER - usleep(5000); + usleep(3000); #endif //printf("<<<<<<<<<<< bitcoind_RPC: %s post_process_bitcoind_RPC.%s.[%s]\n",debugstr,command,rpcstr); if ( command == 0 || rpcstr == 0 || rpcstr[0] == 0 ) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index d785ca933..c78b475e7 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -58,10 +58,13 @@ void cJSON_unregister(cJSON *item) total = 0; DL_FOREACH_SAFE(LP_cJSONlist,ptr,tmp) { - if ( (tmpstr= jprint(ptr->item,0)) != 0 ) + if ( ptr->item != 0 && ptr->item->child != 0 ) { - total += strlen(tmpstr); - free(tmpstr); + if ( (tmpstr= jprint(ptr->item,0)) != 0 ) + { + total += strlen(tmpstr); + free(tmpstr); + } } n++; } From 54a26a1ebad8d4f05dc943e21de0d681cac5b94a Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 14:54:30 +0200 Subject: [PATCH 141/306] Test --- iguana/exchanges/LP_utxo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index c78b475e7..fa1210cfa 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -58,14 +58,14 @@ void cJSON_unregister(cJSON *item) total = 0; DL_FOREACH_SAFE(LP_cJSONlist,ptr,tmp) { - if ( ptr->item != 0 && ptr->item->child != 0 ) + /*if ( ptr->item != 0 && ptr->item->child != 0 ) { if ( (tmpstr= jprint(ptr->item,0)) != 0 ) { total += strlen(tmpstr); free(tmpstr); } - } + }*/ n++; } printf("total %d cJSON pending %s\n",n,mbstr(str,total)); From 66c434d82d697843a93ff2bca53449cc9e7a1353 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 14:55:57 +0200 Subject: [PATCH 142/306] Test --- iguana/exchanges/LP_utxo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index fa1210cfa..de6660b86 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -58,14 +58,14 @@ void cJSON_unregister(cJSON *item) total = 0; DL_FOREACH_SAFE(LP_cJSONlist,ptr,tmp) { - /*if ( ptr->item != 0 && ptr->item->child != 0 ) + if ( ptr->item != 0 && ptr->item->child != 0 && ptr->cjsonid != 0 ) { if ( (tmpstr= jprint(ptr->item,0)) != 0 ) { total += strlen(tmpstr); free(tmpstr); } - }*/ + } n++; } printf("total %d cJSON pending %s\n",n,mbstr(str,total)); From a25ab17cbbe7c727b44469f96794a3e0b56f3832 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 15:00:04 +0200 Subject: [PATCH 143/306] Test --- iguana/exchanges/LP_utxo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index de6660b86..933af800a 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -58,14 +58,14 @@ void cJSON_unregister(cJSON *item) total = 0; DL_FOREACH_SAFE(LP_cJSONlist,ptr,tmp) { - if ( ptr->item != 0 && ptr->item->child != 0 && ptr->cjsonid != 0 ) + /*if ( ptr->item != 0 && ptr->item->child != 0 && ptr->cjsonid != 0 ) { if ( (tmpstr= jprint(ptr->item,0)) != 0 ) { total += strlen(tmpstr); free(tmpstr); } - } + }*/ n++; } printf("total %d cJSON pending %s\n",n,mbstr(str,total)); From 7c29efc217e67da5540e904df1fd2e96d933c7ed Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 15:08:29 +0200 Subject: [PATCH 144/306] Test --- iguana/exchanges/LP_utxo.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 933af800a..8512572e6 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -51,11 +51,10 @@ char *mbstr(char *str,double n); void cJSON_unregister(cJSON *item) { static uint32_t lasttime; - char *tmpstr,str[65]; int32_t n; uint64_t total; struct cJSON_list *ptr,*tmp; - //if ( time(NULL) > lasttime+6 ) + int32_t n; struct cJSON_list *ptr,*tmp; uint32_t now; + if ( (now= time(NULL)) > lasttime+6 ) { n = 0; - total = 0; DL_FOREACH_SAFE(LP_cJSONlist,ptr,tmp) { /*if ( ptr->item != 0 && ptr->item->child != 0 && ptr->cjsonid != 0 ) @@ -68,13 +67,21 @@ void cJSON_unregister(cJSON *item) }*/ n++; } - printf("total %d cJSON pending %s\n",n,mbstr(str,total)); + printf("total %d cJSON pending\n",n); lasttime = (uint32_t)time(NULL); } DL_FOREACH_SAFE(LP_cJSONlist,ptr,tmp) { - if ( ptr->cjsonid == item->cjsonid )//ptr->item == item ) + if ( ptr->item == item ) break; + else if ( now > ptr->timestamp+60 ) + { + portable_mutex_lock(&LP_cJSONmutex); + DL_DELETE(LP_cJSONlist,ptr); + portable_mutex_unlock(&LP_cJSONmutex); + cJSON_Delete(ptr->item); + free(ptr); + } ptr = 0; } if ( ptr != 0 ) From 02df7289d30f72ab6d33331aeba4808a012da5ec Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 15:10:11 +0200 Subject: [PATCH 145/306] Test --- iguana/exchanges/LP_utxo.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 8512572e6..4b0828a3b 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -79,6 +79,7 @@ void cJSON_unregister(cJSON *item) portable_mutex_lock(&LP_cJSONmutex); DL_DELETE(LP_cJSONlist,ptr); portable_mutex_unlock(&LP_cJSONmutex); + printf("free expired\n"); cJSON_Delete(ptr->item); free(ptr); } @@ -90,7 +91,7 @@ void cJSON_unregister(cJSON *item) DL_DELETE(LP_cJSONlist,ptr); free(ptr); portable_mutex_unlock(&LP_cJSONmutex); - } else printf("cJSON_unregister of unknown %p %u\n",item,item->cjsonid); + } //else printf("cJSON_unregister of unknown %p %u\n",item,item->cjsonid); } struct LP_inuse_info *_LP_inuse_find(bits256 txid,int32_t vout) From 49c0feed90b0686b8210d85d8d808e09f2240e19 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 15:12:56 +0200 Subject: [PATCH 146/306] Test --- iguana/exchanges/LP_utxo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 4b0828a3b..1befc1dcf 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -72,9 +72,9 @@ void cJSON_unregister(cJSON *item) } DL_FOREACH_SAFE(LP_cJSONlist,ptr,tmp) { - if ( ptr->item == item ) + if ( ptr->cjsonid == item->cjsonid ) break; - else if ( now > ptr->timestamp+60 ) + else if ( now > ptr->timestamp+60 && item->cjsonid != 0 ) { portable_mutex_lock(&LP_cJSONmutex); DL_DELETE(LP_cJSONlist,ptr); From bea2f74a87beb53592f02099935c6b01a883853b Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 15:16:16 +0200 Subject: [PATCH 147/306] Test --- crypto777/cJSON.c | 18 +++++++++--------- iguana/m_mm | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/crypto777/cJSON.c b/crypto777/cJSON.c index 555fdf29c..93438fe79 100755 --- a/crypto777/cJSON.c +++ b/crypto777/cJSON.c @@ -1132,9 +1132,9 @@ cJSON *cJSON_CreateArray(void) cJSON *item = cJSON_New_Item(); if ( item ) item->type = cJSON_Array; -#ifdef CJSON_GARBAGECOLLECTION - cJSON_register(item); -#endif +//#ifdef CJSON_GARBAGECOLLECTION +// cJSON_register(item); +//#endif return(item); } @@ -1143,17 +1143,17 @@ cJSON *cJSON_CreateObject(void) cJSON *item = cJSON_New_Item(); if ( item ) item->type = cJSON_Object; -#ifdef CJSON_GARBAGECOLLECTION - cJSON_register(item); -#endif +//#ifdef CJSON_GARBAGECOLLECTION +// cJSON_register(item); +//#endif return item; } void free_json(cJSON *item) { -#ifdef CJSON_GARBAGECOLLECTION - cJSON_unregister(item); -#endif +//#ifdef CJSON_GARBAGECOLLECTION +// cJSON_unregister(item); +//#endif if ( item != 0 ) cJSON_Delete(item); } diff --git a/iguana/m_mm b/iguana/m_mm index 0609d842c..36a0acad1 100755 --- a/iguana/m_mm +++ b/iguana/m_mm @@ -1,3 +1,3 @@ cd secp256k1; ./m_unix; cd .. cd ../crypto777; ./m_LP; cd ../iguana -gcc -DCJSON_GARBAGECOLLECTION -g -o marketmaker -I../crypto777 exchanges/mm.c ../crypto777/cJSON.c mini-gmp.c secp256k1.o ../agents/libcrypto777.a -lnanomsg -lcurl -lpthread -lm +gcc -g -o marketmaker -I../crypto777 exchanges/mm.c ../crypto777/cJSON.c mini-gmp.c secp256k1.o ../agents/libcrypto777.a -lnanomsg -lcurl -lpthread -lm From b435fe804c7af8da3ce399b9320346f851a2cf5c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 15:18:53 +0200 Subject: [PATCH 148/306] Test --- iguana/exchanges/LP_commands.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 56ed047e4..a241aa4ab 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -35,7 +35,9 @@ char *LP_numutxos() char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *remoteaddr,uint16_t port) // from rpc port { char *method,*userpass,*base,*rel,*coin,*retstr = 0; int32_t changed,flag = 0; cJSON *retjson,*reqjson = 0; struct iguana_info *ptr; - //printf("stats_JSON(%s)\n",jprint(argjson,0)); + retstr = jprint(argjson,0); + printf("stats_JSON(%s)\n",retstr); + free(retstr), retstr = 0; method = jstr(argjson,"method"); /*if ( (ipaddr= jstr(argjson,"ipaddr")) != 0 && (argport= juint(argjson,"port")) != 0 && (method == 0 || strcmp(method,"electrum") != 0) ) { From cd61cdb07f517ed47b0294890917cc67ae8bb53d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 15:25:35 +0200 Subject: [PATCH 149/306] Test --- iguana/exchanges/LP_commands.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index a241aa4ab..b06fab289 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -35,10 +35,12 @@ char *LP_numutxos() char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *remoteaddr,uint16_t port) // from rpc port { char *method,*userpass,*base,*rel,*coin,*retstr = 0; int32_t changed,flag = 0; cJSON *retjson,*reqjson = 0; struct iguana_info *ptr; - retstr = jprint(argjson,0); - printf("stats_JSON(%s)\n",retstr); - free(retstr), retstr = 0; - method = jstr(argjson,"method"); +retstr = jprint(argjson,0); +printf("stats_JSON(%s)\n",retstr); +free(retstr), retstr = 0; +method = jstr(argjson,"method"); +if ( strcmp(method,"uitem") == 0 || strcmp(method,"postutxos") == 0 ) + return(clonestr("{}")); /*if ( (ipaddr= jstr(argjson,"ipaddr")) != 0 && (argport= juint(argjson,"port")) != 0 && (method == 0 || strcmp(method,"electrum") != 0) ) { if ( strcmp(ipaddr,"127.0.0.1") != 0 && argport >= 1000 ) From db088b68ae6cafedf1e013d802ddc030ec2ecaea Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 15:28:56 +0200 Subject: [PATCH 150/306] Test --- iguana/exchanges/LP_commands.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index b06fab289..c583c5346 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -35,12 +35,12 @@ char *LP_numutxos() char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *remoteaddr,uint16_t port) // from rpc port { char *method,*userpass,*base,*rel,*coin,*retstr = 0; int32_t changed,flag = 0; cJSON *retjson,*reqjson = 0; struct iguana_info *ptr; -retstr = jprint(argjson,0); -printf("stats_JSON(%s)\n",retstr); -free(retstr), retstr = 0; method = jstr(argjson,"method"); if ( strcmp(method,"uitem") == 0 || strcmp(method,"postutxos") == 0 ) return(clonestr("{}")); +retstr = jprint(argjson,0); +printf("stats_JSON(%s)\n",retstr); +free(retstr), retstr = 0; /*if ( (ipaddr= jstr(argjson,"ipaddr")) != 0 && (argport= juint(argjson,"port")) != 0 && (method == 0 || strcmp(method,"electrum") != 0) ) { if ( strcmp(ipaddr,"127.0.0.1") != 0 && argport >= 1000 ) From ecce4d9c0855bc60f49b675836b7ea4ba5272383 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 15:49:57 +0200 Subject: [PATCH 151/306] Test --- iguana/exchanges/LP_commands.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index c583c5346..d4487782d 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -36,7 +36,9 @@ char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *r { char *method,*userpass,*base,*rel,*coin,*retstr = 0; int32_t changed,flag = 0; cJSON *retjson,*reqjson = 0; struct iguana_info *ptr; method = jstr(argjson,"method"); -if ( strcmp(method,"uitem") == 0 || strcmp(method,"postutxos") == 0 ) +if ( strcmp(method,"uitem") == 0 || strcmp(method,"postutxos") == 0 + || strcmp(method,"notify") == 0 || strcmp(method,"postprice") == 0 + ) return(clonestr("{}")); retstr = jprint(argjson,0); printf("stats_JSON(%s)\n",retstr); From 3843e3d1e843b7cc034f8b2fad849016c976f60f Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 16:02:17 +0200 Subject: [PATCH 152/306] Test --- iguana/exchanges/LP_commands.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index d4487782d..fdc2bc6ff 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -37,7 +37,8 @@ char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *r char *method,*userpass,*base,*rel,*coin,*retstr = 0; int32_t changed,flag = 0; cJSON *retjson,*reqjson = 0; struct iguana_info *ptr; method = jstr(argjson,"method"); if ( strcmp(method,"uitem") == 0 || strcmp(method,"postutxos") == 0 - || strcmp(method,"notify") == 0 || strcmp(method,"postprice") == 0 + || strcmp(method,"notify") == 0 + //|| strcmp(method,"postprice") == 0 ) return(clonestr("{}")); retstr = jprint(argjson,0); From 48623418bbeafdae3cc01059f872e52811e3a416 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 16:04:05 +0200 Subject: [PATCH 153/306] Test --- iguana/exchanges/LP_commands.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index fdc2bc6ff..3fc34e752 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -36,14 +36,11 @@ char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *r { char *method,*userpass,*base,*rel,*coin,*retstr = 0; int32_t changed,flag = 0; cJSON *retjson,*reqjson = 0; struct iguana_info *ptr; method = jstr(argjson,"method"); -if ( strcmp(method,"uitem") == 0 || strcmp(method,"postutxos") == 0 - || strcmp(method,"notify") == 0 +if ( //strcmp(method,"uitem") == 0 || strcmp(method,"postutxos") == 0 || + strcmp(method,"notify") == 0 //|| strcmp(method,"postprice") == 0 ) return(clonestr("{}")); -retstr = jprint(argjson,0); -printf("stats_JSON(%s)\n",retstr); -free(retstr), retstr = 0; /*if ( (ipaddr= jstr(argjson,"ipaddr")) != 0 && (argport= juint(argjson,"port")) != 0 && (method == 0 || strcmp(method,"electrum") != 0) ) { if ( strcmp(ipaddr,"127.0.0.1") != 0 && argport >= 1000 ) From 12a6db1ac053c50ca87cde167292b5df8f11dcfc Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 16:06:28 +0200 Subject: [PATCH 154/306] Test --- iguana/exchanges/LP_commands.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 3fc34e752..40f7151c3 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -38,7 +38,7 @@ char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *r method = jstr(argjson,"method"); if ( //strcmp(method,"uitem") == 0 || strcmp(method,"postutxos") == 0 || strcmp(method,"notify") == 0 - //|| strcmp(method,"postprice") == 0 + || strcmp(method,"postprice") == 0 ) return(clonestr("{}")); /*if ( (ipaddr= jstr(argjson,"ipaddr")) != 0 && (argport= juint(argjson,"port")) != 0 && (method == 0 || strcmp(method,"electrum") != 0) ) From 8743a5701fb5265647f5f03f36e1dccfd9074061 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 16:37:34 +0200 Subject: [PATCH 155/306] Test --- iguana/exchanges/LP_cache.c | 6 +++--- iguana/exchanges/LP_commands.c | 6 +++--- iguana/exchanges/LP_swap.c | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/iguana/exchanges/LP_cache.c b/iguana/exchanges/LP_cache.c index a08828966..fdc734fe9 100644 --- a/iguana/exchanges/LP_cache.c +++ b/iguana/exchanges/LP_cache.c @@ -45,10 +45,10 @@ struct LP_transaction *LP_create_transaction(struct iguana_info *coin,bits256 tx vins = jarray(&numvins,txobj,"vin"); vouts = jarray(&numvouts,txobj,"vout"); tx = LP_transactionadd(coin,txid,height,numvouts,numvins); - tx->serialized = serialized; - //free(serialized); + tx->serialized = 0;//serialized; + free(serialized); tx->fpos = fpos; - tx->len = tx->len; + tx->len = 0;//tx->len; tx->SPV = tx->height = height; //printf("tx.%s numvins.%d numvouts.%d\n",bits256_str(str,txid),numvins,numvouts); for (i=0; i= 1000 ) diff --git a/iguana/exchanges/LP_swap.c b/iguana/exchanges/LP_swap.c index 03d08d69e..7e31d21e8 100644 --- a/iguana/exchanges/LP_swap.c +++ b/iguana/exchanges/LP_swap.c @@ -895,7 +895,7 @@ void LP_aliceloop(void *_swap) } basilisk_swap_finished(swap); printf("finish swap.%p\n",swap); - //free(swap); + free(swap); G.LP_pendingswaps--; } From 6b98102ea39de321667e0dac15bc985fc70bf047 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 16:39:27 +0200 Subject: [PATCH 156/306] Test --- iguana/exchanges/LP_utxo.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 1befc1dcf..da6f97cc1 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -51,20 +51,20 @@ char *mbstr(char *str,double n); void cJSON_unregister(cJSON *item) { static uint32_t lasttime; - int32_t n; struct cJSON_list *ptr,*tmp; uint32_t now; - if ( (now= time(NULL)) > lasttime+6 ) + int32_t n; char *tmpstr; uint64_t total = 0; struct cJSON_list *ptr,*tmp; uint32_t now; + if ( (now= (uint32_t)time(NULL)) > lasttime+6 ) { n = 0; DL_FOREACH_SAFE(LP_cJSONlist,ptr,tmp) { - /*if ( ptr->item != 0 && ptr->item->child != 0 && ptr->cjsonid != 0 ) + if ( ptr->item != 0 && ptr->item->child != 0 && ptr->cjsonid != 0 ) { if ( (tmpstr= jprint(ptr->item,0)) != 0 ) { total += strlen(tmpstr); free(tmpstr); } - }*/ + } n++; } printf("total %d cJSON pending\n",n); From 3ef3f0603e5519e6f4c9e393270f272cf81f72c7 Mon Sep 17 00:00:00 2001 From: DeckerSU Date: Wed, 15 Nov 2017 18:45:53 +0400 Subject: [PATCH 157/306] added batch script to automate Windows builds (both 32/64-bit) script can be used to automate Windows builds of marketmaker using MSVC 2015 without jenkins. just follow to repo directory and launch marketmaker_build_32_64.cmd . It will generate 32-bit and 64-bit executables in Release and x64/Release directories. Also it has example how to add executables into archive. You can add any custom automate actions, for example, put archive with release on FTP, or syncing it somewhere with rsync, or any other. --- marketmaker_build_32_64.cmd | 47 +++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 marketmaker_build_32_64.cmd diff --git a/marketmaker_build_32_64.cmd b/marketmaker_build_32_64.cmd new file mode 100644 index 000000000..bac8df5e0 --- /dev/null +++ b/marketmaker_build_32_64.cmd @@ -0,0 +1,47 @@ +@echo off + +@REM Check for Visual Studio +call set "VSPATH=" +if defined VS140COMNTOOLS ( if not defined VSPATH ( + call set "VSPATH=%%VS140COMNTOOLS%%" +) ) + +@REM check if we already have the tools in the environment +if exist "%VCINSTALLDIR%" ( + goto compile +) + +if not defined VSPATH ( + echo You need Microsoft Visual Studio 15 installed + pause + exit +) + +@REM set up the environment +if exist "%VSPATH%..\..\vc\vcvarsall.bat" ( + call "%%VSPATH%%..\..\vc\vcvarsall.bat" amd64 + goto compile +) + +echo Unable to set up the environment +pause +exit + +:compile +rem MSBuild /help +MSBuild marketmaker.sln /t:Rebuild /p:Configuration=Release /p:Platform=x64 +MSBuild marketmaker.sln /t:Rebuild /p:Configuration=Release /p:Platform=x86 + +rem Using to add in marketmaker_release.7z +set host=%COMPUTERNAME% +IF "%host%"=="VM-81" ( + mkdir package_content\win32 + mkdir package_content\win64 + copy /y Release\marketmaker.exe package_content\win32 + copy /y x64\Release\marketmaker.exe package_content\win64 + cd package_content + "C:\Program Files\7-Zip\7z.exe" a C:\komodo\marketmaker_release\marketmaker_release.7z win32\marketmaker.exe + "C:\Program Files\7-Zip\7z.exe" a C:\komodo\marketmaker_release\marketmaker_release.7z win64\marketmaker.exe + cd .. + rd package_content /s /q + ) From 86e95d081609a713cd77fd95f73e3c051e879522 Mon Sep 17 00:00:00 2001 From: DeckerSU Date: Wed, 15 Nov 2017 19:33:33 +0400 Subject: [PATCH 158/306] added new examples of dexscripts for windows and updated it's description --- iguana/dexscripts.win32/bot_buy.cmd | 7 ++++ iguana/dexscripts.win32/bot_list.cmd | 7 ++++ iguana/dexscripts.win32/bot_statuslist.cmd | 7 ++++ iguana/dexscripts.win32/bot_stop.cmd | 7 ++++ iguana/dexscripts.win32/electrum.cmd | 9 +++++ iguana/dexscripts.win32/help.cmd | 2 ++ iguana/dexscripts.win32/how_to_use.md | 33 +++++++++++++++++++ .../dexscripts.win32/sendrawtransaction.cmd | 5 +++ iguana/dexscripts.win32/withdraw.cmd | 8 +++++ iguana/dexscripts.win32/withdraw_10_send.cmd | 14 ++++++++ iguana/dexscripts.win32/withdraw_send.cmd | 14 ++++++++ 11 files changed, 113 insertions(+) create mode 100644 iguana/dexscripts.win32/bot_buy.cmd create mode 100644 iguana/dexscripts.win32/bot_list.cmd create mode 100644 iguana/dexscripts.win32/bot_statuslist.cmd create mode 100644 iguana/dexscripts.win32/bot_stop.cmd create mode 100644 iguana/dexscripts.win32/electrum.cmd create mode 100644 iguana/dexscripts.win32/help.cmd create mode 100644 iguana/dexscripts.win32/sendrawtransaction.cmd create mode 100644 iguana/dexscripts.win32/withdraw.cmd create mode 100644 iguana/dexscripts.win32/withdraw_10_send.cmd create mode 100644 iguana/dexscripts.win32/withdraw_send.cmd diff --git a/iguana/dexscripts.win32/bot_buy.cmd b/iguana/dexscripts.win32/bot_buy.cmd new file mode 100644 index 000000000..641ef1d7b --- /dev/null +++ b/iguana/dexscripts.win32/bot_buy.cmd @@ -0,0 +1,7 @@ +@echo off +set /p TMPUSERPASS= UTXO PAIRS to understand the basics. This script is just for example how you can split your coins in (X, X/777) to start trading them. + ## F.A.Q. ## **Q.** Is any simple way how i can display JSON results returned by all scripts, like orderbook and others, in human readable form? + **A.** Yes, you can use this service [JSON Editor Online](http://jsoneditoronline.org/), just copy and paste output of script in left column and see structured output in right. **Q.** I see an output like this when i'm start `1-client.cmd` : @@ -43,6 +75,7 @@ And nothing works. **A.** Before run `1-client.cmd` make sure in Task Manager that you haven't already running `marketmaker.exe`. If have - kill this process via Task Manager or via command line command `taskkill /f /im taskkill.exe` . **Q.** How can i pretty print JSON answers of marketmaker? + **A.** You can get best results with 2 tools - [conemu](https://conemu.github.io/) and [jq](https://stedolan.github.io/jq/), conemu supports ANSI X3.64 and Xterm 256 colors and jq allow you to pretty-print json output with colors, like this: ![](./images/conemu_jq.png) diff --git a/iguana/dexscripts.win32/sendrawtransaction.cmd b/iguana/dexscripts.win32/sendrawtransaction.cmd new file mode 100644 index 000000000..a19d77355 --- /dev/null +++ b/iguana/dexscripts.win32/sendrawtransaction.cmd @@ -0,0 +1,5 @@ +@echo off +set /p TMPUSERPASS= withdraw.txt +type withdraw.txt diff --git a/iguana/dexscripts.win32/withdraw_10_send.cmd b/iguana/dexscripts.win32/withdraw_10_send.cmd new file mode 100644 index 000000000..44a947787 --- /dev/null +++ b/iguana/dexscripts.win32/withdraw_10_send.cmd @@ -0,0 +1,14 @@ +@echo off +set /p TMPUSERPASS= withdraw.txt +type withdraw.txt +timeout /t 5 /nobreak +for /f "tokens=4 delims=:," %%a in (' find "hex" "withdraw.txt" ') do ( +rem echo [%%~a] +curl -s --url "http://127.0.0.1:7783" --data "{\"userpass\":\"%USERPASS%\",\"method\":\"sendrawtransaction\",\"coin\":\"%COIN%\",\"signedtx\":\"%%~a\"}" +) diff --git a/iguana/dexscripts.win32/withdraw_send.cmd b/iguana/dexscripts.win32/withdraw_send.cmd new file mode 100644 index 000000000..a26b9bf56 --- /dev/null +++ b/iguana/dexscripts.win32/withdraw_send.cmd @@ -0,0 +1,14 @@ +@echo off +set /p TMPUSERPASS= withdraw.txt +type withdraw.txt +timeout /t 5 /nobreak +for /f "tokens=4 delims=:," %%a in (' find "hex" "withdraw.txt" ') do ( +rem echo [%%~a] +curl -s --url "http://127.0.0.1:7783" --data "{\"userpass\":\"%USERPASS%\",\"method\":\"sendrawtransaction\",\"coin\":\"%COIN%\",\"signedtx\":\"%%~a\"}" +) + From 39d2c7a879c5cdfd281322b45ecf14b82730b60c Mon Sep 17 00:00:00 2001 From: DeckerSU Date: Wed, 15 Nov 2017 19:56:36 +0400 Subject: [PATCH 159/306] append faq (q/a: required dlls) --- iguana/dexscripts.win32/how_to_use.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/iguana/dexscripts.win32/how_to_use.md b/iguana/dexscripts.win32/how_to_use.md index e04c14ac1..27b8af5be 100644 --- a/iguana/dexscripts.win32/how_to_use.md +++ b/iguana/dexscripts.win32/how_to_use.md @@ -80,4 +80,21 @@ And nothing works. ![](./images/conemu_jq.png) -Also i'm always recommend to install [Far Manager](https://www.farmanager.com/index.php?l=en) - this is powerful console file manager for Windows, like Midnight Commander in *nix. \ No newline at end of file +Also i'm always recommend to install [Far Manager](https://www.farmanager.com/index.php?l=en) - this is powerful console file manager for Windows, like Midnight Commander in *nix. + +**Q.** What additional dependencies required by marketmaker? + +**A.** Currently marketmaker (Windows) used the following DLLs: + +*32 bit:* +- libcrypto-1_1.dll +- libcurl.dll +- libssl-1_1.dll +- nanomsg.dll +- pthreadvc2.dll + +*64-bit:* +- libcurl.dll +- nanomsg.dll + +It already included in repo and in archive with release. \ No newline at end of file From 496a89c6aa32867a7f232aa49df69d26e932927a Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 18:30:29 +0200 Subject: [PATCH 160/306] Test --- iguana/exchanges/LP_nativeDEX.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index c7ba59d0b..6f90ed93c 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -17,7 +17,6 @@ // LP_nativeDEX.c // marketmaker // -// gc cJSON // more retries for swap sendrawtransaction? // pbca26 unfinished swaps // if ( G.LP_pendingswaps != 0 ) return(-1); @@ -327,7 +326,7 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock, int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int32_t sock,char *remoteaddr,int32_t maxdepth) { - int32_t recvlen=1,nonz = 0; cJSON *argjson; void *ptr; char methodstr[64],*retstr,*str; struct nn_pollfd pfd; + int32_t recvlen=1,nonz = 0; cJSON *argjson; void *ptr,*buf; char methodstr[64],*retstr,*str; struct nn_pollfd pfd; if ( sock >= 0 ) { while ( nonz < maxdepth && recvlen > 0 ) @@ -339,8 +338,11 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int if ( nn_poll(&pfd,1,1) != 1 ) break; ptr = 0; - if ( (recvlen= nn_recv(sock,&ptr,NN_MSG,0)) > 0 ) + buf = malloc(1000000); + if ( (recvlen= nn_recv(sock,buf,1000000,0)) > 0 ) + //if ( (recvlen= nn_recv(sock,&ptr,NN_MSG,0)) > 0 ) { + ptr = buf; methodstr[0] = 0; //printf("%s.(%s)\n",typestr,(char *)ptr); if ( 0 ) @@ -390,7 +392,10 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int } } if ( ptr != 0 ) - nn_freemsg(ptr), ptr = 0; + { + //nn_freemsg(ptr), ptr = 0; + free(buf); + } } } return(nonz); From 401f4d8a35f67ceeb4ca8a2b134ac1f158f75b84 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 18:58:29 +0200 Subject: [PATCH 161/306] Require requestid/quoteid match --- iguana/exchanges/LP_swap.c | 15 ++++++++++++--- iguana/exchanges/mm.c | 5 +++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_swap.c b/iguana/exchanges/LP_swap.c index 7e31d21e8..f551b862b 100644 --- a/iguana/exchanges/LP_swap.c +++ b/iguana/exchanges/LP_swap.c @@ -187,6 +187,8 @@ uint32_t basilisk_requestid(struct basilisk_request *rp) int32_t LP_pubkeys_data(struct basilisk_swap *swap,uint8_t *data,int32_t maxlen) { int32_t i,datalen = 0; + datalen += iguana_rwnum(1,&data[datalen],sizeof(swap->I.req.requestid),&swap->I.req.requestid); + datalen += iguana_rwnum(1,&data[datalen],sizeof(swap->I.req.quoteid),&swap->I.req.quoteid); data[datalen++] = swap->I.aliceconfirms; data[datalen++] = swap->I.bobconfirms; data[datalen++] = swap->I.alicemaxconfirms; @@ -201,9 +203,16 @@ int32_t LP_pubkeys_data(struct basilisk_swap *swap,uint8_t *data,int32_t maxlen) int32_t LP_pubkeys_verify(struct basilisk_swap *swap,uint8_t *data,int32_t datalen) { - int32_t i,nonz=0,alicemaxconfirms,bobmaxconfirms,aliceconfirms,bobconfirms,len = 0; uint8_t other33[33]; - if ( datalen == sizeof(swap->otherdeck)+38 ) + uint32_t requestid,quoteid; int32_t i,nonz=0,alicemaxconfirms,bobmaxconfirms,aliceconfirms,bobconfirms,len = 0; uint8_t other33[33]; + if ( datalen == sizeof(swap->otherdeck)+38+sizeof(uint32_t)*2 ) { + datalen += iguana_rwnum(0,&data[len],sizeof(requestid),&requestid); + datalen += iguana_rwnum(0,&data[len],sizeof(quoteid),"eid); + if ( requestid != swap->I.req.requestid || quoteid != swap->I.req.quoteid ) + { + printf("SWAP requestid.%u quoteid.%u mismatch received r.%u q.%u\n",swap->I.req.requestid,swap->I.req.quoteid,requestid,quoteid); + return(-1); + } aliceconfirms = data[len++]; bobconfirms = data[len++]; alicemaxconfirms = data[len++]; @@ -243,7 +252,7 @@ int32_t LP_pubkeys_verify(struct basilisk_swap *swap,uint8_t *data,int32_t datal len += iguana_rwnum(0,&data[len],sizeof(swap->otherdeck[i>>1][i&1]),&swap->otherdeck[i>>1][i&1]); return(0); } - printf("pubkeys verify size mismatch %d != %d\n",datalen,(int32_t)sizeof(swap->otherdeck)+36); + printf("pubkeys verify size mismatch %d != %d\n",datalen,(int32_t)sizeof(swap->otherdeck)+38+sizeof(uint32_t)*2); return(-1); } diff --git a/iguana/exchanges/mm.c b/iguana/exchanges/mm.c index e20b1dcb6..f906390b8 100644 --- a/iguana/exchanges/mm.c +++ b/iguana/exchanges/mm.c @@ -19,6 +19,11 @@ // Copyright © 2017 SuperNET. All rights reserved. // +/* +#define malloc(n) LP_alloc(n) +#define calloc(a,b) LP_alloc((uint64_t)(a) * (b)) +#define free(ptr) LP_free(ptr)*/ + void PNACL_message(char *arg,...) { From cb8cdd25980f5f3117d0c97494cf064711df1c5d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 19:11:05 +0200 Subject: [PATCH 162/306] Test --- iguana/exchanges/LP_swap.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_swap.c b/iguana/exchanges/LP_swap.c index f551b862b..1b6a17ab3 100644 --- a/iguana/exchanges/LP_swap.c +++ b/iguana/exchanges/LP_swap.c @@ -206,8 +206,8 @@ int32_t LP_pubkeys_verify(struct basilisk_swap *swap,uint8_t *data,int32_t datal uint32_t requestid,quoteid; int32_t i,nonz=0,alicemaxconfirms,bobmaxconfirms,aliceconfirms,bobconfirms,len = 0; uint8_t other33[33]; if ( datalen == sizeof(swap->otherdeck)+38+sizeof(uint32_t)*2 ) { - datalen += iguana_rwnum(0,&data[len],sizeof(requestid),&requestid); - datalen += iguana_rwnum(0,&data[len],sizeof(quoteid),"eid); + len += iguana_rwnum(0,&data[len],sizeof(requestid),&requestid); + len += iguana_rwnum(0,&data[len],sizeof(quoteid),"eid); if ( requestid != swap->I.req.requestid || quoteid != swap->I.req.quoteid ) { printf("SWAP requestid.%u quoteid.%u mismatch received r.%u q.%u\n",swap->I.req.requestid,swap->I.req.quoteid,requestid,quoteid); @@ -252,7 +252,7 @@ int32_t LP_pubkeys_verify(struct basilisk_swap *swap,uint8_t *data,int32_t datal len += iguana_rwnum(0,&data[len],sizeof(swap->otherdeck[i>>1][i&1]),&swap->otherdeck[i>>1][i&1]); return(0); } - printf("pubkeys verify size mismatch %d != %d\n",datalen,(int32_t)sizeof(swap->otherdeck)+38+sizeof(uint32_t)*2); + printf("pubkeys verify size mismatch %d != %d\n",datalen,(int32_t)(sizeof(swap->otherdeck)+38+sizeof(uint32_t)*2)); return(-1); } From a3d3b00649f363abf262567b47eed4f00cee86f5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 19:15:09 +0200 Subject: [PATCH 163/306] Test --- iguana/exchanges/LP_swap.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iguana/exchanges/LP_swap.c b/iguana/exchanges/LP_swap.c index 1b6a17ab3..616ee46f7 100644 --- a/iguana/exchanges/LP_swap.c +++ b/iguana/exchanges/LP_swap.c @@ -189,6 +189,7 @@ int32_t LP_pubkeys_data(struct basilisk_swap *swap,uint8_t *data,int32_t maxlen) int32_t i,datalen = 0; datalen += iguana_rwnum(1,&data[datalen],sizeof(swap->I.req.requestid),&swap->I.req.requestid); datalen += iguana_rwnum(1,&data[datalen],sizeof(swap->I.req.quoteid),&swap->I.req.quoteid); + printf("send >>>>>>>>> r.%u q.%u\n",swap->I.req.requestid,swap->I.req.quoteid); data[datalen++] = swap->I.aliceconfirms; data[datalen++] = swap->I.bobconfirms; data[datalen++] = swap->I.alicemaxconfirms; From 46bd310f62dd4b7ae47ac79ae0079f5602415c3b Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 19:19:53 +0200 Subject: [PATCH 164/306] Test --- iguana/exchanges/LP_swap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_swap.c b/iguana/exchanges/LP_swap.c index 616ee46f7..1002517b0 100644 --- a/iguana/exchanges/LP_swap.c +++ b/iguana/exchanges/LP_swap.c @@ -189,7 +189,6 @@ int32_t LP_pubkeys_data(struct basilisk_swap *swap,uint8_t *data,int32_t maxlen) int32_t i,datalen = 0; datalen += iguana_rwnum(1,&data[datalen],sizeof(swap->I.req.requestid),&swap->I.req.requestid); datalen += iguana_rwnum(1,&data[datalen],sizeof(swap->I.req.quoteid),&swap->I.req.quoteid); - printf("send >>>>>>>>> r.%u q.%u\n",swap->I.req.requestid,swap->I.req.quoteid); data[datalen++] = swap->I.aliceconfirms; data[datalen++] = swap->I.bobconfirms; data[datalen++] = swap->I.alicemaxconfirms; @@ -199,6 +198,7 @@ int32_t LP_pubkeys_data(struct basilisk_swap *swap,uint8_t *data,int32_t maxlen) data[datalen++] = swap->persistent_pubkey33[i]; for (i=0; ideck)/sizeof(swap->deck[0][0]); i++) datalen += iguana_rwnum(1,&data[datalen],sizeof(swap->deck[i>>1][i&1]),&swap->deck[i>>1][i&1]); + printf("send >>>>>>>>> r.%u q.%u datalen.%d\n",swap->I.req.requestid,swap->I.req.quoteid,datalen); return(datalen); } From 3a84ed7eb6ee140ebbab59cb3e0deec871fa1c43 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 19:39:16 +0200 Subject: [PATCH 165/306] Test --- iguana/exchanges/LP_include.h | 2 +- iguana/exchanges/LP_ordermatch.c | 11 ++++++++++ iguana/exchanges/LP_remember.c | 37 ++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 5e530f9c1..b1a78c694 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 "14414" +#define LP_BUILD_NUMBER "14498" #ifdef FROM_JS #include diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 0ab6faca0..7d60f336d 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -449,6 +449,11 @@ int32_t LP_connectstartbob(void *ctx,int32_t pubsock,cJSON *argjson,char *base,c if ( bits256_nonz(privkey) != 0 && bits256_cmp(G.LP_mypub25519,qp->srchash) == 0 ) { LP_requestinit(&qp->R,qp->srchash,qp->desthash,base,qp->satoshis-qp->txfee,rel,qp->destsatoshis-qp->desttxfee,qp->timestamp,qp->quotetime,DEXselector); + if ( LP_pendingswap(qp->R.requestid,qp->R.quoteid) > 0 ) + { + printf("requestid.%u quoteid.%u is already in progres\n",qp->R.requestid,qp->R.quoteid); + return(-1); + } if ( (swap= LP_swapinit(1,0,privkey,&qp->R,qp)) == 0 ) { printf("cant initialize swap\n"); @@ -611,6 +616,12 @@ char *LP_connectedalice(cJSON *argjson) // alice { retjson = cJSON_CreateObject(); 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); + if ( LP_pendingswap(Q.R.requestid,Q.R.quoteid) > 0 ) + { + printf("requestid.%u quoteid.%u is already in progres\n",Q.R.requestid,Q.R.quoteid); + jaddstr(retjson,"error","swap already in progress"); + return(jprint(retjson,1)); + } if ( (swap= LP_swapinit(0,0,Q.privkey,&Q.R,&Q)) == 0 ) { jaddstr(retjson,"error","couldnt swapinit"); diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index d8b264e7c..c0ef0efd7 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -1441,3 +1441,40 @@ char *basilisk_swapentries(char *refbase,char *refrel,int32_t limit) return(jprint(retarray,1)); } +int32_t LP_pendingswap(uint32_t requestid,uint32_t quoteid) +{ + cJSON *retjson,*array,*pending,*item; uint32_t r,q; char *retstr; int32_t i,n,retval = 0; + if ( (retstr= LP_recent_swaps(1000)) != 0 ) + { + if ( (retjson= cJSON_Parse(retstr)) != 0 ) + { + if ( (array= jarray(&n,retjson,"swaps")) != 0 ) + { + for (i=0; i Date: Wed, 15 Nov 2017 19:43:04 +0200 Subject: [PATCH 166/306] Test --- 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 b1a78c694..b6c24be52 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 "14498" +#define LP_BUILD_NUMBER "15000" #ifdef FROM_JS #include From 55837efe446da7e9c77907e03a125f887e52bc49 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 19:50:11 +0200 Subject: [PATCH 167/306] Test --- iguana/exchanges/LP_ordermatch.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 7d60f336d..04faf3715 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -571,7 +571,14 @@ char *LP_connectedalice(cJSON *argjson) // alice LP_aliceid(Q.tradeid,Q.aliceid,"error1",0,0); return(clonestr("{\"result\",\"update stats\"}")); } - printf("CONNECTED.(%s) numpending.%d tradeid.%u\n",jprint(argjson,0),G.LP_pendingswaps,Q.tradeid); + printf("CONNECTED.(%s) numpending.%d tradeid.%u requestid.%u quoteid.%u\n",jprint(argjson,0),G.LP_pendingswaps,Q.tradeid,Q.R.requestid,Q.R.quoteid); + if ( LP_pendingswap(Q.R.requestid,Q.R.quoteid) > 0 ) + { + printf("requestid.%u quoteid.%u is already in progres\n",Q.R.requestid,Q.R.quoteid); + retjson = cJSON_CreateObject(); + jaddstr(retjson,"error","swap already in progress"); + return(jprint(retjson,1)); + } if ( (autxo= LP_utxopairfind(0,Q.desttxid,Q.destvout,Q.feetxid,Q.feevout)) == 0 ) { printf("cant find autxo\n"); @@ -616,12 +623,6 @@ char *LP_connectedalice(cJSON *argjson) // alice { retjson = cJSON_CreateObject(); 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); - if ( LP_pendingswap(Q.R.requestid,Q.R.quoteid) > 0 ) - { - printf("requestid.%u quoteid.%u is already in progres\n",Q.R.requestid,Q.R.quoteid); - jaddstr(retjson,"error","swap already in progress"); - return(jprint(retjson,1)); - } if ( (swap= LP_swapinit(0,0,Q.privkey,&Q.R,&Q)) == 0 ) { jaddstr(retjson,"error","couldnt swapinit"); From 30e638296800bfeae1f9be87d355af83ae95a15f Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 20:38:55 +0200 Subject: [PATCH 168/306] Test --- iguana/exchanges/LP_socket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index e50e648d4..979a0ad0c 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -1034,7 +1034,7 @@ cJSON *LP_electrumserver(struct iguana_info *coin,char *ipaddr,uint16_t port) retjson = cJSON_CreateObject(); jaddstr(retjson,"ipaddr",ipaddr); jaddnum(retjson,"port",port); - if ( (ep= LP_electrum_info(&already,coin->symbol,ipaddr,port,IGUANA_MAXPACKETSIZE * 10)) == 0 ) + if ( (ep= LP_electrum_info(&already,coin->symbol,ipaddr,port,IGUANA_MAXPACKETSIZE)) == 0 ) { jaddstr(retjson,"error","couldnt connect to electrum server"); return(retjson); From 61ebc0b09176a9c9480588af5b7bce402324f587 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 20:45:40 +0200 Subject: [PATCH 169/306] Test --- iguana/exchanges/LP_transaction.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index 3f6ff3e43..d414b2847 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -78,7 +78,8 @@ int32_t LP_gettx_presence(char *symbol,bits256 expectedtxid) bits256 LP_broadcast(char *txname,char *symbol,char *txbytes,bits256 expectedtxid) { - char *retstr; bits256 txid; uint8_t *ptr; cJSON *retjson,*errorobj; int32_t i,len,sentflag = 0; + char *retstr,*errstr; bits256 txid; uint8_t *ptr; cJSON *retjson,*errorobj; struct iguana_info *coin; int32_t i,totalretries=0,len,sentflag = 0; + coin = LP_coinfind(symbol); memset(&txid,0,sizeof(txid)); if ( txbytes == 0 || txbytes[0] == 0 ) return(txid); @@ -115,6 +116,15 @@ bits256 LP_broadcast(char *txname,char *symbol,char *txbytes,bits256 expectedtxi txid = expectedtxid; sentflag = 1; } + else if ( (errstr= jstr(retjson,"error")) != 0 && strcmp(errstr,"timeout") == 0 && coin != 0 && coin->electrum != 0 ) + { + if ( totalretries < 10 ) + { + printf("time error with electrum, retry\n"); + totalretries++; + i--; + } + } else printf("broadcast error.(%s)\n",retstr); } free_json(retjson); From e61d0a0fc4d85dfdd577d929a4cb0b6f64cb0271 Mon Sep 17 00:00:00 2001 From: DeckerSU Date: Wed, 15 Nov 2017 23:28:31 +0400 Subject: [PATCH 170/306] added obtaining version number of mm and commit hash in build script --- marketmaker_build_32_64.cmd | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/marketmaker_build_32_64.cmd b/marketmaker_build_32_64.cmd index bac8df5e0..730081702 100644 --- a/marketmaker_build_32_64.cmd +++ b/marketmaker_build_32_64.cmd @@ -32,6 +32,39 @@ rem MSBuild /help MSBuild marketmaker.sln /t:Rebuild /p:Configuration=Release /p:Platform=x64 MSBuild marketmaker.sln /t:Rebuild /p:Configuration=Release /p:Platform=x86 +rem Obtain version number and latest git commit number + +FOR /F "tokens=* USEBACKQ" %%F IN (`find /i "LP_MAJOR_VERSION" "iguana\exchanges\LP_include.h"`) DO ( +SET LP_MAJOR_VERSION_STR=%%F +) +FOR /F "tokens=* USEBACKQ" %%F IN (`find /i "LP_MINOR_VERSION" "iguana\exchanges\LP_include.h"`) DO ( +SET LP_MINOR_VERSION_STR=%%F +) +FOR /F "tokens=* USEBACKQ" %%F IN (`find /i "LP_BUILD_NUMBER" "iguana\exchanges\LP_include.h"`) DO ( +SET LP_BUILD_NUMBER_STR=%%F +) + +for /f delims^=^"^ tokens^=2 %%a in ('echo %LP_MAJOR_VERSION_STR%') do ( +set LP_MAJOR_VERSION=%%a +) +for /f delims^=^"^ tokens^=2 %%a in ('echo %LP_MINOR_VERSION_STR%') do ( +set LP_MINOR_VERSION=%%a +) +for /f delims^=^"^ tokens^=2 %%a in ('echo %LP_BUILD_NUMBER_STR%') do ( +set LP_BUILD_NUMBER=%%a +) + +rem Check if git command exist and if does - receive latest GIT_COMMIT +git --version >nul 2>&1 && ( + for /f "tokens=1" %%a in ('git rev-parse --short HEAD') do ( + set GIT_COMMIT=_%%a + ) +) || ( + set GIT_COMMIT= +) + +rem echo Marketmaker_%LP_MAJOR_VERSION%.%LP_MINOR_VERSION%_%LP_BUILD_NUMBER%%GIT_COMMIT% + rem Using to add in marketmaker_release.7z set host=%COMPUTERNAME% IF "%host%"=="VM-81" ( @@ -39,9 +72,11 @@ IF "%host%"=="VM-81" ( mkdir package_content\win64 copy /y Release\marketmaker.exe package_content\win32 copy /y x64\Release\marketmaker.exe package_content\win64 + echo Marketmaker_%LP_MAJOR_VERSION%.%LP_MINOR_VERSION%_%LP_BUILD_NUMBER%%GIT_COMMIT% > package_content\version.txt cd package_content "C:\Program Files\7-Zip\7z.exe" a C:\komodo\marketmaker_release\marketmaker_release.7z win32\marketmaker.exe "C:\Program Files\7-Zip\7z.exe" a C:\komodo\marketmaker_release\marketmaker_release.7z win64\marketmaker.exe + "C:\Program Files\7-Zip\7z.exe" a C:\komodo\marketmaker_release\marketmaker_release.7z version.txt cd .. rd package_content /s /q ) From 6738004bf87a671c5b28c3f89bc03ec8e6d4248b Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 21:55:30 +0200 Subject: [PATCH 171/306] Meatiest --- iguana/exchanges/LP_nativeDEX.c | 14 ++++++++++++-- iguana/exchanges/LP_transaction.c | 2 +- iguana/exchanges/mm.c | 11 +++++++---- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 6f90ed93c..b195a292d 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -17,8 +17,6 @@ // LP_nativeDEX.c // marketmaker // -// more retries for swap sendrawtransaction? -// pbca26 unfinished swaps // if ( G.LP_pendingswaps != 0 ) return(-1); // bot safe to exit? // @@ -1190,4 +1188,16 @@ void LP_fromjs_iter() #endif +#undef calloc +#undef free + +void *LP_alloc(uint64_t len) +{ + return(calloc(1,len)); +} + +void LP_free(void *ptr) +{ + free(ptr); +} diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index d414b2847..cfd1a6060 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -120,7 +120,7 @@ bits256 LP_broadcast(char *txname,char *symbol,char *txbytes,bits256 expectedtxi { if ( totalretries < 10 ) { - printf("time error with electrum, retry\n"); + printf("time error with electrum, retry.%d\n",totalretries); totalretries++; i--; } diff --git a/iguana/exchanges/mm.c b/iguana/exchanges/mm.c index f906390b8..e199b6bfd 100644 --- a/iguana/exchanges/mm.c +++ b/iguana/exchanges/mm.c @@ -19,10 +19,7 @@ // Copyright © 2017 SuperNET. All rights reserved. // -/* -#define malloc(n) LP_alloc(n) -#define calloc(a,b) LP_alloc((uint64_t)(a) * (b)) -#define free(ptr) LP_free(ptr)*/ + void PNACL_message(char *arg,...) { @@ -42,6 +39,12 @@ void PNACL_message(char *arg,...) #include "../../crypto777/OS_portable.h" #endif // !_WIN_32 +#define malloc(n) LP_alloc(n) +#define calloc(a,b) LP_alloc((uint64_t)(a) * (b)) +#define free(ptr) LP_free(ptr) + +void *LP_alloc(uint64_t len); +void LP_free(void *ptr); #define MAX(a,b) ((a) > (b) ? (a) : (b)) char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *remoteaddr,uint16_t port); From c02faaadfd525da058d0e75d0fb19e7a2792272a Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 22:19:28 +0200 Subject: [PATCH 172/306] Test --- iguana/exchanges/LP_nativeDEX.c | 40 +++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index b195a292d..1bb412af5 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1191,13 +1191,49 @@ void LP_fromjs_iter() #undef calloc #undef free +struct LP_memory_list +{ + struct LP_memory_list *next,*prev; + void *ptr; + uint32_t timestamp,len; +} *LP_memory_list; + void *LP_alloc(uint64_t len) { - return(calloc(1,len)); + struct LP_memory_list *mp; + mp = calloc(1,sizeof(*mp) + len); + mp->timestamp = (uint32_t)time(NULL); + mp->ptr = calloc(1,len); + mp->len = (uint32_t)len; + portable_mutex_lock(&LP_cJSONmutex); + DL_APPEND(LP_memory_list,mp); + portable_mutex_unlock(&LP_cJSONmutex); + return(&mp[1]); } void LP_free(void *ptr) { - free(ptr); + static uint32_t lasttime; + uint32_t now; int32_t n; uint64_t total = 0; char str[65]; struct LP_memory_list *mp,*tmp,*freemp = ptr; + --freemp; + if ( (now= (uint32_t)time(NULL)) > lasttime+6 ) + { + n = 0; + DL_FOREACH_SAFE(LP_memory_list,mp,tmp) + { + total += mp->len; + n++; + } + printf("total %d allocated total size %s\n",n,mbstr(str,total)); + lasttime = (uint32_t)time(NULL); + } + if ( freemp != 0 ) + { + portable_mutex_lock(&LP_cJSONmutex); + DL_DELETE(LP_memory_list,freemp); + free(freemp); + portable_mutex_unlock(&LP_cJSONmutex); + } //else printf("cJSON_unregister of unknown %p %u\n",item,item->cjsonid); } + From 146b98afffaa6929f2f1c59c25af3ee73f384da9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 22:24:03 +0200 Subject: [PATCH 173/306] 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 1bb412af5..ef97d7d4d 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1194,7 +1194,6 @@ void LP_fromjs_iter() struct LP_memory_list { struct LP_memory_list *next,*prev; - void *ptr; uint32_t timestamp,len; } *LP_memory_list; @@ -1202,8 +1201,8 @@ void *LP_alloc(uint64_t len) { struct LP_memory_list *mp; mp = calloc(1,sizeof(*mp) + len); + printf("mp.%p ptr.%p\n",mp,&mp[1]); mp->timestamp = (uint32_t)time(NULL); - mp->ptr = calloc(1,len); mp->len = (uint32_t)len; portable_mutex_lock(&LP_cJSONmutex); DL_APPEND(LP_memory_list,mp); @@ -1216,6 +1215,7 @@ void LP_free(void *ptr) static uint32_t lasttime; uint32_t now; int32_t n; uint64_t total = 0; char str[65]; struct LP_memory_list *mp,*tmp,*freemp = ptr; --freemp; + printf("freemp.%p\n",freemp); if ( (now= (uint32_t)time(NULL)) > lasttime+6 ) { n = 0; From 2fe9584e526296c37a59308dd41d1180aa02b5e4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 22:35:45 +0200 Subject: [PATCH 174/306] Test --- iguana/exchanges/LP_nativeDEX.c | 10 +++++----- iguana/exchanges/LP_utxo.c | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index ef97d7d4d..0828a393a 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1201,7 +1201,7 @@ void *LP_alloc(uint64_t len) { struct LP_memory_list *mp; mp = calloc(1,sizeof(*mp) + len); - printf("mp.%p ptr.%p\n",mp,&mp[1]); + printf("\n>>>>>>>>>>> LP_alloc mp.%p ptr.%p len.%llu\n",mp,&mp[1],(long long)len); mp->timestamp = (uint32_t)time(NULL); mp->len = (uint32_t)len; portable_mutex_lock(&LP_cJSONmutex); @@ -1213,9 +1213,9 @@ void *LP_alloc(uint64_t len) void LP_free(void *ptr) { static uint32_t lasttime; - uint32_t now; int32_t n; uint64_t total = 0; char str[65]; struct LP_memory_list *mp,*tmp,*freemp = ptr; + uint32_t now; int32_t n; uint64_t total = 0; struct LP_memory_list *mp,*tmp,*freemp = ptr; --freemp; - printf("freemp.%p\n",freemp); + printf("\n>>>>>>>>>>> LP_free freemp.%p\n",freemp); if ( (now= (uint32_t)time(NULL)) > lasttime+6 ) { n = 0; @@ -1224,15 +1224,15 @@ void LP_free(void *ptr) total += mp->len; n++; } - printf("total %d allocated total size %s\n",n,mbstr(str,total)); + printf("total %d allocated total %llu\n",n,(long long)total); lasttime = (uint32_t)time(NULL); } if ( freemp != 0 ) { portable_mutex_lock(&LP_cJSONmutex); DL_DELETE(LP_memory_list,freemp); - free(freemp); portable_mutex_unlock(&LP_cJSONmutex); + free(freemp); } //else printf("cJSON_unregister of unknown %p %u\n",item,item->cjsonid); } diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index da6f97cc1..fcd05feb3 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -27,7 +27,7 @@ struct LP_inuse_info } LP_inuse[1024]; int32_t LP_numinuse; -struct cJSON_list +/*struct cJSON_list { struct cJSON_list *next,*prev; cJSON *item; @@ -92,7 +92,7 @@ void cJSON_unregister(cJSON *item) free(ptr); portable_mutex_unlock(&LP_cJSONmutex); } //else printf("cJSON_unregister of unknown %p %u\n",item,item->cjsonid); -} +}*/ struct LP_inuse_info *_LP_inuse_find(bits256 txid,int32_t vout) { From 21594133c08e482a2861e0d4ff66c0eb97b9a2cb Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 22:46:12 +0200 Subject: [PATCH 175/306] Test --- iguana/exchanges/LP_nativeDEX.c | 7 +++++++ iguana/exchanges/mm.c | 2 ++ 2 files changed, 9 insertions(+) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 0828a393a..4834fd8e8 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1190,6 +1190,7 @@ void LP_fromjs_iter() #undef calloc #undef free +#undef clonestr struct LP_memory_list { @@ -1236,4 +1237,10 @@ void LP_free(void *ptr) } //else printf("cJSON_unregister of unknown %p %u\n",item,item->cjsonid); } +char *LP_clonestr(char *str) +{ + char *retstr = LP_alloc(strlen(str)+1); + strcpy(retstr,str); + return(retstr); +} diff --git a/iguana/exchanges/mm.c b/iguana/exchanges/mm.c index e199b6bfd..f10241da7 100644 --- a/iguana/exchanges/mm.c +++ b/iguana/exchanges/mm.c @@ -42,9 +42,11 @@ void PNACL_message(char *arg,...) #define malloc(n) LP_alloc(n) #define calloc(a,b) LP_alloc((uint64_t)(a) * (b)) #define free(ptr) LP_free(ptr) +#define clonestr(str) LP_clonestr(str) void *LP_alloc(uint64_t len); void LP_free(void *ptr); +char *LP_clonestr(char *str); #define MAX(a,b) ((a) > (b) ? (a) : (b)) char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *remoteaddr,uint16_t port); From abec32f1b69c8655ad3d2f3415b130fc042d0d83 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 22:48:56 +0200 Subject: [PATCH 176/306] Test --- crypto777/bitcoind_RPC.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crypto777/bitcoind_RPC.c b/crypto777/bitcoind_RPC.c index 98c7e7eb0..0a9157b84 100755 --- a/crypto777/bitcoind_RPC.c +++ b/crypto777/bitcoind_RPC.c @@ -13,6 +13,12 @@ * * ******************************************************************************/ + +#define malloc(n) LP_alloc(n) +#define calloc(a,b) LP_alloc((uint64_t)(a) * (b)) +#define free(ptr) LP_free(ptr) +#define clonestr(str) LP_clonestr(str) + #ifndef FROM_JS #include "OS_portable.h" #define LIQUIDITY_PROVIDER 1 From edefcaffe16e55c94da50f49aedf36910bc66469 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 22:49:39 +0200 Subject: [PATCH 177/306] Test --- crypto777/bitcoind_RPC.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/crypto777/bitcoind_RPC.c b/crypto777/bitcoind_RPC.c index 0a9157b84..22c6ebceb 100755 --- a/crypto777/bitcoind_RPC.c +++ b/crypto777/bitcoind_RPC.c @@ -14,15 +14,16 @@ ******************************************************************************/ -#define malloc(n) LP_alloc(n) -#define calloc(a,b) LP_alloc((uint64_t)(a) * (b)) -#define free(ptr) LP_free(ptr) -#define clonestr(str) LP_clonestr(str) #ifndef FROM_JS #include "OS_portable.h" #define LIQUIDITY_PROVIDER 1 +#define malloc(n) LP_alloc(n) +#define calloc(a,b) LP_alloc((uint64_t)(a) * (b)) +#define free(ptr) LP_free(ptr) +#define clonestr(str) LP_clonestr(str) + #if LIQUIDITY_PROVIDER #include #include From eaaaea9d67537414a1767d481bdbff7bc0dacb2f Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 22:50:49 +0200 Subject: [PATCH 178/306] Test --- crypto777/bitcoind_RPC.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crypto777/bitcoind_RPC.c b/crypto777/bitcoind_RPC.c index 22c6ebceb..05144b82a 100755 --- a/crypto777/bitcoind_RPC.c +++ b/crypto777/bitcoind_RPC.c @@ -23,6 +23,9 @@ #define calloc(a,b) LP_alloc((uint64_t)(a) * (b)) #define free(ptr) LP_free(ptr) #define clonestr(str) LP_clonestr(str) +void *LP_alloc(uint64_t len); +void LP_free(void *ptr); +char *LP_clonestr(char *str); #if LIQUIDITY_PROVIDER #include From da58c22fda6440b59f856ee4bce2ea765f397832 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 22:58:23 +0200 Subject: [PATCH 179/306] Test --- crypto777/bitcoind_RPC.c | 4 ++++ iguana/exchanges/LP_nativeDEX.c | 11 +++++++++++ iguana/exchanges/mm.c | 2 ++ 3 files changed, 17 insertions(+) diff --git a/crypto777/bitcoind_RPC.c b/crypto777/bitcoind_RPC.c index 05144b82a..a3488aeae 100755 --- a/crypto777/bitcoind_RPC.c +++ b/crypto777/bitcoind_RPC.c @@ -20,13 +20,17 @@ #define LIQUIDITY_PROVIDER 1 #define malloc(n) LP_alloc(n) +#define realloc(ptr,n) LP_realloc(ptr,n) #define calloc(a,b) LP_alloc((uint64_t)(a) * (b)) #define free(ptr) LP_free(ptr) #define clonestr(str) LP_clonestr(str) + +void *LP_realloc(void *ptr,uint64_t len); void *LP_alloc(uint64_t len); void LP_free(void *ptr); char *LP_clonestr(char *str); + #if LIQUIDITY_PROVIDER #include #include diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 4834fd8e8..cf18369f2 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1190,6 +1190,7 @@ void LP_fromjs_iter() #undef calloc #undef free +#undef realloc #undef clonestr struct LP_memory_list @@ -1211,6 +1212,16 @@ void *LP_alloc(uint64_t len) return(&mp[1]); } +void *LP_realloc(void *ptr,uint64_t len) +{ + struct LP_memory_list *mp = ptr; + --mp; + mp = realloc(mp,len + sizeof(*mp)); + mp->timestamp = (uint32_t)time(NULL); + mp->len = (uint32_t)len; + return(&mp[1]); +} + void LP_free(void *ptr) { static uint32_t lasttime; diff --git a/iguana/exchanges/mm.c b/iguana/exchanges/mm.c index f10241da7..d8ce0ed0d 100644 --- a/iguana/exchanges/mm.c +++ b/iguana/exchanges/mm.c @@ -40,10 +40,12 @@ void PNACL_message(char *arg,...) #endif // !_WIN_32 #define malloc(n) LP_alloc(n) +#define realloc(ptr,n) LP_realloc(ptr,n) #define calloc(a,b) LP_alloc((uint64_t)(a) * (b)) #define free(ptr) LP_free(ptr) #define clonestr(str) LP_clonestr(str) +void *LP_realloc(void *ptr,uint64_t len); void *LP_alloc(uint64_t len); void LP_free(void *ptr); char *LP_clonestr(char *str); From b6366f824ce0e9d0c7c66806170bcf6a10842a4b Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 23:00:48 +0200 Subject: [PATCH 180/306] Test --- iguana/exchanges/LP_nativeDEX.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index cf18369f2..91eadb613 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1215,11 +1215,15 @@ void *LP_alloc(uint64_t len) void *LP_realloc(void *ptr,uint64_t len) { struct LP_memory_list *mp = ptr; - --mp; - mp = realloc(mp,len + sizeof(*mp)); - mp->timestamp = (uint32_t)time(NULL); - mp->len = (uint32_t)len; - return(&mp[1]); + if ( mp != 0 ) + { + --mp; + printf("\n>>>>>>>>>>> LP_realloc mp.%p ptr.%p len.%llu\n",mp,&mp[1],(long long)len); + mp = realloc(mp,len + sizeof(*mp)); + mp->timestamp = (uint32_t)time(NULL); + mp->len = (uint32_t)len; + return(&mp[1]); + } else return(LP_alloc(len)); } void LP_free(void *ptr) From 1b5bd6e2ea96136ac374203253cf38abd1081653 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 23:04:30 +0200 Subject: [PATCH 181/306] Test --- iguana/exchanges/LP_nativeDEX.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 91eadb613..b7489c3f3 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1243,13 +1243,19 @@ void LP_free(void *ptr) printf("total %d allocated total %llu\n",n,(long long)total); lasttime = (uint32_t)time(NULL); } - if ( freemp != 0 ) + DL_FOREACH_SAFE(LP_memory_list,mp,tmp) + { + if ( mp == freemp ) + break; + mp = 0; + } + if ( mp != 0 ) { portable_mutex_lock(&LP_cJSONmutex); - DL_DELETE(LP_memory_list,freemp); + DL_DELETE(LP_memory_list,mp); portable_mutex_unlock(&LP_cJSONmutex); - free(freemp); - } //else printf("cJSON_unregister of unknown %p %u\n",item,item->cjsonid); + free(mp); + } // free from source file with #define redirect for alloc that wasnt } char *LP_clonestr(char *str) From c75d6641712214a0ebc0f17754cc2420d8bc2508 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 23:08:31 +0200 Subject: [PATCH 182/306] Test --- iguana/exchanges/LP_nativeDEX.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index b7489c3f3..05d9a36fd 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1197,41 +1197,33 @@ struct LP_memory_list { struct LP_memory_list *next,*prev; uint32_t timestamp,len; + void *ptr; } *LP_memory_list; void *LP_alloc(uint64_t len) { struct LP_memory_list *mp; - mp = calloc(1,sizeof(*mp) + len); + mp = calloc(1,sizeof(*mp)); printf("\n>>>>>>>>>>> LP_alloc mp.%p ptr.%p len.%llu\n",mp,&mp[1],(long long)len); mp->timestamp = (uint32_t)time(NULL); mp->len = (uint32_t)len; + mp->ptr = calloc(1,len); portable_mutex_lock(&LP_cJSONmutex); DL_APPEND(LP_memory_list,mp); portable_mutex_unlock(&LP_cJSONmutex); - return(&mp[1]); + return(mp->ptr); } void *LP_realloc(void *ptr,uint64_t len) { - struct LP_memory_list *mp = ptr; - if ( mp != 0 ) - { - --mp; - printf("\n>>>>>>>>>>> LP_realloc mp.%p ptr.%p len.%llu\n",mp,&mp[1],(long long)len); - mp = realloc(mp,len + sizeof(*mp)); - mp->timestamp = (uint32_t)time(NULL); - mp->len = (uint32_t)len; - return(&mp[1]); - } else return(LP_alloc(len)); + return(realloc(ptr,len)); } void LP_free(void *ptr) { static uint32_t lasttime; - uint32_t now; int32_t n; uint64_t total = 0; struct LP_memory_list *mp,*tmp,*freemp = ptr; - --freemp; - printf("\n>>>>>>>>>>> LP_free freemp.%p\n",freemp); + uint32_t now; int32_t n; uint64_t total = 0; struct LP_memory_list *mp,*tmp; + printf("\n>>>>>>>>>>> LP_free ptr.%p\n",ptr); if ( (now= (uint32_t)time(NULL)) > lasttime+6 ) { n = 0; @@ -1245,7 +1237,7 @@ void LP_free(void *ptr) } DL_FOREACH_SAFE(LP_memory_list,mp,tmp) { - if ( mp == freemp ) + if ( mp->ptr == ptr ) break; mp = 0; } @@ -1254,6 +1246,7 @@ void LP_free(void *ptr) portable_mutex_lock(&LP_cJSONmutex); DL_DELETE(LP_memory_list,mp); portable_mutex_unlock(&LP_cJSONmutex); + free(mp->ptr); free(mp); } // free from source file with #define redirect for alloc that wasnt } From 3e0217af2bfe48433a01d1d55562fffe3eca2cd8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 23:11:15 +0200 Subject: [PATCH 183/306] 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 05d9a36fd..ae0491bd2 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1204,7 +1204,7 @@ void *LP_alloc(uint64_t len) { struct LP_memory_list *mp; mp = calloc(1,sizeof(*mp)); - printf("\n>>>>>>>>>>> LP_alloc mp.%p ptr.%p len.%llu\n",mp,&mp[1],(long long)len); + //printf("\n>>>>>>>>>>> LP_alloc mp.%p ptr.%p len.%llu\n",mp,mp->ptr,(long long)len); mp->timestamp = (uint32_t)time(NULL); mp->len = (uint32_t)len; mp->ptr = calloc(1,len); @@ -1223,7 +1223,6 @@ void LP_free(void *ptr) { static uint32_t lasttime; uint32_t now; int32_t n; uint64_t total = 0; struct LP_memory_list *mp,*tmp; - printf("\n>>>>>>>>>>> LP_free ptr.%p\n",ptr); if ( (now= (uint32_t)time(NULL)) > lasttime+6 ) { n = 0; @@ -1246,6 +1245,7 @@ void LP_free(void *ptr) portable_mutex_lock(&LP_cJSONmutex); DL_DELETE(LP_memory_list,mp); portable_mutex_unlock(&LP_cJSONmutex); + printf(">>>>>>>>>>> LP_free ptr.%p mp.%p len.%u\n",ptr,mp,mp->len); free(mp->ptr); free(mp); } // free from source file with #define redirect for alloc that wasnt From 2f9c6d37f033bbfa47e2caaae1ad56114157d7d5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 23:14:20 +0200 Subject: [PATCH 184/306] Test --- iguana/exchanges/LP_nativeDEX.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index ae0491bd2..15f431a6f 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1228,6 +1228,7 @@ void LP_free(void *ptr) n = 0; DL_FOREACH_SAFE(LP_memory_list,mp,tmp) { + printf("%d ",mp->len); total += mp->len; n++; } @@ -1245,7 +1246,7 @@ void LP_free(void *ptr) portable_mutex_lock(&LP_cJSONmutex); DL_DELETE(LP_memory_list,mp); portable_mutex_unlock(&LP_cJSONmutex); - printf(">>>>>>>>>>> LP_free ptr.%p mp.%p len.%u\n",ptr,mp,mp->len); + //printf(">>>>>>>>>>> LP_free ptr.%p mp.%p len.%u\n",ptr,mp,mp->len); free(mp->ptr); free(mp); } // free from source file with #define redirect for alloc that wasnt From 52f6758c4da6cbada73cf6fce0ed2a07fe8dcca3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 23:25:50 +0200 Subject: [PATCH 185/306] Test --- crypto777/bitcoind_RPC.c | 2 +- iguana/exchanges/LP_nativeDEX.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crypto777/bitcoind_RPC.c b/crypto777/bitcoind_RPC.c index a3488aeae..d799d5997 100755 --- a/crypto777/bitcoind_RPC.c +++ b/crypto777/bitcoind_RPC.c @@ -277,7 +277,7 @@ try_again: void init_string(struct return_string *s) { - s->len = 0; + s->len = 511; s->ptr = (char *)calloc(1,s->len+1); if ( s->ptr == NULL ) { diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 15f431a6f..3e44cfeb4 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1221,7 +1221,7 @@ void *LP_realloc(void *ptr,uint64_t len) void LP_free(void *ptr) { - static uint32_t lasttime; + static uint32_t lasttime,unknown; uint32_t now; int32_t n; uint64_t total = 0; struct LP_memory_list *mp,*tmp; if ( (now= (uint32_t)time(NULL)) > lasttime+6 ) { @@ -1232,7 +1232,7 @@ void LP_free(void *ptr) total += mp->len; n++; } - printf("total %d allocated total %llu\n",n,(long long)total); + printf("total %d allocated total %llu unknown.%u\n",n,(long long)total,unknown); lasttime = (uint32_t)time(NULL); } DL_FOREACH_SAFE(LP_memory_list,mp,tmp) @@ -1249,7 +1249,7 @@ void LP_free(void *ptr) //printf(">>>>>>>>>>> LP_free ptr.%p mp.%p len.%u\n",ptr,mp,mp->len); free(mp->ptr); free(mp); - } // free from source file with #define redirect for alloc that wasnt + } else unknown++; // free from source file with #define redirect for alloc that wasnt } char *LP_clonestr(char *str) From f855d1de39ff283cf0adcf82355d18753e44b07d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 23:32:12 +0200 Subject: [PATCH 186/306] Test --- iguana/exchanges/LP_nativeDEX.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 3e44cfeb4..306328470 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1200,10 +1200,14 @@ struct LP_memory_list void *ptr; } *LP_memory_list; +int32_t zeroval() { return(0); } + void *LP_alloc(uint64_t len) { struct LP_memory_list *mp; mp = calloc(1,sizeof(*mp)); + if ( len == 72 ) + printf("%d\n",1/zeroval()); //printf("\n>>>>>>>>>>> LP_alloc mp.%p ptr.%p len.%llu\n",mp,mp->ptr,(long long)len); mp->timestamp = (uint32_t)time(NULL); mp->len = (uint32_t)len; From 02c8de08cdc491f04143ba1353947b993fefe766 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 23:33:44 +0200 Subject: [PATCH 187/306] Test --- crypto777/iguana_utils.c | 2 -- iguana/exchanges/LP_nativeDEX.c | 1 - 2 files changed, 3 deletions(-) diff --git a/crypto777/iguana_utils.c b/crypto777/iguana_utils.c index e75257149..2e8f8e18b 100755 --- a/crypto777/iguana_utils.c +++ b/crypto777/iguana_utils.c @@ -446,8 +446,6 @@ char *clonestr(char *str) return(clone); } -int32_t zeroval() { return(0); } - int32_t safecopy(char *dest,char *src,long len) { int32_t i = -1; diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 306328470..b79e3f74c 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1199,7 +1199,6 @@ struct LP_memory_list uint32_t timestamp,len; void *ptr; } *LP_memory_list; - int32_t zeroval() { return(0); } void *LP_alloc(uint64_t len) From 4180e3df314da920fc270385d1e3a2312304ee79 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 23:36:20 +0200 Subject: [PATCH 188/306] Test --- crypto777/bitcoind_RPC.c | 2 +- iguana/exchanges/LP_nativeDEX.c | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/crypto777/bitcoind_RPC.c b/crypto777/bitcoind_RPC.c index d799d5997..f54394d90 100755 --- a/crypto777/bitcoind_RPC.c +++ b/crypto777/bitcoind_RPC.c @@ -277,7 +277,7 @@ try_again: void init_string(struct return_string *s) { - s->len = 511; + s->len = 8191; s->ptr = (char *)calloc(1,s->len+1); if ( s->ptr == NULL ) { diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index b79e3f74c..141cfca81 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1205,8 +1205,8 @@ void *LP_alloc(uint64_t len) { struct LP_memory_list *mp; mp = calloc(1,sizeof(*mp)); - if ( len == 72 ) - printf("%d\n",1/zeroval()); + //if ( len == 72 ) + // printf("%d\n",1/zeroval()); //printf("\n>>>>>>>>>>> LP_alloc mp.%p ptr.%p len.%llu\n",mp,mp->ptr,(long long)len); mp->timestamp = (uint32_t)time(NULL); mp->len = (uint32_t)len; @@ -1231,7 +1231,8 @@ void LP_free(void *ptr) n = 0; DL_FOREACH_SAFE(LP_memory_list,mp,tmp) { - printf("%d ",mp->len); + if ( mp->len != 72 ) + printf("%d ",mp->len); total += mp->len; n++; } From f8d51fe7398f70aa1845882f60a9268f2281c51a Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 23:38:32 +0200 Subject: [PATCH 189/306] 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 141cfca81..9980c7d3e 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1226,7 +1226,7 @@ void LP_free(void *ptr) { static uint32_t lasttime,unknown; uint32_t now; int32_t n; uint64_t total = 0; struct LP_memory_list *mp,*tmp; - if ( (now= (uint32_t)time(NULL)) > lasttime+6 ) + if ( (now= (uint32_t)time(NULL)) > lasttime+600 ) { n = 0; DL_FOREACH_SAFE(LP_memory_list,mp,tmp) From 1626b9f7ac4d7131c5ef4cdfd8c9c7e3cc7e0549 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 23:40:21 +0200 Subject: [PATCH 190/306] Test --- crypto777/bitcoind_RPC.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crypto777/bitcoind_RPC.c b/crypto777/bitcoind_RPC.c index f54394d90..a3488aeae 100755 --- a/crypto777/bitcoind_RPC.c +++ b/crypto777/bitcoind_RPC.c @@ -277,7 +277,7 @@ try_again: void init_string(struct return_string *s) { - s->len = 8191; + s->len = 0; s->ptr = (char *)calloc(1,s->len+1); if ( s->ptr == NULL ) { From 75ae3df6778c3b7063bdc184eebd0be3f62ffa8b Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 23:56:15 +0200 Subject: [PATCH 191/306] Test --- crypto777/bitcoind_RPC.c | 6 ++++-- crypto777/cJSON.c | 6 ++++-- iguana/exchanges/LP_nativeDEX.c | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/crypto777/bitcoind_RPC.c b/crypto777/bitcoind_RPC.c index a3488aeae..1116526fc 100755 --- a/crypto777/bitcoind_RPC.c +++ b/crypto777/bitcoind_RPC.c @@ -47,6 +47,7 @@ struct return_string { size_t accumulate(void *ptr, size_t size, size_t nmemb, struct return_string *s); void init_string(struct return_string *s); +static size_t WriteMemoryCallback(void *ptr,size_t size,size_t nmemb,void *data); /************************************************************************ @@ -161,13 +162,14 @@ try_again: *retstrp = 0; starttime = OS_milliseconds(); curl_handle = curl_easy_init(); - init_string(&s); + //init_string(&s); headers = curl_slist_append(0,"Expect:"); curl_easy_setopt(curl_handle,CURLOPT_USERAGENT,"mozilla/4.0");//"Mozilla/4.0 (compatible; )"); curl_easy_setopt(curl_handle,CURLOPT_HTTPHEADER, headers); curl_easy_setopt(curl_handle,CURLOPT_URL, url); - curl_easy_setopt(curl_handle,CURLOPT_WRITEFUNCTION, (void *)accumulate); // send all data to this function + //curl_easy_setopt(curl_handle,CURLOPT_WRITEFUNCTION, (void *)accumulate); // send all data to this function + curl_easy_setopt(curl_handle,CURLOPT_WRITEFUNCTION, (void *)WriteMemoryCallback); curl_easy_setopt(curl_handle,CURLOPT_WRITEDATA, &s); // we pass our 's' struct to the callback curl_easy_setopt(curl_handle,CURLOPT_NOSIGNAL, 1L); // supposed to fix "Alarm clock" and long jump crash curl_easy_setopt(curl_handle,CURLOPT_NOPROGRESS, 1L); // no progress callback diff --git a/crypto777/cJSON.c b/crypto777/cJSON.c index 93438fe79..4c0777656 100755 --- a/crypto777/cJSON.c +++ b/crypto777/cJSON.c @@ -54,8 +54,10 @@ static int32_t cJSON_strcasecmp(const char *s1,const char *s2) return tolower((int32_t)(*(const unsigned char *)s1)) - tolower((int32_t)(*(const unsigned char *)s2)); } -static void *(*cJSON_malloc)(size_t sz) = malloc; -static void (*cJSON_free)(void *ptr) = free; +void *LP_alloc(uint64_t len); +void LP_free(void *ptr); +static void *(*cJSON_malloc)(size_t sz) = (void *)LP_alloc; +static void (*cJSON_free)(void *ptr) = LP_free; static char* cJSON_strdup(const char* str) { diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 9980c7d3e..141cfca81 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1226,7 +1226,7 @@ void LP_free(void *ptr) { static uint32_t lasttime,unknown; uint32_t now; int32_t n; uint64_t total = 0; struct LP_memory_list *mp,*tmp; - if ( (now= (uint32_t)time(NULL)) > lasttime+600 ) + if ( (now= (uint32_t)time(NULL)) > lasttime+6 ) { n = 0; DL_FOREACH_SAFE(LP_memory_list,mp,tmp) From b4e579eb1caa6b592c31646dc268170f35db9c87 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 00:03:20 +0200 Subject: [PATCH 192/306] Test --- crypto777/bitcoind_RPC.c | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/crypto777/bitcoind_RPC.c b/crypto777/bitcoind_RPC.c index 1116526fc..435e88c22 100755 --- a/crypto777/bitcoind_RPC.c +++ b/crypto777/bitcoind_RPC.c @@ -45,6 +45,8 @@ struct return_string { size_t len; }; +struct MemoryStruct { char *memory; size_t size; }; + size_t accumulate(void *ptr, size_t size, size_t nmemb, struct return_string *s); void init_string(struct return_string *s); static size_t WriteMemoryCallback(void *ptr,size_t size,size_t nmemb,void *data); @@ -137,8 +139,9 @@ char *Jay_NXTrequest(char *command,char *params) char *bitcoind_RPC(char **retstrp,char *debugstr,char *url,char *userpass,char *command,char *params,int32_t timeout) { static int didinit,count,count2; static double elapsedsum,elapsedsum2; extern int32_t USE_JAY; + struct MemoryStruct chunk; struct curl_slist *headers = NULL; struct return_string s; CURLcode res; CURL *curl_handle; - char *bracket0,*bracket1,*databuf = 0; long len; int32_t specialcase,numretries; double starttime; + char *bracket0,*bracket1,*retstr,*databuf = 0; long len; int32_t specialcase,numretries; double starttime; if ( didinit == 0 ) { didinit = 1; @@ -162,13 +165,23 @@ try_again: *retstrp = 0; starttime = OS_milliseconds(); curl_handle = curl_easy_init(); - //init_string(&s); headers = curl_slist_append(0,"Expect:"); curl_easy_setopt(curl_handle,CURLOPT_USERAGENT,"mozilla/4.0");//"Mozilla/4.0 (compatible; )"); curl_easy_setopt(curl_handle,CURLOPT_HTTPHEADER, headers); curl_easy_setopt(curl_handle,CURLOPT_URL, url); - //curl_easy_setopt(curl_handle,CURLOPT_WRITEFUNCTION, (void *)accumulate); // send all data to this function + if ( (0) ) + { + init_string(&s); + curl_easy_setopt(curl_handle,CURLOPT_WRITEFUNCTION, (void *)accumulate); // send all data to this function + } + else + { + memset(&chunk,0,sizeof(chunk)); + curl_easy_setopt(curl_handle,CURLOPT_WRITEFUNCTION,WriteMemoryCallback); + curl_easy_setopt(curl_handle,CURLOPT_WRITEDATA,(void *)&chunk); + + } curl_easy_setopt(curl_handle,CURLOPT_WRITEFUNCTION, (void *)WriteMemoryCallback); curl_easy_setopt(curl_handle,CURLOPT_WRITEDATA, &s); // we pass our 's' struct to the callback curl_easy_setopt(curl_handle,CURLOPT_NOSIGNAL, 1L); // supposed to fix "Alarm clock" and long jump crash @@ -225,23 +238,24 @@ try_again: if ( specialcase != 0 || timeout != 0 ) { //printf("<<<<<<<<<<< bitcoind_RPC.(%s): BTCD.%s timeout params.(%s) s.ptr.(%s) err.%d\n",url,command,params,s.ptr,res); - free(s.ptr); + free(chunk.memory); //free(s.ptr); return(0); } else if ( numretries >= 4 ) { printf( "curl_easy_perform() failed: %s %s.(%s %s), retries: %d\n",curl_easy_strerror(res),debugstr,url,command,numretries); //printf("Maximum number of retries exceeded!\n"); - free(s.ptr); + free(chunk.memory);//free(s.ptr); return(0); } - free(s.ptr); + free(chunk.memory);//free(s.ptr); sleep((1< (%s)\n",params,s.ptr); + fprintf(stderr,"<<<<<<<<<<< bitcoind_RPC: BTCD.(%s) -> (%s)\n",params,retstr); count2++; elapsedsum2 += (OS_milliseconds() - starttime); if ( (count2 % 10000) == 0) printf("%d: ave %9.6f | elapsed %.3f millis | NXT calls.(%s) cmd.(%s)\n",count2,elapsedsum2/count2,(double)(OS_milliseconds() - starttime),url,command); - return(s.ptr); + return(retstr); } } //printf("bitcoind_RPC: impossible case\n"); @@ -310,8 +324,6 @@ size_t accumulate(void *ptr,size_t size,size_t nmemb,struct return_string *s) return(size * nmemb); } -struct MemoryStruct { char *memory; size_t size; }; - static size_t WriteMemoryCallback(void *ptr,size_t size,size_t nmemb,void *data) { size_t realsize = (size * nmemb); From 626c5c905110a3b36eca7c407bfc0628b2be9d02 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 00:06:18 +0200 Subject: [PATCH 193/306] Test --- crypto777/bitcoind_RPC.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crypto777/bitcoind_RPC.c b/crypto777/bitcoind_RPC.c index 435e88c22..865d45387 100755 --- a/crypto777/bitcoind_RPC.c +++ b/crypto777/bitcoind_RPC.c @@ -174,6 +174,7 @@ try_again: { init_string(&s); curl_easy_setopt(curl_handle,CURLOPT_WRITEFUNCTION, (void *)accumulate); // send all data to this function + curl_easy_setopt(curl_handle,CURLOPT_WRITEDATA, &s); // we pass our 's' struct to the callback } else { @@ -182,8 +183,6 @@ try_again: curl_easy_setopt(curl_handle,CURLOPT_WRITEDATA,(void *)&chunk); } - curl_easy_setopt(curl_handle,CURLOPT_WRITEFUNCTION, (void *)WriteMemoryCallback); - curl_easy_setopt(curl_handle,CURLOPT_WRITEDATA, &s); // we pass our 's' struct to the callback curl_easy_setopt(curl_handle,CURLOPT_NOSIGNAL, 1L); // supposed to fix "Alarm clock" and long jump crash curl_easy_setopt(curl_handle,CURLOPT_NOPROGRESS, 1L); // no progress callback if ( timeout > 0 ) From f222f8f4eb513e91b6e5880fd60e4de44b325361 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 00:10:13 +0200 Subject: [PATCH 194/306] Test --- crypto777/bitcoind_RPC.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crypto777/bitcoind_RPC.c b/crypto777/bitcoind_RPC.c index 865d45387..89e4dd28c 100755 --- a/crypto777/bitcoind_RPC.c +++ b/crypto777/bitcoind_RPC.c @@ -19,7 +19,7 @@ #include "OS_portable.h" #define LIQUIDITY_PROVIDER 1 -#define malloc(n) LP_alloc(n) +/*#define malloc(n) LP_alloc(n) #define realloc(ptr,n) LP_realloc(ptr,n) #define calloc(a,b) LP_alloc((uint64_t)(a) * (b)) #define free(ptr) LP_free(ptr) @@ -28,7 +28,7 @@ void *LP_realloc(void *ptr,uint64_t len); void *LP_alloc(uint64_t len); void LP_free(void *ptr); -char *LP_clonestr(char *str); +char *LP_clonestr(char *str);*/ #if LIQUIDITY_PROVIDER From 92360e9a6319e8faca1811b36be4bf4dfc52a6ab Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 00:19:30 +0200 Subject: [PATCH 195/306] Test --- crypto777/bitcoind_RPC.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/crypto777/bitcoind_RPC.c b/crypto777/bitcoind_RPC.c index 89e4dd28c..2a85a48d4 100755 --- a/crypto777/bitcoind_RPC.c +++ b/crypto777/bitcoind_RPC.c @@ -19,7 +19,7 @@ #include "OS_portable.h" #define LIQUIDITY_PROVIDER 1 -/*#define malloc(n) LP_alloc(n) +#define malloc(n) LP_alloc(n) #define realloc(ptr,n) LP_realloc(ptr,n) #define calloc(a,b) LP_alloc((uint64_t)(a) * (b)) #define free(ptr) LP_free(ptr) @@ -28,7 +28,7 @@ void *LP_realloc(void *ptr,uint64_t len); void *LP_alloc(uint64_t len); void LP_free(void *ptr); -char *LP_clonestr(char *str);*/ +char *LP_clonestr(char *str); #if LIQUIDITY_PROVIDER @@ -45,7 +45,7 @@ struct return_string { size_t len; }; -struct MemoryStruct { char *memory; size_t size; }; +struct MemoryStruct { char *memory; size_t size,allocsize; }; size_t accumulate(void *ptr, size_t size, size_t nmemb, struct return_string *s); void init_string(struct return_string *s); @@ -325,9 +325,20 @@ size_t accumulate(void *ptr,size_t size,size_t nmemb,struct return_string *s) static size_t WriteMemoryCallback(void *ptr,size_t size,size_t nmemb,void *data) { - size_t realsize = (size * nmemb); + size_t needed,realsize = (size * nmemb); struct MemoryStruct *mem = (struct MemoryStruct *)data; - mem->memory = (ptr != 0) ? realloc(mem->memory,mem->size + realsize + 1) : malloc(mem->size + realsize + 1); + needed = mem->size + realsize + 1; + if ( ptr == 0 && needed < 512 ) + { + mem->allocsize = 511; + mem->memory = malloc(mem->allocsize); + } + if ( mem->allocsize < needed ) + { + mem->memory = realloc(mem->memory,needed); + mem->allocsize = needed; + } + //mem->memory = (ptr != 0) ? realloc(mem->memory,mem->size + realsize + 1) : malloc(mem->size + realsize + 1); if ( mem->memory != 0 ) { if ( ptr != 0 ) From f9ed653c8abf9fb428fe8813b70639ff8821b243 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 00:21:26 +0200 Subject: [PATCH 196/306] Test --- crypto777/bitcoind_RPC.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crypto777/bitcoind_RPC.c b/crypto777/bitcoind_RPC.c index 2a85a48d4..4d9c21c13 100755 --- a/crypto777/bitcoind_RPC.c +++ b/crypto777/bitcoind_RPC.c @@ -335,7 +335,7 @@ static size_t WriteMemoryCallback(void *ptr,size_t size,size_t nmemb,void *data) } if ( mem->allocsize < needed ) { - mem->memory = realloc(mem->memory,needed); + mem->memory = (ptr != 0) ? realloc(mem->memory,needed) : malloc(needed); mem->allocsize = needed; } //mem->memory = (ptr != 0) ? realloc(mem->memory,mem->size + realsize + 1) : malloc(mem->size + realsize + 1); From f38279383e4c4cc4cfe1cf20717575de82d2b4c7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 00:25:43 +0200 Subject: [PATCH 197/306] Test --- crypto777/bitcoind_RPC.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crypto777/bitcoind_RPC.c b/crypto777/bitcoind_RPC.c index 4d9c21c13..d2e5f7b7f 100755 --- a/crypto777/bitcoind_RPC.c +++ b/crypto777/bitcoind_RPC.c @@ -330,11 +330,12 @@ static size_t WriteMemoryCallback(void *ptr,size_t size,size_t nmemb,void *data) needed = mem->size + realsize + 1; if ( ptr == 0 && needed < 512 ) { - mem->allocsize = 511; + mem->allocsize = 512; mem->memory = malloc(mem->allocsize); } if ( mem->allocsize < needed ) { + printf("curl needs %d more\n",(int32_t)realsize); mem->memory = (ptr != 0) ? realloc(mem->memory,needed) : malloc(needed); mem->allocsize = needed; } From ada5679cd48ee9f33e0d0ab5f71064841fded96b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 00:28:08 +0200 Subject: [PATCH 198/306] Test --- crypto777/bitcoind_RPC.c | 8 ++++---- iguana/exchanges/mm.c | 8 ++------ 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/crypto777/bitcoind_RPC.c b/crypto777/bitcoind_RPC.c index d2e5f7b7f..2708f8b96 100755 --- a/crypto777/bitcoind_RPC.c +++ b/crypto777/bitcoind_RPC.c @@ -19,7 +19,7 @@ #include "OS_portable.h" #define LIQUIDITY_PROVIDER 1 -#define malloc(n) LP_alloc(n) +/*#define malloc(n) LP_alloc(n) #define realloc(ptr,n) LP_realloc(ptr,n) #define calloc(a,b) LP_alloc((uint64_t)(a) * (b)) #define free(ptr) LP_free(ptr) @@ -28,7 +28,7 @@ void *LP_realloc(void *ptr,uint64_t len); void *LP_alloc(uint64_t len); void LP_free(void *ptr); -char *LP_clonestr(char *str); +char *LP_clonestr(char *str);*/ #if LIQUIDITY_PROVIDER @@ -328,9 +328,9 @@ static size_t WriteMemoryCallback(void *ptr,size_t size,size_t nmemb,void *data) size_t needed,realsize = (size * nmemb); struct MemoryStruct *mem = (struct MemoryStruct *)data; needed = mem->size + realsize + 1; - if ( ptr == 0 && needed < 512 ) + if ( ptr == 0 && needed < 1024 ) { - mem->allocsize = 512; + mem->allocsize = 1024; mem->memory = malloc(mem->allocsize); } if ( mem->allocsize < needed ) diff --git a/iguana/exchanges/mm.c b/iguana/exchanges/mm.c index d8ce0ed0d..2fb69cf65 100644 --- a/iguana/exchanges/mm.c +++ b/iguana/exchanges/mm.c @@ -27,10 +27,6 @@ void PNACL_message(char *arg,...) } #define FROM_MARKETMAKER -#ifndef CJSON_GARBAGECOLLECTION -#define CJSON_GARBAGECOLLECTION -#endif - #include #include #ifndef NATIVE_WINDOWS @@ -39,7 +35,7 @@ void PNACL_message(char *arg,...) #include "../../crypto777/OS_portable.h" #endif // !_WIN_32 -#define malloc(n) LP_alloc(n) +/*#define malloc(n) LP_alloc(n) #define realloc(ptr,n) LP_realloc(ptr,n) #define calloc(a,b) LP_alloc((uint64_t)(a) * (b)) #define free(ptr) LP_free(ptr) @@ -48,7 +44,7 @@ void PNACL_message(char *arg,...) void *LP_realloc(void *ptr,uint64_t len); void *LP_alloc(uint64_t len); void LP_free(void *ptr); -char *LP_clonestr(char *str); +char *LP_clonestr(char *str);*/ #define MAX(a,b) ((a) > (b) ? (a) : (b)) char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *remoteaddr,uint16_t port); From ed4935142505a850e7945323886620d90536461b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 00:29:52 +0200 Subject: [PATCH 199/306] Test --- crypto777/bitcoind_RPC.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crypto777/bitcoind_RPC.c b/crypto777/bitcoind_RPC.c index 2708f8b96..15934cc11 100755 --- a/crypto777/bitcoind_RPC.c +++ b/crypto777/bitcoind_RPC.c @@ -328,14 +328,14 @@ static size_t WriteMemoryCallback(void *ptr,size_t size,size_t nmemb,void *data) size_t needed,realsize = (size * nmemb); struct MemoryStruct *mem = (struct MemoryStruct *)data; needed = mem->size + realsize + 1; - if ( ptr == 0 && needed < 1024 ) + if ( ptr == 0 && needed < 256 ) { - mem->allocsize = 1024; + mem->allocsize = 256; mem->memory = malloc(mem->allocsize); } if ( mem->allocsize < needed ) { - printf("curl needs %d more\n",(int32_t)realsize); + //printf("curl needs %d more\n",(int32_t)realsize); mem->memory = (ptr != 0) ? realloc(mem->memory,needed) : malloc(needed); mem->allocsize = needed; } From 2ad3f0b9d705a8eec2e3919dc023bcc44422524a Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 00:31:42 +0200 Subject: [PATCH 200/306] Test --- iguana/exchanges/LP_nativeDEX.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 141cfca81..7f7c4a4b5 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1225,18 +1225,18 @@ void *LP_realloc(void *ptr,uint64_t len) void LP_free(void *ptr) { static uint32_t lasttime,unknown; - uint32_t now; int32_t n; uint64_t total = 0; struct LP_memory_list *mp,*tmp; + uint32_t now; int32_t n,lagging; uint64_t total = 0; struct LP_memory_list *mp,*tmp; if ( (now= (uint32_t)time(NULL)) > lasttime+6 ) { - n = 0; + n = lagging = 0; DL_FOREACH_SAFE(LP_memory_list,mp,tmp) { - if ( mp->len != 72 ) - printf("%d ",mp->len); + if ( now > mp->timestamp+60 ) + lagging++; total += mp->len; n++; } - printf("total %d allocated total %llu unknown.%u\n",n,(long long)total,unknown); + printf("total %d allocated total %llu unknown.%u lagging.%d\n",n,(long long)total,unknown,lagging); lasttime = (uint32_t)time(NULL); } DL_FOREACH_SAFE(LP_memory_list,mp,tmp) From bac171ae6058b60d63b3b0448803c570ebd61094 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 00:37:35 +0200 Subject: [PATCH 201/306] Test --- crypto777/OS_portable.h | 1 + iguana/exchanges/LP_nativeDEX.c | 15 +++++++++++---- iguana/exchanges/LP_utxo.c | 1 - 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/crypto777/OS_portable.h b/crypto777/OS_portable.h index 605eb544e..3d90521bd 100755 --- a/crypto777/OS_portable.h +++ b/crypto777/OS_portable.h @@ -276,6 +276,7 @@ void *queue_delete(queue_t *queue,struct queueitem *copy,int32_t copysize,int32_ void *queue_free(queue_t *queue); void *queue_clone(queue_t *clone,queue_t *queue,int32_t size); int32_t queue_size(queue_t *queue); +char *mbstr(char *str,double n); void iguana_memreset(struct OS_memspace *mem); void iguana_mempurge(struct OS_memspace *mem); diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 7f7c4a4b5..e45b1a08d 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1225,18 +1225,25 @@ void *LP_realloc(void *ptr,uint64_t len) void LP_free(void *ptr) { static uint32_t lasttime,unknown; - uint32_t now; int32_t n,lagging; uint64_t total = 0; struct LP_memory_list *mp,*tmp; + uint32_t now; char str[65]; int32_t n,lagging; uint64_t total = 0; struct LP_memory_list *mp,*tmp; if ( (now= (uint32_t)time(NULL)) > lasttime+6 ) { n = lagging = 0; + portable_mutex_lock(&LP_cJSONmutex); DL_FOREACH_SAFE(LP_memory_list,mp,tmp) { - if ( now > mp->timestamp+60 ) - lagging++; total += mp->len; n++; + if ( now > mp->timestamp+60 ) + { + lagging++; + DL_DELETE(LP_memory_list,mp); + free(mp->ptr); + free(mp); + } } - printf("total %d allocated total %llu unknown.%u lagging.%d\n",n,(long long)total,unknown,lagging); + portable_mutex_unlock(&LP_cJSONmutex); + printf("total %d allocated total %llu %s unknown.%u lagging.%d\n",n,(long long)total,mbstr(str,total),unknown,lagging); lasttime = (uint32_t)time(NULL); } DL_FOREACH_SAFE(LP_memory_list,mp,tmp) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index fcd05feb3..73a8e0260 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -47,7 +47,6 @@ void cJSON_register(cJSON *item) portable_mutex_unlock(&LP_cJSONmutex); } -char *mbstr(char *str,double n); void cJSON_unregister(cJSON *item) { static uint32_t lasttime; From 6fd921733c9a0adc29bf907c3feda6ab6466e353 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 00:49:48 +0200 Subject: [PATCH 202/306] 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 e45b1a08d..e38ac69fe 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1234,7 +1234,7 @@ void LP_free(void *ptr) { total += mp->len; n++; - if ( now > mp->timestamp+60 ) + if ( now > mp->timestamp+600 ) { lagging++; DL_DELETE(LP_memory_list,mp); From 88b4d2ba7939e8afd7bd5a6e32548c613c2f7ae0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 00:58:06 +0200 Subject: [PATCH 203/306] Test --- crypto777/cJSON.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/crypto777/cJSON.c b/crypto777/cJSON.c index 4c0777656..d6c43f2fa 100755 --- a/crypto777/cJSON.c +++ b/crypto777/cJSON.c @@ -829,7 +829,7 @@ char *jstr(cJSON *json,char *field) { if ( json == 0 ) return(0); if ( field == char *jstri(cJSON *json,int32_t i) { return(cJSON_str(cJSON_GetArrayItem(json,i))); } char *jprint(cJSON *json,int32_t freeflag) { - char *str; + char *str,*retstr; /*static portable_mutex_t mutex; static int32_t initflag; if ( initflag == 0 ) { @@ -843,8 +843,11 @@ char *jprint(cJSON *json,int32_t freeflag) str = cJSON_Print(json), _stripwhite(str,' '); if ( freeflag != 0 ) free_json(json); + retstr = malloc(strlen(str) + 1); + strcpy(retstr,str); + cJSON_free(str); //portable_mutex_unlock(&mutex); - return(str); + return(retstr); } bits256 get_API_bits256(cJSON *obj) From a9874c2456f5c8d22eb903517ae3669e13a03427 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 01:08:08 +0200 Subject: [PATCH 204/306] Test --- iguana/exchanges/LP_nativeDEX.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index e38ac69fe..27f4b57bd 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1204,13 +1204,13 @@ int32_t zeroval() { return(0); } void *LP_alloc(uint64_t len) { struct LP_memory_list *mp; - mp = calloc(1,sizeof(*mp)); + mp = calloc(1,sizeof(*mp) + len); //if ( len == 72 ) // printf("%d\n",1/zeroval()); //printf("\n>>>>>>>>>>> LP_alloc mp.%p ptr.%p len.%llu\n",mp,mp->ptr,(long long)len); mp->timestamp = (uint32_t)time(NULL); mp->len = (uint32_t)len; - mp->ptr = calloc(1,len); + mp->ptr = &mp[1]; portable_mutex_lock(&LP_cJSONmutex); DL_APPEND(LP_memory_list,mp); portable_mutex_unlock(&LP_cJSONmutex); @@ -1225,7 +1225,8 @@ void *LP_realloc(void *ptr,uint64_t len) void LP_free(void *ptr) { static uint32_t lasttime,unknown; - uint32_t now; char str[65]; int32_t n,lagging; uint64_t total = 0; struct LP_memory_list *mp,*tmp; + uint32_t now; char str[65]; int32_t n,lagging; uint64_t total = 0; struct LP_memory_list *mp,*tmp,*freemp = ptr; + --freemp; if ( (now= (uint32_t)time(NULL)) > lasttime+6 ) { n = lagging = 0; @@ -1234,11 +1235,11 @@ void LP_free(void *ptr) { total += mp->len; n++; - if ( now > mp->timestamp+600 ) + if ( now > mp->timestamp+60 ) { lagging++; DL_DELETE(LP_memory_list,mp); - free(mp->ptr); + //free(mp->ptr); free(mp); } } @@ -1258,7 +1259,7 @@ void LP_free(void *ptr) DL_DELETE(LP_memory_list,mp); portable_mutex_unlock(&LP_cJSONmutex); //printf(">>>>>>>>>>> LP_free ptr.%p mp.%p len.%u\n",ptr,mp,mp->len); - free(mp->ptr); + //free(mp->ptr); free(mp); } else unknown++; // free from source file with #define redirect for alloc that wasnt } From e092b8a80f2c6c4be71f6332097421d6076bdd1c Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 01:09:06 +0200 Subject: [PATCH 205/306] Test --- iguana/exchanges/LP_nativeDEX.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 27f4b57bd..1f71f2c01 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1253,6 +1253,8 @@ void LP_free(void *ptr) break; mp = 0; } + if ( mp != freemp ) + printf("mp %p != %p\n",mp,freemp); if ( mp != 0 ) { portable_mutex_lock(&LP_cJSONmutex); From 53b669a481ddca9ed644a23306ca9e79b81366af Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 01:11:21 +0200 Subject: [PATCH 206/306] Test --- crypto777/bitcoind_RPC.c | 2 +- iguana/exchanges/LP_nativeDEX.c | 2 +- iguana/exchanges/stats.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crypto777/bitcoind_RPC.c b/crypto777/bitcoind_RPC.c index 15934cc11..f624cd342 100755 --- a/crypto777/bitcoind_RPC.c +++ b/crypto777/bitcoind_RPC.c @@ -95,7 +95,7 @@ char *post_process_bitcoind_RPC(char *debugstr,char *command,char *rpcstr,char * { if ( (error->type&0xff) == cJSON_NULL && (result->type&0xff) != cJSON_NULL ) { - retstr = cJSON_Print(result); + retstr = jprint(result,0); len = strlen(retstr); if ( retstr[0] == '"' && retstr[len-1] == '"' ) { diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 1f71f2c01..542eb5909 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1254,7 +1254,7 @@ void LP_free(void *ptr) mp = 0; } if ( mp != freemp ) - printf("mp %p != %p\n",mp,freemp); + printf("mp %p != %p\n",mp,freemp);` if ( mp != 0 ) { portable_mutex_lock(&LP_cJSONmutex); diff --git a/iguana/exchanges/stats.c b/iguana/exchanges/stats.c index d283b1301..179612c4e 100644 --- a/iguana/exchanges/stats.c +++ b/iguana/exchanges/stats.c @@ -529,7 +529,7 @@ char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *po free(retstr); } #endif - //printf("(%s) {%s} -> (%s) postflag.%d (%s)\n",urlstr,jprint(argjson,0),cJSON_Print(json),*postflagp,retstr); + //printf("(%s) {%s} -> (%s) postflag.%d (%s)\n",urlstr,jprint(argjson,0),jprint(json,0),*postflagp,retstr); } free_json(origargjson); retstr = jprint(retarray,1); From 2ddc69d8fb6353a6016196ef2243f8ec30adaef0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 01:12:39 +0200 Subject: [PATCH 207/306] Test --- iguana/exchanges/LP_nativeDEX.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 542eb5909..a543f8c27 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1188,10 +1188,10 @@ void LP_fromjs_iter() #endif -#undef calloc +/*#undef calloc #undef free #undef realloc -#undef clonestr +#undef clonestr*/ struct LP_memory_list { @@ -1254,7 +1254,7 @@ void LP_free(void *ptr) mp = 0; } if ( mp != freemp ) - printf("mp %p != %p\n",mp,freemp);` + printf("mp %p != %p\n",mp,freemp); if ( mp != 0 ) { portable_mutex_lock(&LP_cJSONmutex); From fa5a2a0b6fc6f16168113941881f602bfc82ee53 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 01:17:03 +0200 Subject: [PATCH 208/306] Test --- crypto777/cJSON.c | 2 +- iguana/exchanges/LP_nativeDEX.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crypto777/cJSON.c b/crypto777/cJSON.c index d6c43f2fa..3c8c376db 100755 --- a/crypto777/cJSON.c +++ b/crypto777/cJSON.c @@ -843,7 +843,7 @@ char *jprint(cJSON *json,int32_t freeflag) str = cJSON_Print(json), _stripwhite(str,' '); if ( freeflag != 0 ) free_json(json); - retstr = malloc(strlen(str) + 1); + retstr = LP_alloc(strlen(str) + 1); strcpy(retstr,str); cJSON_free(str); //portable_mutex_unlock(&mutex); diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index a543f8c27..1f71f2c01 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1188,10 +1188,10 @@ void LP_fromjs_iter() #endif -/*#undef calloc +#undef calloc #undef free #undef realloc -#undef clonestr*/ +#undef clonestr struct LP_memory_list { From f0845127e978cf4485154f39b399f4008fe2d210 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 01:19:17 +0200 Subject: [PATCH 209/306] Test --- crypto777/cJSON.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crypto777/cJSON.c b/crypto777/cJSON.c index 3c8c376db..a1007d34a 100755 --- a/crypto777/cJSON.c +++ b/crypto777/cJSON.c @@ -845,7 +845,7 @@ char *jprint(cJSON *json,int32_t freeflag) free_json(json); retstr = LP_alloc(strlen(str) + 1); strcpy(retstr,str); - cJSON_free(str); + //cJSON_free(str); //portable_mutex_unlock(&mutex); return(retstr); } From 17e0abbe28731ba6b3300db360e5d1105839e7c3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 01:21:18 +0200 Subject: [PATCH 210/306] Test --- crypto777/cJSON.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crypto777/cJSON.c b/crypto777/cJSON.c index a1007d34a..c79287421 100755 --- a/crypto777/cJSON.c +++ b/crypto777/cJSON.c @@ -829,7 +829,7 @@ char *jstr(cJSON *json,char *field) { if ( json == 0 ) return(0); if ( field == char *jstri(cJSON *json,int32_t i) { return(cJSON_str(cJSON_GetArrayItem(json,i))); } char *jprint(cJSON *json,int32_t freeflag) { - char *str,*retstr; + char *str; /*static portable_mutex_t mutex; static int32_t initflag; if ( initflag == 0 ) { @@ -843,11 +843,11 @@ char *jprint(cJSON *json,int32_t freeflag) str = cJSON_Print(json), _stripwhite(str,' '); if ( freeflag != 0 ) free_json(json); - retstr = LP_alloc(strlen(str) + 1); - strcpy(retstr,str); - //cJSON_free(str); + //retstr = LP_alloc(strlen(str) + 1); + //strcpy(retstr,str); + //cJSON_free(str); garbage collected //portable_mutex_unlock(&mutex); - return(retstr); + return(str); } bits256 get_API_bits256(cJSON *obj) From 3e87ced94cca68c241ad25b088f6756e2274b31d Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 01:23:17 +0200 Subject: [PATCH 211/306] Test --- crypto777/cJSON.c | 10 +++++----- iguana/exchanges/LP_nativeDEX.c | 11 ++++------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/crypto777/cJSON.c b/crypto777/cJSON.c index c79287421..3c8c376db 100755 --- a/crypto777/cJSON.c +++ b/crypto777/cJSON.c @@ -829,7 +829,7 @@ char *jstr(cJSON *json,char *field) { if ( json == 0 ) return(0); if ( field == char *jstri(cJSON *json,int32_t i) { return(cJSON_str(cJSON_GetArrayItem(json,i))); } char *jprint(cJSON *json,int32_t freeflag) { - char *str; + char *str,*retstr; /*static portable_mutex_t mutex; static int32_t initflag; if ( initflag == 0 ) { @@ -843,11 +843,11 @@ char *jprint(cJSON *json,int32_t freeflag) str = cJSON_Print(json), _stripwhite(str,' '); if ( freeflag != 0 ) free_json(json); - //retstr = LP_alloc(strlen(str) + 1); - //strcpy(retstr,str); - //cJSON_free(str); garbage collected + retstr = LP_alloc(strlen(str) + 1); + strcpy(retstr,str); + cJSON_free(str); //portable_mutex_unlock(&mutex); - return(str); + return(retstr); } bits256 get_API_bits256(cJSON *obj) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 1f71f2c01..d1cbba606 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1210,7 +1210,7 @@ void *LP_alloc(uint64_t len) //printf("\n>>>>>>>>>>> LP_alloc mp.%p ptr.%p len.%llu\n",mp,mp->ptr,(long long)len); mp->timestamp = (uint32_t)time(NULL); mp->len = (uint32_t)len; - mp->ptr = &mp[1]; + mp->ptr = calloc(1,len); portable_mutex_lock(&LP_cJSONmutex); DL_APPEND(LP_memory_list,mp); portable_mutex_unlock(&LP_cJSONmutex); @@ -1225,8 +1225,7 @@ void *LP_realloc(void *ptr,uint64_t len) void LP_free(void *ptr) { static uint32_t lasttime,unknown; - uint32_t now; char str[65]; int32_t n,lagging; uint64_t total = 0; struct LP_memory_list *mp,*tmp,*freemp = ptr; - --freemp; + uint32_t now; char str[65]; int32_t n,lagging; uint64_t total = 0; struct LP_memory_list *mp,*tmp; if ( (now= (uint32_t)time(NULL)) > lasttime+6 ) { n = lagging = 0; @@ -1239,7 +1238,7 @@ void LP_free(void *ptr) { lagging++; DL_DELETE(LP_memory_list,mp); - //free(mp->ptr); + free(mp->ptr); free(mp); } } @@ -1253,15 +1252,13 @@ void LP_free(void *ptr) break; mp = 0; } - if ( mp != freemp ) - printf("mp %p != %p\n",mp,freemp); if ( mp != 0 ) { portable_mutex_lock(&LP_cJSONmutex); DL_DELETE(LP_memory_list,mp); portable_mutex_unlock(&LP_cJSONmutex); //printf(">>>>>>>>>>> LP_free ptr.%p mp.%p len.%u\n",ptr,mp,mp->len); - //free(mp->ptr); + free(mp->ptr); free(mp); } else unknown++; // free from source file with #define redirect for alloc that wasnt } From 8e2feae84c53e05013d15ae18674ddccd5b07a2e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 01:26:35 +0200 Subject: [PATCH 212/306] Test --- iguana/exchanges/LP_nativeDEX.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index d1cbba606..a4e5131f5 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1229,7 +1229,6 @@ void LP_free(void *ptr) if ( (now= (uint32_t)time(NULL)) > lasttime+6 ) { n = lagging = 0; - portable_mutex_lock(&LP_cJSONmutex); DL_FOREACH_SAFE(LP_memory_list,mp,tmp) { total += mp->len; @@ -1237,12 +1236,16 @@ void LP_free(void *ptr) if ( now > mp->timestamp+60 ) { lagging++; - DL_DELETE(LP_memory_list,mp); - free(mp->ptr); - free(mp); + if ( now > mp->timestamp+600 ) + { + portable_mutex_lock(&LP_cJSONmutex); + DL_DELETE(LP_memory_list,mp); + portable_mutex_unlock(&LP_cJSONmutex); + free(mp->ptr); + free(mp); + } } } - portable_mutex_unlock(&LP_cJSONmutex); printf("total %d allocated total %llu %s unknown.%u lagging.%d\n",n,(long long)total,mbstr(str,total),unknown,lagging); lasttime = (uint32_t)time(NULL); } From 1ffc1e3cb3a2122e1c8d041c16d2cd3da473651e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 01:32:46 +0200 Subject: [PATCH 213/306] Test --- iguana/exchanges/LP_nativeDEX.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index a4e5131f5..45d188cbc 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1225,7 +1225,7 @@ void *LP_realloc(void *ptr,uint64_t len) void LP_free(void *ptr) { static uint32_t lasttime,unknown; - uint32_t now; char str[65]; int32_t n,lagging; uint64_t total = 0; struct LP_memory_list *mp,*tmp; + uint32_t now; char str[65],*tmpstr; int32_t n,lagging; uint64_t total = 0; struct LP_memory_list *mp,*tmp; if ( (now= (uint32_t)time(NULL)) > lasttime+6 ) { n = lagging = 0; @@ -1241,6 +1241,10 @@ void LP_free(void *ptr) portable_mutex_lock(&LP_cJSONmutex); DL_DELETE(LP_memory_list,mp); portable_mutex_unlock(&LP_cJSONmutex); + tmpstr = jprint(mp->ptr,0); + if ( strlen(tmpstr) > 32 ) + printf("laggged.(%s)\n",tmpstr); + free(tmpstr); free(mp->ptr); free(mp); } From 24a4574097e4f5d43d1025048444a6d5b899302a Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 01:40:08 +0200 Subject: [PATCH 214/306] 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 45d188cbc..25b7f7d6b 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1236,7 +1236,7 @@ void LP_free(void *ptr) if ( now > mp->timestamp+60 ) { lagging++; - if ( now > mp->timestamp+600 ) + if ( now > mp->timestamp+60 ) { portable_mutex_lock(&LP_cJSONmutex); DL_DELETE(LP_memory_list,mp); From fdfc1e05b9aa62035ecaefa90bb22ff2fb62e751 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 01:42:46 +0200 Subject: [PATCH 215/306] Test --- crypto777/cJSON.c | 7 ++----- iguana/exchanges/mm.c | 11 ----------- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/crypto777/cJSON.c b/crypto777/cJSON.c index 3c8c376db..4c0777656 100755 --- a/crypto777/cJSON.c +++ b/crypto777/cJSON.c @@ -829,7 +829,7 @@ char *jstr(cJSON *json,char *field) { if ( json == 0 ) return(0); if ( field == char *jstri(cJSON *json,int32_t i) { return(cJSON_str(cJSON_GetArrayItem(json,i))); } char *jprint(cJSON *json,int32_t freeflag) { - char *str,*retstr; + char *str; /*static portable_mutex_t mutex; static int32_t initflag; if ( initflag == 0 ) { @@ -843,11 +843,8 @@ char *jprint(cJSON *json,int32_t freeflag) str = cJSON_Print(json), _stripwhite(str,' '); if ( freeflag != 0 ) free_json(json); - retstr = LP_alloc(strlen(str) + 1); - strcpy(retstr,str); - cJSON_free(str); //portable_mutex_unlock(&mutex); - return(retstr); + return(str); } bits256 get_API_bits256(cJSON *obj) diff --git a/iguana/exchanges/mm.c b/iguana/exchanges/mm.c index 2fb69cf65..a87481f15 100644 --- a/iguana/exchanges/mm.c +++ b/iguana/exchanges/mm.c @@ -35,17 +35,6 @@ void PNACL_message(char *arg,...) #include "../../crypto777/OS_portable.h" #endif // !_WIN_32 -/*#define malloc(n) LP_alloc(n) -#define realloc(ptr,n) LP_realloc(ptr,n) -#define calloc(a,b) LP_alloc((uint64_t)(a) * (b)) -#define free(ptr) LP_free(ptr) -#define clonestr(str) LP_clonestr(str) - -void *LP_realloc(void *ptr,uint64_t len); -void *LP_alloc(uint64_t len); -void LP_free(void *ptr); -char *LP_clonestr(char *str);*/ - #define MAX(a,b) ((a) > (b) ? (a) : (b)) char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *remoteaddr,uint16_t port); #include "stats.c" From 368b115e6937a2b336cf2e99e09bc8a92afe7822 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 01:45:10 +0200 Subject: [PATCH 216/306] Test --- iguana/exchanges/LP_nativeDEX.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 25b7f7d6b..9dc817283 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1225,7 +1225,7 @@ void *LP_realloc(void *ptr,uint64_t len) void LP_free(void *ptr) { static uint32_t lasttime,unknown; - uint32_t now; char str[65],*tmpstr; int32_t n,lagging; uint64_t total = 0; struct LP_memory_list *mp,*tmp; + uint32_t now; char str[65]; int32_t n,lagging; uint64_t total = 0; struct LP_memory_list *mp,*tmp; if ( (now= (uint32_t)time(NULL)) > lasttime+6 ) { n = lagging = 0; @@ -1241,10 +1241,6 @@ void LP_free(void *ptr) portable_mutex_lock(&LP_cJSONmutex); DL_DELETE(LP_memory_list,mp); portable_mutex_unlock(&LP_cJSONmutex); - tmpstr = jprint(mp->ptr,0); - if ( strlen(tmpstr) > 32 ) - printf("laggged.(%s)\n",tmpstr); - free(tmpstr); free(mp->ptr); free(mp); } From 11810f2ecec55a7429c9b0a1e5f9b8b7b51aa1ce Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 01:48:22 +0200 Subject: [PATCH 217/306] Test --- iguana/exchanges/LP_nativeDEX.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 9dc817283..9fb89373c 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1203,6 +1203,7 @@ int32_t zeroval() { return(0); } void *LP_alloc(uint64_t len) { + return(calloc(1,len)); struct LP_memory_list *mp; mp = calloc(1,sizeof(*mp) + len); //if ( len == 72 ) @@ -1225,6 +1226,8 @@ void *LP_realloc(void *ptr,uint64_t len) void LP_free(void *ptr) { static uint32_t lasttime,unknown; + free(ptr); + return; uint32_t now; char str[65]; int32_t n,lagging; uint64_t total = 0; struct LP_memory_list *mp,*tmp; if ( (now= (uint32_t)time(NULL)) > lasttime+6 ) { From 49395f34353d560f24e11c0fc7dc957e51022077 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 02:18:09 +0200 Subject: [PATCH 218/306] Test --- iguana/exchanges/LP_nativeDEX.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 9fb89373c..420224863 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1200,10 +1200,12 @@ struct LP_memory_list void *ptr; } *LP_memory_list; int32_t zeroval() { return(0); } +long LP_cjson_allocated; void *LP_alloc(uint64_t len) { - return(calloc(1,len)); + LP_cjson_allocated += len; + //return(calloc(1,len)); struct LP_memory_list *mp; mp = calloc(1,sizeof(*mp) + len); //if ( len == 72 ) @@ -1226,8 +1228,8 @@ void *LP_realloc(void *ptr,uint64_t len) void LP_free(void *ptr) { static uint32_t lasttime,unknown; - free(ptr); - return; + //free(ptr); + //return; uint32_t now; char str[65]; int32_t n,lagging; uint64_t total = 0; struct LP_memory_list *mp,*tmp; if ( (now= (uint32_t)time(NULL)) > lasttime+6 ) { @@ -1236,7 +1238,7 @@ void LP_free(void *ptr) { total += mp->len; n++; - if ( now > mp->timestamp+60 ) + if ( 0 && now > mp->timestamp+60 ) { lagging++; if ( now > mp->timestamp+60 ) @@ -1249,7 +1251,7 @@ void LP_free(void *ptr) } } } - printf("total %d allocated total %llu %s unknown.%u lagging.%d\n",n,(long long)total,mbstr(str,total),unknown,lagging); + printf("total %d allocated total %llu/%llu %s unknown.%u lagging.%d\n",n,(long long)total,(long long)LP_cjson_allocated,mbstr(str,total),unknown,lagging); lasttime = (uint32_t)time(NULL); } DL_FOREACH_SAFE(LP_memory_list,mp,tmp) @@ -1260,6 +1262,7 @@ void LP_free(void *ptr) } if ( mp != 0 ) { + LP_cjson_allocated -= mp->len; portable_mutex_lock(&LP_cJSONmutex); DL_DELETE(LP_memory_list,mp); portable_mutex_unlock(&LP_cJSONmutex); From ac69ce359cf0e34d1e21d5180898194153183029 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 02:21:43 +0200 Subject: [PATCH 219/306] Test --- iguana/exchanges/LP_nativeDEX.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 420224863..68b481beb 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1200,11 +1200,13 @@ struct LP_memory_list void *ptr; } *LP_memory_list; int32_t zeroval() { return(0); } -long LP_cjson_allocated; +long LP_cjson_allocated,LP_cjson_total,LP_cjson_count; void *LP_alloc(uint64_t len) { LP_cjson_allocated += len; + LP_cjson_total += len; + LP_cjson_count++; //return(calloc(1,len)); struct LP_memory_list *mp; mp = calloc(1,sizeof(*mp) + len); @@ -1231,7 +1233,7 @@ void LP_free(void *ptr) //free(ptr); //return; uint32_t now; char str[65]; int32_t n,lagging; uint64_t total = 0; struct LP_memory_list *mp,*tmp; - if ( (now= (uint32_t)time(NULL)) > lasttime+6 ) + if ( (now= (uint32_t)time(NULL)) > lasttime+60 ) { n = lagging = 0; DL_FOREACH_SAFE(LP_memory_list,mp,tmp) @@ -1251,7 +1253,7 @@ void LP_free(void *ptr) } } } - printf("total %d allocated total %llu/%llu %s unknown.%u lagging.%d\n",n,(long long)total,(long long)LP_cjson_allocated,mbstr(str,total),unknown,lagging); + printf("total %d allocated total %llu/%llu [%llu %llu] %.1f ave %s unknown.%u lagging.%d\n",n,(long long)total,(long long)LP_cjson_allocated,(long long)LP_cjson_total,(long long)LP_cjson_count,(double)LP_cjson_total/LP_cjson_count,mbstr(str,total),unknown,lagging); lasttime = (uint32_t)time(NULL); } DL_FOREACH_SAFE(LP_memory_list,mp,tmp) From 42374bec95a96f6f7c88644a1914b998250f429f Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 06:07:26 +0200 Subject: [PATCH 220/306] Test --- iguana/exchanges/LP_nativeDEX.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 68b481beb..8647c628b 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -28,6 +28,9 @@ // bigendian architectures need to use little endian for sighash calcs #include + +long LP_cjson_allocated,LP_cjson_total,LP_cjson_count; + struct LP_millistats { double lastmilli,millisum,threshold; @@ -367,8 +370,11 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int } if ( validreq != 0 ) { + long startval = LP_cjson_allocated; if ( (retstr= LP_process_message(ctx,typestr,myipaddr,pubsock,ptr,recvlen,sock)) != 0 ) free(retstr); + if ( LP_cjson_allocated > startval ) + printf("leaked.%ld (%s)\n",LP_cjson_allocated - startval,(char *)ptr); if ( Broadcaststr != 0 ) { //printf("self broadcast.(%s)\n",Broadcaststr); @@ -1200,7 +1206,6 @@ struct LP_memory_list void *ptr; } *LP_memory_list; int32_t zeroval() { return(0); } -long LP_cjson_allocated,LP_cjson_total,LP_cjson_count; void *LP_alloc(uint64_t len) { From 4dcee59450b1dae62ec6e735336bc1b10c723778 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 06:10:35 +0200 Subject: [PATCH 221/306] Test --- iguana/exchanges/LP_nativeDEX.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 8647c628b..69b61d57b 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -309,10 +309,15 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock, } else { + long startval = LP_cjson_allocated; if ( (retstr= LP_command_process(ctx,myipaddr,pubsock,argjson,&((uint8_t *)ptr)[len],recvlen - len)) != 0 ) { } - //printf("%.3f %s LP_command_process\n",OS_milliseconds()-millis,jstr(argjson,"method")); + if ( LP_cjson_allocated > startval ) + { + char *str = jprint(argjson,0); + printf("leaked.%ld (%s)\n",LP_cjson_allocated - startval,str); + } } } if ( argjson != 0 ) From be43224300ad87717201451d82f9adaa398c64aa Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 06:13:33 +0200 Subject: [PATCH 222/306] Test --- iguana/exchanges/LP_nativeDEX.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 69b61d57b..4c2d45d39 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -183,12 +183,19 @@ char *LP_command_process(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson return(0); if ( LP_tradecommand(ctx,myipaddr,pubsock,argjson,data,datalen) <= 0 ) { + long startval = LP_cjson_allocated; if ( (retstr= stats_JSON(ctx,myipaddr,pubsock,argjson,"127.0.0.1",0)) != 0 ) { //printf("%s PULL.[%d]-> (%s)\n",myipaddr != 0 ? myipaddr : "127.0.0.1",datalen,retstr); //if ( pubsock >= 0 ) //strncmp("{\"error\":",retstr,strlen("{\"error\":")) != 0 && //LP_send(pubsock,retstr,(int32_t)strlen(retstr)+1,0); } + if ( LP_cjson_allocated > startval ) + { + char *leakstr = jprint(argjson,0); + printf("stats_JSON leaked.%ld (%s)\n",LP_cjson_allocated - startval,leakstr); + free(leakstr); + } } //else printf("finished tradecommand (%s)\n",jprint(argjson,0)); return(retstr); } @@ -315,8 +322,9 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock, } if ( LP_cjson_allocated > startval ) { - char *str = jprint(argjson,0); - printf("leaked.%ld (%s)\n",LP_cjson_allocated - startval,str); + char *leakstr = jprint(argjson,0); + printf("LP_command_process leaked.%ld (%s)\n",LP_cjson_allocated - startval,leakstr); + free(leakstr); } } } From 5a085dfe780cbbbb4711646a46ebd61b3cdd19ef Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 06:19:01 +0200 Subject: [PATCH 223/306] Test --- iguana/exchanges/LP_commands.c | 4 ++++ iguana/exchanges/LP_nativeDEX.c | 1 + 2 files changed, 5 insertions(+) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 28931cd17..72734536e 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -35,6 +35,7 @@ char *LP_numutxos() char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *remoteaddr,uint16_t port) // from rpc port { char *method,*userpass,*base,*rel,*coin,*retstr = 0; int32_t changed,flag = 0; cJSON *retjson,*reqjson = 0; struct iguana_info *ptr; + printf("stats_JSON.0 %ld\n",LP_cjson_allocated); method = jstr(argjson,"method"); /*if ( //strcmp(method,"uitem") == 0 || strcmp(method,"postutxos") == 0 || strcmp(method,"notify") == 0 @@ -158,6 +159,7 @@ bot_resume(botid)\n\ rel = ""; if ( (coin= jstr(argjson,"coin")) == 0 ) coin = ""; + printf("stats_JSON.1 %ld %s\n",LP_cjson_allocated,method); if ( G.USERPASS[0] != 0 && strcmp(remoteaddr,"127.0.0.1") == 0 && port != 0 ) // protected localhost { if ( G.USERPASS_COUNTER == 0 ) @@ -640,8 +642,10 @@ bot_resume(botid)\n\ } if ( retstr == 0 ) printf("ERROR.(%s)\n",jprint(argjson,0)); + printf("stats_JSON.2 %ld reqjson.%p\n",LP_cjson_allocated,reqjson); if ( reqjson != 0 ) free_json(reqjson); + printf("stats_JSON.3 %ld retstr.%p\n",LP_cjson_allocated,retstr); if ( retstr != 0 ) { free(retstr); diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 4c2d45d39..a92a7ca06 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -195,6 +195,7 @@ char *LP_command_process(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson char *leakstr = jprint(argjson,0); printf("stats_JSON leaked.%ld (%s)\n",LP_cjson_allocated - startval,leakstr); free(leakstr); + exit(-1); } } //else printf("finished tradecommand (%s)\n",jprint(argjson,0)); return(retstr); From e013029c47ac0b86209297b69fee0911dae7c315 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 06:22:23 +0200 Subject: [PATCH 224/306] Test --- iguana/exchanges/LP_nativeDEX.c | 6 ++---- iguana/exchanges/LP_signatures.c | 3 +++ iguana/exchanges/LP_utxo.c | 2 ++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index a92a7ca06..61c324f6c 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1229,9 +1229,7 @@ void *LP_alloc(uint64_t len) //return(calloc(1,len)); struct LP_memory_list *mp; mp = calloc(1,sizeof(*mp) + len); - //if ( len == 72 ) - // printf("%d\n",1/zeroval()); - //printf("\n>>>>>>>>>>> LP_alloc mp.%p ptr.%p len.%llu\n",mp,mp->ptr,(long long)len); + printf("\n>>>>>>>>>>> LP_alloc mp.%p ptr.%p len.%llu\n",mp,mp->ptr,(long long)len); mp->timestamp = (uint32_t)time(NULL); mp->len = (uint32_t)len; mp->ptr = calloc(1,len); @@ -1287,7 +1285,7 @@ void LP_free(void *ptr) portable_mutex_lock(&LP_cJSONmutex); DL_DELETE(LP_memory_list,mp); portable_mutex_unlock(&LP_cJSONmutex); - //printf(">>>>>>>>>>> LP_free ptr.%p mp.%p len.%u\n",ptr,mp,mp->len); + printf(">>>>>>>>>>> LP_free ptr.%p mp.%p len.%u\n",ptr,mp,mp->len); free(mp->ptr); free(mp); } else unknown++; // free from source file with #define redirect for alloc that wasnt diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index fee4a1189..0742f49d5 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -649,6 +649,7 @@ void LP_smartutxos_push(struct iguana_info *coin) char *LP_uitem_recv(cJSON *argjson) { bits256 txid; int32_t vout,height; uint64_t value; struct iguana_info *coin; char *coinaddr,*symbol; + printf("LP_uitem_recv.0 %ld\n",LP_cjson_allocated); txid = jbits256(argjson,"txid"); vout = jint(argjson,"vout"); height = jint(argjson,"ht"); @@ -660,7 +661,9 @@ char *LP_uitem_recv(cJSON *argjson) if ( strcmp(coin->smartaddr,coinaddr) != 0 ) LP_address_utxoadd((uint32_t)time(NULL),"LP_uitem_recv",coin,coinaddr,txid,vout,value,height,-1); //else printf("ignore external uitem %s %s\n",symbol,coin->smartaddr); + printf("LP_uitem_recv.1 %ld\n",LP_cjson_allocated); } + printf("LP_uitem_recv.2 %ld\n",LP_cjson_allocated); return(clonestr("{\"result\":\"success\"}")); } diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 73a8e0260..1ebb7039e 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -423,6 +423,7 @@ void LP_mark_spent(char *symbol,bits256 txid,int32_t vout) int32_t LP_address_utxoadd(uint32_t timestamp,char *debug,struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout,uint64_t value,int32_t height,int32_t spendheight) { struct LP_address *ap; cJSON *txobj; struct LP_transaction *tx; struct LP_address_utxo *up,*tmp; int32_t flag,retval = 0; //char str[65]; + printf("LP_address_utxoadd.0 %ld\n",LP_cjson_allocated); if ( coin == 0 ) return(0); if ( spendheight > 0 ) // dont autocreate entries for spends we dont care about @@ -479,6 +480,7 @@ int32_t LP_address_utxoadd(uint32_t timestamp,char *debug,struct iguana_info *co } } // else printf("cant get ap %s %s\n",coin->symbol,coinaddr); //printf("done %s add addr.%s ht.%d\n",coin->symbol,coinaddr,height); + printf("LP_address_utxoadd.1 %ld\n",LP_cjson_allocated); return(retval); } From 5b5433d4eafc161758a4b3443ed4e0d7a5a9f715 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 06:25:50 +0200 Subject: [PATCH 225/306] Test --- iguana/exchanges/LP_nativeDEX.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 61c324f6c..18261cabd 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1066,7 +1066,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu printf("error launching stats rpcloop for port.%u\n",myport); exit(-1); } - if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)command_rpcloop,(void *)myipaddr) != 0 ) + if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)command_rpcloop,(void *)myipaddr) != 0 ) { printf("error launching command_rpcloop for port.%u\n",myport); exit(-1); @@ -1229,7 +1229,7 @@ void *LP_alloc(uint64_t len) //return(calloc(1,len)); struct LP_memory_list *mp; mp = calloc(1,sizeof(*mp) + len); - printf("\n>>>>>>>>>>> LP_alloc mp.%p ptr.%p len.%llu\n",mp,mp->ptr,(long long)len); + printf(">>>>>>>>>>> LP_alloc mp.%p ptr.%p len.%llu %llu\n",mp,mp->ptr,(long long)len,(long long)LP_cjson_allocated); mp->timestamp = (uint32_t)time(NULL); mp->len = (uint32_t)len; mp->ptr = calloc(1,len); @@ -1285,7 +1285,7 @@ void LP_free(void *ptr) portable_mutex_lock(&LP_cJSONmutex); DL_DELETE(LP_memory_list,mp); portable_mutex_unlock(&LP_cJSONmutex); - printf(">>>>>>>>>>> LP_free ptr.%p mp.%p len.%u\n",ptr,mp,mp->len); + printf(">>>>>>>>>>> LP_free ptr.%p mp.%p len.%u %llu\n",ptr,mp,mp->len,(long long)LP_cjson_allocated); free(mp->ptr); free(mp); } else unknown++; // free from source file with #define redirect for alloc that wasnt From 281a757d014c6e47a03fc044cc78c7f07cd5aa2b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 06:27:55 +0200 Subject: [PATCH 226/306] Test --- iguana/exchanges/LP_nativeDEX.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 18261cabd..7ae493eb7 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1045,23 +1045,23 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu printf("error launching LP_psockloop for (%s)\n",myipaddr); exit(-1); } - if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_reserved_msgs,(void *)myipaddr) != 0 ) + if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_reserved_msgs,(void *)myipaddr) != 0 ) { printf("error launching LP_reserved_msgs for (%s)\n",myipaddr); exit(-1); } - if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)utxosQ_loop,(void *)myipaddr) != 0 ) + if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)utxosQ_loop,(void *)myipaddr) != 0 ) { printf("error launching utxosQ_loop for (%s)\n",myipaddr); exit(-1); } - if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)stats_rpcloop,(void *)&myport) != 0 ) + if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)stats_rpcloop,(void *)&myport) != 0 ) { printf("error launching stats rpcloop for port.%u\n",myport); exit(-1); } uint16_t myport2 = myport-1; - if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)stats_rpcloop,(void *)&myport2) != 0 ) + if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)stats_rpcloop,(void *)&myport2) != 0 ) { printf("error launching stats rpcloop for port.%u\n",myport); exit(-1); @@ -1071,12 +1071,12 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu printf("error launching command_rpcloop for port.%u\n",myport); exit(-1); } - if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)queue_loop,(void *)myipaddr) != 0 ) + if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)queue_loop,(void *)myipaddr) != 0 ) { printf("error launching queue_loop for port.%u\n",myport); exit(-1); } - if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)gc_loop,(void *)myipaddr) != 0 ) + if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)gc_loop,(void *)myipaddr) != 0 ) { printf("error launching gc_loop for port.%u\n",myport); exit(-1); @@ -1229,10 +1229,10 @@ void *LP_alloc(uint64_t len) //return(calloc(1,len)); struct LP_memory_list *mp; mp = calloc(1,sizeof(*mp) + len); + mp->ptr = calloc(1,len); printf(">>>>>>>>>>> LP_alloc mp.%p ptr.%p len.%llu %llu\n",mp,mp->ptr,(long long)len,(long long)LP_cjson_allocated); mp->timestamp = (uint32_t)time(NULL); mp->len = (uint32_t)len; - mp->ptr = calloc(1,len); portable_mutex_lock(&LP_cJSONmutex); DL_APPEND(LP_memory_list,mp); portable_mutex_unlock(&LP_cJSONmutex); From b41fc50aa81b4c5407b6045d988a8e5733de45bf Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 06:29:46 +0200 Subject: [PATCH 227/306] Test --- iguana/exchanges/LP_nativeDEX.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 7ae493eb7..539d78dd6 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1081,37 +1081,37 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu printf("error launching gc_loop for port.%u\n",myport); exit(-1); } - if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)prices_loop,ctx) != 0 ) + if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)prices_loop,ctx) != 0 ) { printf("error launching prices_loop for port.%u\n",myport); exit(-1); } - if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_coinsloop,(void *)"") != 0 ) + if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_coinsloop,(void *)"") != 0 ) { printf("error launching LP_coinsloop for port.%u\n",myport); exit(-1); } - if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_coinsloop,(void *)"BTC") != 0 ) + if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_coinsloop,(void *)"BTC") != 0 ) { printf("error launching BTC LP_coinsloop for port.%u\n",myport); exit(-1); } - if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_coinsloop,(void *)"KMD") != 0 ) + if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_coinsloop,(void *)"KMD") != 0 ) { printf("error launching KMD LP_coinsloop for port.%u\n",myport); exit(-1); } - if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_pubkeysloop,(void *)myipaddr) != 0 ) + if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_pubkeysloop,(void *)myipaddr) != 0 ) { printf("error launching LP_pubkeysloop for ctx.%p\n",ctx); exit(-1); } - if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_privkeysloop,(void *)myipaddr) != 0 ) + if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_privkeysloop,(void *)myipaddr) != 0 ) { printf("error launching LP_privkeysloop for ctx.%p\n",ctx); exit(-1); } - if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_swapsloop,(void *)myipaddr) != 0 ) + if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_swapsloop,(void *)myipaddr) != 0 ) { printf("error launching LP_swapsloop for port.%u\n",myport); exit(-1); From 5bb144797c799039368c7b06b3374177570f7b7b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 06:31:40 +0200 Subject: [PATCH 228/306] 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 539d78dd6..b7bb0f3a2 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1126,7 +1126,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu //fprintf(stderr,"."); sleep(3); } - if ( LP_mainloop_iter(ctx,myipaddr,mypeer,pubsock,pushaddr,myport) != 0 ) + if ( 0 && LP_mainloop_iter(ctx,myipaddr,mypeer,pubsock,pushaddr,myport) != 0 ) nonz++; if ( nonz == 0 ) usleep(1000); From ab34e551a25b545f8f897a45a7f627e20c3b3e05 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 06:33:43 +0200 Subject: [PATCH 229/306] 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 b7bb0f3a2..539d78dd6 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1126,7 +1126,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu //fprintf(stderr,"."); sleep(3); } - if ( 0 && LP_mainloop_iter(ctx,myipaddr,mypeer,pubsock,pushaddr,myport) != 0 ) + if ( LP_mainloop_iter(ctx,myipaddr,mypeer,pubsock,pushaddr,myport) != 0 ) nonz++; if ( nonz == 0 ) usleep(1000); From c7a4d3ecaf681904cbea3d8bb18d0d1ff19a0187 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 06:35:08 +0200 Subject: [PATCH 230/306] 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 539d78dd6..071f3bad7 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1045,7 +1045,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu printf("error launching LP_psockloop for (%s)\n",myipaddr); exit(-1); } - if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_reserved_msgs,(void *)myipaddr) != 0 ) + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_reserved_msgs,(void *)myipaddr) != 0 ) { printf("error launching LP_reserved_msgs for (%s)\n",myipaddr); exit(-1); From 33975fa1138c77a9205377996578fffe8f5751dc Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 06:36:01 +0200 Subject: [PATCH 231/306] 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 071f3bad7..49cffb4ae 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1050,7 +1050,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu printf("error launching LP_reserved_msgs for (%s)\n",myipaddr); exit(-1); } - if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)utxosQ_loop,(void *)myipaddr) != 0 ) + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)utxosQ_loop,(void *)myipaddr) != 0 ) { printf("error launching utxosQ_loop for (%s)\n",myipaddr); exit(-1); From 1e228137e2fda1e626a818e95aca486cf4b95f34 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 06:37:20 +0200 Subject: [PATCH 232/306] 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 49cffb4ae..1e5554648 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1055,13 +1055,13 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu printf("error launching utxosQ_loop for (%s)\n",myipaddr); exit(-1); } - if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)stats_rpcloop,(void *)&myport) != 0 ) + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)stats_rpcloop,(void *)&myport) != 0 ) { printf("error launching stats rpcloop for port.%u\n",myport); exit(-1); } uint16_t myport2 = myport-1; - if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)stats_rpcloop,(void *)&myport2) != 0 ) + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)stats_rpcloop,(void *)&myport2) != 0 ) { printf("error launching stats rpcloop for port.%u\n",myport); exit(-1); From 931763427bf30aad10a3a4627d1ce9cd3dc4b8d0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 06:38:22 +0200 Subject: [PATCH 233/306] 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 1e5554648..b54e1d82c 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1071,12 +1071,12 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu printf("error launching command_rpcloop for port.%u\n",myport); exit(-1); } - if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)queue_loop,(void *)myipaddr) != 0 ) + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)queue_loop,(void *)myipaddr) != 0 ) { printf("error launching queue_loop for port.%u\n",myport); exit(-1); } - if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)gc_loop,(void *)myipaddr) != 0 ) + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)gc_loop,(void *)myipaddr) != 0 ) { printf("error launching gc_loop for port.%u\n",myport); exit(-1); From ae5497af8f0fe73594a5df8cd7ecc74992522216 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 06:40:01 +0200 Subject: [PATCH 234/306] Test --- iguana/exchanges/LP_nativeDEX.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index b54e1d82c..c5410aed6 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1086,17 +1086,17 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu printf("error launching prices_loop for port.%u\n",myport); exit(-1); } - if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_coinsloop,(void *)"") != 0 ) + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_coinsloop,(void *)"") != 0 ) { printf("error launching LP_coinsloop for port.%u\n",myport); exit(-1); } - if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_coinsloop,(void *)"BTC") != 0 ) + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_coinsloop,(void *)"BTC") != 0 ) { printf("error launching BTC LP_coinsloop for port.%u\n",myport); exit(-1); } - if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_coinsloop,(void *)"KMD") != 0 ) + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_coinsloop,(void *)"KMD") != 0 ) { printf("error launching KMD LP_coinsloop for port.%u\n",myport); exit(-1); From 22310de9f3b9f59e5612948c3f91ec93c9b2cd03 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 06:41:20 +0200 Subject: [PATCH 235/306] 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 c5410aed6..6327c5337 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1106,7 +1106,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu printf("error launching LP_pubkeysloop for ctx.%p\n",ctx); exit(-1); } - if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_privkeysloop,(void *)myipaddr) != 0 ) + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_privkeysloop,(void *)myipaddr) != 0 ) { printf("error launching LP_privkeysloop for ctx.%p\n",ctx); exit(-1); From 1f61ce249a26d8bb0e543ca10f9aa76ee30b61b1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 06:43:45 +0200 Subject: [PATCH 236/306] Test --- iguana/exchanges/LP_nativeDEX.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 6327c5337..92ee37ced 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1050,18 +1050,18 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu printf("error launching LP_reserved_msgs for (%s)\n",myipaddr); exit(-1); } - if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)utxosQ_loop,(void *)myipaddr) != 0 ) + if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)utxosQ_loop,(void *)myipaddr) != 0 ) { printf("error launching utxosQ_loop for (%s)\n",myipaddr); exit(-1); } - if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)stats_rpcloop,(void *)&myport) != 0 ) + if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)stats_rpcloop,(void *)&myport) != 0 ) { printf("error launching stats rpcloop for port.%u\n",myport); exit(-1); } uint16_t myport2 = myport-1; - if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)stats_rpcloop,(void *)&myport2) != 0 ) + if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)stats_rpcloop,(void *)&myport2) != 0 ) { printf("error launching stats rpcloop for port.%u\n",myport); exit(-1); @@ -1076,7 +1076,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu printf("error launching queue_loop for port.%u\n",myport); exit(-1); } - if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)gc_loop,(void *)myipaddr) != 0 ) + if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)gc_loop,(void *)myipaddr) != 0 ) { printf("error launching gc_loop for port.%u\n",myport); exit(-1); @@ -1086,17 +1086,17 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu printf("error launching prices_loop for port.%u\n",myport); exit(-1); } - if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_coinsloop,(void *)"") != 0 ) + if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_coinsloop,(void *)"") != 0 ) { printf("error launching LP_coinsloop for port.%u\n",myport); exit(-1); } - if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_coinsloop,(void *)"BTC") != 0 ) + if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_coinsloop,(void *)"BTC") != 0 ) { printf("error launching BTC LP_coinsloop for port.%u\n",myport); exit(-1); } - if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_coinsloop,(void *)"KMD") != 0 ) + if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_coinsloop,(void *)"KMD") != 0 ) { printf("error launching KMD LP_coinsloop for port.%u\n",myport); exit(-1); From 6585624a988e751e2878f37d579150a21ace5556 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 06:54:49 +0200 Subject: [PATCH 237/306] Test --- iguana/exchanges/LP_include.h | 2 +- iguana/exchanges/LP_nativeDEX.c | 2 +- iguana/exchanges/LP_utxos.c | 11 +++++------ 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index b6c24be52..72f99d81f 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -275,7 +275,7 @@ struct iguana_info void *electrum; void *ctx; uint64_t maxamount,kmd_equiv,balanceA,balanceB,valuesumA,valuesumB; uint8_t pubkey33[33],zcash; - bits256 lastprivkey; uint32_t lastprivkeytime; int32_t privkeydepth; + int32_t privkeydepth; bits256 cachedtxid; uint8_t *cachedtxiddata; int32_t cachedtxidlen; bits256 cachedmerkle; int32_t cachedmerkleheight; }; diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 92ee37ced..8309305d5 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1066,7 +1066,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu printf("error launching stats rpcloop for port.%u\n",myport); exit(-1); } - if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)command_rpcloop,(void *)myipaddr) != 0 ) + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)command_rpcloop,(void *)myipaddr) != 0 ) { printf("error launching command_rpcloop for port.%u\n",myport); exit(-1); diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 2816dd303..497760624 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -568,19 +568,17 @@ int32_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypri //printf("coin not active\n"); return(0); } - /*if ( bits256_cmp(myprivkey,coin->lastprivkey) == 0 && time(NULL) < coin->lastprivkeytime+60 ) - return(0);*/ - coin->lastprivkey = myprivkey; - coin->lastprivkeytime = (uint32_t)time(NULL); if ( coin->privkeydepth > 0 ) return(0); + printf("LP_privkey_init.0 %ld\n",LP_cjson_allocated); coin->privkeydepth++; LP_address(coin,coin->smartaddr); - //printf("privkey init.(%s) %s depth.%d\n",coin->symbol,coin->smartaddr,coin->privkeydepth); + printf("LP_privkey_init.1 %ld\n",LP_cjson_allocated); if ( coin->inactive == 0 ) LP_listunspent_issue(coin->symbol,coin->smartaddr,0); + printf("LP_privkey_init.2 %ld\n",LP_cjson_allocated); array = LP_listunspent(coin->symbol,coin->smartaddr); - //printf("unspent array %ld\n",strlen(jprint(array,0))); + printf("LP_privkey_init.3 %ld\n",LP_cjson_allocated); if ( array != 0 ) { txfee = LP_txfeecalc(coin,0,0); @@ -709,6 +707,7 @@ int32_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypri if ( flag != 0 ) LP_postutxos(coin->symbol,coin->smartaddr); } + printf("LP_privkey_init.4 %ld\n",LP_cjson_allocated); if ( values != 0 ) free(values); if ( coin->privkeydepth > 0 ) From 77f1f8f6a756be38fa0c69c4691f98e7b3995805 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 06:56:00 +0200 Subject: [PATCH 238/306] Test --- iguana/exchanges/LP_nativeDEX.c | 1 - 1 file changed, 1 deletion(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 8309305d5..7fcdd92ed 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -195,7 +195,6 @@ char *LP_command_process(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson char *leakstr = jprint(argjson,0); printf("stats_JSON leaked.%ld (%s)\n",LP_cjson_allocated - startval,leakstr); free(leakstr); - exit(-1); } } //else printf("finished tradecommand (%s)\n",jprint(argjson,0)); return(retstr); From d27ffaf556acbded1f8eb4737ee51399bac552ad Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 07:19:06 +0200 Subject: [PATCH 239/306] Test --- iguana/exchanges/LP_commands.c | 11 +--------- iguana/exchanges/LP_nativeDEX.c | 34 ++++++++---------------------- iguana/exchanges/LP_ordermatch.c | 1 + iguana/exchanges/LP_prices.c | 1 + iguana/exchanges/LP_rpc.c | 9 -------- iguana/exchanges/LP_signatures.c | 3 --- iguana/exchanges/LP_statemachine.c | 10 +++++++++ iguana/exchanges/LP_utxo.c | 6 +++--- iguana/exchanges/LP_utxos.c | 8 ++----- 9 files changed, 27 insertions(+), 56 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 72734536e..72c64d04b 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -35,13 +35,7 @@ char *LP_numutxos() char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *remoteaddr,uint16_t port) // from rpc port { char *method,*userpass,*base,*rel,*coin,*retstr = 0; int32_t changed,flag = 0; cJSON *retjson,*reqjson = 0; struct iguana_info *ptr; - printf("stats_JSON.0 %ld\n",LP_cjson_allocated); method = jstr(argjson,"method"); -/*if ( //strcmp(method,"uitem") == 0 || strcmp(method,"postutxos") == 0 || - strcmp(method,"notify") == 0 - || strcmp(method,"postprice") == 0 - ) - return(clonestr("{}"));*/ /*if ( (ipaddr= jstr(argjson,"ipaddr")) != 0 && (argport= juint(argjson,"port")) != 0 && (method == 0 || strcmp(method,"electrum") != 0) ) { if ( strcmp(ipaddr,"127.0.0.1") != 0 && argport >= 1000 ) @@ -159,7 +153,6 @@ bot_resume(botid)\n\ rel = ""; if ( (coin= jstr(argjson,"coin")) == 0 ) coin = ""; - printf("stats_JSON.1 %ld %s\n",LP_cjson_allocated,method); if ( G.USERPASS[0] != 0 && strcmp(remoteaddr,"127.0.0.1") == 0 && port != 0 ) // protected localhost { if ( G.USERPASS_COUNTER == 0 ) @@ -437,7 +430,7 @@ bot_resume(botid)\n\ } else if ( strcmp(method,"getrawtransaction") == 0 ) { - return(jprint(LP_gettx(coin,jbits256(argjson,"txid")),0)); + return(jprint(LP_gettx(coin,jbits256(argjson,"txid")),1)); } else if ( strcmp(method,"withdraw") == 0 ) { @@ -642,10 +635,8 @@ bot_resume(botid)\n\ } if ( retstr == 0 ) printf("ERROR.(%s)\n",jprint(argjson,0)); - printf("stats_JSON.2 %ld reqjson.%p\n",LP_cjson_allocated,reqjson); if ( reqjson != 0 ) free_json(reqjson); - printf("stats_JSON.3 %ld retstr.%p\n",LP_cjson_allocated,retstr); if ( retstr != 0 ) { free(retstr); diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 7fcdd92ed..9c260bdaa 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -183,19 +183,12 @@ char *LP_command_process(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson return(0); if ( LP_tradecommand(ctx,myipaddr,pubsock,argjson,data,datalen) <= 0 ) { - long startval = LP_cjson_allocated; if ( (retstr= stats_JSON(ctx,myipaddr,pubsock,argjson,"127.0.0.1",0)) != 0 ) { //printf("%s PULL.[%d]-> (%s)\n",myipaddr != 0 ? myipaddr : "127.0.0.1",datalen,retstr); //if ( pubsock >= 0 ) //strncmp("{\"error\":",retstr,strlen("{\"error\":")) != 0 && //LP_send(pubsock,retstr,(int32_t)strlen(retstr)+1,0); } - if ( LP_cjson_allocated > startval ) - { - char *leakstr = jprint(argjson,0); - printf("stats_JSON leaked.%ld (%s)\n",LP_cjson_allocated - startval,leakstr); - free(leakstr); - } } //else printf("finished tradecommand (%s)\n",jprint(argjson,0)); return(retstr); } @@ -316,16 +309,9 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock, } else { - long startval = LP_cjson_allocated; if ( (retstr= LP_command_process(ctx,myipaddr,pubsock,argjson,&((uint8_t *)ptr)[len],recvlen - len)) != 0 ) { } - if ( LP_cjson_allocated > startval ) - { - char *leakstr = jprint(argjson,0); - printf("LP_command_process leaked.%ld (%s)\n",LP_cjson_allocated - startval,leakstr); - free(leakstr); - } } } if ( argjson != 0 ) @@ -383,11 +369,8 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int } if ( validreq != 0 ) { - long startval = LP_cjson_allocated; if ( (retstr= LP_process_message(ctx,typestr,myipaddr,pubsock,ptr,recvlen,sock)) != 0 ) free(retstr); - if ( LP_cjson_allocated > startval ) - printf("leaked.%ld (%s)\n",LP_cjson_allocated - startval,(char *)ptr); if ( Broadcaststr != 0 ) { //printf("self broadcast.(%s)\n",Broadcaststr); @@ -1222,10 +1205,10 @@ int32_t zeroval() { return(0); } void *LP_alloc(uint64_t len) { + return(calloc(1,len)); LP_cjson_allocated += len; LP_cjson_total += len; LP_cjson_count++; - //return(calloc(1,len)); struct LP_memory_list *mp; mp = calloc(1,sizeof(*mp) + len); mp->ptr = calloc(1,len); @@ -1238,16 +1221,11 @@ void *LP_alloc(uint64_t len) return(mp->ptr); } -void *LP_realloc(void *ptr,uint64_t len) -{ - return(realloc(ptr,len)); -} - void LP_free(void *ptr) { static uint32_t lasttime,unknown; - //free(ptr); - //return; + free(ptr); + return; uint32_t now; char str[65]; int32_t n,lagging; uint64_t total = 0; struct LP_memory_list *mp,*tmp; if ( (now= (uint32_t)time(NULL)) > lasttime+60 ) { @@ -1297,3 +1275,9 @@ char *LP_clonestr(char *str) return(retstr); } +void *LP_realloc(void *ptr,uint64_t len) +{ + return(realloc(ptr,len)); +} + + diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 04faf3715..b541200a1 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -718,6 +718,7 @@ int32_t LP_listunspent_both(char *symbol,char *coinaddr,int32_t fullflag) LP_address_utxoadd(now,"LP_listunspent_both",coin,coinaddr,txid,v,value,height,-1); } } + free_json(array); } } } //else printf("%s coin.%p inactive.%d\n",symbol,coin,coin!=0?coin->inactive:-1); diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 7313c733b..d299b8368 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -265,6 +265,7 @@ uint64_t LP_unspents_metric(struct iguana_info *coin,char *coinaddr) } } metric = _LP_unspents_metric(total,n); + free_json(array); } return(metric); } diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 2a66c9b94..320eec701 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -682,15 +682,6 @@ int32_t LP_listunspent_issue(char *symbol,char *coinaddr,int32_t fullflag) { //printf("LP_listunspent_query.(%s %s)\n",symbol,coinaddr); LP_listunspent_query(coin->symbol,coin->smartaddr); - /*if ( fullflag != 0 ) - { - if ( (destport= LP_randpeer(destip)) > 0 ) - { - retstr = issue_LP_listunspent(destip,destport,symbol,coinaddr); - //printf("issue %s %s %s -> (%s)\n",coin->symbol,coinaddr,destip,retstr); - retjson = cJSON_Parse(retstr); - } else printf("LP_listunspent_issue couldnt get a random peer?\n"); - }*/ } if ( retjson != 0 ) { diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index 0742f49d5..fee4a1189 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -649,7 +649,6 @@ void LP_smartutxos_push(struct iguana_info *coin) char *LP_uitem_recv(cJSON *argjson) { bits256 txid; int32_t vout,height; uint64_t value; struct iguana_info *coin; char *coinaddr,*symbol; - printf("LP_uitem_recv.0 %ld\n",LP_cjson_allocated); txid = jbits256(argjson,"txid"); vout = jint(argjson,"vout"); height = jint(argjson,"ht"); @@ -661,9 +660,7 @@ char *LP_uitem_recv(cJSON *argjson) if ( strcmp(coin->smartaddr,coinaddr) != 0 ) LP_address_utxoadd((uint32_t)time(NULL),"LP_uitem_recv",coin,coinaddr,txid,vout,value,height,-1); //else printf("ignore external uitem %s %s\n",symbol,coin->smartaddr); - printf("LP_uitem_recv.1 %ld\n",LP_cjson_allocated); } - printf("LP_uitem_recv.2 %ld\n",LP_cjson_allocated); return(clonestr("{\"result\":\"success\"}")); } diff --git a/iguana/exchanges/LP_statemachine.c b/iguana/exchanges/LP_statemachine.c index 3c32b8cad..86997fcd5 100644 --- a/iguana/exchanges/LP_statemachine.c +++ b/iguana/exchanges/LP_statemachine.c @@ -355,6 +355,16 @@ char *issue_LP_getprices(char *destip,uint16_t destport) return(LP_issue_curl("getprices",destip,destport,url)); //return(issue_curlt(url,LP_HTTP_TIMEOUT)); } +/*if ( fullflag != 0 ) + { + if ( (destport= LP_randpeer(destip)) > 0 ) + { + retstr = issue_LP_listunspent(destip,destport,symbol,coinaddr); + //printf("issue %s %s %s -> (%s)\n",coin->symbol,coinaddr,destip,retstr); + retjson = cJSON_Parse(retstr); + } else printf("LP_listunspent_issue couldnt get a random peer?\n"); + }*/ + void issue_LP_listunspent(char *destip,uint16_t destport,char *symbol,char *coinaddr) { cJSON *reqjson = cJSON_CreateObject(); diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 1ebb7039e..c93f5e0fc 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -423,7 +423,6 @@ void LP_mark_spent(char *symbol,bits256 txid,int32_t vout) int32_t LP_address_utxoadd(uint32_t timestamp,char *debug,struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout,uint64_t value,int32_t height,int32_t spendheight) { struct LP_address *ap; cJSON *txobj; struct LP_transaction *tx; struct LP_address_utxo *up,*tmp; int32_t flag,retval = 0; //char str[65]; - printf("LP_address_utxoadd.0 %ld\n",LP_cjson_allocated); if ( coin == 0 ) return(0); if ( spendheight > 0 ) // dont autocreate entries for spends we dont care about @@ -480,7 +479,6 @@ int32_t LP_address_utxoadd(uint32_t timestamp,char *debug,struct iguana_info *co } } // else printf("cant get ap %s %s\n",coin->symbol,coinaddr); //printf("done %s add addr.%s ht.%d\n",coin->symbol,coinaddr,height); - printf("LP_address_utxoadd.1 %ld\n",LP_cjson_allocated); return(retval); } @@ -505,7 +503,7 @@ struct LP_address *LP_address_utxo_reset(struct iguana_info *coin) up->spendheight = (int32_t)time(NULL); DL_APPEND(LP_garbage_collector2,up); portable_mutex_unlock(&LP_gcmutex); - } + } now = (uint32_t)time(NULL); if ( (n= cJSON_GetArraySize(array)) > 0 ) { @@ -636,6 +634,7 @@ cJSON *LP_address_balance(struct iguana_info *coin,char *coinaddr,int32_t electr balance += LP_value_extract(item,1); } } + free_json(array); } } else @@ -654,6 +653,7 @@ cJSON *LP_address_balance(struct iguana_info *coin,char *coinaddr,int32_t electr balance += j64bits(item,"value"); } } + free_json(array); } } } diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 497760624..2498d4da4 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -570,15 +570,11 @@ int32_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypri } if ( coin->privkeydepth > 0 ) return(0); - printf("LP_privkey_init.0 %ld\n",LP_cjson_allocated); coin->privkeydepth++; LP_address(coin,coin->smartaddr); - printf("LP_privkey_init.1 %ld\n",LP_cjson_allocated); if ( coin->inactive == 0 ) LP_listunspent_issue(coin->symbol,coin->smartaddr,0); - printf("LP_privkey_init.2 %ld\n",LP_cjson_allocated); array = LP_listunspent(coin->symbol,coin->smartaddr); - printf("LP_privkey_init.3 %ld\n",LP_cjson_allocated); if ( array != 0 ) { txfee = LP_txfeecalc(coin,0,0); @@ -707,7 +703,6 @@ int32_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypri if ( flag != 0 ) LP_postutxos(coin->symbol,coin->smartaddr); } - printf("LP_privkey_init.4 %ld\n",LP_cjson_allocated); if ( values != 0 ) free(values); if ( coin->privkeydepth > 0 ) @@ -819,7 +814,8 @@ bits256 LP_privkeycalc(void *ctx,uint8_t *pubkey33,bits256 *pubkeyp,struct iguan printf("cant importprivkey.%s -> (%s), abort session\n",coin->symbol,jprint(retjson,1)); exit(-1); } - } else free_json(retjson); + free_json(retjson); + } coin->importedprivkey = (uint32_t)time(NULL); } vcalc_sha256(0,checkkey.bytes,privkey.bytes,sizeof(privkey)); From d596bcfc940bd1683894a5a6573be71084529108 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 07:21:01 +0200 Subject: [PATCH 240/306] Test --- iguana/exchanges/LP_nativeDEX.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 9c260bdaa..9fb48bb7f 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1032,18 +1032,18 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu printf("error launching LP_reserved_msgs for (%s)\n",myipaddr); exit(-1); } - if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)utxosQ_loop,(void *)myipaddr) != 0 ) + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)utxosQ_loop,(void *)myipaddr) != 0 ) { printf("error launching utxosQ_loop for (%s)\n",myipaddr); exit(-1); } - if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)stats_rpcloop,(void *)&myport) != 0 ) + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)stats_rpcloop,(void *)&myport) != 0 ) { printf("error launching stats rpcloop for port.%u\n",myport); exit(-1); } uint16_t myport2 = myport-1; - if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)stats_rpcloop,(void *)&myport2) != 0 ) + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)stats_rpcloop,(void *)&myport2) != 0 ) { printf("error launching stats rpcloop for port.%u\n",myport); exit(-1); @@ -1058,32 +1058,32 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu printf("error launching queue_loop for port.%u\n",myport); exit(-1); } - if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)gc_loop,(void *)myipaddr) != 0 ) + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)gc_loop,(void *)myipaddr) != 0 ) { printf("error launching gc_loop for port.%u\n",myport); exit(-1); } - if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)prices_loop,ctx) != 0 ) + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)prices_loop,ctx) != 0 ) { printf("error launching prices_loop for port.%u\n",myport); exit(-1); } - if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_coinsloop,(void *)"") != 0 ) + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_coinsloop,(void *)"") != 0 ) { printf("error launching LP_coinsloop for port.%u\n",myport); exit(-1); } - if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_coinsloop,(void *)"BTC") != 0 ) + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_coinsloop,(void *)"BTC") != 0 ) { printf("error launching BTC LP_coinsloop for port.%u\n",myport); exit(-1); } - if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_coinsloop,(void *)"KMD") != 0 ) + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_coinsloop,(void *)"KMD") != 0 ) { printf("error launching KMD LP_coinsloop for port.%u\n",myport); exit(-1); } - if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_pubkeysloop,(void *)myipaddr) != 0 ) + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_pubkeysloop,(void *)myipaddr) != 0 ) { printf("error launching LP_pubkeysloop for ctx.%p\n",ctx); exit(-1); @@ -1093,7 +1093,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu printf("error launching LP_privkeysloop for ctx.%p\n",ctx); exit(-1); } - if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_swapsloop,(void *)myipaddr) != 0 ) + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_swapsloop,(void *)myipaddr) != 0 ) { printf("error launching LP_swapsloop for port.%u\n",myport); exit(-1); From dce7ba29d7d29fff92dde3e0be9e7c306dcd32c9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 09:53:37 +0200 Subject: [PATCH 241/306] Test --- iguana/exchanges/LP_RTmetrics.c | 2 +- iguana/exchanges/LP_nativeDEX.c | 3 +- iguana/exchanges/LP_ordermatch.c | 2 +- iguana/exchanges/LP_remember.c | 23 ------- iguana/exchanges/LP_rpc.c | 61 +++++++++--------- iguana/exchanges/LP_scan.c | 2 +- iguana/exchanges/LP_socket.c | 2 +- iguana/exchanges/LP_statemachine.c | 100 +++++++++++++++++++++++++++++ iguana/exchanges/LP_transaction.c | 11 ---- iguana/exchanges/LP_utxo.c | 66 ------------------- 10 files changed, 138 insertions(+), 134 deletions(-) diff --git a/iguana/exchanges/LP_RTmetrics.c b/iguana/exchanges/LP_RTmetrics.c index ac01d3025..53466e5e7 100644 --- a/iguana/exchanges/LP_RTmetrics.c +++ b/iguana/exchanges/LP_RTmetrics.c @@ -161,7 +161,7 @@ void LP_RTmetrics_update(char *base,char *rel) { if ( (swaps= jarray(&numswaps,statsjson,"swaps")) != 0 ) { - printf("LP_RTmetrics_update for (%s)\n",jprint(swaps,0)); + //printf("LP_RTmetrics_update for (%s)\n",jprint(swaps,0)); if ( numswaps > 0 ) LP_RTmetrics_swapsinfo(base,rel,swaps,numswaps); } diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 9fb48bb7f..b265c8d7b 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -19,10 +19,11 @@ // // if ( G.LP_pendingswaps != 0 ) return(-1); // bot safe to exit? -// +// 324744 and 50mb // BCH signing // single utxo allocations alice // alice waiting for bestprice +// // previously, it used to show amount, kmd equiv, perc // dPoW security -> 4: KMD notarized, 5: BTC notarized, after next notary elections // bigendian architectures need to use little endian for sighash calcs diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index b541200a1..e1f7bf62e 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -889,7 +889,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, price += (r * range) / 100.; bestprice = LP_bob_competition(&counter,aliceid,price,0); printf(">>>>>>>>>>>>> price %.8f qprice %.8f r.%d range %.8f -> %.8f, bestprice %.8f counter.%d\n",ask,qprice,r,range,price,bestprice,counter); - if ( counter > 5 || price > bestprice*1.1 ) // skip if late or bad price + if ( counter > 3 || price > bestprice ) // skip if late or bad price return(retval); } else return(retval); LP_RTmetrics_update(Q.srccoin,Q.destcoin); diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index c0ef0efd7..7889181bf 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -1247,29 +1247,6 @@ char *basilisk_swapentry(uint32_t requestid,uint32_t quoteid) 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 ) - { - if ( (array= jarray(&n,retjson,"swaps")) != 0 ) - { - for (i=0; iserverport,coin->userpass,"signrawtransaction",paramstr)) != 0 ) + if ( (0) ) { - if ( (json= cJSON_Parse(retstr)) != 0 ) + array = cJSON_CreateArray(); + jaddistr(array,rawtx); + jaddi(array,jduplicate(vins)); + jaddi(array,jduplicate(privkeys)); + paramstr = jprint(array,1); + //printf("signrawtransaction\n"); + if ( (retstr= bitcoind_passthru(symbol,coin->serverport,coin->userpass,"signrawtransaction",paramstr)) != 0 ) { - if ( (hexstr= jstr(json,"hex")) != 0 ) + if ( (json= cJSON_Parse(retstr)) != 0 ) { - len = (int32_t)strlen(hexstr); - signedtx = calloc(1,len+1); - strcpy(signedtx,hexstr); - *completedp = is_cJSON_True(jobj(json,"complete")); - len >>= 1; - data = malloc(len); - decode_hex(data,len,hexstr); - *signedtxidp = bits256_doublesha256(0,data,len); + if ( (hexstr= jstr(json,"hex")) != 0 ) + { + len = (int32_t)strlen(hexstr); + signedtx = calloc(1,len+1); + strcpy(signedtx,hexstr); + *completedp = is_cJSON_True(jobj(json,"complete")); + len >>= 1; + data = malloc(len); + decode_hex(data,len,hexstr); + *signedtxidp = bits256_doublesha256(0,data,len); + } + //else + printf("%s signrawtransaction.(%s) params.(%s)\n",coin->symbol,retstr,paramstr); + free_json(json); } - //else - printf("%s signrawtransaction.(%s) params.(%s)\n",coin->symbol,retstr,paramstr); - free_json(json); + free(retstr); } - free(retstr); + free(paramstr); + return(signedtx); } - free(paramstr); - return(signedtx); } cJSON *LP_getblock(char *symbol,bits256 txid) @@ -1032,7 +1035,7 @@ uint32_t LP_heighttime(char *symbol,int32_t height) { if ( (retjson= cJSON_Parse(blockhashstr)) != 0 ) { - printf("height.(%s)\n",jprint(retjson,0)); + //printf("height.(%s)\n",jprint(retjson,0)); timestamp = juint(retjson,"time"); free_json(retjson); } @@ -1043,7 +1046,7 @@ uint32_t LP_heighttime(char *symbol,int32_t height) { if ( (retjson= electrum_getheader(coin->symbol,ep,&retjson,height)) != 0 ) { - printf("%s\n",jprint(retjson,0)); + //printf("%s\n",jprint(retjson,0)); timestamp = juint(retjson,"timestamp"); free_json(retjson); } @@ -1074,7 +1077,7 @@ cJSON *LP_blockjson(int32_t *heightp,char *symbol,char *blockhashstr,int32_t hei *heightp = juint(json,"height"); if ( height >= 0 && *heightp != height ) { - printf("unexpected height %d vs %d for %s (%s)\n",*heightp,height,blockhashstr,jprint(json,0)); + //printf("unexpected height %d vs %d for %s (%s)\n",*heightp,height,blockhashstr,jprint(json,0)); *heightp = -1; free_json(json); json = 0; @@ -1255,7 +1258,7 @@ int32_t LP_notarization_latest(int32_t *bestheightp,struct iguana_info *coin) blockhash = jbits256(blockjson,"previousblockhash"); if ( bits256_nonz(blockhash) == 0 ) { - printf("null prev.(%s)\n",jprint(blockjson,0)); + //printf("null prev.(%s)\n",jprint(blockjson,0)); free_json(blockjson); break; } diff --git a/iguana/exchanges/LP_scan.c b/iguana/exchanges/LP_scan.c index 5a5a12051..f3b67476b 100644 --- a/iguana/exchanges/LP_scan.c +++ b/iguana/exchanges/LP_scan.c @@ -466,7 +466,7 @@ int32_t LP_waitmempool(char *symbol,char *coinaddr,bits256 txid,int32_t vout,int { if ( (array= electrum_address_getmempool(symbol,coin->electrum,&array,coinaddr)) != 0 ) { - char str[65]; printf("check %s mempool.(%s)\n",bits256_str(str,txid),jprint(array,0)); + //char str[65]; printf("check %s mempool.(%s)\n",bits256_str(str,txid),jprint(array,0)); if ( (n= cJSON_GetArraySize(array)) > 0 ) { for (i=0; i lasthello+600 ) { char *hellostr,*retstr; cJSON *retjson; int32_t allgood,sock = LP_bindsock; @@ -347,6 +359,94 @@ void issue_LP_uitem(char *destip,uint16_t destport,char *symbol,char *coinaddr,b return(retstr);*/ } +/*if ( (liststr= basilisk_swaplist(requestid,quoteid)) != 0 ) + { + //printf("swapentry.(%s)\n",liststr); + if ( (retjson= cJSON_Parse(liststr)) != 0 ) + { + if ( (array= jarray(&n,retjson,"swaps")) != 0 ) + { + for (i=0; itimestamp = (uint32_t)time(NULL); + ptr->item = item; + item->cjsonid = rand(); + ptr->cjsonid = item->cjsonid; + portable_mutex_lock(&LP_cJSONmutex); + DL_APPEND(LP_cJSONlist,ptr); + portable_mutex_unlock(&LP_cJSONmutex); + } + + void cJSON_unregister(cJSON *item) + { + static uint32_t lasttime; + int32_t n; char *tmpstr; uint64_t total = 0; struct cJSON_list *ptr,*tmp; uint32_t now; + if ( (now= (uint32_t)time(NULL)) > lasttime+6 ) + { + n = 0; + DL_FOREACH_SAFE(LP_cJSONlist,ptr,tmp) + { + if ( ptr->item != 0 && ptr->item->child != 0 && ptr->cjsonid != 0 ) + { + if ( (tmpstr= jprint(ptr->item,0)) != 0 ) + { + total += strlen(tmpstr); + free(tmpstr); + } + } + n++; + } + printf("total %d cJSON pending\n",n); + lasttime = (uint32_t)time(NULL); + } + DL_FOREACH_SAFE(LP_cJSONlist,ptr,tmp) + { + if ( ptr->cjsonid == item->cjsonid ) + break; + else if ( now > ptr->timestamp+60 && item->cjsonid != 0 ) + { + portable_mutex_lock(&LP_cJSONmutex); + DL_DELETE(LP_cJSONlist,ptr); + portable_mutex_unlock(&LP_cJSONmutex); + printf("free expired\n"); + cJSON_Delete(ptr->item); + free(ptr); + } + ptr = 0; + } + if ( ptr != 0 ) + { + portable_mutex_lock(&LP_cJSONmutex); + DL_DELETE(LP_cJSONlist,ptr); + free(ptr); + portable_mutex_unlock(&LP_cJSONmutex); + } //else printf("cJSON_unregister of unknown %p %u\n",item,item->cjsonid); + }*/ char *issue_LP_getprices(char *destip,uint16_t destport) { char url[512]; diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index cfd1a6060..f90a87170 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -1651,17 +1651,6 @@ void LP_swap_coinaddr(struct iguana_info *coin,char *coinaddr,uint64_t *valuep,u vout = jitem(vouts,v); if ( valuep != 0 ) *valuep = LP_value_extract(vout,1); - //printf("VOUT.(%s)\n",jprint(vout,0)); - /*if ( (skey= jobj(vout,"scriptPubKey")) != 0 && (addresses= jarray(&m,skey,"addresses")) != 0 ) - { - item = jitem(addresses,0); - //printf("item.(%s)\n",jprint(item,0)); - if ( (addr= jstr(item,0)) != 0 ) - { - safecopy(coinaddr,addr,64); - //printf("extracted.(%s)\n",coinaddr); - } - }*/ LP_destaddr(coinaddr,vout); } free_json(txobj); diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index c93f5e0fc..59b8b8b8e 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -27,72 +27,6 @@ struct LP_inuse_info } LP_inuse[1024]; int32_t LP_numinuse; -/*struct cJSON_list -{ - struct cJSON_list *next,*prev; - cJSON *item; - uint32_t timestamp,cjsonid; -} *LP_cJSONlist; - -void cJSON_register(cJSON *item) -{ - struct cJSON_list *ptr; - ptr = calloc(1,sizeof(*ptr)); - ptr->timestamp = (uint32_t)time(NULL); - ptr->item = item; - item->cjsonid = rand(); - ptr->cjsonid = item->cjsonid; - portable_mutex_lock(&LP_cJSONmutex); - DL_APPEND(LP_cJSONlist,ptr); - portable_mutex_unlock(&LP_cJSONmutex); -} - -void cJSON_unregister(cJSON *item) -{ - static uint32_t lasttime; - int32_t n; char *tmpstr; uint64_t total = 0; struct cJSON_list *ptr,*tmp; uint32_t now; - if ( (now= (uint32_t)time(NULL)) > lasttime+6 ) - { - n = 0; - DL_FOREACH_SAFE(LP_cJSONlist,ptr,tmp) - { - if ( ptr->item != 0 && ptr->item->child != 0 && ptr->cjsonid != 0 ) - { - if ( (tmpstr= jprint(ptr->item,0)) != 0 ) - { - total += strlen(tmpstr); - free(tmpstr); - } - } - n++; - } - printf("total %d cJSON pending\n",n); - lasttime = (uint32_t)time(NULL); - } - DL_FOREACH_SAFE(LP_cJSONlist,ptr,tmp) - { - if ( ptr->cjsonid == item->cjsonid ) - break; - else if ( now > ptr->timestamp+60 && item->cjsonid != 0 ) - { - portable_mutex_lock(&LP_cJSONmutex); - DL_DELETE(LP_cJSONlist,ptr); - portable_mutex_unlock(&LP_cJSONmutex); - printf("free expired\n"); - cJSON_Delete(ptr->item); - free(ptr); - } - ptr = 0; - } - if ( ptr != 0 ) - { - portable_mutex_lock(&LP_cJSONmutex); - DL_DELETE(LP_cJSONlist,ptr); - free(ptr); - portable_mutex_unlock(&LP_cJSONmutex); - } //else printf("cJSON_unregister of unknown %p %u\n",item,item->cjsonid); -}*/ - struct LP_inuse_info *_LP_inuse_find(bits256 txid,int32_t vout) { int32_t i; From 838df594ae564cefd091bd7e5bc673edfbb61c18 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 10:33:10 +0200 Subject: [PATCH 242/306] Test --- crypto777/cJSON.c | 93 +++++++++++++++++++++++---------- iguana/exchanges/LP_nativeDEX.c | 11 ++-- 2 files changed, 69 insertions(+), 35 deletions(-) diff --git a/crypto777/cJSON.c b/crypto777/cJSON.c index 4c0777656..901e6fc98 100755 --- a/crypto777/cJSON.c +++ b/crypto777/cJSON.c @@ -59,13 +59,46 @@ void LP_free(void *ptr); static void *(*cJSON_malloc)(size_t sz) = (void *)LP_alloc; static void (*cJSON_free)(void *ptr) = LP_free; +static void *cJSON_mallocstr(int32_t len) +{ + return(cJSON_malloc(len)); +} + +static char **cJSON_mallocptrs(int32_t num,char **space,int32_t max) +{ + if ( num < max ) + return(space); + else return(cJSON_malloc(num * sizeof(char *))); +} + +static void *cJSON_mallocnode() +{ + return(cJSON_malloc(sizeof(cJSON))); +} + +static void cJSON_freeptrs(char **ptrs,int32_t num,char **space) +{ + if ( ptrs != space ) + cJSON_free(ptrs); +} + +static void cJSON_freestr(char *str) +{ + cJSON_free(str); +} + +static void cJSON_freenode(cJSON *item) +{ + cJSON_free(item); +} + static char* cJSON_strdup(const char* str) { size_t len; char* copy; len = strlen(str) + 1; - if (!(copy = (char*)cJSON_malloc(len+1))) return 0; + if (!(copy = (char*)cJSON_mallocstr((int32_t)len+1))) return 0; memcpy(copy,str,len); return copy; } @@ -78,14 +111,14 @@ void cJSON_InitHooks(cJSON_Hooks* hooks) return; } - cJSON_malloc = (hooks->malloc_fn)?hooks->malloc_fn:malloc; - cJSON_free = (hooks->free_fn)?hooks->free_fn:free; + cJSON_malloc = (hooks->malloc_fn)?hooks->malloc_fn:malloc; + cJSON_free = (hooks->free_fn)?hooks->free_fn:free; } /* Internal constructor. */ static cJSON *cJSON_New_Item(void) { - cJSON* node = (cJSON*)cJSON_malloc(sizeof(cJSON)); + cJSON* node = (cJSON*)cJSON_mallocnode(); if (node) memset(node,0,sizeof(cJSON)); return node; } @@ -98,9 +131,9 @@ void cJSON_Delete(cJSON *c) { next=c->next; if (!(c->type&cJSON_IsReference) && c->child) cJSON_Delete(c->child); - if (!(c->type&cJSON_IsReference) && c->valuestring) cJSON_free(c->valuestring); - if (c->string) cJSON_free(c->string); - cJSON_free(c); + if (!(c->type&cJSON_IsReference) && c->valuestring) cJSON_freestr(c->valuestring); + if (c->string) cJSON_freestr(c->string); + cJSON_freenode(c); c=next; } } @@ -134,13 +167,13 @@ static char *print_number(cJSON *item) double d = item->valuedouble; if ( fabs(((double)item->valueint) - d) <= DBL_EPSILON && d >= (1. - DBL_EPSILON) && d < (1LL << 62) )//d <= INT_MAX && d >= INT_MIN ) { - str = (char *)cJSON_malloc(24); /* 2^64+1 can be represented in 21 chars + sign. */ + str = (char *)cJSON_mallocstr(24); /* 2^64+1 can be represented in 21 chars + sign. */ if ( str != 0 ) sprintf(str,"%lld",(long long)item->valueint); } else { - str = (char *)cJSON_malloc(66); /* This is a nice tradeoff. */ + str = (char *)cJSON_mallocstr(66); /* This is a nice tradeoff. */ if ( str != 0 ) { if ( fabs(floor(d) - d) <= DBL_EPSILON && fabs(d) < 1.0e60 ) @@ -175,7 +208,7 @@ static const char *parse_string(cJSON *item,const char *str) while (*ptr!='\"' && *ptr && ++len) if (*ptr++ == '\\') ptr++; // Skip escaped quotes - out=(char*)cJSON_malloc(len+2); /* This is how long we need for the string, roughly. */ + out=(char*)cJSON_mallocstr(len+2); /* This is how long we need for the string, roughly. */ if (!out) return 0; ptr=str+1;ptr2=out; @@ -240,7 +273,7 @@ static char *print_string_ptr(const char *str) if (!str) return cJSON_strdup(""); ptr=str;while ((token=*ptr) && ++len) {if (strchr("\"\\\b\f\n\r\t",token)) len++; else if (token<32) len+=5;ptr++;} - out=(char*)cJSON_malloc(len+3+1); + out=(char*)cJSON_mallocstr(len+3+1); if (!out) return 0; ptr2=out;ptr=str; @@ -374,7 +407,7 @@ static const char *parse_array(cJSON *item,const char *value) /* Render an array to text */ static char *print_array(cJSON *item,int32_t depth,int32_t fmt) { - char **entries; + char **entries,*space_entries[512]; char *out=0,*ptr,*ret;int32_t len=5; cJSON *child=item->child; int32_t numentries=0,i=0,fail=0; @@ -384,12 +417,12 @@ static char *print_array(cJSON *item,int32_t depth,int32_t fmt) /* Explicitly handle numentries==0 */ if (!numentries) { - out=(char*)cJSON_malloc(3+1); + out=(char*)cJSON_mallocstr(3+1); if (out) strcpy(out,"[]"); return out; } /* Allocate an array to hold the values for each */ - entries=(char**)cJSON_malloc((1+numentries)*sizeof(char*)); + entries=cJSON_mallocptrs(1+numentries,space_entries,sizeof(space_entries)/sizeof(*space_entries)); if (!entries) return 0; memset(entries,0,numentries*sizeof(char*)); /* Retrieve all the results: */ @@ -403,15 +436,15 @@ static char *print_array(cJSON *item,int32_t depth,int32_t fmt) } /* If we didn't fail, try to malloc the output string */ - if (!fail) out=(char*)cJSON_malloc(len+1); + if (!fail) out=(char*)cJSON_mallocstr(len+1); /* If that fails, we fail. */ if (!out) fail=1; /* Handle failure. */ if (fail) { - for (i=0;ichild,*firstchild; int32_t numentries=0,fail=0; @@ -487,7 +520,7 @@ static char *print_object(cJSON *item,int32_t depth,int32_t fmt) /* Explicitly handle empty object case */ if (!numentries) { - out=(char*)cJSON_malloc(fmt?depth+4+1:3+1); + out=(char*)cJSON_mallocstr(fmt?depth+4+1:3+1); if (!out) return 0; ptr=out;*ptr++='{'; if (fmt) {*ptr++='\n';for (i=0;i 32 && cipherlen <= sizeof(decoded)*2 ) + if ( 0 && (cipherstr= jstr(argjson,"cipher")) != 0 && (cipherlen= is_hexstr(cipherstr,0)) > 32 && cipherlen <= sizeof(decoded)*2 ) { method2 = jstr(argjson,"method2"); if ( (method= jstr(argjson,"method")) != 0 && (strcmp(method,"encrypted") == 0 ||(method2 != 0 && strcmp(method2,"encrypted") == 0)) ) @@ -1206,14 +1206,14 @@ int32_t zeroval() { return(0); } void *LP_alloc(uint64_t len) { - return(calloc(1,len)); + //return(calloc(1,len)); LP_cjson_allocated += len; LP_cjson_total += len; LP_cjson_count++; struct LP_memory_list *mp; mp = calloc(1,sizeof(*mp) + len); mp->ptr = calloc(1,len); - printf(">>>>>>>>>>> LP_alloc mp.%p ptr.%p len.%llu %llu\n",mp,mp->ptr,(long long)len,(long long)LP_cjson_allocated); + //printf(">>>>>>>>>>> LP_alloc mp.%p ptr.%p len.%llu %llu\n",mp,mp->ptr,(long long)len,(long long)LP_cjson_allocated); mp->timestamp = (uint32_t)time(NULL); mp->len = (uint32_t)len; portable_mutex_lock(&LP_cJSONmutex); @@ -1225,8 +1225,7 @@ void *LP_alloc(uint64_t len) void LP_free(void *ptr) { static uint32_t lasttime,unknown; - free(ptr); - return; + // free(ptr); return; uint32_t now; char str[65]; int32_t n,lagging; uint64_t total = 0; struct LP_memory_list *mp,*tmp; if ( (now= (uint32_t)time(NULL)) > lasttime+60 ) { @@ -1263,7 +1262,7 @@ void LP_free(void *ptr) portable_mutex_lock(&LP_cJSONmutex); DL_DELETE(LP_memory_list,mp); portable_mutex_unlock(&LP_cJSONmutex); - printf(">>>>>>>>>>> LP_free ptr.%p mp.%p len.%u %llu\n",ptr,mp,mp->len,(long long)LP_cjson_allocated); + //printf(">>>>>>>>>>> LP_free ptr.%p mp.%p len.%u %llu\n",ptr,mp,mp->len,(long long)LP_cjson_allocated); free(mp->ptr); free(mp); } else unknown++; // free from source file with #define redirect for alloc that wasnt From ef31b37fce7919122c121f751f4f6b3a9dbd5146 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 10:35:53 +0200 Subject: [PATCH 243/306] Test --- iguana/exchanges/LP_nativeDEX.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index e10ce33be..93f37280e 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -250,7 +250,7 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock, uint8_t decoded[LP_ENCRYPTED_MAXSIZE + crypto_box_ZEROBYTES]; //printf("[%s]\n",jsonstr); cipherlen = 0; - if ( 0 && (cipherstr= jstr(argjson,"cipher")) != 0 && (cipherlen= is_hexstr(cipherstr,0)) > 32 && cipherlen <= sizeof(decoded)*2 ) + if ( (cipherstr= jstr(argjson,"cipher")) != 0 && (cipherlen= is_hexstr(cipherstr,0)) > 32 && cipherlen <= sizeof(decoded)*2 ) { method2 = jstr(argjson,"method2"); if ( (method= jstr(argjson,"method")) != 0 && (strcmp(method,"encrypted") == 0 ||(method2 != 0 && strcmp(method2,"encrypted") == 0)) ) @@ -1084,17 +1084,17 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu printf("error launching KMD LP_coinsloop for port.%u\n",myport); exit(-1); } - if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_pubkeysloop,(void *)myipaddr) != 0 ) + if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_pubkeysloop,(void *)myipaddr) != 0 ) { printf("error launching LP_pubkeysloop for ctx.%p\n",ctx); exit(-1); } - if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_privkeysloop,(void *)myipaddr) != 0 ) + if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_privkeysloop,(void *)myipaddr) != 0 ) { printf("error launching LP_privkeysloop for ctx.%p\n",ctx); exit(-1); } - if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_swapsloop,(void *)myipaddr) != 0 ) + if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_swapsloop,(void *)myipaddr) != 0 ) { printf("error launching LP_swapsloop for port.%u\n",myport); exit(-1); From 83bb9a061b7de944c876e586dd40540d9965f0cc Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 10:39:33 +0200 Subject: [PATCH 244/306] Test --- iguana/exchanges/LP_commands.c | 2 +- iguana/exchanges/LP_nativeDEX.c | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 72c64d04b..c7b2b84fb 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -542,7 +542,7 @@ bot_resume(botid)\n\ return(LP_postprice_recv(argjson)); else if ( strcmp(method,"postutxos") == 0 ) return(LP_postutxos_recv(argjson)); - else if ( strcmp(method,"uitem") == 0 ) + else if ( 0 && strcmp(method,"uitem") == 0 ) return(LP_uitem_recv(argjson)); else if ( strcmp(method,"notify") == 0 ) return(LP_notify_recv(argjson)); diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 93f37280e..30548d1c6 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -327,7 +327,7 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock, int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int32_t sock,char *remoteaddr,int32_t maxdepth) { - int32_t recvlen=1,nonz = 0; cJSON *argjson; void *ptr,*buf; char methodstr[64],*retstr,*str; struct nn_pollfd pfd; + int32_t recvlen=1,nonz = 0; cJSON *argjson; void *ptr; char methodstr[64],*retstr,*str; struct nn_pollfd pfd; if ( sock >= 0 ) { while ( nonz < maxdepth && recvlen > 0 ) @@ -339,11 +339,11 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int if ( nn_poll(&pfd,1,1) != 1 ) break; ptr = 0; - buf = malloc(1000000); - if ( (recvlen= nn_recv(sock,buf,1000000,0)) > 0 ) - //if ( (recvlen= nn_recv(sock,&ptr,NN_MSG,0)) > 0 ) + //buf = malloc(1000000); + //if ( (recvlen= nn_recv(sock,buf,1000000,0)) > 0 ) + if ( (recvlen= nn_recv(sock,&ptr,NN_MSG,0)) > 0 ) { - ptr = buf; + //ptr = buf; methodstr[0] = 0; //printf("%s.(%s)\n",typestr,(char *)ptr); if ( 0 ) @@ -394,8 +394,8 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int } if ( ptr != 0 ) { - //nn_freemsg(ptr), ptr = 0; - free(buf); + nn_freemsg(ptr), ptr = 0; + //free(buf); } } } From ce6dd7022046a38b3187243f35396c2d6678fe12 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 10:48:30 +0200 Subject: [PATCH 245/306] Test --- iguana/exchanges/LP_commands.c | 2 +- iguana/exchanges/LP_nativeDEX.c | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index c7b2b84fb..72c64d04b 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -542,7 +542,7 @@ bot_resume(botid)\n\ return(LP_postprice_recv(argjson)); else if ( strcmp(method,"postutxos") == 0 ) return(LP_postutxos_recv(argjson)); - else if ( 0 && strcmp(method,"uitem") == 0 ) + else if ( strcmp(method,"uitem") == 0 ) return(LP_uitem_recv(argjson)); else if ( strcmp(method,"notify") == 0 ) return(LP_notify_recv(argjson)); diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 30548d1c6..dce105e65 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1028,23 +1028,23 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu printf("error launching LP_psockloop for (%s)\n",myipaddr); exit(-1); } - if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_reserved_msgs,(void *)myipaddr) != 0 ) + if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_reserved_msgs,(void *)myipaddr) != 0 ) { printf("error launching LP_reserved_msgs for (%s)\n",myipaddr); exit(-1); } - if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)utxosQ_loop,(void *)myipaddr) != 0 ) + if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)utxosQ_loop,(void *)myipaddr) != 0 ) { printf("error launching utxosQ_loop for (%s)\n",myipaddr); exit(-1); } - if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)stats_rpcloop,(void *)&myport) != 0 ) + if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)stats_rpcloop,(void *)&myport) != 0 ) { printf("error launching stats rpcloop for port.%u\n",myport); exit(-1); } uint16_t myport2 = myport-1; - if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)stats_rpcloop,(void *)&myport2) != 0 ) + if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)stats_rpcloop,(void *)&myport2) != 0 ) { printf("error launching stats rpcloop for port.%u\n",myport); exit(-1); @@ -1054,7 +1054,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu printf("error launching command_rpcloop for port.%u\n",myport); exit(-1); } - if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)queue_loop,(void *)myipaddr) != 0 ) + if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)queue_loop,(void *)myipaddr) != 0 ) { printf("error launching queue_loop for port.%u\n",myport); exit(-1); @@ -1084,17 +1084,17 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu printf("error launching KMD LP_coinsloop for port.%u\n",myport); exit(-1); } - if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_pubkeysloop,(void *)myipaddr) != 0 ) + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_pubkeysloop,(void *)myipaddr) != 0 ) { printf("error launching LP_pubkeysloop for ctx.%p\n",ctx); exit(-1); } - if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_privkeysloop,(void *)myipaddr) != 0 ) + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_privkeysloop,(void *)myipaddr) != 0 ) { printf("error launching LP_privkeysloop for ctx.%p\n",ctx); exit(-1); } - if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_swapsloop,(void *)myipaddr) != 0 ) + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_swapsloop,(void *)myipaddr) != 0 ) { printf("error launching LP_swapsloop for port.%u\n",myport); exit(-1); From 83293ad5b26a1343066b5c726579bc1326183f95 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 10:52:49 +0200 Subject: [PATCH 246/306] Test --- iguana/exchanges/LP_nativeDEX.c | 18 +++++++++--------- iguana/exchanges/LP_utxo.c | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index dce105e65..220770d43 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1028,23 +1028,23 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu printf("error launching LP_psockloop for (%s)\n",myipaddr); exit(-1); } - if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_reserved_msgs,(void *)myipaddr) != 0 ) + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_reserved_msgs,(void *)myipaddr) != 0 ) { printf("error launching LP_reserved_msgs for (%s)\n",myipaddr); exit(-1); } - if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)utxosQ_loop,(void *)myipaddr) != 0 ) + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)utxosQ_loop,(void *)myipaddr) != 0 ) { printf("error launching utxosQ_loop for (%s)\n",myipaddr); exit(-1); } - if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)stats_rpcloop,(void *)&myport) != 0 ) + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)stats_rpcloop,(void *)&myport) != 0 ) { printf("error launching stats rpcloop for port.%u\n",myport); exit(-1); } uint16_t myport2 = myport-1; - if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)stats_rpcloop,(void *)&myport2) != 0 ) + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)stats_rpcloop,(void *)&myport2) != 0 ) { printf("error launching stats rpcloop for port.%u\n",myport); exit(-1); @@ -1054,7 +1054,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu printf("error launching command_rpcloop for port.%u\n",myport); exit(-1); } - if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)queue_loop,(void *)myipaddr) != 0 ) + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)queue_loop,(void *)myipaddr) != 0 ) { printf("error launching queue_loop for port.%u\n",myport); exit(-1); @@ -1206,7 +1206,7 @@ int32_t zeroval() { return(0); } void *LP_alloc(uint64_t len) { - //return(calloc(1,len)); +return(calloc(1,len)); LP_cjson_allocated += len; LP_cjson_total += len; LP_cjson_count++; @@ -1225,7 +1225,7 @@ void *LP_alloc(uint64_t len) void LP_free(void *ptr) { static uint32_t lasttime,unknown; - // free(ptr); return; +free(ptr); return; uint32_t now; char str[65]; int32_t n,lagging; uint64_t total = 0; struct LP_memory_list *mp,*tmp; if ( (now= (uint32_t)time(NULL)) > lasttime+60 ) { @@ -1268,7 +1268,7 @@ void LP_free(void *ptr) } else unknown++; // free from source file with #define redirect for alloc that wasnt } -char *LP_clonestr(char *str) +/*char *LP_clonestr(char *str) { char *retstr = LP_alloc(strlen(str)+1); strcpy(retstr,str); @@ -1278,6 +1278,6 @@ char *LP_clonestr(char *str) void *LP_realloc(void *ptr,uint64_t len) { return(realloc(ptr,len)); -} +}*/ diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 59b8b8b8e..4458feaa1 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -382,7 +382,7 @@ int32_t LP_address_utxoadd(uint32_t timestamp,char *debug,struct iguana_info *co break; } } - if ( flag == 0 && value != 0 ) + if ( 0 && flag == 0 && value != 0 ) { if ( coin->electrum == 0 ) { @@ -739,7 +739,7 @@ struct LP_transaction *LP_transactionadd(struct iguana_info *coin,bits256 txid,i cJSON *LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter,cJSON *txobj) { struct LP_transaction *tx; int32_t i,height,numvouts,numvins,spentvout; cJSON *vins,*vouts,*vout,*vin; bits256 spenttxid; char str[65]; - if ( coin->inactive != 0 ) + //if ( coin->inactive != 0 ) return(0); if ( txobj != 0 || (txobj= LP_gettx(coin->symbol,txid)) != 0 ) { From 2af1ae8f4055b79674137666e019832883484f67 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 10:54:17 +0200 Subject: [PATCH 247/306] Test --- iguana/exchanges/LP_utxo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 4458feaa1..59b8b8b8e 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -382,7 +382,7 @@ int32_t LP_address_utxoadd(uint32_t timestamp,char *debug,struct iguana_info *co break; } } - if ( 0 && flag == 0 && value != 0 ) + if ( flag == 0 && value != 0 ) { if ( coin->electrum == 0 ) { @@ -739,7 +739,7 @@ struct LP_transaction *LP_transactionadd(struct iguana_info *coin,bits256 txid,i cJSON *LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter,cJSON *txobj) { struct LP_transaction *tx; int32_t i,height,numvouts,numvins,spentvout; cJSON *vins,*vouts,*vout,*vin; bits256 spenttxid; char str[65]; - //if ( coin->inactive != 0 ) + if ( coin->inactive != 0 ) return(0); if ( txobj != 0 || (txobj= LP_gettx(coin->symbol,txid)) != 0 ) { From 6cf6360c1315751c398535c046629338a46158f5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 11:10:48 +0200 Subject: [PATCH 248/306] Test --- iguana/exchanges/LP_swap.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_swap.c b/iguana/exchanges/LP_swap.c index 1002517b0..8df54f58d 100644 --- a/iguana/exchanges/LP_swap.c +++ b/iguana/exchanges/LP_swap.c @@ -113,8 +113,8 @@ void basilisk_rawtx_purge(struct basilisk_rawtx *rawtx) { if ( rawtx->vins != 0 ) free_json(rawtx->vins); - //if ( rawtx->txbytes != 0 ) - // free(rawtx->txbytes), rawtx->txbytes = 0; + if ( rawtx->txbytes != 0 ) + free(rawtx->txbytes), rawtx->txbytes = 0; } void basilisk_swap_finished(struct basilisk_swap *swap) @@ -831,7 +831,7 @@ void LP_bobloop(void *_swap) } } basilisk_swap_finished(swap); - //free(swap); + free(swap); } else printf("swap timed out\n"); G.LP_pendingswaps--; } From 5472f4ed20716503c51377c18f6bcaa349d8b656 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 11:12:40 +0200 Subject: [PATCH 249/306] Test --- iguana/exchanges/LP_swap.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_swap.c b/iguana/exchanges/LP_swap.c index 8df54f58d..ba323ae97 100644 --- a/iguana/exchanges/LP_swap.c +++ b/iguana/exchanges/LP_swap.c @@ -112,9 +112,9 @@ void basilisk_rawtx_purge(struct basilisk_rawtx *rawtx) { if ( rawtx->vins != 0 ) - free_json(rawtx->vins); - if ( rawtx->txbytes != 0 ) - free(rawtx->txbytes), rawtx->txbytes = 0; + free_json(rawtx->vins), rawtx->vins = 0; + //if ( rawtx->txbytes != 0 ) + // free(rawtx->txbytes), rawtx->txbytes = 0; } void basilisk_swap_finished(struct basilisk_swap *swap) From 36a1ae9fb4f1b45a4464fd03d4b3e43d43447140 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 13:35:51 +0200 Subject: [PATCH 250/306] Test --- iguana/exchanges/LP_nativeDEX.c | 8 ++++---- iguana/exchanges/LP_statemachine.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 220770d43..ef26d9882 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1206,14 +1206,14 @@ int32_t zeroval() { return(0); } void *LP_alloc(uint64_t len) { -return(calloc(1,len)); +//return(calloc(1,len)); LP_cjson_allocated += len; LP_cjson_total += len; LP_cjson_count++; struct LP_memory_list *mp; mp = calloc(1,sizeof(*mp) + len); mp->ptr = calloc(1,len); - //printf(">>>>>>>>>>> LP_alloc mp.%p ptr.%p len.%llu %llu\n",mp,mp->ptr,(long long)len,(long long)LP_cjson_allocated); + printf(">>>>>>>>>>> LP_alloc mp.%p ptr.%p len.%llu %llu\n",mp,mp->ptr,(long long)len,(long long)LP_cjson_allocated); mp->timestamp = (uint32_t)time(NULL); mp->len = (uint32_t)len; portable_mutex_lock(&LP_cJSONmutex); @@ -1225,7 +1225,7 @@ return(calloc(1,len)); void LP_free(void *ptr) { static uint32_t lasttime,unknown; -free(ptr); return; +//free(ptr); return; uint32_t now; char str[65]; int32_t n,lagging; uint64_t total = 0; struct LP_memory_list *mp,*tmp; if ( (now= (uint32_t)time(NULL)) > lasttime+60 ) { @@ -1262,7 +1262,7 @@ free(ptr); return; portable_mutex_lock(&LP_cJSONmutex); DL_DELETE(LP_memory_list,mp); portable_mutex_unlock(&LP_cJSONmutex); - //printf(">>>>>>>>>>> LP_free ptr.%p mp.%p len.%u %llu\n",ptr,mp,mp->len,(long long)LP_cjson_allocated); + printf(">>>>>>>>>>> LP_free ptr.%p mp.%p len.%u %llu\n",ptr,mp,mp->len,(long long)LP_cjson_allocated); free(mp->ptr); free(mp); } else unknown++; // free from source file with #define redirect for alloc that wasnt diff --git a/iguana/exchanges/LP_statemachine.c b/iguana/exchanges/LP_statemachine.c index 1832e2895..593bc3330 100644 --- a/iguana/exchanges/LP_statemachine.c +++ b/iguana/exchanges/LP_statemachine.c @@ -1765,7 +1765,7 @@ void basilisk_swaploop(void *_utxo) else tradebot_pendingadd(swapjson(swap),swap->I.req.dest,dstr(swap->I.req.destamount),swap->I.req.src,dstr(swap->I.req.srcamount)); } printf("%s swap finished statebits %x\n",swap->I.iambob!=0?"BOB":"ALICE",swap->I.statebits); - //basilisk_swap_purge(swap); + basilisk_swap_purge(swap); free(data); } #endif From a30ecba4d7464ab92f62c929781c3aff9ac7bfc1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 13:40:07 +0200 Subject: [PATCH 251/306] Test --- iguana/exchanges/LP_nativeDEX.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index ef26d9882..b63b8ecb9 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1213,7 +1213,7 @@ void *LP_alloc(uint64_t len) struct LP_memory_list *mp; mp = calloc(1,sizeof(*mp) + len); mp->ptr = calloc(1,len); - printf(">>>>>>>>>>> LP_alloc mp.%p ptr.%p len.%llu %llu\n",mp,mp->ptr,(long long)len,(long long)LP_cjson_allocated); + //printf(">>>>>>>>>>> LP_alloc mp.%p ptr.%p len.%llu %llu\n",mp,mp->ptr,(long long)len,(long long)LP_cjson_allocated); mp->timestamp = (uint32_t)time(NULL); mp->len = (uint32_t)len; portable_mutex_lock(&LP_cJSONmutex); @@ -1234,10 +1234,10 @@ void LP_free(void *ptr) { total += mp->len; n++; - if ( 0 && now > mp->timestamp+60 ) + if ( now > mp->timestamp+120 ) { lagging++; - if ( now > mp->timestamp+60 ) + if ( now > mp->timestamp+240 ) { portable_mutex_lock(&LP_cJSONmutex); DL_DELETE(LP_memory_list,mp); @@ -1262,7 +1262,7 @@ void LP_free(void *ptr) portable_mutex_lock(&LP_cJSONmutex); DL_DELETE(LP_memory_list,mp); portable_mutex_unlock(&LP_cJSONmutex); - printf(">>>>>>>>>>> LP_free ptr.%p mp.%p len.%u %llu\n",ptr,mp,mp->len,(long long)LP_cjson_allocated); + //printf(">>>>>>>>>>> LP_free ptr.%p mp.%p len.%u %llu\n",ptr,mp,mp->len,(long long)LP_cjson_allocated); free(mp->ptr); free(mp); } else unknown++; // free from source file with #define redirect for alloc that wasnt From c5a41e2cc100941e6d938b817735f5e8862d2050 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 13:48:00 +0200 Subject: [PATCH 252/306] Test --- iguana/exchanges/LP_commands.c | 1 + iguana/exchanges/LP_nativeDEX.c | 15 +++++++-------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 72c64d04b..c9ef8b70b 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -36,6 +36,7 @@ char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *r { char *method,*userpass,*base,*rel,*coin,*retstr = 0; int32_t changed,flag = 0; cJSON *retjson,*reqjson = 0; struct iguana_info *ptr; method = jstr(argjson,"method"); + printf("stats_JSON %s\n",method); /*if ( (ipaddr= jstr(argjson,"ipaddr")) != 0 && (argport= juint(argjson,"port")) != 0 && (method == 0 || strcmp(method,"electrum") != 0) ) { if ( strcmp(ipaddr,"127.0.0.1") != 0 && argport >= 1000 ) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index b63b8ecb9..3af21780f 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -768,7 +768,7 @@ void LP_pubkeysloop(void *ctx) } if ( time(NULL) > lasttime+LP_ORDERBOOK_DURATION*0.5 ) { - //printf("LP_pubkeysloop %u\n",(uint32_t)time(NULL)); +printf("LP_pubkeysloop %u\n",(uint32_t)time(NULL)); LP_notify_pubkeys(ctx,LP_mypubsock); lasttime = (uint32_t)time(NULL); } @@ -785,7 +785,7 @@ void LP_privkeysloop(void *ctx) { LP_millistats_update(&LP_privkeysloop_stats); LP_counter += 1000; - //printf("LP_privkeysloop %u\n",LP_counter); +printf("LP_privkeysloop %u\n",LP_counter); LP_privkey_updates(ctx,LP_mypubsock,0); sleep(LP_ORDERBOOK_DURATION * .777); } @@ -801,10 +801,9 @@ void LP_swapsloop(void *ignore) { LP_millistats_update(&LP_swapsloop_stats); LP_counter += 10000; - //printf("LP_swapsloop %u\n",LP_counter); +printf("LP_swapsloop %u\n",LP_counter); if ( (retstr= basilisk_swapentry(0,0)) != 0 ) free(retstr); - //LP_millistats_update(0); sleep(600); } } @@ -837,14 +836,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; } @@ -1227,14 +1226,14 @@ void LP_free(void *ptr) static uint32_t lasttime,unknown; //free(ptr); return; uint32_t now; char str[65]; int32_t n,lagging; uint64_t total = 0; struct LP_memory_list *mp,*tmp; - if ( (now= (uint32_t)time(NULL)) > lasttime+60 ) + if ( (now= (uint32_t)time(NULL)) > lasttime+6 ) { n = lagging = 0; DL_FOREACH_SAFE(LP_memory_list,mp,tmp) { total += mp->len; n++; - if ( now > mp->timestamp+120 ) + if ( 0 && now > mp->timestamp+120 ) { lagging++; if ( now > mp->timestamp+240 ) From 8138f553cd7faa610d703a093899479e138535c1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 13:51:37 +0200 Subject: [PATCH 253/306] 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 59b8b8b8e..d94c1c5b9 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -405,7 +405,7 @@ int32_t LP_address_utxoadd(uint32_t timestamp,char *debug,struct iguana_info *co up->SPV = tx->SPV; } char str[65]; - if ( 0 && strcmp(coin->smartaddr,coinaddr) == 0 && strcmp("KMD",coin->symbol) == 0 ) + //if ( 0 && strcmp(coin->smartaddr,coinaddr) == 0 && strcmp("KMD",coin->symbol) == 0 ) printf("%s ADD UTXO >> %s %s %s/v%d ht.%d %.8f\n",debug,coin->symbol,coinaddr,bits256_str(str,txid),vout,height,dstr(value)); portable_mutex_lock(&coin->addrmutex); DL_APPEND(ap->utxos,up); From 06b926112bb173cb4525119e07888bfe8cfa7608 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 13:53:13 +0200 Subject: [PATCH 254/306] Test --- iguana/exchanges/LP_nativeDEX.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 3af21780f..f0c378bf5 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1223,7 +1223,7 @@ void *LP_alloc(uint64_t len) void LP_free(void *ptr) { - static uint32_t lasttime,unknown; + static uint32_t lasttime,unknown; static int64_t lasttotal; //free(ptr); return; uint32_t now; char str[65]; int32_t n,lagging; uint64_t total = 0; struct LP_memory_list *mp,*tmp; if ( (now= (uint32_t)time(NULL)) > lasttime+6 ) @@ -1246,8 +1246,9 @@ void LP_free(void *ptr) } } } - printf("total %d allocated total %llu/%llu [%llu %llu] %.1f ave %s unknown.%u lagging.%d\n",n,(long long)total,(long long)LP_cjson_allocated,(long long)LP_cjson_total,(long long)LP_cjson_count,(double)LP_cjson_total/LP_cjson_count,mbstr(str,total),unknown,lagging); + printf("[%lld] total %d allocated total %llu/%llu [%llu %llu] %.1f ave %s unknown.%u lagging.%d\n",(long long)(total-lasttotal),n,(long long)total,(long long)LP_cjson_allocated,(long long)LP_cjson_total,(long long)LP_cjson_count,(double)LP_cjson_total/LP_cjson_count,mbstr(str,total),unknown,lagging); lasttime = (uint32_t)time(NULL); + lasttotal = total; } DL_FOREACH_SAFE(LP_memory_list,mp,tmp) { From b977dff87b62f3413a466fcb20453be0e51893e1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 14:20:30 +0200 Subject: [PATCH 255/306] Test --- iguana/exchanges/LP_commands.c | 2 +- iguana/exchanges/LP_nativeDEX.c | 20 +++++++++++++++----- iguana/exchanges/LP_network.c | 10 +++++----- iguana/exchanges/LP_ordermatch.c | 6 +++--- iguana/exchanges/LP_peers.c | 2 +- iguana/exchanges/LP_prices.c | 2 +- iguana/exchanges/LP_rpc.c | 4 ++-- iguana/exchanges/LP_signatures.c | 8 ++++---- iguana/exchanges/LP_socket.c | 2 +- iguana/exchanges/LP_statemachine.c | 22 +++++++++++----------- iguana/exchanges/LP_tradebots.c | 2 +- iguana/exchanges/LP_utxo.c | 2 +- iguana/exchanges/LP_utxos.c | 2 +- 13 files changed, 47 insertions(+), 37 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index c9ef8b70b..3b0734349 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -36,7 +36,7 @@ char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *r { char *method,*userpass,*base,*rel,*coin,*retstr = 0; int32_t changed,flag = 0; cJSON *retjson,*reqjson = 0; struct iguana_info *ptr; method = jstr(argjson,"method"); - printf("stats_JSON %s\n",method); + //printf("stats_JSON %s\n",method); /*if ( (ipaddr= jstr(argjson,"ipaddr")) != 0 && (argport= juint(argjson,"port")) != 0 && (method == 0 || strcmp(method,"electrum") != 0) ) { if ( strcmp(ipaddr,"127.0.0.1") != 0 && argport >= 1000 ) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index f0c378bf5..6725bbf34 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -118,6 +118,16 @@ struct LP_globals struct LP_privkey LP_privkeys[100]; } G; +uint32_t LP_rand() +{ + uint32_t retval; + retval = rand(); + retval = (retval << 7) ^ (retval >> 17) ^ rand(); + retval = (retval << 13) ^ (retval >> 13) ^ rand(); + retval = (retval << 17) ^ (retval >> 7) ^ rand(); + return(retval); +} + #include "LP_network.c" char *activecoins[] = { "BTC", "KMD" }; @@ -130,7 +140,6 @@ char *default_LPnodes[] = { "5.9.253.195", "5.9.253.196", "5.9.253.197", "5.9.25 "51.15.203.171", "51.15.86.136", "51.15.94.249", "51.15.80.18", "51.15.91.40", "51.15.54.2", "51.15.86.31", "51.15.82.29", "51.15.89.155", };//"5.9.253.204" }; // - // stubs void tradebot_swap_balancingtrade(struct basilisk_swap *swap,int32_t iambob) @@ -230,7 +239,7 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock, dup++; else uniq++; portable_mutex_lock(&LP_commandmutex); - if ( (rand() % 10000) == 0 ) + if ( (LP_rand() % 10000) == 0 ) printf("%s dup.%d (%u / %u) %.1f%% encrypted.%d recv.%u [%02x %02x] vs %02x %02x\n",typestr,duplicate,dup,dup+uniq,(double)100*dup/(dup+uniq),encrypted,crc32,ptr[0],ptr[1],crc32&0xff,(crc32>>8)&0xff); if ( duplicate == 0 ) { @@ -412,7 +421,7 @@ int32_t LP_nanomsg_recvs(void *ctx) { if ( peer->errors >= LP_MAXPEER_ERRORS ) { - if ( (rand() % 10000) == 0 ) + if ( (LP_rand() % 10000) == 0 ) peer->errors--; else { @@ -896,6 +905,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu } #endif OS_randombytes((void *)&n,sizeof(n)); + srand((uint32_t)n); if ( jobj(argjson,"gui") != 0 ) safecopy(LP_gui,jstr(argjson,"gui"),sizeof(LP_gui)); if ( jobj(argjson,"canbind") == 0 ) @@ -1205,7 +1215,7 @@ int32_t zeroval() { return(0); } void *LP_alloc(uint64_t len) { -//return(calloc(1,len)); +return(calloc(1,len)); LP_cjson_allocated += len; LP_cjson_total += len; LP_cjson_count++; @@ -1224,7 +1234,7 @@ void *LP_alloc(uint64_t len) void LP_free(void *ptr) { static uint32_t lasttime,unknown; static int64_t lasttotal; -//free(ptr); return; +free(ptr); return; uint32_t now; char str[65]; int32_t n,lagging; uint64_t total = 0; struct LP_memory_list *mp,*tmp; if ( (now= (uint32_t)time(NULL)) > lasttime+6 ) { diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index f45f5142d..d1b147bc8 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -183,7 +183,7 @@ bits256 LP_calc_magic(uint8_t *msg,int32_t len) sum += (OS_milliseconds() - millis); nsum += n; counter++; - if ( n > maxn || (rand() % 10000) == 0 ) + if ( n > maxn || (LP_rand() % 10000) == 0 ) { if ( n > maxn ) { @@ -237,7 +237,7 @@ int32_t LP_crc32find(int32_t *duplicatep,int32_t ind,uint32_t crc32) break; } if ( i >= sizeof(crcs)/sizeof(*crcs) ) - i = (rand() % (sizeof(crcs)/sizeof(*crcs))); + i = (LP_rand() % (sizeof(crcs)/sizeof(*crcs))); return(i); } else @@ -316,7 +316,7 @@ void queue_loop(void *arg) flag = 0; if ( ptr->sock >= 0 ) { - if ( ptr->notready == 0 || (rand() % ptr->notready) == 0 ) + if ( ptr->notready == 0 || (LP_rand() % ptr->notready) == 0 ) { if ( LP_sockcheck(ptr->sock) > 0 ) { @@ -387,11 +387,11 @@ void _LP_queuesend(uint32_t crc32,int32_t sock0,int32_t sock1,uint8_t *msg,int32 if ( sock0 < 0 && sock1 < 0 ) { if ( (maxind= LP_numpeers()) > 0 ) - peerind = (rand() % maxind) + 1; + peerind = (LP_rand() % maxind) + 1; else peerind = 1; sock0 = LP_peerindsock(&peerind); if ( (maxind= LP_numpeers()) > 0 ) - peerind = (rand() % maxind) + 1; + peerind = (LP_rand() % maxind) + 1; else peerind = 1; sock1 = LP_peerindsock(&peerind); } diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index e1f7bf62e..3ad0fe345 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -52,7 +52,7 @@ double LP_bob_competition(int32_t *counterp,uint64_t aliceid,double price,int32_ firsti = i; } if ( firsti < 0 ) - firsti = (rand() % (sizeof(Bob_competition)/sizeof(*Bob_competition))); + firsti = (LP_rand() % (sizeof(Bob_competition)/sizeof(*Bob_competition))); Bob_competition[firsti].starttime = (uint32_t)time(NULL); Bob_competition[firsti].counter = counter; Bob_competition[firsti].aliceid = aliceid; @@ -252,7 +252,7 @@ int32_t LP_nanobind(void *ctx,char *pairstr) { for (i=0; i<10; i++) { - r = (10000 + (rand() % 50000)) & 0xffff; + r = (10000 + (LP_rand() % 50000)) & 0xffff; if ( LP_fixed_pairport != 0 ) r = LP_fixed_pairport; nanomsg_transportname(0,pairstr,LP_myipaddr,r); @@ -884,7 +884,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, } else return(retval); if ( qprice > price ) { - r = (rand() % 100); + r = (LP_rand() % 100); range = (qprice - price); price += (r * range) / 100.; bestprice = LP_bob_competition(&counter,aliceid,price,0); diff --git a/iguana/exchanges/LP_peers.c b/iguana/exchanges/LP_peers.c index e65d4806a..4e5e9a231 100644 --- a/iguana/exchanges/LP_peers.c +++ b/iguana/exchanges/LP_peers.c @@ -235,7 +235,7 @@ uint16_t LP_randpeer(char *destip) numpeers = LP_numpeers(); if ( numpeers > 0 ) { - r = rand() % numpeers; + r = LP_rand() % numpeers; n = 0; HASH_ITER(hh,LP_peerinfos,peer,tmp) { diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index d299b8368..80e056b6a 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -1070,7 +1070,7 @@ void LP_pricefeedupdate(bits256 pubkey,char *base,char *rel,double price) } if ( (pubp= LP_pubkeyadd(pubkey)) != 0 ) { - if ( (rand() % 1000) == 0 ) + if ( (LP_rand() % 1000) == 0 ) printf("PRICEFEED UPDATE.(%-6s/%6s) %12.8f %s %12.8f\n",base,rel,price,bits256_str(str,pubkey),1./price); pubp->timestamp = (uint32_t)time(NULL); if ( fabs(pubp->matrix[basepp->ind][relpp->ind] - price) > SMALLVAL ) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 2f8a7d5ff..11924e51c 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -314,13 +314,13 @@ char *account = "NXT-MRBN-8DFH-PFMK-A4DBM"; cJSON *LP_assethbla(char *assetid) { char url[1024],*retstr; int32_t n; cJSON *array,*bid=0,*ask=0,*retjson; - sprintf(url,"http://%s:7876/nxt?requestType=getBidOrders&asset=%s&firstIndex=0&lastIndex=0",NXTnodes[rand() % (sizeof(NXTnodes)/sizeof(*NXTnodes))],assetid); + sprintf(url,"http://%s:7876/nxt?requestType=getBidOrders&asset=%s&firstIndex=0&lastIndex=0",NXTnodes[LP_rand() % (sizeof(NXTnodes)/sizeof(*NXTnodes))],assetid); if ( (retstr= issue_curlt(url,LP_HTTP_TIMEOUT)) != 0 ) { bid = cJSON_Parse(retstr); free(retstr); } - sprintf(url,"http://%s:7876/nxt?requestType=getAskOrders&asset=%s&firstIndex=0&lastIndex=0",NXTnodes[rand() % (sizeof(NXTnodes)/sizeof(*NXTnodes))],assetid); + sprintf(url,"http://%s:7876/nxt?requestType=getAskOrders&asset=%s&firstIndex=0&lastIndex=0",NXTnodes[LP_rand() % (sizeof(NXTnodes)/sizeof(*NXTnodes))],assetid); if ( (retstr= issue_curlt(url,LP_HTTP_TIMEOUT)) != 0 ) { ask = cJSON_Parse(retstr); diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index fee4a1189..0cbcaff3f 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -132,14 +132,14 @@ int32_t LP_quoteparse(struct LP_quoteinfo *qp,cJSON *argjson) qp->R.quoteid = juint(argjson,"quoteid"); if ( qp->R.requestid == 0 ) { - rid= basilisk_requestid(&qp->R); - //printf("requestid.%u -> %u\n",qp->R.requestid,rid); + rid = basilisk_requestid(&qp->R); + printf("requestid.%u -> %u\n",qp->R.requestid,rid); qp->R.requestid = rid; } if ( qp->R.quoteid == 0 ) { - qid= basilisk_quoteid(&qp->R); - //printf("quoteid.%u -> %u\n",qp->R.quoteid,qid); + qid = basilisk_quoteid(&qp->R); + printf("quoteid.%u -> %u\n",qp->R.quoteid,qid); qp->R.quoteid = qid; } return(0); diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index af396cde8..36e6988ca 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -272,7 +272,7 @@ struct electrum_info *electrum_server(char *symbol,struct electrum_info *ep) ep = recent_ep; if ( n > 0 ) { - i = (rand() % n); + i = (LP_rand() % n); ep = rbuf[i]; } } diff --git a/iguana/exchanges/LP_statemachine.c b/iguana/exchanges/LP_statemachine.c index 593bc3330..54d9ddc95 100644 --- a/iguana/exchanges/LP_statemachine.c +++ b/iguana/exchanges/LP_statemachine.c @@ -186,7 +186,7 @@ FILE *basilisk_swap_save(struct basilisk_swap *swap,bits256 privkey,struct basil { if ( peer->errors >= LP_MAXPEER_ERRORS ) { - if ( (rand() % 10000) == 0 ) + if ( (LP_rand() % 10000) == 0 ) { peer->errors--; if ( peer->errors < LP_MAXPEER_ERRORS ) @@ -195,7 +195,7 @@ FILE *basilisk_swap_save(struct basilisk_swap *swap,bits256 privkey,struct basil if ( IAMLP == 0 ) continue; } - if ( now > peer->lastpeers+LP_ORDERBOOK_DURATION*.777 || (rand() % 100000) == 0 ) + if ( now > peer->lastpeers+LP_ORDERBOOK_DURATION*.777 || (LP_rand() % 100000) == 0 ) { if ( strcmp(peer->ipaddr,myipaddr) != 0 ) { @@ -241,7 +241,7 @@ int32_t LP_peersparse(struct LP_peerinfo *mypeer,int32_t mypubsock,char *destipa if ( (peer= LP_peerfind(argipbits,argport)) == 0 ) { numpeers = LP_numpeers(); - if ( IAMLP != 0 || numpeers < LP_MIN_PEERS || (IAMLP == 0 && (rand() % LP_MAX_PEERS) > numpeers) ) + if ( IAMLP != 0 || numpeers < LP_MIN_PEERS || (IAMLP == 0 && (LP_rand() % LP_MAX_PEERS) > numpeers) ) peer = LP_addpeer(mypeer,mypubsock,argipaddr,argport,pushport,subport,jint(item,"numpeers"),jint(item,"numutxos"),juint(item,"session")); } if ( peer != 0 ) @@ -395,7 +395,7 @@ void issue_LP_uitem(char *destip,uint16_t destport,char *symbol,char *coinaddr,b ptr = calloc(1,sizeof(*ptr)); ptr->timestamp = (uint32_t)time(NULL); ptr->item = item; - item->cjsonid = rand(); + item->cjsonid = LP_rand(); ptr->cjsonid = item->cjsonid; portable_mutex_lock(&LP_cJSONmutex); DL_APPEND(LP_cJSONlist,ptr); @@ -955,7 +955,7 @@ int32_t _basilisk_rawtx_gen(char *str,uint32_t swapstarted,uint8_t *pubkey33,int { char scriptstr[1024],wifstr[256],coinaddr[64],*signedtx,*rawtxbytes; uint32_t basilisktag; int32_t retval = -1; cJSON *vins,*privkeys,*addresses,*valsobj; struct vin_info *V; init_hexbytes_noT(scriptstr,script,scriptlen); - basilisktag = (uint32_t)rand(); + basilisktag = (uint32_t)LP_rand(); valsobj = cJSON_CreateObject(); jaddstr(valsobj,"coin",rawtx->coin->symbol); jaddstr(valsobj,"spendscript",scriptstr); @@ -1195,7 +1195,7 @@ int32_t basilisk_swapiteration(struct basilisk_swap *swap,uint8_t *data,int32_t basilisk_swap_saveupdate(swap); if ( swap->connected == 0 ) basilisk_psockinit(swap,swap->I.iambob != 0); - //if ( (rand() % 30) == 0 ) + //if ( (LP_rand() % 30) == 0 ) printf("E r%u/q%u swapstate.%x otherstate.%x remaining %d\n",swap->I.req.requestid,swap->I.req.quoteid,swap->I.statebits,swap->I.otherstatebits,(int32_t)(swap->I.expiration-time(NULL))); if ( swap->I.iambob != 0 ) { @@ -1369,7 +1369,7 @@ int32_t basilisk_swapiteration(struct basilisk_swap *swap,uint8_t *data,int32_t } } } - if ( (rand() % 30) == 0 ) + if ( (LP_rand() % 30) == 0 ) printf("finished swapstate.%x other.%x\n",swap->I.statebits,swap->I.otherstatebits); if ( swap->I.statebits == savestatebits && swap->I.otherstatebits == saveotherbits ) sleep(DEX_SLEEP + (swap->I.iambob == 0)*1); @@ -2792,7 +2792,7 @@ void LP_price_broadcastloop(void *ctx) minprice = LP_pricevol_invert(&basevol,bot->maxprice,bot->totalrelvolume - bot->relsum); printf("simulated trade sell %s/%s minprice %.8f volume %.8f, %.8f %s -> %s price %.8f relvol %.8f\n",bot->rel,bot->base,minprice,basevol,v,bot->base,bot->rel,p,relvol); } - if ( (rand() % 2) == 0 ) + if ( (LP_rand() % 2) == 0 ) { bot->relsum += relvol; bot->basesum += v; @@ -2809,7 +2809,7 @@ void LP_price_broadcastloop(void *ctx) #ifdef FROM_JS int32_t sentbytes,sock,peerind,maxind; if ( (maxind= LP_numpeers()) > 0 ) -peerind = (rand() % maxind) + 1; +peerind = (LP_rand() % maxind) + 1; else peerind = 1; sock = LP_peerindsock(&peerind); if ( sock >= 0 ) @@ -2851,11 +2851,11 @@ void _LP_queuesend(uint32_t crc32,int32_t sock0,int32_t sock1,uint8_t *msg,int32 else { if ( (maxind= LP_numpeers()) > 0 ) - peerind = (rand() % maxind) + 1; + peerind = (LP_rand() % maxind) + 1; else peerind = 1; sock0 = LP_peerindsock(&peerind); if ( (maxind= LP_numpeers()) > 0 ) - peerind = (rand() % maxind) + 1; + peerind = (LP_rand() % maxind) + 1; else peerind = 1; sock1 = LP_peerindsock(&peerind); } diff --git a/iguana/exchanges/LP_tradebots.c b/iguana/exchanges/LP_tradebots.c index 762a5c6bf..ec00553e4 100644 --- a/iguana/exchanges/LP_tradebots.c +++ b/iguana/exchanges/LP_tradebots.c @@ -324,7 +324,7 @@ void LP_tradebot_timeslice(void *ctx,struct LP_tradebot *bot) printf("try autobuy %s/%s remaining %.8f maxprice %.8f maxrel %.8f\n",bot->base,bot->rel,remaining,bot->maxprice,maxrel); if ( maxrel < remaining ) remaining = maxrel; - tradeid = rand(); + tradeid = LP_rand(); for (i=1; i<=maxiters; i++) { if ( remaining < 0.001 ) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index d94c1c5b9..59b8b8b8e 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -405,7 +405,7 @@ int32_t LP_address_utxoadd(uint32_t timestamp,char *debug,struct iguana_info *co up->SPV = tx->SPV; } char str[65]; - //if ( 0 && strcmp(coin->smartaddr,coinaddr) == 0 && strcmp("KMD",coin->symbol) == 0 ) + if ( 0 && strcmp(coin->smartaddr,coinaddr) == 0 && strcmp("KMD",coin->symbol) == 0 ) printf("%s ADD UTXO >> %s %s %s/v%d ht.%d %.8f\n",debug,coin->symbol,coinaddr,bits256_str(str,txid),vout,height,dstr(value)); portable_mutex_lock(&coin->addrmutex); DL_APPEND(ap->utxos,up); diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 2498d4da4..fc05779cb 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -848,7 +848,7 @@ void LP_privkey_updates(void *ctx,int32_t pubsock,char *passphrase) else if ( IAMLP == 0 || coin->inactive == 0 ) { //printf("from updates %s\n",coin->symbol); - if ( LP_privkey_init(pubsock,coin,G.LP_privkey,G.LP_mypub25519) == 0 && (rand() % 10) == 0 ) + if ( LP_privkey_init(pubsock,coin,G.LP_privkey,G.LP_mypub25519) == 0 && (LP_rand() % 10) == 0 ) LP_postutxos(coin->symbol,coin->smartaddr); } } From 146ebb01bd470b5644732c0c9e3256d2fc6e807d Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 14:22:17 +0200 Subject: [PATCH 256/306] Test --- iguana/exchanges/LP_nativeDEX.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 6725bbf34..9ba577394 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -777,7 +777,7 @@ void LP_pubkeysloop(void *ctx) } if ( time(NULL) > lasttime+LP_ORDERBOOK_DURATION*0.5 ) { -printf("LP_pubkeysloop %u\n",(uint32_t)time(NULL)); +//printf("LP_pubkeysloop %u\n",(uint32_t)time(NULL)); LP_notify_pubkeys(ctx,LP_mypubsock); lasttime = (uint32_t)time(NULL); } @@ -794,7 +794,7 @@ void LP_privkeysloop(void *ctx) { LP_millistats_update(&LP_privkeysloop_stats); LP_counter += 1000; -printf("LP_privkeysloop %u\n",LP_counter); +//printf("LP_privkeysloop %u\n",LP_counter); LP_privkey_updates(ctx,LP_mypubsock,0); sleep(LP_ORDERBOOK_DURATION * .777); } @@ -810,7 +810,7 @@ void LP_swapsloop(void *ignore) { LP_millistats_update(&LP_swapsloop_stats); LP_counter += 10000; -printf("LP_swapsloop %u\n",LP_counter); +//printf("LP_swapsloop %u\n",LP_counter); if ( (retstr= basilisk_swapentry(0,0)) != 0 ) free(retstr); sleep(600); @@ -845,14 +845,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 2054f886dcc1c7c11876b7f757596f5212243e38 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 14:23:41 +0200 Subject: [PATCH 257/306] Test --- iguana/exchanges/LP_signatures.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index 0cbcaff3f..651e9c0e8 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -133,13 +133,15 @@ int32_t LP_quoteparse(struct LP_quoteinfo *qp,cJSON *argjson) if ( qp->R.requestid == 0 ) { rid = basilisk_requestid(&qp->R); - printf("requestid.%u -> %u\n",qp->R.requestid,rid); + if ( qp->R.requestid != 0 && qp->R.requestid != rid ) + printf("requestid.%u -> %u\n",qp->R.requestid,rid); qp->R.requestid = rid; } if ( qp->R.quoteid == 0 ) { qid = basilisk_quoteid(&qp->R); - printf("quoteid.%u -> %u\n",qp->R.quoteid,qid); + if ( qp->R.quoteid != 0 && qp->R.quoteid != qid ) + printf("quoteid.%u -> %u\n",qp->R.quoteid,qid); qp->R.quoteid = qid; } return(0); From 0dff7d0e183a7c849029c005e6c2480b9567c46d Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 14:45:37 +0200 Subject: [PATCH 258/306] Test --- iguana/exchanges/LP_ordermatch.c | 5 +++-- iguana/exchanges/LP_swap.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 3ad0fe345..2711f7f42 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -572,6 +572,8 @@ char *LP_connectedalice(cJSON *argjson) // alice return(clonestr("{\"result\",\"update stats\"}")); } printf("CONNECTED.(%s) numpending.%d tradeid.%u requestid.%u quoteid.%u\n",jprint(argjson,0),G.LP_pendingswaps,Q.tradeid,Q.R.requestid,Q.R.quoteid); + 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); + printf("calculated requestid.%u quoteid.%u\n",Q.R.requestid,Q.R.quoteid); if ( LP_pendingswap(Q.R.requestid,Q.R.quoteid) > 0 ) { printf("requestid.%u quoteid.%u is already in progres\n",Q.R.requestid,Q.R.quoteid); @@ -622,7 +624,6 @@ char *LP_connectedalice(cJSON *argjson) // alice if ( bits256_nonz(Q.privkey) != 0 )//&& Q.quotetime >= Q.timestamp-3 ) { retjson = cJSON_CreateObject(); - 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); if ( (swap= LP_swapinit(0,0,Q.privkey,&Q.R,&Q)) == 0 ) { jaddstr(retjson,"error","couldnt swapinit"); @@ -771,7 +772,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: received %12s aliceid.%22llu %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("(%u-%u): received %12s aliceid.%22llu %5s/%-5s %12.8f -> %12.8f price %12.8f\n",Q.R.requestid,Q.R.quoteid,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; diff --git a/iguana/exchanges/LP_swap.c b/iguana/exchanges/LP_swap.c index ba323ae97..23f8d0a39 100644 --- a/iguana/exchanges/LP_swap.c +++ b/iguana/exchanges/LP_swap.c @@ -1189,7 +1189,7 @@ struct basilisk_swap *LP_swapinit(int32_t iambob,int32_t optionduration,bits256 G.LP_skipstatus[G.LP_numskips] = ((uint64_t)rp->requestid << 32) | rp->quoteid; if ( G.LP_numskips < sizeof(G.LP_skipstatus)/sizeof(*G.LP_skipstatus) ) G.LP_numskips++; - printf("basilisk_thread_start request.%u iambob.%d (%s/%s) quoteid.%u\n",rp->requestid,iambob,rp->src,rp->dest,rp->quoteid); + printf("LP_swapinit request.%u iambob.%d (%s/%s) quoteid.%u\n",rp->requestid,iambob,rp->src,rp->dest,rp->quoteid); bitcoin_pubkey33(swap->ctx,pubkey33,privkey); pubkey25519 = curve25519(privkey,curve25519_basepoint9()); swap->persistent_pubkey = pubkey25519; From 14cafd3da616ea973f415ef4fbd0c441d75db176 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 15:04:35 +0200 Subject: [PATCH 259/306] Test --- iguana/exchanges/LP_nativeDEX.c | 5 +++-- iguana/exchanges/LP_ordermatch.c | 8 +------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 9ba577394..2159505ec 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -888,8 +888,9 @@ int32_t LP_reserved_msg(int32_t priority,char *base,char *rel,bits256 pubkey,cha void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybusport,char *passphrase,int32_t amclient,char *userhome,cJSON *argjson) { - char *myipaddr=0; long filesize,n; int32_t valid,timeout,pubsock=-1; struct LP_peerinfo *mypeer=0; char pushaddr[128],subaddr[128],bindaddr[128],*coins_str=0; cJSON *coinsjson=0; void *ctx = bitcoin_ctx(); - printf("Marketmaker %s.%s %s\n",LP_MAJOR_VERSION,LP_MINOR_VERSION,LP_BUILD_NUMBER); + char *myipaddr=0,version[64]; long filesize,n; int32_t valid,timeout,pubsock=-1; struct LP_peerinfo *mypeer=0; char pushaddr[128],subaddr[128],bindaddr[128],*coins_str=0; cJSON *coinsjson=0; void *ctx = bitcoin_ctx(); + sprintf(version,"Marketmaker %s.%s %s",LP_MAJOR_VERSION,LP_MINOR_VERSION,LP_BUILD_NUMBER); + printf("%s %u\n",version,calc_crc32(0,version,(int32_t)strlen(version))); LP_showwif = juint(argjson,"wif"); if ( passphrase == 0 || passphrase[0] == 0 ) { diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 2711f7f42..d0641e578 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -587,12 +587,6 @@ char *LP_connectedalice(cJSON *argjson) // alice LP_aliceid(Q.tradeid,Q.aliceid,"error2",0,0); return(clonestr("{\"error\":\"cant find autxo\"}")); } - /*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\"}")); - }*/ LP_aliceid(Q.tradeid,Q.aliceid,"connected",Q.R.requestid,Q.R.quoteid); butxo = &B; memset(butxo,0,sizeof(*butxo)); @@ -772,7 +766,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("(%u-%u): received %12s aliceid.%22llu %5s/%-5s %12.8f -> %12.8f price %12.8f\n",Q.R.requestid,Q.R.quoteid,method,(long long)Q.aliceid,Q.srccoin,Q.destcoin,dstr(Q.satoshis),dstr(Q.destsatoshis),(double)Q.destsatoshis/Q.satoshis); + printf("(%-10u %10u) %12s aliceid.%22llu %5s/%-5s %12.8f -> %12.8f price %12.8f\n",Q.R.requestid,Q.R.quoteid,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; From 48464283c7d754cb5f082d300a29f83f515692ee Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 15:10:56 +0200 Subject: [PATCH 260/306] Test --- iguana/exchanges/LP_nativeDEX.c | 2 +- iguana/exchanges/LP_swap.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 2159505ec..00eabb24a 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -889,7 +889,7 @@ int32_t LP_reserved_msg(int32_t priority,char *base,char *rel,bits256 pubkey,cha void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybusport,char *passphrase,int32_t amclient,char *userhome,cJSON *argjson) { char *myipaddr=0,version[64]; long filesize,n; int32_t valid,timeout,pubsock=-1; struct LP_peerinfo *mypeer=0; char pushaddr[128],subaddr[128],bindaddr[128],*coins_str=0; cJSON *coinsjson=0; void *ctx = bitcoin_ctx(); - sprintf(version,"Marketmaker %s.%s %s",LP_MAJOR_VERSION,LP_MINOR_VERSION,LP_BUILD_NUMBER); + sprintf(version,"Marketmaker %s.%s %s rsize.%ld",LP_MAJOR_VERSION,LP_MINOR_VERSION,LP_BUILD_NUMBER,sizeof(struct basilisk_request)); printf("%s %u\n",version,calc_crc32(0,version,(int32_t)strlen(version))); LP_showwif = juint(argjson,"wif"); if ( passphrase == 0 || passphrase[0] == 0 ) diff --git a/iguana/exchanges/LP_swap.c b/iguana/exchanges/LP_swap.c index 23f8d0a39..e1c80d505 100644 --- a/iguana/exchanges/LP_swap.c +++ b/iguana/exchanges/LP_swap.c @@ -1127,7 +1127,7 @@ struct basilisk_swap *bitcoin_swapinit(bits256 privkey,uint8_t *pubkey33,bits256 swap->I.aliceconfirms = swap->I.alicemaxconfirms; swap->I.bobconfirms *= !swap->I.bobistrusted; swap->I.aliceconfirms *= !swap->I.aliceistrusted; - printf(">>>>>>>>>> jumblrflag.%d <<<<<<<<< use smart address, %.8f bobconfs.%d, %.8f aliceconfs.%d taddr.%d %d\n",jumblrflag,dstr(swap->I.bobsatoshis),swap->I.bobconfirms,dstr(swap->I.alicesatoshis),swap->I.aliceconfirms,bobcoin->taddr,alicecoin->taddr); + printf(">>>>>>>>>> jumblrflag.%d <<<<<<<<< r.%u q.%u, %.8f bobconfs.%d, %.8f aliceconfs.%d taddr.%d %d\n",jumblrflag,swap->I.req.requestid,swap->I.req.quoteid,dstr(swap->I.bobsatoshis),swap->I.bobconfirms,dstr(swap->I.alicesatoshis),swap->I.aliceconfirms,bobcoin->taddr,alicecoin->taddr); if ( swap->I.iambob != 0 ) { basilisk_rawtx_setparms("myfee",swap->I.req.quoteid,&swap->myfee,bobcoin,0,0,LP_DEXFEE(swap->I.bobsatoshis) + 0*bobcoin->txfee,0,0,jumblrflag); From 05c5e9078cf7350f505950dba74a71d2eb58b8f3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 15:30:17 +0200 Subject: [PATCH 261/306] Test --- iguana/exchanges/LP_signatures.c | 1 + iguana/exchanges/LP_socket.c | 5 ++++- iguana/exchanges/LP_utxos.c | 6 ++++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index 651e9c0e8..0d013b68e 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -616,6 +616,7 @@ char *LP_notify_recv(cJSON *argjson) void LP_smartutxos_push(struct iguana_info *coin) { uint64_t value; bits256 zero,txid; int32_t i,vout,height,n; cJSON *array,*item,*req; + return; if ( coin->smartaddr[0] == 0 ) return; //LP_notify_pubkeys(coin->ctx,LP_mypubsock); diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 36e6988ca..723a61a92 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -602,7 +602,10 @@ cJSON *electrum_address_listunspent(char *symbol,struct electrum_info *ep,cJSON 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 ) - LP_postutxos(coin->symbol,addr), updatedflag = 1; + { + //LP_postutxos(coin->symbol,addr); + updatedflag = 1; + } if ( strcmp(addr,coin->smartaddr) == 0 ) { retstr = jprint(retjson,0); diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index fc05779cb..90e0aafc8 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -700,7 +700,7 @@ int32_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypri } } free_json(array); - if ( flag != 0 ) + if ( 0 && flag != 0 ) LP_postutxos(coin->symbol,coin->smartaddr); } if ( values != 0 ) @@ -849,7 +849,9 @@ void LP_privkey_updates(void *ctx,int32_t pubsock,char *passphrase) { //printf("from updates %s\n",coin->symbol); if ( LP_privkey_init(pubsock,coin,G.LP_privkey,G.LP_mypub25519) == 0 && (LP_rand() % 10) == 0 ) - LP_postutxos(coin->symbol,coin->smartaddr); + { + //LP_postutxos(coin->symbol,coin->smartaddr); + } } } } From 7ba7a49601e62c8e48a4f78d8af653c35e3f10ec Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 15:37:42 +0200 Subject: [PATCH 262/306] Test --- iguana/exchanges/LP_commands.c | 2 +- iguana/exchanges/LP_nativeDEX.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 3b0734349..9155291fb 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -36,7 +36,7 @@ char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *r { char *method,*userpass,*base,*rel,*coin,*retstr = 0; int32_t changed,flag = 0; cJSON *retjson,*reqjson = 0; struct iguana_info *ptr; method = jstr(argjson,"method"); - //printf("stats_JSON %s\n",method); +printf("stats_JSON %s\n",method); /*if ( (ipaddr= jstr(argjson,"ipaddr")) != 0 && (argport= juint(argjson,"port")) != 0 && (method == 0 || strcmp(method,"electrum") != 0) ) { if ( strcmp(ipaddr,"127.0.0.1") != 0 && argport >= 1000 ) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 00eabb24a..f73c9474f 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1216,7 +1216,7 @@ int32_t zeroval() { return(0); } void *LP_alloc(uint64_t len) { -return(calloc(1,len)); +//return(calloc(1,len)); LP_cjson_allocated += len; LP_cjson_total += len; LP_cjson_count++; @@ -1235,9 +1235,9 @@ return(calloc(1,len)); void LP_free(void *ptr) { static uint32_t lasttime,unknown; static int64_t lasttotal; -free(ptr); return; +//free(ptr); return; uint32_t now; char str[65]; int32_t n,lagging; uint64_t total = 0; struct LP_memory_list *mp,*tmp; - if ( (now= (uint32_t)time(NULL)) > lasttime+6 ) + if ( (now= (uint32_t)time(NULL)) > lasttime+1 ) { n = lagging = 0; DL_FOREACH_SAFE(LP_memory_list,mp,tmp) From e8b2923ffcbb893601023034bea777778173804e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 15:49:52 +0200 Subject: [PATCH 263/306] Test --- iguana/exchanges/LP_nativeDEX.c | 4 ++-- iguana/exchanges/LP_signatures.c | 2 +- iguana/exchanges/stats.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index f73c9474f..681f8a907 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1216,7 +1216,7 @@ int32_t zeroval() { return(0); } void *LP_alloc(uint64_t len) { -//return(calloc(1,len)); +return(calloc(1,len)); LP_cjson_allocated += len; LP_cjson_total += len; LP_cjson_count++; @@ -1235,7 +1235,7 @@ void *LP_alloc(uint64_t len) void LP_free(void *ptr) { static uint32_t lasttime,unknown; static int64_t lasttotal; -//free(ptr); return; +free(ptr); return; uint32_t now; char str[65]; int32_t n,lagging; uint64_t total = 0; struct LP_memory_list *mp,*tmp; if ( (now= (uint32_t)time(NULL)) > lasttime+1 ) { diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index 0d013b68e..647daa1ba 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -616,7 +616,7 @@ char *LP_notify_recv(cJSON *argjson) void LP_smartutxos_push(struct iguana_info *coin) { uint64_t value; bits256 zero,txid; int32_t i,vout,height,n; cJSON *array,*item,*req; - return; +return; if ( coin->smartaddr[0] == 0 ) return; //LP_notify_pubkeys(coin->ctx,LP_mypubsock); diff --git a/iguana/exchanges/stats.c b/iguana/exchanges/stats.c index 179612c4e..681da52d2 100644 --- a/iguana/exchanges/stats.c +++ b/iguana/exchanges/stats.c @@ -32,7 +32,7 @@ char *stats_JSON(void *ctx,char *myipaddr,int32_t mypubsock,cJSON *argjson,char char *stats_validmethods[] = { - "psock", "getprices", "listunspent", "notify", "getpeers", "uitem", // from issue_ + "psock", "getprices", "notify", "getpeers", // from issue_ "uitem", "listunspent", "orderbook", "help", "getcoins", "pricearray", "balance", "tradestatus" }; From b89adb55f6634f2e6f735efb2798e4fe5d1b397e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 15:54:06 +0200 Subject: [PATCH 264/306] Test --- iguana/exchanges/LP_commands.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 9155291fb..53ff69f19 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -36,6 +36,8 @@ char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *r { char *method,*userpass,*base,*rel,*coin,*retstr = 0; int32_t changed,flag = 0; cJSON *retjson,*reqjson = 0; struct iguana_info *ptr; method = jstr(argjson,"method"); + if ( method != 0 && strcmp(method,"uitem") == 0 ) + return(0); printf("stats_JSON %s\n",method); /*if ( (ipaddr= jstr(argjson,"ipaddr")) != 0 && (argport= juint(argjson,"port")) != 0 && (method == 0 || strcmp(method,"electrum") != 0) ) { From 14b6e3acc7f0894cf2ec3157d9dba8c15a6e35e4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 15:57:39 +0200 Subject: [PATCH 265/306] Test --- iguana/exchanges/LP_commands.c | 2 +- iguana/exchanges/LP_nativeDEX.c | 2 +- iguana/exchanges/LP_signatures.c | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 53ff69f19..0ec77c466 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -36,7 +36,7 @@ char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *r { char *method,*userpass,*base,*rel,*coin,*retstr = 0; int32_t changed,flag = 0; cJSON *retjson,*reqjson = 0; struct iguana_info *ptr; method = jstr(argjson,"method"); - if ( method != 0 && strcmp(method,"uitem") == 0 ) + if ( method != 0 && (strcmp(method,"uitem") == 0 || strcmp(method,"postutxos") == 0) ) return(0); printf("stats_JSON %s\n",method); /*if ( (ipaddr= jstr(argjson,"ipaddr")) != 0 && (argport= juint(argjson,"port")) != 0 && (method == 0 || strcmp(method,"electrum") != 0) ) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 681f8a907..30e1d9753 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1043,7 +1043,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu printf("error launching LP_reserved_msgs for (%s)\n",myipaddr); exit(-1); } - if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)utxosQ_loop,(void *)myipaddr) != 0 ) + if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)utxosQ_loop,(void *)myipaddr) != 0 ) { printf("error launching utxosQ_loop for (%s)\n",myipaddr); exit(-1); diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index 647daa1ba..0008ee1b5 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -330,6 +330,7 @@ int32_t LP_utxos_sigadd(cJSON *item,uint32_t timestamp,bits256 priv,uint8_t *pub void LP_postutxos(char *symbol,char *coinaddr) { bits256 zero; uint32_t timestamp; bits256 utxoshash; char pubsecpstr[67]; struct iguana_info *coin; cJSON *array,*reqjson = cJSON_CreateObject(); +return; if ( (coin= LP_coinfind(symbol)) != 0 && (array= LP_address_utxos(coin,coinaddr,1)) != 0 ) { //printf("LP_postutxos pubsock.%d %s %s\n",pubsock,symbol,coin->smartaddr); @@ -362,6 +363,7 @@ struct LP_utxos_qitem { struct queueitem DL; cJSON *argjson; }; char *LP_postutxos_recv(cJSON *argjson) { struct LP_utxos_qitem *uitem; struct iguana_info *coin; char *coinaddr,*symbol; bits256 utxoshash,pubkey; cJSON *obj; struct LP_pubkeyinfo *pubp; +printf("LP_postutxos_recv deprecated\n"); pubkey = jbits256(argjson,"pubkey"); pubp = LP_pubkeyfind(pubkey); if ( pubp != 0 && pubp->numerrors > LP_MAXPUBKEY_ERRORS ) @@ -652,6 +654,7 @@ return; char *LP_uitem_recv(cJSON *argjson) { bits256 txid; int32_t vout,height; uint64_t value; struct iguana_info *coin; char *coinaddr,*symbol; +printf("LP_uitem_recv deprecated\n"); txid = jbits256(argjson,"txid"); vout = jint(argjson,"vout"); height = jint(argjson,"ht"); From e2e6c5091986361c155870bb6f384a8b350078c2 Mon Sep 17 00:00:00 2001 From: DeckerSU Date: Thu, 16 Nov 2017 17:10:45 +0300 Subject: [PATCH 266/306] fix structure alignment issue on Windows (error LP_sendwait pubkeys) structure alignment on Windows should be same as on Unix, when you have to start compiled marketmaker first line should be: Marketmaker 0.1 15000 rsize.248 451196191 rsize = 248. otherwise you will get this error on every swap: waitfor timedout didnt get pubkeys error LP_sendwait pubkeys finish swap.0000008AC93A3100 --- marketmaker.vcxproj | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/marketmaker.vcxproj b/marketmaker.vcxproj index 0dbe62279..7d3862568 100644 --- a/marketmaker.vcxproj +++ b/marketmaker.vcxproj @@ -87,7 +87,7 @@ Level2 Disabled _CRT_SECURE_NO_WARNINGS;NATIVE_WINDOWS;WIN32;_DEBUG;_CONSOLE;IGUANA_LOG2PACKETSIZE=20;IGUANA_MAXPACKETSIZE=1572864;%(PreprocessorDefinitions) - 1Byte + 8Bytes .\iguana;%(AdditionalIncludeDirectories) @@ -104,7 +104,7 @@ Level3 Disabled _DEBUG;_CONSOLE;NATIVE_WINDOWS;WIN32;IGUANA_LOG2PACKETSIZE=20;IGUANA_MAXPACKETSIZE=1572864;%(PreprocessorDefinitions) - 1Byte + 8Bytes Console @@ -122,7 +122,7 @@ true true _CRT_SECURE_NO_WARNINGS;NATIVE_WINDOWS;WIN32;_CONSOLE;NDEBUG;IGUANA_LOG2PACKETSIZE=20;IGUANA_MAXPACKETSIZE=1572864;%(PreprocessorDefinitions) - 1Byte + 8Bytes MachineX86 @@ -142,7 +142,7 @@ true true WIN64;_WIN64;_CRT_SECURE_NO_WARNINGS;NATIVE_WINDOWS;WIN32;WIN32_LEAN_AND_MEAN;_CONSOLE;NDEBUG;IGUANA_LOG2PACKETSIZE=20;IGUANA_MAXPACKETSIZE=1572864;%(PreprocessorDefinitions) - 1Byte + 8Bytes MultiThreaded From 1e10b2c083800e7f9338f89641ef9eac13ea968e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 16:14:09 +0200 Subject: [PATCH 267/306] Test --- iguana/exchanges/LP_commands.c | 2 +- iguana/exchanges/LP_ordermatch.c | 2 +- iguana/exchanges/LP_prices.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 0ec77c466..e5f232d4b 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -36,7 +36,7 @@ char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *r { char *method,*userpass,*base,*rel,*coin,*retstr = 0; int32_t changed,flag = 0; cJSON *retjson,*reqjson = 0; struct iguana_info *ptr; method = jstr(argjson,"method"); - if ( method != 0 && (strcmp(method,"uitem") == 0 || strcmp(method,"postutxos") == 0) ) + if ( method != 0 && (strcmp(method,"addr_unspents") == 0 || strcmp(method,"uitem") == 0 || strcmp(method,"postutxos") == 0) ) return(0); printf("stats_JSON %s\n",method); /*if ( (ipaddr= jstr(argjson,"ipaddr")) != 0 && (argport= juint(argjson,"port")) != 0 && (method == 0 || strcmp(method,"electrum") != 0) ) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index d0641e578..9dbb4e210 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -1046,7 +1046,7 @@ struct LP_utxoinfo *LP_buyutxo(double *ordermatchpricep,int64_t *bestsatoshisp,i { bitcoin_address(coinaddr,basecoin->taddr,basecoin->pubtype,pubp->rmd160,sizeof(pubp->rmd160)); asatoshis = autxo->S.satoshis; - LP_listunspent_query(base,coinaddr); + //LP_listunspent_query(base,coinaddr); for (j=0; jpubkey,gui)) != 0 ) diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 80e056b6a..ade6b75f5 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -818,7 +818,7 @@ char *LP_orderbook(char *base,char *rel,int32_t duration) { //printf("bid ping %s %s\n",rel,bids[i]->coinaddr); LP_address(relcoin,bids[i]->coinaddr); - if ( relcoin->electrum == 0 ) + if ( 0 && relcoin->electrum == 0 ) { LP_listunspent_issue(rel,bids[i]->coinaddr,0); //else if ( (tmpjson= LP_listunspent(rel,bids[i]->coinaddr)) != 0 ) @@ -842,7 +842,7 @@ char *LP_orderbook(char *base,char *rel,int32_t duration) { //printf("ask ping %s %s\n",base,asks[i]->coinaddr); LP_address(basecoin,asks[i]->coinaddr); - if ( basecoin->electrum == 0 ) + if ( 0 && basecoin->electrum == 0 ) { LP_listunspent_issue(base,asks[i]->coinaddr,0); //else if ( (tmpjson= LP_listunspent(base,asks[i]->coinaddr)) != 0 ) From f1dba700fc3a07d57f6b1ca12600291d8fe7590e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 16:21:53 +0200 Subject: [PATCH 268/306] Test --- iguana/exchanges/LP_commands.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index e5f232d4b..d2f72406d 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -38,7 +38,7 @@ char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *r method = jstr(argjson,"method"); if ( method != 0 && (strcmp(method,"addr_unspents") == 0 || strcmp(method,"uitem") == 0 || strcmp(method,"postutxos") == 0) ) return(0); -printf("stats_JSON %s\n",method); +//printf("stats_JSON %s\n",method); /*if ( (ipaddr= jstr(argjson,"ipaddr")) != 0 && (argport= juint(argjson,"port")) != 0 && (method == 0 || strcmp(method,"electrum") != 0) ) { if ( strcmp(ipaddr,"127.0.0.1") != 0 && argport >= 1000 ) From 597f9cdafceb291693526750fb0022cfe3c740f5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 16:32:30 +0200 Subject: [PATCH 269/306] Test --- iguana/exchanges/LP_ordermatch.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 9dbb4e210..f28c779bd 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -126,7 +126,7 @@ double LP_quote_validate(struct LP_utxoinfo *autxo,struct LP_utxoinfo *butxo,str { if ( LP_iseligible(&srcvalue,&srcvalue2,1,qp->srccoin,qp->txid,qp->vout,qp->satoshis,qp->txid2,qp->vout2) == 0 ) { - printf("bob not eligible %s (%.8f %.8f)\n",jprint(LP_quotejson(qp),1),dstr(srcvalue),dstr(srcvalue2)); + //printf("bob not eligible %s (%.8f %.8f)\n",jprint(LP_quotejson(qp),1),dstr(srcvalue),dstr(srcvalue2)); return(-2); } if ( (txout= LP_gettxout(qp->srccoin,qp->coinaddr,qp->txid,qp->vout)) != 0 ) @@ -159,7 +159,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 ) { //alice not eligible 0.36893923 -> dest 0.55020000 1.49130251 (0.61732249 0.00104324) 14b8b74808d2d34a70e5eddd1cad47d855858f8b23cac802576d4d37b5f8af8f/v1 abec6e76169bcb738235ca67fab02cc55390f39e422aa71f1badf8747c290cc4/v1 - 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); + //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 ) @@ -321,7 +321,7 @@ int32_t LP_nearest_utxovalue(struct iguana_info *coin,char *coinaddr,struct LP_a } if ( replacei >= 0 ) { - printf("REPLACE bestdist %.8f height %d with dist %.8f height %d\n",dstr(bestdist),bestup->U.height,dstr(utxos[replacei]->U.value - targetval),utxos[replacei]->U.height); + //printf("REPLACE bestdist %.8f height %d with dist %.8f height %d\n",dstr(bestdist),bestup->U.height,dstr(utxos[replacei]->U.value - targetval),utxos[replacei]->U.height); return(replacei); } } @@ -396,7 +396,7 @@ struct LP_utxoinfo *LP_address_myutxopair(struct LP_utxoinfo *butxo,int32_t iamb { if ( (m= LP_address_utxo_ptrs(coin,iambob,utxos,max,ap,coinaddr)) > 1 ) { - if ( 1 ) + if ( 0 ) { int32_t i; for (i=0; i Date: Thu, 16 Nov 2017 17:32:03 +0200 Subject: [PATCH 270/306] Test --- iguana/exchanges/LP_include.h | 2 +- iguana/exchanges/LP_utxo.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 72f99d81f..7ccde2a10 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 "15000" +#define LP_BUILD_NUMBER "15096" #ifdef FROM_JS #include diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 59b8b8b8e..90a6d016e 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -999,7 +999,7 @@ int32_t LP_iseligible(uint64_t *valp,uint64_t *val2p,int32_t iambob,char *symbol strcpy(destaddr,destaddr2); if ( coin != 0 ) { - if ( coin->electrum != 0 ) + /*if ( coin->electrum != 0 ) { if ( (tx= LP_transactionfind(coin,txid)) != 0 && vout < tx->numvouts && tx->outpoints[vout].spendheight > 0 ) { @@ -1022,7 +1022,7 @@ int32_t LP_iseligible(uint64_t *valp,uint64_t *val2p,int32_t iambob,char *symbol return(0); } } - else + else*/ { if ( (txobj= LP_gettxout(coin->symbol,destaddr,txid,vout)) == 0 ) return(0); From 4b8b1553227da5c9cd0a4827a4c5134185c6e98a Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 17:48:46 +0200 Subject: [PATCH 271/306] 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 f28c779bd..0d1590bfc 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -1126,6 +1126,7 @@ char *LP_autobuy(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel memset(pubkeys,0,sizeof(pubkeys)); LP_txfees(&txfee,&desttxfee,base,rel); destsatoshis = SATOSHIDEN * relvolume; + LP_address_utxo_reset(relcoin); if ( (autxo= LP_utxo_bestfit(rel,destsatoshis + 2*desttxfee)) == 0 ) return(clonestr("{\"error\":\"cant find alice utxo that is big enough\"}")); //printf("bestfit selected alice (%.8f %.8f) for %.8f sats %.8f\n",dstr(autxo->payment.value),dstr(autxo->fee.value),dstr(destsatoshis),dstr(autxo->S.satoshis)); From 5c15665ca64091e9ec5e30f4836a6e79c73bb98f Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 17:56:47 +0200 Subject: [PATCH 272/306] Test --- iguana/exchanges/LP_signatures.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index 0008ee1b5..e729421ad 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -704,7 +704,7 @@ void LP_query(void *ctx,char *myipaddr,int32_t mypubsock,char *method,struct LP_ jaddnum(reqjson,"timestamp",time(NULL)); msg = jprint(reqjson,1); msg2 = clonestr(msg); - //printf("QUERY.(%s)\n",msg); + printf("QUERY.(%s)\n",msg); memset(&zero,0,sizeof(zero)); portable_mutex_lock(&LP_reservedmutex); if ( num_Reserved_msgs[1] < sizeof(Reserved_msgs[1])/sizeof(*Reserved_msgs[1])-2 ) From 380c7d0ec24d71c982074dd8b11f16860df77f8c Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 18:01:04 +0200 Subject: [PATCH 273/306] Test --- iguana/exchanges/LP_utxo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 90a6d016e..21e89c92a 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -405,7 +405,7 @@ int32_t LP_address_utxoadd(uint32_t timestamp,char *debug,struct iguana_info *co up->SPV = tx->SPV; } char str[65]; - if ( 0 && strcmp(coin->smartaddr,coinaddr) == 0 && strcmp("KMD",coin->symbol) == 0 ) + if ( strcmp(coin->smartaddr,coinaddr) == 0 && strcmp("KMD",coin->symbol) == 0 ) printf("%s ADD UTXO >> %s %s %s/v%d ht.%d %.8f\n",debug,coin->symbol,coinaddr,bits256_str(str,txid),vout,height,dstr(value)); portable_mutex_lock(&coin->addrmutex); DL_APPEND(ap->utxos,up); @@ -464,7 +464,7 @@ struct LP_address *LP_address_utxo_reset(struct iguana_info *coin) if ( (up= LP_address_utxofind(coin,coin->smartaddr,txid,vout)) == 0 ) printf("couldnt find just added %s/%d ht.%d %.8f\n",bits256_str(str,txid),vout,height,dstr(value)); } - //printf("added %d from listunspents\n",n); + printf("added %d from listunspents\n",n); } free_json(array); } From 6c24e6c05656cbb5e112906f9d7c3fc2ea0f2592 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 18:06:18 +0200 Subject: [PATCH 274/306] 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 0d1590bfc..48fea4b1f 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -791,6 +791,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, } if ( bits256_cmp(G.LP_mypub25519,Q.desthash) == 0 && bits256_cmp(G.LP_mypub25519,Q.srchash) != 0 && LP_alice_eligible() > 0 ) { + printf("alice %s received RESERVED.(%s)\n",bits256_str(str,G.LP_mypub25519),jprint(argjson,0)); if ( (qprice= LP_quote_validate(autxo,butxo,&Q,0)) <= SMALLVAL ) { printf("reserved quote validate error %.0f\n",qprice); @@ -807,7 +808,6 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, return(retval); } LP_aliceid(Q.tradeid,Q.aliceid,"reserved",0,0); - //printf("alice %s received RESERVED.(%s)\n",bits256_str(str,G.LP_mypub25519),jprint(argjson,0)); if ( (retstr= LP_quotereceived(argjson)) != 0 ) free(retstr); LP_reserved(ctx,myipaddr,pubsock,&Q); From da4fe5720ad21b6b4abc89da7fcc04773524f782 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 18:12:07 +0200 Subject: [PATCH 275/306] 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 48fea4b1f..c00ef313a 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -532,9 +532,9 @@ void LP_alicequery_clear() Alice_expiration = 0; } -int32_t LP_alice_eligible() +int32_t LP_alice_eligible(uint32_t quotetime) { - if ( Alice_expiration != 0 && time(NULL) > Alice_expiration ) + if ( Alice_expiration != 0 && quotetime > Alice_expiration ) { printf("time expired for Alice_request\n"); LP_alicequery_clear(); @@ -545,7 +545,7 @@ int32_t LP_alice_eligible() void LP_reserved(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo *qp) { double price=0.,maxprice = LP_Alicemaxprice; - if ( LP_alice_eligible() > 0 && LP_quotecmp(qp,&LP_Alicequery) == 0 ) + if ( LP_quotecmp(qp,&LP_Alicequery) == 0 ) { price = LP_pricecache(qp,qp->srccoin,qp->destcoin,qp->txid,qp->vout); if ( LP_pricevalid(price) > 0 && maxprice > SMALLVAL && price <= maxprice ) @@ -555,7 +555,7 @@ void LP_reserved(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo printf("send CONNECT\n"); LP_query(ctx,myipaddr,mypubsock,"connect",qp); } else printf("LP_reserved price %.8f vs maxprice %.8f\n",price,maxprice*1.005); - } else printf("probably a timeout, reject reserved due to not eligible.%d or mismatched quote price %.8f vs maxprice %.8f\n",LP_alice_eligible(),price,maxprice); + } else printf("probably a timeout, reject reserved due to not eligible.%d or mismatched quote price %.8f vs maxprice %.8f\n",LP_alice_eligible(qp->quotetime),price,maxprice); } char *LP_connectedalice(cJSON *argjson) // alice @@ -789,7 +789,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, return(retval); } else printf("got reserved response from destpubkey %s\n",bits256_str(str,Q.srchash)); } - if ( bits256_cmp(G.LP_mypub25519,Q.desthash) == 0 && bits256_cmp(G.LP_mypub25519,Q.srchash) != 0 && LP_alice_eligible() > 0 ) + if ( bits256_cmp(G.LP_mypub25519,Q.desthash) == 0 && bits256_cmp(G.LP_mypub25519,Q.srchash) != 0 && Q.quotetime > time(NULL)-20 && LP_alice_eligible(Q.quotetime) > 0 ) { printf("alice %s received RESERVED.(%s)\n",bits256_str(str,G.LP_mypub25519),jprint(argjson,0)); if ( (qprice= LP_quote_validate(autxo,butxo,&Q,0)) <= SMALLVAL ) From dc259fe34f9894d027d37d346ead41597beaa8ed Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 18:13:25 +0200 Subject: [PATCH 276/306] 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 21e89c92a..e9ff90d3a 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -405,7 +405,7 @@ int32_t LP_address_utxoadd(uint32_t timestamp,char *debug,struct iguana_info *co up->SPV = tx->SPV; } char str[65]; - if ( strcmp(coin->smartaddr,coinaddr) == 0 && strcmp("KMD",coin->symbol) == 0 ) + if ( 0 && strcmp(coin->smartaddr,coinaddr) == 0 && strcmp("KMD",coin->symbol) == 0 ) printf("%s ADD UTXO >> %s %s %s/v%d ht.%d %.8f\n",debug,coin->symbol,coinaddr,bits256_str(str,txid),vout,height,dstr(value)); portable_mutex_lock(&coin->addrmutex); DL_APPEND(ap->utxos,up); From 77ffa9bfaa3b64cce3abaefc7fe79da8617cea1c Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 18:22:41 +0200 Subject: [PATCH 277/306] Test --- crypto777/cJSON.c | 4 ++-- iguana/exchanges/LP_nativeDEX.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crypto777/cJSON.c b/crypto777/cJSON.c index 901e6fc98..54df964f5 100755 --- a/crypto777/cJSON.c +++ b/crypto777/cJSON.c @@ -56,8 +56,8 @@ static int32_t cJSON_strcasecmp(const char *s1,const char *s2) void *LP_alloc(uint64_t len); void LP_free(void *ptr); -static void *(*cJSON_malloc)(size_t sz) = (void *)LP_alloc; -static void (*cJSON_free)(void *ptr) = LP_free; +static void *(*cJSON_malloc)(size_t sz) = (void *)malloc;//LP_alloc; +static void (*cJSON_free)(void *ptr) = free;//LP_free; static void *cJSON_mallocstr(int32_t len) { diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 30e1d9753..f73c9474f 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1043,7 +1043,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu printf("error launching LP_reserved_msgs for (%s)\n",myipaddr); exit(-1); } - if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)utxosQ_loop,(void *)myipaddr) != 0 ) + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)utxosQ_loop,(void *)myipaddr) != 0 ) { printf("error launching utxosQ_loop for (%s)\n",myipaddr); exit(-1); @@ -1216,7 +1216,7 @@ int32_t zeroval() { return(0); } void *LP_alloc(uint64_t len) { -return(calloc(1,len)); +//return(calloc(1,len)); LP_cjson_allocated += len; LP_cjson_total += len; LP_cjson_count++; @@ -1235,7 +1235,7 @@ return(calloc(1,len)); void LP_free(void *ptr) { static uint32_t lasttime,unknown; static int64_t lasttotal; -free(ptr); return; +//free(ptr); return; uint32_t now; char str[65]; int32_t n,lagging; uint64_t total = 0; struct LP_memory_list *mp,*tmp; if ( (now= (uint32_t)time(NULL)) > lasttime+1 ) { From 5d0933752975bcc44ae8297761e755b57247bcfd Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 18:28:46 +0200 Subject: [PATCH 278/306] Test --- iguana/exchanges/LP_ordermatch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index c00ef313a..fb294d2dc 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -505,7 +505,7 @@ char *LP_trade(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo *q qp->tradeid = tradeid; LP_query(ctx,myipaddr,mypubsock,"request",qp); LP_Alicequery = *qp, LP_Alicemaxprice = maxprice, Alice_expiration = qp->timestamp + timeout, LP_Alicedestpubkey = destpubkey; - char str[65]; printf("LP_trade %s/%s %.8f vol %.8f dest.(%s)\n",qp->srccoin,qp->destcoin,dstr(qp->satoshis),dstr(qp->destsatoshis),bits256_str(str,LP_Alicedestpubkey)); + char str[65]; printf("LP_trade %s/%s %.8f vol %.8f dest.(%s) maxprice %.8f\n",qp->srccoin,qp->destcoin,dstr(qp->satoshis),dstr(qp->destsatoshis),bits256_str(str,LP_Alicedestpubkey),maxprice); return(LP_recent_swaps(0)); } @@ -778,7 +778,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, if ( strcmp(method,"reserved") == 0 ) { bestprice = LP_bob_competition(&counter,aliceid,qprice,1); - //printf("aliceid.%llu price %.8f -> bestprice %.8f\n",(long long)aliceid,qprice,bestprice); + printf("aliceid.%llu price %.8f -> bestprice %.8f Alice max %.8f\n",(long long)aliceid,qprice,bestprice,LP_Alicemaxprice); if ( LP_Alicemaxprice == 0. ) return(retval); if ( bits256_nonz(LP_Alicedestpubkey) != 0 ) From d00e0b0e8be5264babf39084d0cc165efc74f799 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 18:32:07 +0200 Subject: [PATCH 279/306] 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 fb294d2dc..a8d8f98c8 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -778,7 +778,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, if ( strcmp(method,"reserved") == 0 ) { bestprice = LP_bob_competition(&counter,aliceid,qprice,1); - printf("aliceid.%llu price %.8f -> bestprice %.8f Alice max %.8f\n",(long long)aliceid,qprice,bestprice,LP_Alicemaxprice); + printf("%s lag %ld: aliceid.%llu price %.8f -> bestprice %.8f Alice max %.8f\n",jprint(argjson,0),Q.quotetime - (time(NULL)-20),(long long)aliceid,qprice,bestprice,LP_Alicemaxprice); if ( LP_Alicemaxprice == 0. ) return(retval); if ( bits256_nonz(LP_Alicedestpubkey) != 0 ) From f3794fe375cff809f3d251e5546b4e875886aaa3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 18:34:14 +0200 Subject: [PATCH 280/306] 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 a8d8f98c8..0927b5222 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -904,6 +904,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; + Q.quotetime = (uint32_t)time(NULL); printf("found %.8f -> %.8f newprice %.8f vs ask %.8f += %.8f qprice %.8f\n",dstr(Q.satoshis),dstr(Q.destsatoshis),(double)Q.destsatoshis/Q.satoshis,ask,price,qprice); } else From 271ef52511e436f219dc12b0a53a3c3ad2d1252c Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 18:34:41 +0200 Subject: [PATCH 281/306] Test --- iguana/exchanges/LP_include.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 7ccde2a10..e1a8c933d 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -24,6 +24,8 @@ #define LP_MAJOR_VERSION "0" #define LP_MINOR_VERSION "1" #define LP_BUILD_NUMBER "15096" +#define LP_BARTERDEX_VERSION 2 +#define LP_MAGICBITS 8 #ifdef FROM_JS #include @@ -38,8 +40,6 @@ void emscripten_usleep(int32_t x); // returns immediate, no sense for sleeping #endif //#define LP_STRICTPEERS -#define LP_BARTERDEX_VERSION 1 -#define LP_MAGICBITS 8 #define LP_MAXVINS 64 #define LP_HTTP_TIMEOUT 3 // 1 is too small due to edge cases of time(NULL) From 367b9b0dfa37cdae981204509bfd666f3183c8df Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 18:35:21 +0200 Subject: [PATCH 282/306] Test --- 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 e1a8c933d..c728dee1f 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -180,7 +180,7 @@ struct basilisk_request int64_t srcamount,unused; // 16 to 31 bits256 srchash; // 32 to 63 bits256 desthash; - char src[65],dest[65]; + char src[68],dest[68]; uint64_t destamount; int32_t optionhours,DEXselector; }; From 05e76ee08b8547895ed5e54a5a8cf626c461101e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 18:36:55 +0200 Subject: [PATCH 283/306] Test --- iguana/exchanges/LP_network.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index d1b147bc8..5449dc7d7 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -204,8 +204,8 @@ int32_t LP_magic_check(uint8_t *msg,int32_t recvlen,char *remoteaddr) vcalc_sha256(0,hash.bytes,msg,recvlen); memcpy(magic.bytes,&msg[recvlen],sizeof(magic)); val = _LP_magic_check(hash,magic); - if ( val != LP_BARTERDEX_VERSION ) - printf("magicval = %x from %s\n",val,remoteaddr); + //if ( val != LP_BARTERDEX_VERSION ) + // printf("magicval = %x from %s\n",val,remoteaddr); return(val == LP_BARTERDEX_VERSION); } return(-1); From ff2c4f62256a7526086ee4b225fb8984687aff21 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 18:41:38 +0200 Subject: [PATCH 284/306] Test --- iguana/exchanges/LP_include.h | 2 +- iguana/exchanges/LP_network.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index c728dee1f..f66fcc9c1 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -24,7 +24,7 @@ #define LP_MAJOR_VERSION "0" #define LP_MINOR_VERSION "1" #define LP_BUILD_NUMBER "15096" -#define LP_BARTERDEX_VERSION 2 +#define LP_BARTERDEX_VERSION 1 #define LP_MAGICBITS 8 #ifdef FROM_JS diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index 5449dc7d7..d1b147bc8 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -204,8 +204,8 @@ int32_t LP_magic_check(uint8_t *msg,int32_t recvlen,char *remoteaddr) vcalc_sha256(0,hash.bytes,msg,recvlen); memcpy(magic.bytes,&msg[recvlen],sizeof(magic)); val = _LP_magic_check(hash,magic); - //if ( val != LP_BARTERDEX_VERSION ) - // printf("magicval = %x from %s\n",val,remoteaddr); + if ( val != LP_BARTERDEX_VERSION ) + printf("magicval = %x from %s\n",val,remoteaddr); return(val == LP_BARTERDEX_VERSION); } return(-1); From 070cc756eccb63a296fc4fa14d88eeab2a6b3cd7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 18:55:33 +0200 Subject: [PATCH 285/306] Test --- iguana/exchanges/LP_ordermatch.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 0927b5222..6ae82acf0 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -778,7 +778,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, if ( strcmp(method,"reserved") == 0 ) { bestprice = LP_bob_competition(&counter,aliceid,qprice,1); - printf("%s lag %ld: aliceid.%llu price %.8f -> bestprice %.8f Alice max %.8f\n",jprint(argjson,0),Q.quotetime - (time(NULL)-20),(long long)aliceid,qprice,bestprice,LP_Alicemaxprice); + //printf("%s lag %ld: aliceid.%llu price %.8f -> bestprice %.8f Alice max %.8f\n",jprint(argjson,0),Q.quotetime - (time(NULL)-20),(long long)aliceid,qprice,bestprice,LP_Alicemaxprice); if ( LP_Alicemaxprice == 0. ) return(retval); if ( bits256_nonz(LP_Alicedestpubkey) != 0 ) @@ -948,9 +948,11 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, retjson = LP_quotejson(&Q); LP_unavailableset(Q.txid,Q.vout,Q.timestamp + LP_RESERVETIME,Q.desthash); LP_unavailableset(Q.txid2,Q.vout2,Q.timestamp + LP_RESERVETIME,Q.desthash); + if ( Q.quotetime == 0 ) + Q.quotetime = (uint32_t)time(NULL); jaddnum(retjson,"quotetime",Q.quotetime); jaddnum(retjson,"pending",Q.timestamp + LP_RESERVETIME); - jaddbits256(retjson,"desthash",Q.desthash); + //jaddbits256(retjson,"desthash",Q.desthash); jaddstr(retjson,"method","reserved"); msg = jprint(retjson,0); printf("return after queued RESERVED: set swappending.%u accept qprice %.8f, min %.8f\n(%s)\n",Q.timestamp + LP_RESERVETIME,qprice,ask,msg); From eb3d5667eded61cd05aa66b33c24791680549a3a Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 19:03:47 +0200 Subject: [PATCH 286/306] 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 6ae82acf0..435e32cb1 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -502,7 +502,8 @@ char *LP_trade(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo *q memset(qp->txid.bytes,0,sizeof(qp->txid)); qp->txid2 = qp->txid; qp->aliceid = LP_aliceid_calc(qp->desttxid,qp->destvout,qp->feetxid,qp->feevout); - qp->tradeid = tradeid; + if ( (qp->tradeid= tradeid) == 0 ) + qp->tradeid = LP_rand(); LP_query(ctx,myipaddr,mypubsock,"request",qp); LP_Alicequery = *qp, LP_Alicemaxprice = maxprice, Alice_expiration = qp->timestamp + timeout, LP_Alicedestpubkey = destpubkey; char str[65]; printf("LP_trade %s/%s %.8f vol %.8f dest.(%s) maxprice %.8f\n",qp->srccoin,qp->destcoin,dstr(qp->satoshis),dstr(qp->destsatoshis),bits256_str(str,LP_Alicedestpubkey),maxprice); From 1b9d12dd71075c0e859a609edf9aeb9b4d89705f Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 19:40:03 +0200 Subject: [PATCH 287/306] Test --- iguana/exchanges/LP_ordermatch.c | 32 +++++++++++++++++++------------- iguana/exchanges/LP_tradebots.c | 2 +- iguana/exchanges/LP_utxo.c | 2 +- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 435e32cb1..60de857a8 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -18,7 +18,7 @@ // LP_ordermatch.c // marketmaker // -struct LP_quoteinfo LP_Alicequery; +struct LP_quoteinfo LP_Alicequery,LP_Alicereserved; double LP_Alicemaxprice; bits256 LP_Alicedestpubkey; uint32_t Alice_expiration; @@ -510,7 +510,7 @@ char *LP_trade(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo *q return(LP_recent_swaps(0)); } -int32_t LP_quotecmp(struct LP_quoteinfo *qp,struct LP_quoteinfo *qp2) +int32_t LP_quotecmp(int32_t strictflag,struct LP_quoteinfo *qp,struct LP_quoteinfo *qp2) { if ( bits256_nonz(LP_Alicedestpubkey) != 0 ) { @@ -520,9 +520,13 @@ int32_t LP_quotecmp(struct LP_quoteinfo *qp,struct LP_quoteinfo *qp2) return(-1); } else printf("dont reject quote from destpubkey\n"); } - if ( bits256_cmp(qp->desthash,qp2->desthash) == 0 && strcmp(qp->srccoin,qp2->srccoin) == 0 && strcmp(qp->destcoin,qp2->destcoin) == 0 && bits256_cmp(qp->desttxid,qp2->desttxid) == 0 && qp->destvout == qp2->destvout && bits256_cmp(qp->feetxid,qp2->feetxid) == 0 && qp->feevout == qp2->feevout && qp->destsatoshis == qp2->destsatoshis && qp->txfee >= qp2->txfee && qp->desttxfee == qp2->desttxfee ) //bits256_cmp(qp->srchash,qp2->srchash) == 0 && - return(0); - else return(-1); + if ( bits256_cmp(qp->desthash,qp2->desthash) == 0 && strcmp(qp->srccoin,qp2->srccoin) == 0 && strcmp(qp->destcoin,qp2->destcoin) == 0 && bits256_cmp(qp->desttxid,qp2->desttxid) == 0 && qp->destvout == qp2->destvout && bits256_cmp(qp->feetxid,qp2->feetxid) == 0 && qp->feevout == qp2->feevout && qp->destsatoshis == qp2->destsatoshis && qp->txfee >= qp2->txfee && qp->desttxfee == qp2->desttxfee ) + { + if ( strictflag == 0 || (qp->aliceid == qp2->aliceid && qp->R.requestid == qp2->R.requestid && qp->R.quoteid == qp2->R.quoteid && qp->vout == qp2->vout && qp->vout2 == qp2->vout2 && qp->satoshis == qp2->satoshis && bits256_cmp(qp->txid,qp2->txid) == 0 && bits256_cmp(qp->txid2,qp2->txid2) == 0 && bits256_cmp(qp->srchash,qp2->srchash) == 0) ) + return(0); + else printf("strict compare failure\n"); + } + return(-1); } void LP_alicequery_clear() @@ -546,12 +550,13 @@ int32_t LP_alice_eligible(uint32_t quotetime) void LP_reserved(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo *qp) { double price=0.,maxprice = LP_Alicemaxprice; - if ( LP_quotecmp(qp,&LP_Alicequery) == 0 ) + if ( LP_quotecmp(0,qp,&LP_Alicequery) == 0 ) { price = LP_pricecache(qp,qp->srccoin,qp->destcoin,qp->txid,qp->vout); if ( LP_pricevalid(price) > 0 && maxprice > SMALLVAL && price <= maxprice ) { qp->tradeid = LP_Alicequery.tradeid; + LP_Alicereserved = *qp; LP_alicequery_clear(); printf("send CONNECT\n"); LP_query(ctx,myipaddr,mypubsock,"connect",qp); @@ -561,7 +566,7 @@ void LP_reserved(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo char *LP_connectedalice(cJSON *argjson) // alice { - cJSON *retjson; double bid,ask,price,qprice; int32_t pairsock = -1; char *pairstr; int32_t DEXselector = 0; struct LP_utxoinfo *autxo,B,*butxo; struct LP_quoteinfo Q; struct basilisk_swap *swap; struct iguana_info *coin; //uint64_t value,value2; + cJSON *retjson; double bid,ask,price,qprice; int32_t pairsock = -1; char *pairstr; int32_t DEXselector = 0; struct LP_utxoinfo *autxo,A,B,*butxo; struct LP_quoteinfo Q; struct basilisk_swap *swap; struct iguana_info *coin; if ( LP_quoteparse(&Q,argjson) < 0 ) { LP_aliceid(Q.tradeid,Q.aliceid,"error0",0,0); @@ -572,7 +577,7 @@ char *LP_connectedalice(cJSON *argjson) // alice LP_aliceid(Q.tradeid,Q.aliceid,"error1",0,0); return(clonestr("{\"result\",\"update stats\"}")); } - printf("CONNECTED.(%s) numpending.%d tradeid.%u requestid.%u quoteid.%u\n",jprint(argjson,0),G.LP_pendingswaps,Q.tradeid,Q.R.requestid,Q.R.quoteid); + printf("CONNECTED.(%s) numpending.%d tradeid.%u requestid.%u quoteid.%u\n",jprint(argjson,0),G.LP_pendingswaps,Q.tradeid,Q.R.requestid,Q.R.quoteid); 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); printf("calculated requestid.%u quoteid.%u\n",Q.R.requestid,Q.R.quoteid); if ( LP_pendingswap(Q.R.requestid,Q.R.quoteid) > 0 ) @@ -582,16 +587,17 @@ char *LP_connectedalice(cJSON *argjson) // alice jaddstr(retjson,"error","swap already in progress"); return(jprint(retjson,1)); } - if ( (autxo= LP_utxopairfind(0,Q.desttxid,Q.destvout,Q.feetxid,Q.feevout)) == 0 ) + if ( LP_quotecmp(1,&Q,&LP_Alicereserved) == 0 ) { - printf("cant find autxo\n"); - LP_aliceid(Q.tradeid,Q.aliceid,"error2",0,0); - return(clonestr("{\"error\":\"cant find autxo\"}")); + printf("mismatched between reserved and connected\n"); } + memset(&LP_Alicereserved,0,sizeof(LP_Alicereserved)); LP_aliceid(Q.tradeid,Q.aliceid,"connected",Q.R.requestid,Q.R.quoteid); + autxo = &A; butxo = &B; + memset(autxo,0,sizeof(*autxo)); memset(butxo,0,sizeof(*butxo)); - LP_abutxo_set(0,butxo,&Q); + LP_abutxo_set(autxo,butxo,&Q); if ( (qprice= LP_quote_validate(autxo,butxo,&Q,0)) <= SMALLVAL ) { LP_availableset(Q.desttxid,Q.vout); diff --git a/iguana/exchanges/LP_tradebots.c b/iguana/exchanges/LP_tradebots.c index ec00553e4..d4a2fdfd5 100644 --- a/iguana/exchanges/LP_tradebots.c +++ b/iguana/exchanges/LP_tradebots.c @@ -386,7 +386,7 @@ void LP_aliceid(uint32_t tradeid,uint64_t aliceid,char *event,uint32_t requestid if ( matched != 0 ) break; } - if ( matched == 0 ) + if ( 0 && matched == 0 ) printf("NO MATCH: bot event tradeid.%u aliceid.%llu (%s) r.%u q.%u\n",tradeid,(long long)aliceid,event,requestid,quoteid); } diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index e9ff90d3a..8ea1d2db5 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -966,7 +966,7 @@ uint64_t LP_txvalue(char *coinaddr,char *symbol,bits256 txid,int32_t vout) int32_t LP_iseligible(uint64_t *valp,uint64_t *val2p,int32_t iambob,char *symbol,bits256 txid,int32_t vout,uint64_t satoshis,bits256 txid2,int32_t vout2) { - uint64_t val,val2=0,txfee,threshold=0; cJSON *txobj; int32_t bypass = 0; char destaddr[64],destaddr2[64]; struct LP_transaction *tx; struct LP_address_utxo *up; struct iguana_info *coin = LP_coinfind(symbol); + uint64_t val,val2=0,txfee,threshold=0; cJSON *txobj; int32_t bypass = 0; char destaddr[64],destaddr2[64]; struct iguana_info *coin = LP_coinfind(symbol); if ( bits256_nonz(txid) == 0 || bits256_nonz(txid2) == 0 ) { printf("null txid not eligible\n"); From 3174532f3c380659a5e09599ba8244fd738b7bff Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 20:08:36 +0200 Subject: [PATCH 288/306] Test --- iguana/exchanges/LP_nativeDEX.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index f73c9474f..6edb2f03d 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -624,7 +624,9 @@ void LP_coinsloop(void *_coins) { if ( LP_blockinit(coin,coin->lastscanht) < 0 ) { - printf("blockinit.%s %d error\n",coin->symbol,coin->lastscanht); + static uint32_t counter; + if ( counter++ < 3 ) + printf("blockinit.%s %d error\n",coin->symbol,coin->lastscanht); break; } coin->lastscanht++; From c0c36f2076ad4964daddcbaf8e0a268f2933d142 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 17 Nov 2017 12:45:44 +0200 Subject: [PATCH 289/306] Test --- iguana/exchanges/LP_cache.c | 2 +- iguana/exchanges/LP_nativeDEX.c | 3 +-- iguana/exchanges/LP_ordermatch.c | 15 ++++++++++++++- iguana/exchanges/LP_rpc.c | 4 ++-- iguana/exchanges/LP_socket.c | 21 ++++++++++++++++++--- iguana/exchanges/LP_transaction.c | 2 +- 6 files changed, 37 insertions(+), 10 deletions(-) diff --git a/iguana/exchanges/LP_cache.c b/iguana/exchanges/LP_cache.c index fdc734fe9..fbce9ddff 100644 --- a/iguana/exchanges/LP_cache.c +++ b/iguana/exchanges/LP_cache.c @@ -235,7 +235,7 @@ int32_t LP_merkleproof(struct iguana_info *coin,char *coinaddr,struct electrum_i return(0); if ( (tx= LP_transactionfind(coin,txid)) == 0 && strcmp(coinaddr,coin->smartaddr) == 0 ) { - if ( (retjson= electrum_transaction(coin->symbol,ep,&retjson,txid)) != 0 ) + if ( (retjson= electrum_transaction(coin->symbol,ep,&retjson,txid,0)) != 0 ) free_json(retjson); } if ( tx != 0 ) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 6edb2f03d..3ca6cb879 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -17,11 +17,10 @@ // LP_nativeDEX.c // marketmaker // +// destpubkey // if ( G.LP_pendingswaps != 0 ) return(-1); // bot safe to exit? -// 324744 and 50mb // BCH signing -// single utxo allocations alice // alice waiting for bestprice // // previously, it used to show amount, kmd equiv, perc diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 60de857a8..7e440d990 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -746,10 +746,23 @@ int32_t LP_aliceonly(char *symbol) int32_t LP_validSPV(char *symbol,char *coinaddr,bits256 txid,int32_t vout) { - struct electrum_info *ep,*backupep; struct LP_address_utxo *up; struct iguana_info *coin; + struct electrum_info *ep,*backupep; cJSON *txobj; struct LP_address_utxo *up; struct iguana_info *coin; struct LP_transaction *tx; coin = LP_coinfind(symbol); if ( coin != 0 && (ep= coin->electrum) != 0 ) { + if ( (up= LP_address_utxofind(coin,coinaddr,txid,vout)) == 0 ) + { + if ( (txobj= electrum_transaction(symbol,ep,&txobj,txid,coinaddr)) != 0 ) + free_json(txobj); + if ( (tx= LP_transactionfind(coin,txid)) != 0 ) + { + if ( vout < tx->numvouts && tx->height > 0 ) + LP_address_utxoadd((uint32_t)time(NULL),"LP_validSPV",coin,coinaddr,txid,vout,tx->outpoints[vout].value,tx->height,-1); + if ( tx->SPV <= 0 ) + return(-1); + return(0); + } + } if ( (up= LP_address_utxofind(coin,coinaddr,txid,vout)) != 0 ) { if ( up->SPV < 0 ) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 11924e51c..8639646ee 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -429,7 +429,7 @@ cJSON *LP_gettx(char *symbol,bits256 txid) } else { - if ( (retjson= electrum_transaction(symbol,coin->electrum,&retjson,txid)) != 0 ) + if ( (retjson= electrum_transaction(symbol,coin->electrum,&retjson,txid,0)) != 0 ) return(retjson); else printf("failed blockchain.transaction.get %s %s\n",coin->symbol,bits256_str(str,txid)); return(cJSON_Parse("{\"error\":\"no transaction bytes\"}")); @@ -507,7 +507,7 @@ cJSON *LP_gettxout(char *symbol,char *coinaddr,bits256 txid,int32_t vout) } if ( coinaddr[0] == 0 ) { - if ( (txobj= electrum_transaction(symbol,coin->electrum,&txobj,txid)) != 0 ) + if ( (txobj= electrum_transaction(symbol,coin->electrum,&txobj,txid,0)) != 0 ) { if ( (vouts= jarray(&n,txobj,"vout")) != 0 && n > 0 ) LP_destaddr(coinaddr,jitem(vouts,vout)); diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 723a61a92..f1a895b38 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -742,12 +742,27 @@ cJSON *_electrum_transaction(char *symbol,struct electrum_info *ep,cJSON **retjs return(*retjsonp); } -cJSON *electrum_transaction(char *symbol,struct electrum_info *ep,cJSON **retjsonp,bits256 txid) +cJSON *electrum_transaction(char *symbol,struct electrum_info *ep,cJSON **retjsonp,bits256 txid,char *SPVcheck) { - cJSON *retjson; + cJSON *retjson,*array; struct LP_transaction *tx; struct iguana_info *coin; + coin = LP_coinfind(symbol); if ( ep != 0 ) portable_mutex_lock(&ep->txmutex); retjson = _electrum_transaction(symbol,ep,retjsonp,txid); + if ( ep != 0 && coin != 0 && SPVcheck != 0 && SPVcheck[0] != 0 && (tx= LP_transactionfind(coin,txid)) != 0 ) + { + if ( tx->height <= 0 ) + { + if ( (array= electrum_address_listunspent(symbol,ep,&array,SPVcheck,2)) != 0 ) + { + printf("SPVcheck.%s got %d unspents\n",SPVcheck,cJSON_GetArraySize(array)); + free_json(array); + } + } + if ( tx->height > 0 ) + tx->SPV = LP_merkleproof(coin,SPVcheck,ep,txid,tx->height); + char str[65]; printf("%s %s %s SPV height %d SPV %d\n",coin->symbol,SPVcheck,bits256_str(str,txid),tx->height,tx->SPV); + } if ( ep != 0 ) portable_mutex_unlock(&ep->txmutex); return(retjson); @@ -789,7 +804,7 @@ void electrum_test() decode_hex(hash.bytes,sizeof(hash),"b967a7d55889fe11e993430921574ec6379bc8ce712a652c3fcb66c6be6e925c"); if ( (retjson= electrum_getmerkle(symbol,ep,0,hash,403000)) != 0 ) printf("electrum_getmerkle %s\n",jprint(retjson,1)); - if ( (retjson= electrum_transaction(symbol,ep,0,hash)) != 0 ) + if ( (retjson= electrum_transaction(symbol,ep,0,hash,0)) != 0 ) printf("electrum_transaction %s\n",jprint(retjson,1)); addr = "14NeevLME8UAANiTCVNgvDrynUPk1VcQKb"; if ( (retjson= electrum_address_gethistory(symbol,ep,0,addr)) != 0 ) diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index f90a87170..133ee6c41 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -118,7 +118,7 @@ bits256 LP_broadcast(char *txname,char *symbol,char *txbytes,bits256 expectedtxi } else if ( (errstr= jstr(retjson,"error")) != 0 && strcmp(errstr,"timeout") == 0 && coin != 0 && coin->electrum != 0 ) { - if ( totalretries < 10 ) + if ( totalretries < 4 ) { printf("time error with electrum, retry.%d\n",totalretries); totalretries++; From 10dac4ab97796051d8c7c8540348a9b28abc8b2b Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 17 Nov 2017 15:57:19 +0200 Subject: [PATCH 290/306] Add back utxo info --- iguana/exchanges/LP_include.h | 11 +++- iguana/exchanges/LP_nativeDEX.c | 7 +- iguana/exchanges/LP_prices.c | 110 +++++++++++++++++++++++++------ iguana/exchanges/LP_signatures.c | 15 ++++- 4 files changed, 119 insertions(+), 24 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index f66fcc9c1..2d928676f 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -364,12 +364,21 @@ struct basilisk_swap }; +struct LP_pubkey_quote +{ + struct LP_pubkey_quote *next,*prev; + float price; + uint32_t maxutxo,aveutxo; + uint8_t baseind,relind,numutxos,scale; +}; + #define LP_MAXPRICEINFOS 256 struct LP_pubkeyinfo { UT_hash_handle hh; bits256 pubkey; - float matrix[LP_MAXPRICEINFOS][LP_MAXPRICEINFOS]; + struct LP_pubkey_quote *quotes; + //float matrix[LP_MAXPRICEINFOS][LP_MAXPRICEINFOS]; //uint32_t timestamps[LP_MAXPRICEINFOS][LP_MAXPRICEINFOS]; uint32_t timestamp,numerrors,lasttime; int32_t istrusted; diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 3ca6cb879..5b44da252 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -533,8 +533,6 @@ void LP_coinsloop(void *_coins) { if ( (backupep= ep->prev) == 0 ) backupep = ep; - // 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 ) @@ -892,6 +890,11 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu char *myipaddr=0,version[64]; long filesize,n; int32_t valid,timeout,pubsock=-1; struct LP_peerinfo *mypeer=0; char pushaddr[128],subaddr[128],bindaddr[128],*coins_str=0; cJSON *coinsjson=0; void *ctx = bitcoin_ctx(); sprintf(version,"Marketmaker %s.%s %s rsize.%ld",LP_MAJOR_VERSION,LP_MINOR_VERSION,LP_BUILD_NUMBER,sizeof(struct basilisk_request)); printf("%s %u\n",version,calc_crc32(0,version,(int32_t)strlen(version))); + if ( LP_MAXPRICEINFOS > 256 ) + { + printf("LP_MAXPRICEINFOS %d wont fit in a uint8_t, need to increase the width of the baseind and relind for struct LP_pubkey_quote\n",LP_MAXPRICEINFOS); + exit(-1); + } LP_showwif = juint(argjson,"wif"); if ( passphrase == 0 || passphrase[0] == 0 ) { diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index ade6b75f5..4962d2972 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -18,7 +18,7 @@ // marketmaker // -struct LP_orderbookentry { bits256 pubkey; double price; uint64_t minsatoshis,maxsatoshis,depth; uint32_t timestamp; int32_t numutxos; char coinaddr[64]; }; +struct LP_orderbookentry { bits256 pubkey; double price; uint64_t avesatoshis,maxsatoshis,depth; uint32_t timestamp; int32_t numutxos; char coinaddr[64]; }; struct LP_priceinfo { @@ -48,6 +48,75 @@ struct LP_cacheinfo uint32_t timestamp; } *LP_cacheinfos; + +float LP_pubkey_price(int32_t *numutxosp,int64_t *avesatoshisp,int64_t *maxsatoshisp,struct LP_pubkeyinfo *pubp,uint32_t baseind,uint32_t relind) +{ + struct LP_pubkey_quote *pq,*tmp; int32_t scale; int64_t scale64; + *numutxosp = 0; + *avesatoshisp = *maxsatoshisp = 0; + DL_FOREACH_SAFE(pubp->quotes,pq,tmp) + { + if ( baseind == pq->baseind && relind == pq->relind ) + { + if ( (scale= pq->scale) == 0 ) + pq->scale = scale = 6; + scale64 = 1; + while ( scale > 0 ) + { + scale64 *= 10; + scale--; + } + *numutxosp = pq->numutxos; + *avesatoshisp = pq->aveutxo * scale64; + *maxsatoshisp = pq->maxutxo * scale64; + return(pq->price); + } + } + return(0); +} + +void LP_pubkey_update(struct LP_pubkeyinfo *pubp,uint32_t baseind,uint32_t relind,float price,int64_t balance,int32_t numutxos,int64_t minutxo,int64_t maxutxo) +{ + struct LP_pubkey_quote *pq,*tmp; int64_t aveutxo,scale64,ave64,max64; int32_t scale; + DL_FOREACH_SAFE(pubp->quotes,pq,tmp) + { + if ( baseind == pq->baseind && relind == pq->relind ) + break; + pq = 0; + } + if ( pq == 0 ) + { + pq = calloc(1,sizeof(*pq)); + pq->baseind = baseind; + pq->relind = relind; + pq->scale = 6; // millions of SATOSHIS, ie. 0.01 + DL_APPEND(pubp->quotes,pq); // already serialized as only path is via stats_JSON() + } + pq->price = price; + if ( numutxos != 0 ) + { + if ( (scale= pq->scale) == 0 ) + pq->scale = scale = 6; + scale64 = 1; + while ( scale > 0 ) + { + scale64 *= 10; + scale--; + } + if ( numutxos > (1L << sizeof(pq->numutxos)) ) + pq->numutxos = (1L << sizeof(pq->numutxos)) - 1; + else pq->numutxos = numutxos; + aveutxo = balance / numutxos; + if ( (ave64= (aveutxo / scale64)) > (1LL << 32) ) + ave64 = (1LL << 32) - 1; + if ( (max64= (maxutxo / scale64)) > (1LL << 32) ) + max64 = (1LL << 32) - 1; + pq->aveutxo = (uint32_t)ave64; + pq->maxutxo = (uint32_t)max64; + printf("scale64 = %llu, ave %llu, ave32 %u (%llu) max32 %u (%llu)\n",(long long)scale64,(long long)aveutxo,pq->aveutxo,(long long)pq->aveutxo * scale64,pq->maxutxo,(long long)pq->maxutxo * scale64); + } +} + struct LP_priceinfo *LP_priceinfo(int32_t ind) { if ( ind < 0 || ind >= LP_MAXPRICEINFOS ) @@ -272,7 +341,7 @@ uint64_t LP_unspents_metric(struct iguana_info *coin,char *coinaddr) cJSON *LP_pubkeyjson(struct LP_pubkeyinfo *pubp) { - int32_t baseid,relid; char *base,hexstr[67],hexstr2[67],sigstr[256]; double price; cJSON *item,*array,*obj; + int32_t baseid,relid,numutxos; int64_t avesatoshis,maxsatoshis; char *base,hexstr[67],hexstr2[67],sigstr[256]; double price; cJSON *item,*array,*obj; obj = cJSON_CreateObject(); array = cJSON_CreateArray(); for (baseid=0; baseidmatrix[baseid][relid]; + price = LP_pubkey_price(&numutxos,&avesatoshis,&maxsatoshis,pubp,baseid,relid);//pubp->matrix[baseid][relid]; if ( LP_pricevalid(price) > 0 ) { item = cJSON_CreateArray(); @@ -495,7 +564,8 @@ int32_t LP_mypriceset(int32_t *changedp,char *base,char *rel,double price) if ( (pubp= LP_pubkeyadd(G.LP_mypub25519)) != 0 ) { pubp->timestamp = (uint32_t)time(NULL); - pubp->matrix[basepp->ind][relpp->ind] = price; + LP_pubkey_update(pubp,basepp->ind,relpp->ind,price,0,0,0,0); + //pubp->matrix[basepp->ind][relpp->ind] = price; //pubp->timestamps[basepp->ind][relpp->ind] = pubp->timestamp; //pubp->matrix[relpp->ind][basepp->ind] = (1. / price); } @@ -671,7 +741,7 @@ cJSON *LP_orderbookjson(char *symbol,struct LP_orderbookentry *op) jaddstr(item,"address",op->coinaddr); jaddnum(item,"price",op->price); jaddnum(item,"numutxos",op->numutxos); - jaddnum(item,"minvolume",dstr(op->minsatoshis)*0.8); + jaddnum(item,"avevolume",dstr(op->avesatoshis)*0.8); jaddnum(item,"maxvolume",dstr(op->maxsatoshis)*0.8); jaddnum(item,"depth",dstr(op->depth)*0.8); jaddbits256(item,"pubkey",op->pubkey); @@ -680,7 +750,7 @@ cJSON *LP_orderbookjson(char *symbol,struct LP_orderbookentry *op) return(item); } -struct LP_orderbookentry *LP_orderbookentry(char *address,char *base,char *rel,double price,int32_t numutxos,uint64_t minsatoshis,uint64_t maxsatoshis,bits256 pubkey,uint32_t timestamp,uint64_t balance) +struct LP_orderbookentry *LP_orderbookentry(char *address,char *base,char *rel,double price,int32_t numutxos,uint64_t avesatoshis,uint64_t maxsatoshis,bits256 pubkey,uint32_t timestamp,uint64_t balance) { struct LP_orderbookentry *op; if ( (op= calloc(1,sizeof(*op))) != 0 ) @@ -688,8 +758,8 @@ struct LP_orderbookentry *LP_orderbookentry(char *address,char *base,char *rel,d safecopy(op->coinaddr,address,sizeof(op->coinaddr)); op->price = price; op->numutxos = numutxos; - op->minsatoshis = minsatoshis; - op->maxsatoshis = maxsatoshis; + op->avesatoshis = avesatoshis; + op->maxsatoshis = avesatoshis; op->pubkey = pubkey; op->timestamp = timestamp; op->depth = balance; @@ -718,7 +788,7 @@ void LP_pubkeys_query() int32_t LP_orderbook_utxoentries(uint32_t now,int32_t polarity,char *base,char *rel,struct LP_orderbookentry *(**arrayp),int32_t num,int32_t cachednum,int32_t duration) { - char coinaddr[64]; uint8_t zeroes[20]; struct LP_pubkeyinfo *pubp=0,*tmp; struct LP_priceinfo *basepp; struct LP_orderbookentry *op; struct LP_address *ap; struct iguana_info *basecoin; uint32_t oldest; double price; int32_t baseid,relid,n; uint64_t minsatoshis,maxsatoshis,balance; + char coinaddr[64]; uint8_t zeroes[20]; struct LP_pubkeyinfo *pubp=0,*tmp; struct LP_priceinfo *basepp; struct LP_orderbookentry *op; struct LP_address *ap; struct iguana_info *basecoin; uint32_t oldest; double price; int32_t baseid,relid,n; int64_t maxsatoshis,balance,avesatoshis; if ( (basepp= LP_priceinfoptr(&relid,base,rel)) != 0 ) baseid = basepp->ind; else return(num); @@ -737,23 +807,23 @@ int32_t LP_orderbook_utxoentries(uint32_t now,int32_t polarity,char *base,char * if ( pubp->timestamp < oldest ) continue; bitcoin_address(coinaddr,basecoin->taddr,basecoin->pubtype,pubp->rmd160,sizeof(pubp->rmd160)); - minsatoshis = maxsatoshis = n = 0; + avesatoshis = maxsatoshis = n = 0; ap = 0; - if ( (price= pubp->matrix[baseid][relid]) > SMALLVAL )//&& pubp->timestamps[baseid][relid] >= oldest ) + if ( (price= LP_pubkey_price(&n,&avesatoshis,&maxsatoshis,pubp,baseid,relid)) > SMALLVAL ) //pubp->matrix[baseid][relid]) > SMALLVAL )//&& pubp->timestamps[baseid][relid] >= oldest ) { - balance = 0; - if ( (ap= LP_addressfind(basecoin,coinaddr)) != 0 ) + balance = avesatoshis * n; + //if ( (ap= LP_addressfind(basecoin,coinaddr)) != 0 ) { - n = LP_address_minmax(&balance,&minsatoshis,&maxsatoshis,ap); + //n = LP_address_minmax(&balance,&minsatoshis,&maxsatoshis,ap); if ( polarity > 0 ) { balance *= price; - minsatoshis *= price; + avesatoshis *= price; maxsatoshis *= price; } //printf("%s/%s %s n.%d ap->n.%d %.8f\n",base,rel,coinaddr,n,ap->n,dstr(ap->total)); } - if ( (op= LP_orderbookentry(coinaddr,base,rel,polarity > 0 ? price : 1./price,n,minsatoshis,maxsatoshis,pubp->pubkey,pubp->timestamp,balance)) != 0 ) + if ( (op= LP_orderbookentry(coinaddr,base,rel,polarity > 0 ? price : 1./price,n,avesatoshis,maxsatoshis,pubp->pubkey,pubp->timestamp,balance)) != 0 ) { *arrayp = realloc(*arrayp,sizeof(*(*arrayp)) * (num+1)); (*arrayp)[num++] = op; @@ -1036,7 +1106,7 @@ cJSON *LP_pricearray(char *base,char *rel,uint32_t firsttime,uint32_t lasttime,i return(retarray); } -void LP_pricefeedupdate(bits256 pubkey,char *base,char *rel,double price) +void LP_pricefeedupdate(bits256 pubkey,char *base,char *rel,double price,int32_t numutxos,int64_t balance,int64_t minutxo,int64_t maxutxo) { struct LP_priceinfo *basepp,*relpp; uint32_t now; uint64_t price64; struct LP_pubkeyinfo *pubp; char str[65],fname[512]; FILE *fp; //printf("check PRICEFEED UPDATE.(%s/%s) %.8f %s\n",base,rel,price,bits256_str(str,pubkey)); @@ -1073,9 +1143,11 @@ void LP_pricefeedupdate(bits256 pubkey,char *base,char *rel,double price) if ( (LP_rand() % 1000) == 0 ) printf("PRICEFEED UPDATE.(%-6s/%6s) %12.8f %s %12.8f\n",base,rel,price,bits256_str(str,pubkey),1./price); pubp->timestamp = (uint32_t)time(NULL); - if ( fabs(pubp->matrix[basepp->ind][relpp->ind] - price) > SMALLVAL ) + LP_pubkey_update(pubp,basepp->ind,relpp->ind,price,balance,numutxos,minutxo,maxutxo); + //pubp->depthinfo[basepp->ind][relpp->ind] = LP_depthinfo_compact(); + //if ( fabs(pubp->matrix[basepp->ind][relpp->ind] - price) > SMALLVAL ) { - pubp->matrix[basepp->ind][relpp->ind] = price; + //pubp->matrix[basepp->ind][relpp->ind] = price; //pubp->timestamps[basepp->ind][relpp->ind] = pubp->timestamp; dxblend(&basepp->relvals[relpp->ind],price,0.9); dxblend(&relpp->relvals[basepp->ind],1. / price,0.9); diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index e729421ad..5a7ab184d 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -451,7 +451,8 @@ int32_t LP_price_sigadd(cJSON *item,uint32_t timestamp,bits256 priv,uint8_t *pub char *LP_pricepings(void *ctx,char *myipaddr,int32_t pubsock,char *base,char *rel,double price) { - struct iguana_info *basecoin,*relcoin; char pubsecpstr[67]; uint32_t timestamp; uint64_t price64; bits256 zero; cJSON *reqjson = cJSON_CreateObject(); + struct iguana_info *basecoin,*relcoin; struct LP_address *ap; char pubsecpstr[67]; uint32_t numutxos,timestamp; uint64_t price64,balance,minsize,maxsize; bits256 zero; cJSON *reqjson; + reqjson = cJSON_CreateObject(); // LP_addsig if ( (basecoin= LP_coinfind(base)) != 0 && (relcoin= LP_coinfind(rel)) != 0 && basecoin->electrum == 0 )//&& relcoin->electrum == 0 ) { @@ -467,6 +468,16 @@ char *LP_pricepings(void *ctx,char *myipaddr,int32_t pubsock,char *base,char *re jaddnum(reqjson,"timestamp",timestamp); init_hexbytes_noT(pubsecpstr,G.LP_pubsecp,33); jaddstr(reqjson,"pubsecp",pubsecpstr); + if ( (ap= LP_address(basecoin,basecoin->smartaddr)) != 0 ) + { + if ( (numutxos= LP_address_minmax(&balance,&minsize,&maxsize,ap)) != 0 ) + { + jaddnum(reqjson,"n",numutxos); + jaddnum(reqjson,"bal",dstr(balance)); + jaddnum(reqjson,"min",dstr(minsize)); + jaddnum(reqjson,"max",dstr(maxsize)); + } + } LP_price_sigadd(reqjson,timestamp,G.LP_privkey,G.LP_pubsecp,G.LP_mypub25519,base,rel,price64); LP_reserved_msg(0,base,rel,zero,jprint(reqjson,1)); return(clonestr("{\"result\":\"success\"}")); @@ -484,7 +495,7 @@ char *LP_postprice_recv(cJSON *argjson) { if ( LP_price_sigcheck(juint(argjson,"timestamp"),jstr(argjson,"sig"),jstr(argjson,"pubsecp"),pubkey,base,rel,j64bits(argjson,"price64")) == 0 ) { - LP_pricefeedupdate(pubkey,base,rel,price); + LP_pricefeedupdate(pubkey,base,rel,price,jint(argjson,"n"),jdouble(argjson,"bal")*SATOSHIDEN,jdouble(argjson,"min")*SATOSHIDEN,jdouble(argjson,"max")*SATOSHIDEN); return(clonestr("{\"result\":\"success\"}")); } else return(clonestr("{\"error\":\"sig failure\"}")); } From eb6d6fe7f0d5b11e59ade3c71d1e1d805fdfdae5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 17 Nov 2017 16:10:25 +0200 Subject: [PATCH 291/306] Test --- iguana/exchanges/LP_prices.c | 7 ++++--- iguana/exchanges/LP_signatures.c | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 4962d2972..4db3df60d 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -106,14 +106,15 @@ void LP_pubkey_update(struct LP_pubkeyinfo *pubp,uint32_t baseind,uint32_t relin if ( numutxos > (1L << sizeof(pq->numutxos)) ) pq->numutxos = (1L << sizeof(pq->numutxos)) - 1; else pq->numutxos = numutxos; - aveutxo = balance / numutxos; + aveutxo = (balance + (scale64>>1)) / numutxos; if ( (ave64= (aveutxo / scale64)) > (1LL << 32) ) ave64 = (1LL << 32) - 1; - if ( (max64= (maxutxo / scale64)) > (1LL << 32) ) + max64 = ((maxutxo + (scale64>>1)) / scale64); + if ( max64 > (1LL << 32) ) max64 = (1LL << 32) - 1; pq->aveutxo = (uint32_t)ave64; pq->maxutxo = (uint32_t)max64; - printf("scale64 = %llu, ave %llu, ave32 %u (%llu) max32 %u (%llu)\n",(long long)scale64,(long long)aveutxo,pq->aveutxo,(long long)pq->aveutxo * scale64,pq->maxutxo,(long long)pq->maxutxo * scale64); + printf("base.%s scale64 = %llu, ave %llu, ave32 %u (%llu) max32 %u (%llu)\n",LP_priceinfos[baseind].symbol,(long long)scale64,(long long)aveutxo,pq->aveutxo,(long long)pq->aveutxo * scale64,pq->maxutxo,(long long)pq->maxutxo * scale64); } } diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index 5a7ab184d..6089e8366 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -472,6 +472,7 @@ char *LP_pricepings(void *ctx,char *myipaddr,int32_t pubsock,char *base,char *re { if ( (numutxos= LP_address_minmax(&balance,&minsize,&maxsize,ap)) != 0 ) { + printf("%s numutxos.%d balance %.8f min %.8f max %.8f\n",base,numutxos,dstr(balance),dstr(minsize),dstr(maxsize)); jaddnum(reqjson,"n",numutxos); jaddnum(reqjson,"bal",dstr(balance)); jaddnum(reqjson,"min",dstr(minsize)); From b38e6f678a31bf9dd812c206a3b07928d5be40c5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 17 Nov 2017 16:16:19 +0200 Subject: [PATCH 292/306] Test --- iguana/exchanges/LP_include.h | 2 +- iguana/exchanges/LP_prices.c | 22 +++++++++++----------- iguana/exchanges/LP_signatures.c | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 2d928676f..7d9b1d9ab 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -369,7 +369,7 @@ struct LP_pubkey_quote struct LP_pubkey_quote *next,*prev; float price; uint32_t maxutxo,aveutxo; - uint8_t baseind,relind,numutxos,scale; + uint8_t baseind,relind,numrelutxos,scale; }; #define LP_MAXPRICEINFOS 256 diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 4db3df60d..b058e1c18 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -49,10 +49,10 @@ struct LP_cacheinfo } *LP_cacheinfos; -float LP_pubkey_price(int32_t *numutxosp,int64_t *avesatoshisp,int64_t *maxsatoshisp,struct LP_pubkeyinfo *pubp,uint32_t baseind,uint32_t relind) +float LP_pubkey_price(int32_t *numrelutxosp,int64_t *avesatoshisp,int64_t *maxsatoshisp,struct LP_pubkeyinfo *pubp,uint32_t baseind,uint32_t relind) { struct LP_pubkey_quote *pq,*tmp; int32_t scale; int64_t scale64; - *numutxosp = 0; + *numrelutxosp = 0; *avesatoshisp = *maxsatoshisp = 0; DL_FOREACH_SAFE(pubp->quotes,pq,tmp) { @@ -66,7 +66,7 @@ float LP_pubkey_price(int32_t *numutxosp,int64_t *avesatoshisp,int64_t *maxsatos scale64 *= 10; scale--; } - *numutxosp = pq->numutxos; + *numrelutxosp = pq->numrelutxos; *avesatoshisp = pq->aveutxo * scale64; *maxsatoshisp = pq->maxutxo * scale64; return(pq->price); @@ -75,7 +75,7 @@ float LP_pubkey_price(int32_t *numutxosp,int64_t *avesatoshisp,int64_t *maxsatos return(0); } -void LP_pubkey_update(struct LP_pubkeyinfo *pubp,uint32_t baseind,uint32_t relind,float price,int64_t balance,int32_t numutxos,int64_t minutxo,int64_t maxutxo) +void LP_pubkey_update(struct LP_pubkeyinfo *pubp,uint32_t baseind,uint32_t relind,float price,int64_t balance,int32_t numrelutxos,int64_t minutxo,int64_t maxutxo) { struct LP_pubkey_quote *pq,*tmp; int64_t aveutxo,scale64,ave64,max64; int32_t scale; DL_FOREACH_SAFE(pubp->quotes,pq,tmp) @@ -93,7 +93,7 @@ void LP_pubkey_update(struct LP_pubkeyinfo *pubp,uint32_t baseind,uint32_t relin DL_APPEND(pubp->quotes,pq); // already serialized as only path is via stats_JSON() } pq->price = price; - if ( numutxos != 0 ) + if ( numrelutxos != 0 ) { if ( (scale= pq->scale) == 0 ) pq->scale = scale = 6; @@ -103,9 +103,9 @@ void LP_pubkey_update(struct LP_pubkeyinfo *pubp,uint32_t baseind,uint32_t relin scale64 *= 10; scale--; } - if ( numutxos > (1L << sizeof(pq->numutxos)) ) - pq->numutxos = (1L << sizeof(pq->numutxos)) - 1; - else pq->numutxos = numutxos; + if ( numrelutxos > (1L << sizeof(pq->numutxos)) ) + pq->numrelutxos = (1L << sizeof(pq->numutxos)) - 1; + else pq->numrelutxos = numrelutxos; aveutxo = (balance + (scale64>>1)) / numutxos; if ( (ave64= (aveutxo / scale64)) > (1LL << 32) ) ave64 = (1LL << 32) - 1; @@ -114,7 +114,7 @@ void LP_pubkey_update(struct LP_pubkeyinfo *pubp,uint32_t baseind,uint32_t relin max64 = (1LL << 32) - 1; pq->aveutxo = (uint32_t)ave64; pq->maxutxo = (uint32_t)max64; - printf("base.%s scale64 = %llu, ave %llu, ave32 %u (%llu) max32 %u (%llu)\n",LP_priceinfos[baseind].symbol,(long long)scale64,(long long)aveutxo,pq->aveutxo,(long long)pq->aveutxo * scale64,pq->maxutxo,(long long)pq->maxutxo * scale64); + printf("base.%s numutxos.%u %u scale64 = %llu, ave %llu, ave32 %u (%llu) max32 %u (%llu)\n",LP_priceinfos[relind].symbol,numrelutxos,pq->numrelutxos,(long long)scale64,(long long)aveutxo,pq->aveutxo,(long long)pq->aveutxo * scale64,pq->maxutxo,(long long)pq->maxutxo * scale64); } } @@ -1107,7 +1107,7 @@ cJSON *LP_pricearray(char *base,char *rel,uint32_t firsttime,uint32_t lasttime,i return(retarray); } -void LP_pricefeedupdate(bits256 pubkey,char *base,char *rel,double price,int32_t numutxos,int64_t balance,int64_t minutxo,int64_t maxutxo) +void LP_pricefeedupdate(bits256 pubkey,char *base,char *rel,double price,int32_t numrelutxos,int64_t balance,int64_t minutxo,int64_t maxutxo) { struct LP_priceinfo *basepp,*relpp; uint32_t now; uint64_t price64; struct LP_pubkeyinfo *pubp; char str[65],fname[512]; FILE *fp; //printf("check PRICEFEED UPDATE.(%s/%s) %.8f %s\n",base,rel,price,bits256_str(str,pubkey)); @@ -1144,7 +1144,7 @@ void LP_pricefeedupdate(bits256 pubkey,char *base,char *rel,double price,int32_t if ( (LP_rand() % 1000) == 0 ) printf("PRICEFEED UPDATE.(%-6s/%6s) %12.8f %s %12.8f\n",base,rel,price,bits256_str(str,pubkey),1./price); pubp->timestamp = (uint32_t)time(NULL); - LP_pubkey_update(pubp,basepp->ind,relpp->ind,price,balance,numutxos,minutxo,maxutxo); + LP_pubkey_update(pubp,basepp->ind,relpp->ind,price,balance,numrelutxos,minutxo,maxutxo); //pubp->depthinfo[basepp->ind][relpp->ind] = LP_depthinfo_compact(); //if ( fabs(pubp->matrix[basepp->ind][relpp->ind] - price) > SMALLVAL ) { diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index 6089e8366..252d19df4 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -468,11 +468,11 @@ char *LP_pricepings(void *ctx,char *myipaddr,int32_t pubsock,char *base,char *re jaddnum(reqjson,"timestamp",timestamp); init_hexbytes_noT(pubsecpstr,G.LP_pubsecp,33); jaddstr(reqjson,"pubsecp",pubsecpstr); - if ( (ap= LP_address(basecoin,basecoin->smartaddr)) != 0 ) + if ( (ap= LP_address(relcoin,relcoin->smartaddr)) != 0 ) { if ( (numutxos= LP_address_minmax(&balance,&minsize,&maxsize,ap)) != 0 ) { - printf("%s numutxos.%d balance %.8f min %.8f max %.8f\n",base,numutxos,dstr(balance),dstr(minsize),dstr(maxsize)); + printf("%s numutxos.%d balance %.8f min %.8f max %.8f\n",rel,numutxos,dstr(balance),dstr(minsize),dstr(maxsize)); jaddnum(reqjson,"n",numutxos); jaddnum(reqjson,"bal",dstr(balance)); jaddnum(reqjson,"min",dstr(minsize)); From 7ee7fbdca53581ee984dbcfc528b0882babce99f Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 17 Nov 2017 16:18:25 +0200 Subject: [PATCH 293/306] Test --- iguana/exchanges/LP_prices.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index b058e1c18..f1b312de8 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -103,10 +103,10 @@ void LP_pubkey_update(struct LP_pubkeyinfo *pubp,uint32_t baseind,uint32_t relin scale64 *= 10; scale--; } - if ( numrelutxos > (1L << sizeof(pq->numutxos)) ) - pq->numrelutxos = (1L << sizeof(pq->numutxos)) - 1; + if ( numrelutxos > (1L << sizeof(pq->numrelutxos)) ) + pq->numrelutxos = (1L << sizeof(pq->numrelutxos)) - 1; else pq->numrelutxos = numrelutxos; - aveutxo = (balance + (scale64>>1)) / numutxos; + aveutxo = (balance + (scale64>>1)) / numrelutxos; if ( (ave64= (aveutxo / scale64)) > (1LL << 32) ) ave64 = (1LL << 32) - 1; max64 = ((maxutxo + (scale64>>1)) / scale64); From dd77fb3331a6b7d666b746fe07524b98d3ba25ad Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 17 Nov 2017 16:29:15 +0200 Subject: [PATCH 294/306] Test --- iguana/exchanges/LP_prices.c | 16 ++++++++-------- iguana/exchanges/LP_signatures.c | 7 ++++--- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index f1b312de8..5042955b1 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -75,7 +75,7 @@ float LP_pubkey_price(int32_t *numrelutxosp,int64_t *avesatoshisp,int64_t *maxsa return(0); } -void LP_pubkey_update(struct LP_pubkeyinfo *pubp,uint32_t baseind,uint32_t relind,float price,int64_t balance,int32_t numrelutxos,int64_t minutxo,int64_t maxutxo) +void LP_pubkey_update(struct LP_pubkeyinfo *pubp,uint32_t baseind,uint32_t relind,float price,int64_t balance,char *utxocoin,int32_t numutxos,int64_t minutxo,int64_t maxutxo) { struct LP_pubkey_quote *pq,*tmp; int64_t aveutxo,scale64,ave64,max64; int32_t scale; DL_FOREACH_SAFE(pubp->quotes,pq,tmp) @@ -93,7 +93,7 @@ void LP_pubkey_update(struct LP_pubkeyinfo *pubp,uint32_t baseind,uint32_t relin DL_APPEND(pubp->quotes,pq); // already serialized as only path is via stats_JSON() } pq->price = price; - if ( numrelutxos != 0 ) + if ( numutxos != 0 ) { if ( (scale= pq->scale) == 0 ) pq->scale = scale = 6; @@ -103,10 +103,10 @@ void LP_pubkey_update(struct LP_pubkeyinfo *pubp,uint32_t baseind,uint32_t relin scale64 *= 10; scale--; } - if ( numrelutxos > (1L << sizeof(pq->numrelutxos)) ) + if ( numutxos > (1L << sizeof(pq->numrelutxos)) ) pq->numrelutxos = (1L << sizeof(pq->numrelutxos)) - 1; - else pq->numrelutxos = numrelutxos; - aveutxo = (balance + (scale64>>1)) / numrelutxos; + else pq->numrelutxos = numutxos; + aveutxo = (balance + (scale64>>1)) / numutxos; if ( (ave64= (aveutxo / scale64)) > (1LL << 32) ) ave64 = (1LL << 32) - 1; max64 = ((maxutxo + (scale64>>1)) / scale64); @@ -114,7 +114,7 @@ void LP_pubkey_update(struct LP_pubkeyinfo *pubp,uint32_t baseind,uint32_t relin max64 = (1LL << 32) - 1; pq->aveutxo = (uint32_t)ave64; pq->maxutxo = (uint32_t)max64; - printf("base.%s numutxos.%u %u scale64 = %llu, ave %llu, ave32 %u (%llu) max32 %u (%llu)\n",LP_priceinfos[relind].symbol,numrelutxos,pq->numrelutxos,(long long)scale64,(long long)aveutxo,pq->aveutxo,(long long)pq->aveutxo * scale64,pq->maxutxo,(long long)pq->maxutxo * scale64); + printf("base.%s rel.%s utxocoin.%s numutxos.%u %u scale64 = %llu, ave %llu, ave32 %u (%llu) max32 %u (%llu)\n",LP_priceinfos[baseind].symbol,LP_priceinfos[relind].symbol,utxocoin,numutxos,pq->numrelutxos,(long long)scale64,(long long)aveutxo,pq->aveutxo,(long long)pq->aveutxo * scale64,pq->maxutxo,(long long)pq->maxutxo * scale64); } } @@ -1107,7 +1107,7 @@ cJSON *LP_pricearray(char *base,char *rel,uint32_t firsttime,uint32_t lasttime,i return(retarray); } -void LP_pricefeedupdate(bits256 pubkey,char *base,char *rel,double price,int32_t numrelutxos,int64_t balance,int64_t minutxo,int64_t maxutxo) +void LP_pricefeedupdate(bits256 pubkey,char *base,char *rel,double price,char *utxocoin,int32_t numrelutxos,int64_t balance,int64_t minutxo,int64_t maxutxo) { struct LP_priceinfo *basepp,*relpp; uint32_t now; uint64_t price64; struct LP_pubkeyinfo *pubp; char str[65],fname[512]; FILE *fp; //printf("check PRICEFEED UPDATE.(%s/%s) %.8f %s\n",base,rel,price,bits256_str(str,pubkey)); @@ -1144,7 +1144,7 @@ void LP_pricefeedupdate(bits256 pubkey,char *base,char *rel,double price,int32_t if ( (LP_rand() % 1000) == 0 ) printf("PRICEFEED UPDATE.(%-6s/%6s) %12.8f %s %12.8f\n",base,rel,price,bits256_str(str,pubkey),1./price); pubp->timestamp = (uint32_t)time(NULL); - LP_pubkey_update(pubp,basepp->ind,relpp->ind,price,balance,numrelutxos,minutxo,maxutxo); + LP_pubkey_update(pubp,basepp->ind,relpp->ind,price,balance,utxocoin,numrelutxos,minutxo,maxutxo); //pubp->depthinfo[basepp->ind][relpp->ind] = LP_depthinfo_compact(); //if ( fabs(pubp->matrix[basepp->ind][relpp->ind] - price) > SMALLVAL ) { diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index 252d19df4..2253bcc09 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -468,11 +468,12 @@ char *LP_pricepings(void *ctx,char *myipaddr,int32_t pubsock,char *base,char *re jaddnum(reqjson,"timestamp",timestamp); init_hexbytes_noT(pubsecpstr,G.LP_pubsecp,33); jaddstr(reqjson,"pubsecp",pubsecpstr); - if ( (ap= LP_address(relcoin,relcoin->smartaddr)) != 0 ) + if ( (ap= LP_address(basecoin,basecoin->smartaddr)) != 0 ) { if ( (numutxos= LP_address_minmax(&balance,&minsize,&maxsize,ap)) != 0 ) { - printf("%s numutxos.%d balance %.8f min %.8f max %.8f\n",rel,numutxos,dstr(balance),dstr(minsize),dstr(maxsize)); + printf("%s numutxos.%d balance %.8f min %.8f max %.8f\n",base,numutxos,dstr(balance),dstr(minsize),dstr(maxsize)); + jaddstr(reqjson,"utxocoin",base); jaddnum(reqjson,"n",numutxos); jaddnum(reqjson,"bal",dstr(balance)); jaddnum(reqjson,"min",dstr(minsize)); @@ -496,7 +497,7 @@ char *LP_postprice_recv(cJSON *argjson) { if ( LP_price_sigcheck(juint(argjson,"timestamp"),jstr(argjson,"sig"),jstr(argjson,"pubsecp"),pubkey,base,rel,j64bits(argjson,"price64")) == 0 ) { - LP_pricefeedupdate(pubkey,base,rel,price,jint(argjson,"n"),jdouble(argjson,"bal")*SATOSHIDEN,jdouble(argjson,"min")*SATOSHIDEN,jdouble(argjson,"max")*SATOSHIDEN); + LP_pricefeedupdate(pubkey,base,rel,price,jstr(argjson,"utxocoin"),jint(argjson,"n"),jdouble(argjson,"bal")*SATOSHIDEN,jdouble(argjson,"min")*SATOSHIDEN,jdouble(argjson,"max")*SATOSHIDEN); return(clonestr("{\"result\":\"success\"}")); } else return(clonestr("{\"error\":\"sig failure\"}")); } From c4410b76974237ec9ad25622c6fa3e7474edf5ee Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 17 Nov 2017 16:30:49 +0200 Subject: [PATCH 295/306] Test --- iguana/exchanges/LP_prices.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 5042955b1..52ec96ee6 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -93,7 +93,7 @@ void LP_pubkey_update(struct LP_pubkeyinfo *pubp,uint32_t baseind,uint32_t relin DL_APPEND(pubp->quotes,pq); // already serialized as only path is via stats_JSON() } pq->price = price; - if ( numutxos != 0 ) + if ( utxocoin != 0 && utxocoin[0] != 0 ) { if ( (scale= pq->scale) == 0 ) pq->scale = scale = 6; @@ -565,7 +565,7 @@ int32_t LP_mypriceset(int32_t *changedp,char *base,char *rel,double price) if ( (pubp= LP_pubkeyadd(G.LP_mypub25519)) != 0 ) { pubp->timestamp = (uint32_t)time(NULL); - LP_pubkey_update(pubp,basepp->ind,relpp->ind,price,0,0,0,0); + LP_pubkey_update(pubp,basepp->ind,relpp->ind,price,0,0,0,0,0); //pubp->matrix[basepp->ind][relpp->ind] = price; //pubp->timestamps[basepp->ind][relpp->ind] = pubp->timestamp; //pubp->matrix[relpp->ind][basepp->ind] = (1. / price); From f13ac23ce93df70f14f49ebfe39248cbf7402540 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 17 Nov 2017 16:37:22 +0200 Subject: [PATCH 296/306] Test --- iguana/exchanges/LP_include.h | 2 +- iguana/exchanges/LP_prices.c | 14 +++++++------- iguana/exchanges/LP_signatures.c | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 7d9b1d9ab..2d928676f 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -369,7 +369,7 @@ struct LP_pubkey_quote struct LP_pubkey_quote *next,*prev; float price; uint32_t maxutxo,aveutxo; - uint8_t baseind,relind,numrelutxos,scale; + uint8_t baseind,relind,numutxos,scale; }; #define LP_MAXPRICEINFOS 256 diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 52ec96ee6..7245c19b2 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -49,10 +49,10 @@ struct LP_cacheinfo } *LP_cacheinfos; -float LP_pubkey_price(int32_t *numrelutxosp,int64_t *avesatoshisp,int64_t *maxsatoshisp,struct LP_pubkeyinfo *pubp,uint32_t baseind,uint32_t relind) +float LP_pubkey_price(int32_t *numutxosp,int64_t *avesatoshisp,int64_t *maxsatoshisp,struct LP_pubkeyinfo *pubp,uint32_t baseind,uint32_t relind) { struct LP_pubkey_quote *pq,*tmp; int32_t scale; int64_t scale64; - *numrelutxosp = 0; + *numutxosp = 0; *avesatoshisp = *maxsatoshisp = 0; DL_FOREACH_SAFE(pubp->quotes,pq,tmp) { @@ -66,7 +66,7 @@ float LP_pubkey_price(int32_t *numrelutxosp,int64_t *avesatoshisp,int64_t *maxsa scale64 *= 10; scale--; } - *numrelutxosp = pq->numrelutxos; + *numutxosp = pq->numutxos; *avesatoshisp = pq->aveutxo * scale64; *maxsatoshisp = pq->maxutxo * scale64; return(pq->price); @@ -103,9 +103,9 @@ void LP_pubkey_update(struct LP_pubkeyinfo *pubp,uint32_t baseind,uint32_t relin scale64 *= 10; scale--; } - if ( numutxos > (1L << sizeof(pq->numrelutxos)) ) - pq->numrelutxos = (1L << sizeof(pq->numrelutxos)) - 1; - else pq->numrelutxos = numutxos; + if ( numutxos > (1L << sizeof(pq->numutxos)) ) + pq->numutxos = (1L << sizeof(pq->numutxos)) - 1; + else pq->numutxos = numutxos; aveutxo = (balance + (scale64>>1)) / numutxos; if ( (ave64= (aveutxo / scale64)) > (1LL << 32) ) ave64 = (1LL << 32) - 1; @@ -114,7 +114,7 @@ void LP_pubkey_update(struct LP_pubkeyinfo *pubp,uint32_t baseind,uint32_t relin max64 = (1LL << 32) - 1; pq->aveutxo = (uint32_t)ave64; pq->maxutxo = (uint32_t)max64; - printf("base.%s rel.%s utxocoin.%s numutxos.%u %u scale64 = %llu, ave %llu, ave32 %u (%llu) max32 %u (%llu)\n",LP_priceinfos[baseind].symbol,LP_priceinfos[relind].symbol,utxocoin,numutxos,pq->numrelutxos,(long long)scale64,(long long)aveutxo,pq->aveutxo,(long long)pq->aveutxo * scale64,pq->maxutxo,(long long)pq->maxutxo * scale64); + //printf("base.%s rel.%s utxocoin.%s numutxos.%u %u scale64 = %llu, ave %llu, ave32 %u (%llu) max32 %u (%llu)\n",LP_priceinfos[baseind].symbol,LP_priceinfos[relind].symbol,utxocoin,numutxos,pq->numutxos,(long long)scale64,(long long)aveutxo,pq->aveutxo,(long long)pq->aveutxo * scale64,pq->maxutxo,(long long)pq->maxutxo * scale64); } } diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index 2253bcc09..6e99495cb 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -472,7 +472,7 @@ char *LP_pricepings(void *ctx,char *myipaddr,int32_t pubsock,char *base,char *re { if ( (numutxos= LP_address_minmax(&balance,&minsize,&maxsize,ap)) != 0 ) { - printf("%s numutxos.%d balance %.8f min %.8f max %.8f\n",base,numutxos,dstr(balance),dstr(minsize),dstr(maxsize)); + //printf("%s numutxos.%d balance %.8f min %.8f max %.8f\n",base,numutxos,dstr(balance),dstr(minsize),dstr(maxsize)); jaddstr(reqjson,"utxocoin",base); jaddnum(reqjson,"n",numutxos); jaddnum(reqjson,"bal",dstr(balance)); From 0c5bb4bf96f15e2993bdebe138bf2f30c7b5c33a Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 17 Nov 2017 16:45:24 +0200 Subject: [PATCH 297/306] Test --- iguana/exchanges/LP_prices.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 7245c19b2..6dcdedb52 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -114,7 +114,11 @@ void LP_pubkey_update(struct LP_pubkeyinfo *pubp,uint32_t baseind,uint32_t relin max64 = (1LL << 32) - 1; pq->aveutxo = (uint32_t)ave64; pq->maxutxo = (uint32_t)max64; - //printf("base.%s rel.%s utxocoin.%s numutxos.%u %u scale64 = %llu, ave %llu, ave32 %u (%llu) max32 %u (%llu)\n",LP_priceinfos[baseind].symbol,LP_priceinfos[relind].symbol,utxocoin,numutxos,pq->numutxos,(long long)scale64,(long long)aveutxo,pq->aveutxo,(long long)pq->aveutxo * scale64,pq->maxutxo,(long long)pq->maxutxo * scale64); + printf("base.%s rel.%s utxocoin.%s balance %.8f numutxos.%u %u scale64 = %llu, ave %llu, ave32 %u (%llu) max32 %u (%llu)\n",LP_priceinfos[baseind].symbol,LP_priceinfos[relind].symbol,utxocoin,dstr(balance),numutxos,pq->numutxos,(long long)scale64,(long long)aveutxo,pq->aveutxo,(long long)pq->aveutxo * scale64,pq->maxutxo,(long long)pq->maxutxo * scale64); + int64_t avesatoshis,maxsatoshis; + price = LP_pubkey_price(&numutxos,&avesatoshis,&maxsatoshis,pubp,baseind,relind); + printf("checkprice %.8f numutxos.%d ave %.8f max %.8f\n",price,numutxos,dstr(avesatoshis),dstr(maxsatoshis)); + } } From 33bf3c8a3cbd6ddf058c1bf3fa9cc45bf1515fb9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 17 Nov 2017 16:51:15 +0200 Subject: [PATCH 298/306] Test --- iguana/exchanges/LP_prices.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 6dcdedb52..53d3acc34 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -103,22 +103,21 @@ void LP_pubkey_update(struct LP_pubkeyinfo *pubp,uint32_t baseind,uint32_t relin scale64 *= 10; scale--; } - if ( numutxos > (1L << sizeof(pq->numutxos)) ) - pq->numutxos = (1L << sizeof(pq->numutxos)) - 1; + if ( numutxos >= 256 ) + pq->numutxos = 255; else pq->numutxos = numutxos; aveutxo = (balance + (scale64>>1)) / numutxos; - if ( (ave64= (aveutxo / scale64)) > (1LL << 32) ) + if ( (ave64= (aveutxo / scale64)) >= (1LL << 32) ) ave64 = (1LL << 32) - 1; max64 = ((maxutxo + (scale64>>1)) / scale64); - if ( max64 > (1LL << 32) ) + if ( max64 >= (1LL << 32) ) max64 = (1LL << 32) - 1; pq->aveutxo = (uint32_t)ave64; pq->maxutxo = (uint32_t)max64; - printf("base.%s rel.%s utxocoin.%s balance %.8f numutxos.%u %u scale64 = %llu, ave %llu, ave32 %u (%llu) max32 %u (%llu)\n",LP_priceinfos[baseind].symbol,LP_priceinfos[relind].symbol,utxocoin,dstr(balance),numutxos,pq->numutxos,(long long)scale64,(long long)aveutxo,pq->aveutxo,(long long)pq->aveutxo * scale64,pq->maxutxo,(long long)pq->maxutxo * scale64); + printf("price %.8f base.%s rel.%s utxocoin.%s balance %.8f numutxos.%u %u scale64 = %llu, ave %llu, ave32 %u (%llu) max32 %u (%llu)\n",price,LP_priceinfos[baseind].symbol,LP_priceinfos[relind].symbol,utxocoin,dstr(balance),numutxos,pq->numutxos,(long long)scale64,(long long)aveutxo,pq->aveutxo,(long long)pq->aveutxo * scale64,pq->maxutxo,(long long)pq->maxutxo * scale64); int64_t avesatoshis,maxsatoshis; price = LP_pubkey_price(&numutxos,&avesatoshis,&maxsatoshis,pubp,baseind,relind); printf("checkprice %.8f numutxos.%d ave %.8f max %.8f\n",price,numutxos,dstr(avesatoshis),dstr(maxsatoshis)); - } } From 9e568b10659713d03ba9e1b5c9f7412f2483c0e5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 17 Nov 2017 16:53:00 +0200 Subject: [PATCH 299/306] Test --- iguana/exchanges/LP_prices.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 53d3acc34..c18403704 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -114,10 +114,10 @@ void LP_pubkey_update(struct LP_pubkeyinfo *pubp,uint32_t baseind,uint32_t relin max64 = (1LL << 32) - 1; pq->aveutxo = (uint32_t)ave64; pq->maxutxo = (uint32_t)max64; - printf("price %.8f base.%s rel.%s utxocoin.%s balance %.8f numutxos.%u %u scale64 = %llu, ave %llu, ave32 %u (%llu) max32 %u (%llu)\n",price,LP_priceinfos[baseind].symbol,LP_priceinfos[relind].symbol,utxocoin,dstr(balance),numutxos,pq->numutxos,(long long)scale64,(long long)aveutxo,pq->aveutxo,(long long)pq->aveutxo * scale64,pq->maxutxo,(long long)pq->maxutxo * scale64); - int64_t avesatoshis,maxsatoshis; - price = LP_pubkey_price(&numutxos,&avesatoshis,&maxsatoshis,pubp,baseind,relind); - printf("checkprice %.8f numutxos.%d ave %.8f max %.8f\n",price,numutxos,dstr(avesatoshis),dstr(maxsatoshis)); + //printf("price %.8f base.%s rel.%s utxocoin.%s balance %.8f numutxos.%u %u scale64 = %llu, ave %llu, ave32 %u (%llu) max32 %u (%llu)\n",price,LP_priceinfos[baseind].symbol,LP_priceinfos[relind].symbol,utxocoin,dstr(balance),numutxos,pq->numutxos,(long long)scale64,(long long)aveutxo,pq->aveutxo,(long long)pq->aveutxo * scale64,pq->maxutxo,(long long)pq->maxutxo * scale64); + //int64_t avesatoshis,maxsatoshis; + //price = LP_pubkey_price(&numutxos,&avesatoshis,&maxsatoshis,pubp,baseind,relind); + //printf("checkprice %.8f numutxos.%d ave %.8f max %.8f\n",price,numutxos,dstr(avesatoshis),dstr(maxsatoshis)); } } From df2fd85218add8aca41ea3f639a6428098179eee Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 17 Nov 2017 17:04:03 +0200 Subject: [PATCH 300/306] Test --- iguana/exchanges/LP_prices.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index c18403704..7c91647aa 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -763,7 +763,7 @@ struct LP_orderbookentry *LP_orderbookentry(char *address,char *base,char *rel,d op->price = price; op->numutxos = numutxos; op->avesatoshis = avesatoshis; - op->maxsatoshis = avesatoshis; + op->maxsatoshis = maxsatoshis; op->pubkey = pubkey; op->timestamp = timestamp; op->depth = balance; From d30ca25ed7b4fe76c1eced37065e09251d0559a5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 17 Nov 2017 17:17:56 +0200 Subject: [PATCH 301/306] Test --- iguana/exchanges/LP_ordermatch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 7e440d990..d1ad77b2d 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -405,7 +405,7 @@ struct LP_utxoinfo *LP_address_myutxopair(struct LP_utxoinfo *butxo,int32_t iamb printf("targetval %.8f vol %.8f price %.8f txfee %.8f %s %s\n",dstr(targetval),relvolume,price,dstr(txfee),coin->symbol,coinaddr); } mini = -1; - if ( targetval != 0 && (mini= LP_nearest_utxovalue(coin,coinaddr,utxos,m,targetval)) >= 0 ) + if ( targetval != 0 && (mini= LP_nearest_utxovalue(coin,coinaddr,utxos,m,targetval+txfee)) >= 0 ) { up = utxos[mini]; utxos[mini] = 0; @@ -1170,7 +1170,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(dstr(destsatoshis),maxprice,txfee,desttxfee); + bestsatoshis = 1.001 * 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 746dc87850fdff4128f43147540c20f7dcb41f62 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 17 Nov 2017 17:35:39 +0200 Subject: [PATCH 302/306] Test --- iguana/exchanges/LP_nativeDEX.c | 2 +- iguana/exchanges/LP_remember.c | 6 ++++++ iguana/exchanges/LP_swap.c | 9 +++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 5b44da252..5c10f50ba 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -96,7 +96,7 @@ struct LP_address_utxo *LP_garbage_collector2; //uint32_t LP_deadman_switch; uint16_t LP_fixed_pairport,LP_publicport; -uint32_t LP_lastnonce,LP_counter; +uint32_t LP_lastnonce,LP_counter,LP_swap_endcritical,LP_swap_critical; int32_t LP_mybussock = -1; int32_t LP_mypubsock = -1; int32_t LP_mypullsock = -1; diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index 7889181bf..f5ea3229a 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -456,6 +456,12 @@ cJSON *LP_swap_json(struct LP_swap_remember *rswap) { cJSON *item,*array; int32_t i; item = cJSON_CreateObject(); + if ( LP_swap_endcritical < LP_swap_critical ) + { + jaddstr(item,"warning","swaps in critical section"); + jaddnum(item,"critical",LP_swap_critical); + jaddnum(item,"endcritical",LP_swap_endcritical); + } jaddnum(item,"expiration",rswap->expiration);// - INSTANTDEX_LOCKTIME*2); jaddnum(item,"tradeid",rswap->tradeid); jaddnum(item,"requestid",rswap->requestid); diff --git a/iguana/exchanges/LP_swap.c b/iguana/exchanges/LP_swap.c index e1c80d505..30329c864 100644 --- a/iguana/exchanges/LP_swap.c +++ b/iguana/exchanges/LP_swap.c @@ -796,6 +796,7 @@ void LP_bobloop(void *_swap) basilisk_bobdeposit_refund(swap,swap->I.putduration); //printf("depositlen.%d\n",swap->bobdeposit.I.datalen); LP_swapsfp_update(&swap->I.req); + LP_swap_critical = (uint32_t)time(NULL); if ( LP_waitfor(swap->N.pair,swap,LP_SWAPSTEP_TIMEOUT*10,LP_verify_otherfee) < 0 ) printf("error waiting for alicefee\n"); else if ( LP_swapdata_rawtxsend(swap->N.pair,swap,0x200,data,maxlen,&swap->bobdeposit,0x100,0) == 0 ) @@ -804,6 +805,7 @@ void LP_bobloop(void *_swap) printf("error waiting for alicepayment\n"); else { + LP_swap_critical = (uint32_t)time(NULL); if ( basilisk_bobscripts_set(swap,0,1) < 0 ) printf("error bobscripts payment\n"); else @@ -813,9 +815,11 @@ void LP_bobloop(void *_swap) else m = swap->I.aliceconfirms; while ( (n= LP_numconfirms(swap->I.alicestr,swap->alicepayment.I.destaddr,swap->alicepayment.I.signedtxid,0,1)) < m ) // sync with alice { + LP_swap_critical = (uint32_t)time(NULL); char str[65];printf("%d wait for alicepayment %s numconfs.%d %s %s\n",n,swap->alicepayment.I.destaddr,m,swap->I.alicestr,bits256_str(str,swap->alicepayment.I.signedtxid)); sleep(10); } + LP_swap_critical = (uint32_t)time(NULL); if ( LP_swapdata_rawtxsend(swap->N.pair,swap,0x8000,data,maxlen,&swap->bobpayment,0x4000,0) == 0 ) printf("error sending bobpayment\n"); //if ( LP_waitfor(swap->N.pair,swap,10,LP_verify_alicespend) < 0 ) @@ -826,6 +830,7 @@ void LP_bobloop(void *_swap) basilisk_bobpayment_reclaim(swap,swap->I.callduration); if ( swap->N.pair >= 0 ) nn_close(swap->N.pair), swap->N.pair = -1; + LP_swap_endcritical = (uint32_t)time(NULL); LP_swapwait(swap->I.req.requestid,swap->I.req.quoteid,LP_atomic_locktime(swap->I.bobstr,swap->I.alicestr)*2,30); } } @@ -857,6 +862,7 @@ void LP_aliceloop(void *_swap) else { LP_swapsfp_update(&swap->I.req); + LP_swap_critical = (uint32_t)time(NULL); if ( LP_swapdata_rawtxsend(swap->N.pair,swap,0x80,data,maxlen,&swap->myfee,0x40,0) == 0 ) printf("error sending alicefee\n"); else if ( LP_waitfor(swap->N.pair,swap,1800,LP_verify_bobdeposit) < 0 ) @@ -870,14 +876,17 @@ void LP_aliceloop(void *_swap) else m = swap->I.aliceconfirms; while ( (n= LP_numconfirms(swap->I.alicestr,swap->alicepayment.I.destaddr,swap->alicepayment.I.signedtxid,0,1)) < m ) { + LP_swap_critical = (uint32_t)time(NULL); char str[65];printf("%d wait for alicepayment %s numconfs.%d %s %s\n",n,swap->alicepayment.I.destaddr,m,swap->I.alicestr,bits256_str(str,swap->alicepayment.I.signedtxid)); sleep(10); } swap->sentflag = 1; + LP_swap_critical = (uint32_t)time(NULL); if ( LP_waitfor(swap->N.pair,swap,1800,LP_verify_bobpayment) < 0 ) printf("error waiting for bobpayment\n"); else { + LP_swap_endcritical = (uint32_t)time(NULL); while ( (n= LP_numconfirms(swap->I.bobstr,swap->bobpayment.I.destaddr,swap->bobpayment.I.signedtxid,0,1)) < swap->I.bobconfirms ) { char str[65];printf("%d wait for bobpayment %s numconfs.%d %s %s\n",n,swap->bobpayment.I.destaddr,swap->I.bobconfirms,swap->I.bobstr,bits256_str(str,swap->bobpayment.I.signedtxid)); From 547c86257e1ee82b05d47d58ab6a0d32a2f20f2a Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 17 Nov 2017 17:53:31 +0200 Subject: [PATCH 303/306] Test --- iguana/exchanges/LP_nativeDEX.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 5c10f50ba..bc988e680 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -17,9 +17,6 @@ // LP_nativeDEX.c // marketmaker // -// destpubkey -// if ( G.LP_pendingswaps != 0 ) return(-1); -// bot safe to exit? // BCH signing // alice waiting for bestprice // From c73392d51567a618b3e78195a08315d9f12569e8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 17 Nov 2017 17:54:16 +0200 Subject: [PATCH 304/306] Test --- 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 2d928676f..163408e7d 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 "15096" +#define LP_BUILD_NUMBER "15256" #define LP_BARTERDEX_VERSION 1 #define LP_MAGICBITS 8 From ca982683cb04f51a4a3f072d501791fb4768ce11 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 17 Nov 2017 19:38:14 +0200 Subject: [PATCH 305/306] BCH fix? --- iguana/exchanges/LP_bitcoin.c | 10 +++++++--- iguana/exchanges/LP_nativeDEX.c | 5 ++++- iguana/exchanges/LP_transaction.c | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_bitcoin.c b/iguana/exchanges/LP_bitcoin.c index a9aa5751b..7c90807b1 100644 --- a/iguana/exchanges/LP_bitcoin.c +++ b/iguana/exchanges/LP_bitcoin.c @@ -2340,7 +2340,7 @@ int32_t iguana_scriptgen(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,int32_t return(scriptlen); } -int32_t bitcoin_scriptget(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,int32_t *hashtypep,uint32_t *sigsizep,uint32_t *pubkeysizep,uint8_t **userdatap,uint32_t *userdatalenp,struct vin_info *vp,uint8_t *scriptsig,int32_t len,int32_t spendtype) +int32_t bitcoin_scriptget(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint32_t *hashtypep,uint32_t *sigsizep,uint32_t *pubkeysizep,uint8_t **userdatap,uint32_t *userdatalenp,struct vin_info *vp,uint8_t *scriptsig,int32_t len,int32_t spendtype) { int32_t j,n,siglen,plen; uint8_t *p2shscript; j = n = 0; @@ -3248,7 +3248,7 @@ int32_t iguana_vinarray_check(cJSON *vinarray,bits256 txid,int32_t vout) int32_t iguana_rwmsgtx(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t isPoS,int32_t height,int32_t rwflag,cJSON *json,uint8_t *serialized,int32_t maxsize,struct iguana_msgtx *msg,bits256 *txidp,char *vpnstr,uint8_t *extraspace,int32_t extralen,cJSON *vins,int32_t suppress_pubkeys,int32_t zcash); -bits256 bitcoin_sigtxid(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t isPoS,int32_t height,uint8_t *serialized,int32_t maxlen,struct iguana_msgtx *msgtx,int32_t vini,uint8_t *spendscript,int32_t spendlen,int32_t hashtype,char *vpnstr,int32_t suppress_pubkeys,int32_t zcash) +bits256 bitcoin_sigtxid(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t isPoS,int32_t height,uint8_t *serialized,int32_t maxlen,struct iguana_msgtx *msgtx,int32_t vini,uint8_t *spendscript,int32_t spendlen,uint32_t hashtype,char *vpnstr,int32_t suppress_pubkeys,int32_t zcash) { int32_t i,len; bits256 sigtxid,txid,revsigtxid; struct iguana_msgtx dest; dest = *msgtx; @@ -3500,8 +3500,12 @@ int32_t iguana_rwmsgtx(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t is memset(sigtxid.bytes,0,sizeof(sigtxid)); if ( vins != 0 && jitem(vins,i) != 0 ) { + uint32_t sighash; iguana_vinobjset(&msg->vins[i],jitem(vins,i),spendscript,sizeof(spendscript)); - sigtxid = bitcoin_sigtxid(taddr,pubtype,p2shtype,isPoS,height,sigser,maxsize*2,msg,i,msg->vins[i].spendscript,msg->vins[i].spendlen,SIGHASH_ALL,vpnstr,suppress_pubkeys,zcash); + sighash = SIGHASH_ALL; + if ( zcash == LP_IS_BITCOINCASH ) + sighash |= SIGHASH_FORKID; + sigtxid = bitcoin_sigtxid(taddr,pubtype,p2shtype,isPoS,height,sigser,maxsize*2,msg,i,msg->vins[i].spendscript,msg->vins[i].spendlen,sighash,vpnstr,suppress_pubkeys,zcash); //printf("after vini.%d vinscript.%p spendscript.%p spendlen.%d (%s)\n",i,msg->vins[i].vinscript,msg->vins[i].spendscript,msg->vins[i].spendlen,jprint(jitem(vins,i),0)); if ( iguana_vinarray_check(vinarray,msg->vins[i].prev_hash,msg->vins[i].prev_vout) < 0 ) jaddi(vinarray,iguana_vinjson(&msg->vins[i],sigtxid)); diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index bc988e680..7de806d8a 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -19,7 +19,9 @@ // // BCH signing // alice waiting for bestprice -// +// MNZ getcoin strangeness +// improve critical section detection when parallel trades +// reduce mem: dont redundant store pubkey utxo info // previously, it used to show amount, kmd equiv, perc // dPoW security -> 4: KMD notarized, 5: BTC notarized, after next notary elections // bigendian architectures need to use little endian for sighash calcs @@ -887,6 +889,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu char *myipaddr=0,version[64]; long filesize,n; int32_t valid,timeout,pubsock=-1; struct LP_peerinfo *mypeer=0; char pushaddr[128],subaddr[128],bindaddr[128],*coins_str=0; cJSON *coinsjson=0; void *ctx = bitcoin_ctx(); sprintf(version,"Marketmaker %s.%s %s rsize.%ld",LP_MAJOR_VERSION,LP_MINOR_VERSION,LP_BUILD_NUMBER,sizeof(struct basilisk_request)); printf("%s %u\n",version,calc_crc32(0,version,(int32_t)strlen(version))); + //test_validate("02000000010e62f95ff5881de8853ce1a5ddbaad731a62879d719367f539103600f1895477010000006b483045022100c684a0871689519bd97f2e61275752124f0f1498360750c87cf99a8acf06fd8c022047e7e62a7bfd481599130e6f40c95833f6ed6f44aa8b6ead7b0ec86a738b98a041210361857e1ba609aadff520a2ca9886fe7548c7154fab2cbe108c3b0e1e7635eb1ffeffffff02a0860100000000001976a9146cfa0a987f4c8f2ffee7e9944ef0c86fcda9671d88ac1e6f0700000000001976a9147f4b7113f9e26d84b150f2cc6d219baaf27f884488ace6b00700"); if ( LP_MAXPRICEINFOS > 256 ) { printf("LP_MAXPRICEINFOS %d wont fit in a uint8_t, need to increase the width of the baseind and relind for struct LP_pubkey_quote\n",LP_MAXPRICEINFOS); diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index 133ee6c41..c1c3ab5bb 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -535,7 +535,7 @@ int32_t iguana_signrawtransaction(void *ctx,char *symbol,uint8_t wiftaddr,uint8_ { if ( msgtx->vins[i].p2shlen != 0 ) { - char coinaddr[64]; uint32_t userdatalen,sigsize,pubkeysize; uint8_t *userdata; int32_t j,k,hashtype,type,flag; struct vin_info mvin,mainvin; bits256 zero; + char coinaddr[64]; uint32_t userdatalen,hashtype,sigsize,pubkeysize; uint8_t *userdata; int32_t j,k,type,flag; struct vin_info mvin,mainvin; bits256 zero; memset(zero.bytes,0,sizeof(zero)); coinaddr[0] = 0; sigsize = 0; From 9501c31536bd464972d144906b4292f3c2b89940 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 19 Nov 2017 11:49:26 +0400 Subject: [PATCH 306/306] Test --- .gitignore | 4 ++ iguana/exchanges/LP_bitcoin.c | 33 +++++++++ iguana/exchanges/LP_include.h | 4 +- iguana/exchanges/LP_nativeDEX.c | 6 +- iguana/exchanges/LP_ordermatch.c | 6 +- iguana/exchanges/LP_transaction.c | 111 +++++++++++++++++++++++++++++- 6 files changed, 155 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index f6a9cbe17..c7962cf39 100755 --- a/.gitignore +++ b/.gitignore @@ -489,3 +489,7 @@ iguana/DB/PRICES/.tmpmarker iguana/DB/KMD/0/.tmpmarker *.swp + +iguana/myipaddr + +iguana/DB/UNSPENTS/.tmpmarker diff --git a/iguana/exchanges/LP_bitcoin.c b/iguana/exchanges/LP_bitcoin.c index 7c90807b1..1444658c9 100644 --- a/iguana/exchanges/LP_bitcoin.c +++ b/iguana/exchanges/LP_bitcoin.c @@ -2583,6 +2583,39 @@ int32_t iguana_calcrmd160(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,char *a return(vp->type); } +uint32_t iguana_vinscriptparse(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,struct vin_info *vp,uint32_t *sigsizep,uint32_t *pubkeysizep,uint32_t *p2shsizep,uint32_t *userdatalenp,uint8_t *vinscript,int32_t scriptlen) +{ + uint32_t hashtype; uint8_t *userdata = 0; + *sigsizep = *pubkeysizep = *p2shsizep = *userdatalenp = 0; + if ( bitcoin_scriptget(taddr,pubtype,p2shtype,&hashtype,sigsizep,pubkeysizep,&userdata,userdatalenp,vp,vinscript,scriptlen,0) < 0 ) + { + printf("iguana_vinscriptparse: error parsing vinscript?\n"); + return(-1); + } + if ( userdata != 0 && *userdatalenp > 0 ) + memcpy(vp->userdata,userdata,*userdatalenp); + if ( vp->type == IGUANA_SCRIPT_P2SH ) + { + *p2shsizep = vp->p2shlen + 1 + (vp->p2shlen >= 0xfd)*2; + //printf("P2SHSIZE.%d\n",*p2shsizep); + } + return(hashtype); +} + +/*char *iguana_scriptget(struct iguana_info *coin,char *scriptstr,char *asmstr,int32_t max,int32_t hdrsi,uint32_t unspentind,bits256 txid,int32_t vout,uint8_t *rmd160,int32_t type,uint8_t *pubkey33) +{ + int32_t scriptlen; uint8_t script[IGUANA_MAXSCRIPTSIZE]; struct vin_info V,*vp = &V; + memset(vp,0,sizeof(*vp)); + scriptstr[0] = 0; + if ( asmstr != 0 ) + asmstr[0] = 0; + if ( pubkey33 != 0 && bitcoin_pubkeylen(pubkey33) > 0 ) + memcpy(vp->signers[0].pubkey,pubkey33,33); + scriptlen = iguana_scriptgen(coin,&vp->M,&vp->N,vp->coinaddr,script,asmstr,rmd160,type,(const struct vin_info *)vp,vout); + init_hexbytes_noT(scriptstr,script,scriptlen); + return(scriptstr); +}*/ + cJSON *bitcoin_txscript(char *asmstr,char **vardata,int32_t numvars) { int32_t i; cJSON *scriptjson,*array; diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 163408e7d..3bea50380 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -150,8 +150,8 @@ struct vin_signer { bits256 privkey; char coinaddr[64]; uint8_t siglen,sig[80],r struct vin_info { struct iguana_msgvin vin; uint64_t amount; cJSON *extras; bits256 sigtxid; - int32_t M,N,validmask,spendlen,type,p2shlen,numpubkeys,numsigs,height,hashtype,userdatalen,suppress_pubkeys,ignore_cltverr; - uint32_t sequence,unspentind; struct vin_signer signers[16]; char coinaddr[65]; + int32_t M,N,validmask,spendlen,type,p2shlen,numpubkeys,numsigs,height,userdatalen,suppress_pubkeys,ignore_cltverr; + uint32_t sequence,unspentind,hashtype; struct vin_signer signers[16]; char coinaddr[65]; uint8_t rmd160[20],spendscript[10000],p2shscript[10000],userdata[10000]; }; diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 7de806d8a..f1b89a40b 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -17,7 +17,7 @@ // LP_nativeDEX.c // marketmaker // -// BCH signing +// BCH signing: FORKID_BCC = 0, FORKID_BTG = 79, // Atomic number AU // alice waiting for bestprice // MNZ getcoin strangeness // improve critical section detection when parallel trades @@ -679,6 +679,8 @@ void LP_initcoins(void *ctx,int32_t pubsock,cJSON *coins) printf("%s ",activecoins[i]); LP_coinfind(activecoins[i]); LP_priceinfoadd(activecoins[i]); + //test_validate("02000000010e62f95ff5881de8853ce1a5ddbaad731a62879d719367f539103600f1895477010000006b483045022100c684a0871689519bd97f2e61275752124f0f1498360750c87cf99a8acf06fd8c022047e7e62a7bfd481599130e6f40c95833f6ed6f44aa8b6ead7b0ec86a738b98a041210361857e1ba609aadff520a2ca9886fe7548c7154fab2cbe108c3b0e1e7635eb1ffeffffff02a0860100000000001976a9146cfa0a987f4c8f2ffee7e9944ef0c86fcda9671d88ac1e6f0700000000001976a9147f4b7113f9e26d84b150f2cc6d219baaf27f884488ace6b00700"); + //getchar(); if ( (coin= LP_coinfind(activecoins[i])) != 0 ) { if ( LP_getheight(coin) <= 0 ) @@ -889,7 +891,6 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu char *myipaddr=0,version[64]; long filesize,n; int32_t valid,timeout,pubsock=-1; struct LP_peerinfo *mypeer=0; char pushaddr[128],subaddr[128],bindaddr[128],*coins_str=0; cJSON *coinsjson=0; void *ctx = bitcoin_ctx(); sprintf(version,"Marketmaker %s.%s %s rsize.%ld",LP_MAJOR_VERSION,LP_MINOR_VERSION,LP_BUILD_NUMBER,sizeof(struct basilisk_request)); printf("%s %u\n",version,calc_crc32(0,version,(int32_t)strlen(version))); - //test_validate("02000000010e62f95ff5881de8853ce1a5ddbaad731a62879d719367f539103600f1895477010000006b483045022100c684a0871689519bd97f2e61275752124f0f1498360750c87cf99a8acf06fd8c022047e7e62a7bfd481599130e6f40c95833f6ed6f44aa8b6ead7b0ec86a738b98a041210361857e1ba609aadff520a2ca9886fe7548c7154fab2cbe108c3b0e1e7635eb1ffeffffff02a0860100000000001976a9146cfa0a987f4c8f2ffee7e9944ef0c86fcda9671d88ac1e6f0700000000001976a9147f4b7113f9e26d84b150f2cc6d219baaf27f884488ace6b00700"); if ( LP_MAXPRICEINFOS > 256 ) { printf("LP_MAXPRICEINFOS %d wont fit in a uint8_t, need to increase the width of the baseind and relind for struct LP_pubkey_quote\n",LP_MAXPRICEINFOS); @@ -1034,6 +1035,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu exit(-1); } LP_initcoins(ctx,pubsock,coinsjson); + G.waiting = 1; LP_passphrase_init(passphrase,jstr(argjson,"gui")); #ifndef FROM_JS diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index d1ad77b2d..bc73ee840 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -757,10 +757,10 @@ int32_t LP_validSPV(char *symbol,char *coinaddr,bits256 txid,int32_t vout) if ( (tx= LP_transactionfind(coin,txid)) != 0 ) { if ( vout < tx->numvouts && tx->height > 0 ) + { + printf("added missing utxo for SPV checking\n"); LP_address_utxoadd((uint32_t)time(NULL),"LP_validSPV",coin,coinaddr,txid,vout,tx->outpoints[vout].value,tx->height,-1); - if ( tx->SPV <= 0 ) - return(-1); - return(0); + } } } if ( (up= LP_address_utxofind(coin,coinaddr,txid,vout)) != 0 ) diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index c1c3ab5bb..d61940855 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -619,6 +619,100 @@ int32_t iguana_signrawtransaction(void *ctx,char *symbol,uint8_t wiftaddr,uint8_ return(complete); } +char *iguana_validaterawtx(void *ctx,struct iguana_info *coin,struct iguana_msgtx *msgtx,uint8_t *extraspace,int32_t extralen,char *rawtx,int32_t mempool,int32_t suppress_pubkeys,int32_t zcash) +{ + bits256 signedtxid; struct iguana_msgvin vin; cJSON *log,*vins,*vouts,*txobj,*retjson; char *signedtx; int32_t plen,height,finalized = 1,i,len,maxsize,numinputs,numoutputs,complete; struct vin_info *V; uint8_t *serialized,*serialized2; uint32_t sigsize,pubkeysize,p2shsize,suffixlen; int64_t inputsum,outputsum; struct iguana_msgvout vout; + char *symbol; uint8_t wiftaddr,taddr,pubtype,p2shtype,isPoS; + height = coin->longestchain; + symbol = coin->symbol; + wiftaddr = coin->wiftaddr; + taddr = coin->taddr; + pubtype = coin->pubtype; + p2shtype = coin->p2shtype; + isPoS = coin->isPoS; + retjson = cJSON_CreateObject(); + inputsum = outputsum = numinputs = numoutputs = 0; + if ( rawtx != 0 && rawtx[0] != 0 ) + { + if ( (strlen(rawtx) & 1) != 0 ) + return(clonestr("{\"error\":\"rawtx hex has odd length\"}")); + memset(msgtx,0,sizeof(*msgtx)); + if ( (txobj= bitcoin_hex2json(taddr,pubtype,p2shtype,isPoS,height,&msgtx->txid,msgtx,rawtx,extraspace,extralen,0,0,suppress_pubkeys,zcash)) != 0 ) + { + maxsize = (int32_t)strlen(rawtx); + serialized = malloc(maxsize); + serialized2 = malloc(maxsize); + V = calloc(numinputs,sizeof(*V)); + if ( (vouts= jarray(&numoutputs,txobj,"vout")) > 0 ) + { + for (i=0; i 0 ) + outputsum += vout.value; + } + } + if ( (vins= jarray(&numinputs,txobj,"vin")) > 0 ) + { + len = 0; + for (i=0; ivins[i].spendscript = V[i].spendscript; + if ( (msgtx->vins[i].spendlen= V[i].spendlen) == 35 ) + { + if ( (plen= bitcoin_pubkeylen(msgtx->vins[i].spendscript+1)) > 0 ) + { + memcpy(V[i].signers[0].pubkey,msgtx->vins[i].spendscript+1,plen); + V[i].suppress_pubkeys = 1; + } + } + V[i].hashtype = iguana_vinscriptparse(taddr,pubtype,p2shtype,&V[i],&sigsize,&pubkeysize,&p2shsize,&suffixlen,msgtx->vins[i].vinscript,msgtx->vins[i].scriptlen); + if ( (V[i].signers[0].siglen= sigsize) > 0 ) + memcpy(V[i].signers[0].sig,msgtx->vins[i].vinscript+1,sigsize); + V[i].userdatalen = suffixlen; + memcpy(V[i].spendscript,msgtx->vins[i].spendscript,msgtx->vins[i].spendlen); + V[i].spendlen = msgtx->vins[i].spendlen; + if ( msgtx->vins[i].sequence < IGUANA_SEQUENCEID_FINAL ) + finalized = 0; + if ( V[i].M == 0 ) + V[i].M = 1; + if ( V[i].N < V[i].M ) + V[i].N = V[i].M; + printf("V %dof%d %.8f (%s) spendscript.[%d] scriptlen.%d\n",V[i].M,V[i].N,dstr(V[i].amount),V[i].coinaddr,V[i].spendlen,V[i].spendlen); + } + complete = bitcoin_verifyvins(ctx,symbol,taddr,pubtype,p2shtype,isPoS,height,&signedtxid,&signedtx,msgtx,serialized2,maxsize,V,SIGHASH_ALL,1,V->suppress_pubkeys,LP_IS_BITCOINCASH); + msgtx->txid = signedtxid; + log = cJSON_CreateArray(); + if ( iguana_interpreter(ctx,log,0,V,numinputs) < 0 ) + jaddstr(retjson,"error","interpreter rejects tx"); + else complete = 1; + jadd(retjson,"interpreter",log); + jaddnum(retjson,"complete",complete); + free(serialized), free(serialized2); + if ( signedtx != 0 ) + free(signedtx); + free(V); + } + } + //char str[65]; printf("got txid.(%s)\n",bits256_str(str,txid)); + } + msgtx->inputsum = inputsum; + msgtx->numinputs = numinputs; + msgtx->outputsum = outputsum; + msgtx->numoutputs = numoutputs; + msgtx->txfee = (inputsum - outputsum); + return(jprint(retjson,1)); +} + +void test_validate(char *signedtx) +{ + char *retstr; uint8_t extraspace[8192]; int32_t mempool=0; struct iguana_msgtx msgtx; struct iguana_info *coin = LP_coinfind("BTC"); + retstr = iguana_validaterawtx(bitcoin_ctx(),coin,&msgtx,extraspace,sizeof(extraspace),signedtx,mempool,0,coin->zcash); + printf("validate test.(%s)\n",retstr); +} + char *basilisk_swap_bobtxspend(bits256 *signedtxidp,uint64_t txfee,char *name,char *symbol,uint8_t wiftaddr,uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t isPoS,uint8_t wiftype,void *ctx,bits256 privkey,bits256 *privkey2p,uint8_t *redeemscript,int32_t redeemlen,uint8_t *userdata,int32_t userdatalen,bits256 utxotxid,int32_t utxovout,char *destaddr,uint8_t *pubkey33,int32_t finalseqid,uint32_t expiration,int64_t *destamountp,uint64_t satoshis,char *changeaddr,char *vinaddr,int32_t suppress_pubkeys,int32_t zcash) { char *rawtxbytes=0,*signedtx=0,str[65],tmpaddr[64],hexstr[999],wifstr[128],_destaddr[64]; uint8_t spendscript[512],addrtype,rmd160[20]; cJSON *txobj,*vins,*obj,*vouts,*item,*privkeys; int32_t completed,spendlen,n,ignore_cltverr=1; struct vin_info V[8]; uint32_t timestamp,locktime = 0,sequenceid = 0xffffffff * finalseqid; bits256 txid; uint64_t value=0,change = 0; struct iguana_msgtx msgtx; struct iguana_info *coin; @@ -933,11 +1027,24 @@ int32_t LP_vins_select(void *ctx,struct iguana_info *coin,int64_t *totalp,int64_ } } if ( dustcombine >= 1 && min0 != 0 && min0->U.value < LP_DUSTCOMBINE_THRESHOLD && (coin->electrum == 0 || min0->SPV > 0) ) - preselected[numpre++] = min0; + { + for (j=0; j= 2 && min1 != 0 && min1->U.value < LP_DUSTCOMBINE_THRESHOLD && (coin->electrum == 0 || min1->SPV > 0) ) - preselected[numpre++] = min1; + { + for (j=0; j