From fa29d5d1fe02d7761fd46fef499e249c09fada68 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 20 Feb 2018 19:04:51 +0200 Subject: [PATCH] estimatesmartfee --- iguana/exchanges/LP_include.h | 2 +- iguana/exchanges/LP_rpc.c | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index c19a2c85e..2fa885d56 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -305,7 +305,7 @@ struct iguana_info int32_t numutxos,notarized,longestchain,firstrefht,firstscanht,lastscanht,height; uint16_t busport,did_addrutxo_reset; uint32_t txversion,dPoWtime,lastresetutxo,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[128],smartaddr[64],userpass[1024],serverport[128],instantdex_address[64]; + char symbol[128],smartaddr[64],userpass[1024],serverport[128],instantdex_address[64],estimatefeestr[32]; // portfolio double price_kmd,force,perc,goal,goalperc,relvolume,rate; void *electrum; void *ctx; diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 0e2daec6b..6784d593d 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -602,14 +602,17 @@ cJSON *LP_importprivkey(char *symbol,char *wifstr,char *label,int32_t flag) double _LP_getestimatedrate(struct iguana_info *coin) { - char buf[512],*retstr=0; int32_t numblocks; cJSON *errjson,*retjson; double rate = 0.00000020; + char buf[512],*retstr=0; int32_t numblocks,err=0; cJSON *errjson,*retjson; double rate = 0.00000020; if ( coin->rate < 0. || time(NULL) > coin->ratetime+30 ) { + if ( coin->estimatefeestr[0] == 0 ) + strcpy(coin->estimatefeestr,"estimatefee"); numblocks = strcmp(coin->symbol,"BTC") == 0 ? 6 : 2; +again: if ( coin->electrum == 0 ) { sprintf(buf,"[%d]",numblocks); - retstr = LP_apicall(coin,"estimatefee",buf); + retstr = LP_apicall(coin,coin->estimatefeestr,buf); } else { @@ -621,7 +624,10 @@ double _LP_getestimatedrate(struct iguana_info *coin) if ( retstr[0] == '{' && (errjson= cJSON_Parse(retstr)) != 0 ) { if ( jobj(errjson,"error") != 0 ) + { rate = 0.; + err++; + } free_json(errjson); } else if ( retstr[0] != '-' ) @@ -638,6 +644,11 @@ double _LP_getestimatedrate(struct iguana_info *coin) coin->ratetime = (uint32_t)time(NULL); } free(retstr); + if ( err == 1 && coin->electrum == 0 && strcmp("BTC",coin->symbol) == 0 ) + { + strcpy(coin->estimatefeestr,"estimatesmartfee"); + goto again; + } } else rate = coin->rate; } else rate = coin->rate; return(rate);