diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index b2b9e7026..c122ff233 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -109,7 +109,6 @@ myprice(base, rel)\n\ enable(coin)\n\ disable(coin)\n\ notarizations(coin)\n\ -parselog()\n\ statsdisp(starttime=0, endtime=0, gui="", pubkey="", base="", rel="")\n\ tradesarray(base, rel, starttime=-timescale*1024, endtime=, timescale=60) -> [timestamp, high, low, open, close, relvolume, basevolume, aveprice, numtrades]\n\ pricearray(base, rel, starttime=0, endtime=0, timescale=60) -> [timestamp, avebid, aveask, highbid, lowask]\n\ @@ -269,12 +268,6 @@ zeroconf_claim(address, expiration=0)\n\ { return(LP_portfolio()); } - else if ( strcmp(method,"parselog") == 0 ) - { - bits256 zero; - memset(zero.bytes,0,sizeof(zero)); - return(jprint(LP_statslog_disp(2000000000,2000000000,"",zero,0,0),1)); - } else if ( strcmp(method,"statsdisp") == 0 ) { return(jprint(LP_statslog_disp(juint(argjson,"starttime"),juint(argjson,"endtime"),jstr(argjson,"gui"),jbits256(argjson,"pubkey"),jstr(argjson,"base"),jstr(argjson,"rel")),1)); @@ -299,11 +292,12 @@ zeroconf_claim(address, expiration=0)\n\ return(basilisk_swapentries(base,rel,jint(argjson,"limit"))); else return(basilisk_swaplist(0,0)); } - else if ( strcmp(method,"dynamictrust") == 0 ) + /*else if ( strcmp(method,"dynamictrust") == 0 ) { struct LP_address *ap; char *coinaddr; if ( (ptr= LP_coinsearch("KMD")) != 0 && (coinaddr= jstr(argjson,"address")) != 0 ) { + LP_zeroconf_deposits(ptr); if ( (ap= LP_addressfind(ptr,coinaddr)) != 0 ) { retjson = cJSON_CreateObject(); @@ -314,7 +308,7 @@ zeroconf_claim(address, expiration=0)\n\ } } return(clonestr("{\"error\":\"cant find address\"}")); - } + }*/ else if ( (retstr= LP_istradebots_command(ctx,pubsock,method,argjson)) != 0 ) return(retstr); if ( base[0] != 0 && rel[0] != 0 ) @@ -630,15 +624,12 @@ zeroconf_claim(address, expiration=0)\n\ else if ( strcmp(method,"tradestatus") == 0 ) { - bits256 zero; cJSON *tmpjson; + bits256 zero; cJSON *tmpjson; struct LP_quoteinfo Q; LP_tradecommand_log(argjson); - //printf("GOT TRADESTATUS! %s\n",jprint(argjson,0)); - if ( LP_statslog_parse() > 0 ) - { - memset(zero.bytes,0,sizeof(zero)); - if ( (tmpjson= LP_statslog_disp(2000000000,2000000000,"",zero,0,0))) // pending swaps - free_json(tmpjson); - } + 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,0); + LP_tradecommand_log(argjson); + printf("%-4d (%-10u %10u) %12s id.%22llu %5s/%-5s %12.8f -> %11.8f price %11.8f | RT.%d %d\n",(uint32_t)time(NULL) % 3600,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,LP_RTcount,LP_swapscount); retstr = clonestr("{\"result\":\"success\"}"); } else if ( strcmp(method,"wantnotify") == 0 ) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index aced90d80..9533d7199 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -17,23 +17,25 @@ // LP_nativeDEX.c // marketmaker // -// feature requests: // alice waiting for bestprice -// USD paxprice based USDvalue in portfolio // cancel bid/ask // delay swap credit back until notarization // electrum dynamic trust over 1000 // https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki for signing BCH/BTG // -// bugs, validations: // portfolio value based on ask? // verify encrypted destpubkey, broadcast:0 setprice +// USD paxprice based USDvalue in portfolio // improve critical section detection when parallel trades -// 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 - +// dont change error messages: +// if (enable_electrum_coin_output_data.error == 'couldnt find coin locally installed') { //{error: "couldnt find coin locally installed", coin: "BTC"} +//if (enable_native_coin_output_data.error == 'couldnt find coin locally installed') { //{error: "couldnt find coin locally installed", coin: "BTC"} +// if (!data.error === true && data.error !== 'coin is disabled') { +// if (bot_output_data.error == 'not enough funds') { + #include long LP_cjson_allocated,LP_cjson_total,LP_cjson_count; @@ -89,7 +91,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,LP_cJSONmutex,LP_logmutex; +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,LP_logmutex,LP_statslogmutex; int32_t LP_canbind; char *Broadcaststr,*Reserved_msgs[2][1000]; int32_t num_Reserved_msgs[2],max_Reserved_msgs[2]; @@ -1127,6 +1129,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu portable_mutex_init(&LP_tradebotsmutex); portable_mutex_init(&LP_cJSONmutex); portable_mutex_init(&LP_logmutex); + portable_mutex_init(&LP_statslogmutex); myipaddr = clonestr("127.0.0.1"); #ifndef _WIN32 #ifndef FROM_JS diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 78ba7552f..4a5617469 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -496,7 +496,7 @@ int32_t LP_connectstartbob(void *ctx,int32_t pubsock,cJSON *argjson,char *base,c bits256 zero; memset(zero.bytes,0,sizeof(zero)); LP_reserved_msg(1,base,rel,zero,jprint(retjson,0)); - //LP_reserved_msg(0,base,rel,zero,jprint(retjson,0)); + LP_reserved_msg(0,base,rel,zero,jprint(retjson,0)); free_json(retjson); retval = 0; } else printf("error launching swaploop\n"); diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index 9c3dd87cd..f2f9cf13b 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -30,7 +30,6 @@ static uint32_t LP_requests,LP_reserveds,LP_connects,LP_connecteds,LP_tradestatu void LP_tradecommand_log(cJSON *argjson) { static FILE *logfp; char *jsonstr; - portable_mutex_lock(&LP_logmutex); if ( logfp == 0 ) { if ( (logfp= fopen(LP_STATSLOG_FNAME,"rb+")) != 0 ) @@ -44,7 +43,6 @@ void LP_tradecommand_log(cJSON *argjson) free(jsonstr); fflush(logfp); } - portable_mutex_unlock(&LP_logmutex); } void LP_statslog_parseline(cJSON *lineobj) diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index 99e84135e..a7e70ab5f 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -1126,7 +1126,7 @@ int32_t LP_vins_select(void *ctx,struct iguana_info *coin,int64_t *totalp,int64_ if ( LP_validSPV(coin->symbol,coin->smartaddr,up->U.txid,up->U.vout) < 0 ) continue; } - if ( LP_allocated(up->U.txid,up->U.vout) != 0 ) + if ( bits256_cmp(utxotxid,up->U.txid) != 0 && LP_allocated(up->U.txid,up->U.vout) != 0 ) continue; up->spendheight = 1; total += up->U.value; diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index d0c26c788..6669963be 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -419,7 +419,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; int64_t value; bits256 txid; uint32_t now; + 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; LP_address(coin,coin->smartaddr); LP_listunspent_issue(coin->symbol,coin->smartaddr,2); if ( (ap= LP_addressfind(coin,coin->smartaddr)) == 0 ) @@ -448,6 +448,9 @@ 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); value = LP_listunspent_parseitem(coin,&txid,&vout,&height,item); + if ( (txobj= LP_gettxout(coin->symbol,coin->symbol,txid,vout)) == 0 ) + continue; + else free_json(txobj); 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));