From 4fcdad97c8dabe1cc44d71f3fdba4decfd9529fb Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Nov 2017 17:24:21 +0400 Subject: [PATCH 01/17] 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 9dcd04f35..5b53a63e9 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -790,7 +790,7 @@ void LP_initpeers(int32_t pubsock,struct LP_peerinfo *mypeer,char *myipaddr,uint void LP_pubkeysloop(void *ctx) { static uint32_t lasttime; - struct LP_pubkey_info *pubp,*ptmp; //cJSON *retjson; struct iguana_info *coin,*tmp; + //struct LP_pubkey_info *pubp,*ptmp; //cJSON *retjson; struct iguana_info *coin,*tmp; strcpy(LP_pubkeysloop_stats.name,"LP_pubkeysloop"); LP_pubkeysloop_stats.threshold = 15000.; sleep(10); From 30422c2593cc638854607d366f4d5bc664d0d320 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Nov 2017 17:37:23 +0400 Subject: [PATCH 02/17] Test --- iguana/exchanges/LP_rpc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index d3376beb3..b47319391 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -665,7 +665,7 @@ cJSON *LP_listunspent(char *symbol,char *coinaddr) { if ( ap->unspenttime == 0 ) usecache = 0; - else if ( G.LP_pendingswaps != 0 && time(NULL) > ap->unspenttime+3 ) + else if ( G.LP_pendingswaps != 0 && time(NULL) > ap->unspenttime+1 ) usecache = 0; if ( usecache != 0 && (retstr= LP_unspents_filestr(symbol,coinaddr)) != 0 ) { From c58aeb278b2b186cfd194e01a637c986107a3985 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Nov 2017 17:42:30 +0400 Subject: [PATCH 03/17] 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 88e0f831a..2b32ac8ac 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -416,7 +416,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 < ratio-1 ) { - if ( 1 ) + if ( 0 ) { int32_t i; for (i=0; i Date: Fri, 24 Nov 2017 19:53:39 +0400 Subject: [PATCH 04/17] Test --- iguana/exchanges/LP_stats.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index d6ce19cdb..02ef164f0 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -519,7 +519,7 @@ struct LP_ohlc cJSON *LP_ohlc_json(struct LP_ohlc *bar) { cJSON *item; - if ( bar->numtrades != 0 && bar->relsum > SMALLVAL && bar->basesum > SMALLVAL ) + //if ( bar->numtrades != 0 && bar->relsum > SMALLVAL && bar->basesum > SMALLVAL ) { item = cJSON_CreateArray(); jaddinum(item,bar->timestamp); @@ -529,7 +529,9 @@ cJSON *LP_ohlc_json(struct LP_ohlc *bar) jaddinum(item,bar->close); jaddinum(item,bar->relsum); jaddinum(item,bar->basesum); - jaddinum(item,bar->relsum / bar->basesum); + if ( bar->basesum != 0 ) + jaddinum(item,bar->relsum / bar->basesum); + else jaddinum(item,0); jaddinum(item,bar->numtrades); return(item); } From f142c0357435c1358ea52406ff3e515ab9f70c23 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Nov 2017 19:56:49 +0400 Subject: [PATCH 05/17] Test --- iguana/exchanges/LP_transaction.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index a7e70ab5f..f8f0f2c5c 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -1288,7 +1288,7 @@ char *LP_createrawtransaction(cJSON **txobjp,int32_t *numvinsp,struct iguana_inf char *LP_withdraw(struct iguana_info *coin,cJSON *argjson) { static void *ctx; - int32_t iter,utxovout,autofee,completed=0,maxV,numvins,numvouts,datalen,suppress_pubkeys; bits256 privkey; char changeaddr[64],vinaddr[64],str[65],*signedtx=0,*rawtx=0; struct vin_info *V; uint32_t locktime; cJSON *retjson,*outputs,*vins=0,*txobj=0,*privkeys=0; struct iguana_msgtx msgtx; bits256 utxotxid,signedtxid; uint64_t txfee,newtxfee=10000; + int32_t iter,i,utxovout,autofee,completed=0,maxV,numvins,numvouts,datalen,suppress_pubkeys; bits256 privkey; char changeaddr[64],vinaddr[64],str[65],*signedtx=0,*rawtx=0; struct vin_info *V; uint32_t locktime; cJSON *retjson,*item,*outputs,*vins=0,*txobj=0,*privkeys=0; struct iguana_msgtx msgtx; bits256 utxotxid,signedtxid; uint64_t txfee,newtxfee=10000; if ( ctx == 0 ) ctx = bitcoin_ctx(); if ( (outputs= jarray(&numvouts,argjson,"outputs")) == 0 ) @@ -1342,6 +1342,11 @@ char *LP_withdraw(struct iguana_info *coin,cJSON *argjson) printf("txfee %.8f -> newtxfee %.8f\n",dstr(txfee),dstr(newtxfee)); } else break; } else break; + for (i=0; i Date: Fri, 24 Nov 2017 20:02:34 +0400 Subject: [PATCH 06/17] 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 ca8016bab..983dd1637 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -45,6 +45,7 @@ int32_t _LP_inuse_delete(bits256 txid,int32_t vout) if ( (lp= _LP_inuse_find(txid,vout)) != 0 ) { ind = lp->ind; + char str[65]; printf("_LP_inuse_delete removing %s/v%d\n",bits256_str(str,txid),vout); *lp = LP_inuse[--LP_numinuse]; lp->ind = ind; memset(&LP_inuse[LP_numinuse],0,sizeof(struct LP_inuse_info)); @@ -52,7 +53,6 @@ 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); return(-1); } @@ -423,7 +423,7 @@ 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,*txobj; int64_t value; bits256 txid; uint32_t now; + struct LP_address *ap; struct LP_address_utxo *up,*tmp; int32_t i,n,m,vout,height; cJSON *array,*item,*txobj; 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 ) @@ -447,7 +447,7 @@ struct LP_address *LP_address_utxo_reset(struct iguana_info *coin) 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)); + else m++; } - printf("added %d from listunspents\n",n); + printf("added %d from listunspents\n",m); } free_json(array); } From 90643fec8f93f97da660f16e91bc29aea8e525e3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Nov 2017 20:09:08 +0400 Subject: [PATCH 07/17] Test --- iguana/exchanges/LP_transaction.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index f8f0f2c5c..66c61b2cb 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -1210,7 +1210,7 @@ char *LP_createrawtransaction(cJSON **txobjp,int32_t *numvinsp,struct iguana_inf return(0); } } - if ( (ap= LP_address_utxo_reset(coin)) == 0 ) + 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 ) @@ -1288,7 +1288,7 @@ char *LP_createrawtransaction(cJSON **txobjp,int32_t *numvinsp,struct iguana_inf char *LP_withdraw(struct iguana_info *coin,cJSON *argjson) { static void *ctx; - int32_t iter,i,utxovout,autofee,completed=0,maxV,numvins,numvouts,datalen,suppress_pubkeys; bits256 privkey; char changeaddr[64],vinaddr[64],str[65],*signedtx=0,*rawtx=0; struct vin_info *V; uint32_t locktime; cJSON *retjson,*item,*outputs,*vins=0,*txobj=0,*privkeys=0; struct iguana_msgtx msgtx; bits256 utxotxid,signedtxid; uint64_t txfee,newtxfee=10000; + int32_t iter,i,utxovout,autofee,completed=0,maxV,numvins,numvouts,datalen,suppress_pubkeys; bits256 privkey; struct LP_address *ap; char changeaddr[64],vinaddr[64],str[65],*signedtx=0,*rawtx=0; struct vin_info *V; uint32_t locktime; cJSON *retjson,*item,*outputs,*vins=0,*txobj=0,*privkeys=0; struct iguana_msgtx msgtx; bits256 utxotxid,signedtxid; uint64_t txfee,newtxfee=10000; if ( ctx == 0 ) ctx = bitcoin_ctx(); if ( (outputs= jarray(&numvouts,argjson,"outputs")) == 0 ) @@ -1317,6 +1317,8 @@ char *LP_withdraw(struct iguana_info *coin,cJSON *argjson) V = malloc(maxV * sizeof(*V)); for (iter=0; iter<2; iter++) { + if ( (ap= LP_address_utxo_reset(coin)) == 0 ) + return(0); privkeys = cJSON_CreateArray(); vins = cJSON_CreateArray(); memset(V,0,sizeof(*V) * maxV); From 843fd4dee3426d1f3137e62d8ccf338dfa5ea153 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Nov 2017 20:14:31 +0400 Subject: [PATCH 08/17] Test --- iguana/exchanges/LP_utxo.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 983dd1637..2e8f65e01 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -268,11 +268,12 @@ 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); + if ( coin->electrum != 0 ) + 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)); + 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 ) @@ -281,7 +282,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 ) @@ -292,7 +293,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; @@ -303,7 +304,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; @@ -314,7 +315,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 e8d46c4acb26d9cd49f22b475ba4d3b56c476e6b Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Nov 2017 20:20:29 +0400 Subject: [PATCH 09/17] Test --- iguana/exchanges/LP_transaction.c | 5 +++-- iguana/exchanges/LP_utxo.c | 18 +++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index 66c61b2cb..2c9fa38cc 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -1315,10 +1315,10 @@ char *LP_withdraw(struct iguana_info *coin,cJSON *argjson) privkey = LP_privkey(vinaddr,coin->taddr); maxV = LP_MAXVINS; V = malloc(maxV * sizeof(*V)); + if ( (ap= LP_address_utxo_reset(coin)) == 0 ) + return(0); for (iter=0; iter<2; iter++) { - if ( (ap= LP_address_utxo_reset(coin)) == 0 ) - return(0); privkeys = cJSON_CreateArray(); vins = cJSON_CreateArray(); memset(V,0,sizeof(*V) * maxV); @@ -1347,6 +1347,7 @@ char *LP_withdraw(struct iguana_info *coin,cJSON *argjson) for (i=0; iind; - char str[65]; printf("_LP_inuse_delete removing %s/v%d\n",bits256_str(str,txid),vout); + printf("_LP_inuse_delete removing %s/v%d\n",bits256_str(str,txid),vout); *lp = LP_inuse[--LP_numinuse]; lp->ind = ind; memset(&LP_inuse[LP_numinuse],0,sizeof(struct LP_inuse_info)); for (ind=0; indcoinaddr,coinaddr) != 0 ) printf("UNEXPECTED coinaddr mismatch (%s) != (%s)\n",ap->coinaddr,coinaddr); - if ( coin->electrum != 0 ) + if ( 0 && coin->electrum != 0 ) 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)); + //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 ) @@ -282,7 +282,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 ) @@ -293,7 +293,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; @@ -304,7 +304,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; @@ -315,7 +315,7 @@ printf("LP_address_utxo_ptrs skips %s/v%u due to SPV.%d ht.%d\n",bits256_str(str utxos[n++] = up; if ( n >= max ) break; - } else printf("LP_allocated skip\n"); + } //else printf("LP_allocated skip\n"); } else { From a4a3a46aa7239e6e5d156c0fc64fcfb9686363b4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Nov 2017 20:24:08 +0400 Subject: [PATCH 10/17] Test --- iguana/exchanges/LP_transaction.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index 2c9fa38cc..3edd206b1 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -1341,15 +1341,15 @@ char *LP_withdraw(struct iguana_info *coin,cJSON *argjson) if ( strcmp(coin->symbol,"BTC") == 0 ) { newtxfee = LP_txfeecalc(coin,0,datalen); - printf("txfee %.8f -> newtxfee %.8f\n",dstr(txfee),dstr(newtxfee)); + printf("txfee %.8f -> newtxfee %.8f, numvins.%d\n",dstr(txfee),dstr(newtxfee),numvins); + for (i=0; i Date: Fri, 24 Nov 2017 20:25:43 +0400 Subject: [PATCH 11/17] Test --- iguana/exchanges/LP_transaction.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index 3edd206b1..d4b769d15 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -1282,6 +1282,7 @@ char *LP_createrawtransaction(cJSON **txobjp,int32_t *numvinsp,struct iguana_inf { } else printf("error making rawtx suppress.%d\n",suppress_pubkeys); *txobjp = txobj; + *numvinsp = numvins; return(rawtxbytes); } @@ -1350,6 +1351,7 @@ char *LP_withdraw(struct iguana_info *coin,cJSON *argjson) } } else break; } else break; + printf("free vars for second iter\n"); free_json(vins), vins = 0; free_json(txobj), txobj = 0; free_json(privkeys), privkeys = 0; From a6e5535774e08c054466d29afbf8c6a8c5c796f1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Nov 2017 20:29:45 +0400 Subject: [PATCH 12/17] Test --- iguana/exchanges/LP_transaction.c | 3 +-- iguana/exchanges/LP_utxo.c | 7 ++++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index d4b769d15..387d156e8 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -1346,12 +1346,11 @@ char *LP_withdraw(struct iguana_info *coin,cJSON *argjson) for (i=0; iind; - printf("_LP_inuse_delete removing %s/v%d\n",bits256_str(str,txid),vout); - *lp = LP_inuse[--LP_numinuse]; + if ( LP_numinuse > 0 ) + *lp = LP_inuse[--LP_numinuse]; lp->ind = ind; memset(&LP_inuse[LP_numinuse],0,sizeof(struct LP_inuse_info)); + printf("_LP_inuse_delete deleted %s/v%d find.%p\n",bits256_str(str,txid),vout,_LP_inuse_find(txid,vout)); for (ind=0; ind Date: Fri, 24 Nov 2017 20:32:14 +0400 Subject: [PATCH 13/17] 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 bb0f294c6..abd62173f 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -274,7 +274,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 ) @@ -316,7 +316,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 %u\n",LP_allocated(up->U.txid,up->U.vout)); } else { From 9089bd83d9556c46dd4c4d845799928b8175040e Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Nov 2017 20:35:35 +0400 Subject: [PATCH 14/17] Test --- iguana/exchanges/LP_transaction.c | 4 ++-- iguana/exchanges/LP_utxo.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index 387d156e8..752964c5d 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -1316,10 +1316,10 @@ char *LP_withdraw(struct iguana_info *coin,cJSON *argjson) privkey = LP_privkey(vinaddr,coin->taddr); maxV = LP_MAXVINS; V = malloc(maxV * sizeof(*V)); - if ( (ap= LP_address_utxo_reset(coin)) == 0 ) - return(0); for (iter=0; iter<2; iter++) { + if ( (ap= LP_address_utxo_reset(coin)) == 0 ) + return(0); privkeys = cJSON_CreateArray(); vins = cJSON_CreateArray(); memset(V,0,sizeof(*V) * maxV); diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index abd62173f..44d0162dd 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -49,7 +49,7 @@ int32_t _LP_inuse_delete(bits256 txid,int32_t vout) *lp = LP_inuse[--LP_numinuse]; lp->ind = ind; memset(&LP_inuse[LP_numinuse],0,sizeof(struct LP_inuse_info)); - printf("_LP_inuse_delete deleted %s/v%d find.%p\n",bits256_str(str,txid),vout,_LP_inuse_find(txid,vout)); + //printf("_LP_inuse_delete deleted %s/v%d find.%p\n",bits256_str(str,txid),vout,_LP_inuse_find(txid,vout)); for (ind=0; indutxos,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 ) @@ -316,7 +316,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 %u\n",LP_allocated(up->U.txid,up->U.vout)); + } //else printf("LP_allocated skip %u\n",LP_allocated(up->U.txid,up->U.vout)); } else { From 6489816e83284618e11f1d837ec61a74acdfef3d Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Nov 2017 20:39:26 +0400 Subject: [PATCH 15/17] 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 44d0162dd..93eca3034 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -49,7 +49,7 @@ int32_t _LP_inuse_delete(bits256 txid,int32_t vout) *lp = LP_inuse[--LP_numinuse]; lp->ind = ind; memset(&LP_inuse[LP_numinuse],0,sizeof(struct LP_inuse_info)); - //printf("_LP_inuse_delete deleted %s/v%d find.%p\n",bits256_str(str,txid),vout,_LP_inuse_find(txid,vout)); + printf("_LP_inuse_delete mark as free %s/v%d find.%p\n",bits256_str(str,txid),vout,_LP_inuse_find(txid,vout)); for (ind=0; ind Date: Fri, 24 Nov 2017 22:41:33 +0400 Subject: [PATCH 16/17] Test --- iguana/exchanges/LP_nativeDEX.c | 5 +++-- iguana/exchanges/LP_socket.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 5b53a63e9..270193c63 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -18,11 +18,12 @@ // marketmaker // // alice waiting for bestprice -// cancel bid/ask +// big BTC swaps // delay swap credit back until notarization -// electrum dynamic trust over 1000 +// electrum dynamic trust over 1000 tx // https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki for signing BCH/BTG // +// cancel bid/ask // portfolio value based on ask? // verify encrypted destpubkey, broadcast:0 setprice // USD paxprice based USDvalue in portfolio diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 0a9ef7f09..7d1762e96 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -417,7 +417,7 @@ cJSON *electrum_submit(char *symbol,struct electrum_info *ep,cJSON **retjsonp,ch { *retjsonp = 0; sprintf(stratumreq,"{ \"jsonrpc\":\"2.0\", \"id\": %u, \"method\":\"%s\", \"params\": %s }\n",ep->stratumid,method,params); -//printf("%s %s",symbol,stratumreq); +printf("%s %s",symbol,stratumreq); memset(ep->buf,0,ep->bufsize); sitem = electrum_sitem(ep,stratumreq,timeout,retjsonp); portable_mutex_lock(&ep->mutex); // this helps performance! From 87dddf4f8ff3334355a93c2840971163809eaae1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Nov 2017 22:49:49 +0400 Subject: [PATCH 17/17] Test --- iguana/exchanges/LP_socket.c | 2 +- iguana/exchanges/LP_swap.c | 30 ++++++++++++++++++------------ 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 7d1762e96..0a9ef7f09 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -417,7 +417,7 @@ cJSON *electrum_submit(char *symbol,struct electrum_info *ep,cJSON **retjsonp,ch { *retjsonp = 0; sprintf(stratumreq,"{ \"jsonrpc\":\"2.0\", \"id\": %u, \"method\":\"%s\", \"params\": %s }\n",ep->stratumid,method,params); -printf("%s %s",symbol,stratumreq); +//printf("%s %s",symbol,stratumreq); memset(ep->buf,0,ep->bufsize); sitem = electrum_sitem(ep,stratumreq,timeout,retjsonp); portable_mutex_lock(&ep->mutex); // this helps performance! diff --git a/iguana/exchanges/LP_swap.c b/iguana/exchanges/LP_swap.c index fd108821d..c19c10df2 100644 --- a/iguana/exchanges/LP_swap.c +++ b/iguana/exchanges/LP_swap.c @@ -132,18 +132,21 @@ void basilisk_swap_finished(struct basilisk_swap *swap) 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 + swap->I.finished = (uint32_t)time(NULL);*/ + if ( swap->I.finished == 0 ) { - LP_availableset(swap->alicepayment.utxotxid,swap->alicepayment.utxovout); - LP_availableset(swap->myfee.utxotxid,swap->myfee.utxovout); + 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 basilisk_rawtx_purge(&swap->bobdeposit); basilisk_rawtx_purge(&swap->bobpayment); @@ -739,7 +742,7 @@ uint32_t LP_swapdata_rawtxsend(int32_t pairsock,struct basilisk_swap *swap,uint3 return(0); } -int32_t LP_swapwait(uint32_t requestid,uint32_t quoteid,int32_t duration,int32_t sleeptime) +int32_t LP_swapwait(struct basilisk_swap *swap,uint32_t requestid,uint32_t quoteid,int32_t duration,int32_t sleeptime) { char *retstr; cJSON *retjson=0; uint32_t expiration = (uint32_t)(time(NULL) + duration); printf("wait %d:%d for SWAP.(r%u/q%u) to complete\n",duration,sleeptime,requestid,quoteid); @@ -753,7 +756,10 @@ int32_t LP_swapwait(uint32_t requestid,uint32_t quoteid,int32_t duration,int32_t if ( (retjson= cJSON_Parse(retstr)) != 0 ) { if ( jstr(retjson,"status") != 0 && strcmp(jstr(retjson,"status"),"finished") == 0 ) + { + swap->I.finished = (uint32_t)time(NULL); break; + } //else printf("NOT FINISHED.(%s)\n",jprint(retjson,0)); free_json(retjson); retjson = 0; @@ -838,7 +844,7 @@ void LP_bobloop(void *_swap) 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,swap->I.aliceconfirms == 0 ? 3 : 30); + LP_swapwait(swap,swap->I.req.requestid,swap->I.req.quoteid,LP_atomic_locktime(swap->I.bobstr,swap->I.alicestr)*2,swap->I.aliceconfirms == 0 ? 3 : 30); } } } @@ -919,7 +925,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->I.bobstr,swap->I.alicestr)*2,swap->I.aliceconfirms == 0 ? 3 : 30); + LP_swapwait(swap,swap->I.req.requestid,swap->I.req.quoteid,LP_atomic_locktime(swap->I.bobstr,swap->I.alicestr)*2,swap->I.aliceconfirms == 0 ? 3 : 30); } } }