From 38bf61e56c23ebfc11afc87f06ea195621ec05a6 Mon Sep 17 00:00:00 2001 From: Artem Pikulin Date: Sun, 22 Jul 2018 19:28:45 +0700 Subject: [PATCH] #97 Do not request ETOMIC from faucet if balance >= 20. --- iguana/exchanges/LP_commands.c | 11 +---------- iguana/exchanges/LP_socket.c | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 871d04195..1c77bc4f7 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -613,7 +613,7 @@ version\n\ return(jprint(retjson,1)); } #ifndef NOTETOMIC - if (strcmp(coin, "ETOMIC") == 0) { + if (strcmp(coin, "ETOMIC") == 0 && LP_RTsmartbalance(ptr) < 20 * SATOSHIDEN) { if (get_etomic_from_faucet(ptr->smartaddr) != 1) { return(clonestr("{\"error\":\"Could not get ETOMIC from faucet!\"}")); } @@ -641,8 +641,6 @@ version\n\ { cJSON *array; ptr->inactive = 0; - if ( ptr->smartaddr[0] != 0 ) - LP_unspents_load(coin,ptr->smartaddr); LP_unspents_load(coin,ptr->smartaddr); if ( strcmp(ptr->symbol,"KMD") == 0 ) LP_importaddress("KMD",BOTS_BONDADDRESS); @@ -708,13 +706,6 @@ version\n\ { if ( (ptr= LP_coinsearch(coin)) != 0 ) { -#ifndef NOTETOMIC - if (strcmp(coin, "ETOMIC") == 0) { - if (get_etomic_from_faucet(ptr->smartaddr) != 1) { - return(clonestr("{\"error\":\"Could not get ETOMIC from faucet!\"}")); - } - } -#endif ptr->inactive = 0; return(jprint(LP_electrumserver(ptr,jstr(argjson,"ipaddr"),juint(argjson,"port")),1)); } else return(clonestr("{\"error\":\"cant find coind\"}")); diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 71162b67d..8c71e1586 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -1277,7 +1277,21 @@ cJSON *LP_electrumserver(struct iguana_info *coin,char *ipaddr,uint16_t port) jaddnum(retjson,"restart",kickval); } } +#ifndef NOTETOMIC + if (strcmp(coin->symbol, "ETOMIC") == 0) { + cJSON *balance = cJSON_CreateObject(); + electrum_address_getbalance(coin->symbol, ep, &balance, coin->smartaddr); + int64_t confirmed = get_cJSON_int(balance, "confirmed"); + int64_t unconfirmed = get_cJSON_int(balance, "unconfirmed"); + if ((confirmed + unconfirmed) < 20 * SATOSHIDEN && get_etomic_from_faucet(coin->smartaddr) != 1) { + coin->inactive = (uint32_t)time(NULL); + coin->electrum = ep->prev; + cJSON_Delete(balance); + return(cJSON_Parse("{\"error\":\"Could not get ETOMIC from faucet!\"}")); + } + cJSON_Delete(balance); + } +#endif //printf("(%s)\n",jprint(retjson,0)); return(retjson); } -