From f036d8cee58d55adac59472b559dc73e32df4773 Mon Sep 17 00:00:00 2001 From: Artem Pikulin Date: Mon, 19 Mar 2018 13:58:02 +0700 Subject: [PATCH] Add ETH/ERC20 balance to few API methods. --- iguana/exchanges/LP_coins.c | 7 +++++++ iguana/exchanges/LP_etomic.c | 14 ++++++++++++++ iguana/exchanges/LP_etomic.h | 2 ++ iguana/exchanges/LP_portfolio.c | 6 ++++++ iguana/exchanges/LP_utxo.c | 6 +----- 5 files changed, 30 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_coins.c b/iguana/exchanges/LP_coins.c index d37152137..a493654e6 100644 --- a/iguana/exchanges/LP_coins.c +++ b/iguana/exchanges/LP_coins.c @@ -236,6 +236,13 @@ cJSON *LP_coinjson(struct iguana_info *coin,int32_t showwif) jaddnum(item,"balance",dstr(balance)); jaddnum(item,"KMDvalue",dstr(LP_KMDvalue(coin,balance))); } +#ifndef NOTETOMIC + else if (coin->etomic[0] != 0) { + balance = LP_etomic_get_balance(coin, coin->smartaddr); + jaddnum(item,"height",-1); + jaddnum(item,"balance",dstr(balance)); + } +#endif else { jaddnum(item,"height",-1); diff --git a/iguana/exchanges/LP_etomic.c b/iguana/exchanges/LP_etomic.c index a548dbf18..0086b47d3 100644 --- a/iguana/exchanges/LP_etomic.c +++ b/iguana/exchanges/LP_etomic.c @@ -697,3 +697,17 @@ uint8_t LP_etomic_is_empty_tx_id(char *txId) } return 0; } + +uint64_t LP_etomic_get_balance(struct iguana_info *coin, char *coinaddr) +{ + if (coin->etomic[0] == 0) { + printf("Trying to get etomic balance for non-etomic coin %s!", coin->symbol); + return 0; + } + + if (strcmp(coin->symbol, "ETH") == 0) { + return getEthBalance(coinaddr); + } else { + return getErc20BalanceSatoshi(coinaddr, coin->etomic); + } +} diff --git a/iguana/exchanges/LP_etomic.h b/iguana/exchanges/LP_etomic.h index 0e2927211..31da07237 100644 --- a/iguana/exchanges/LP_etomic.h +++ b/iguana/exchanges/LP_etomic.h @@ -49,4 +49,6 @@ int32_t LP_etomic_pub2addr(char *coinaddr,uint8_t pub64[64]); uint8_t LP_etomic_is_empty_tx_id(char *txId); +uint64_t LP_etomic_get_balance(struct iguana_info *coin, char *coinaddr); + #endif //SUPERNET_LP_ETOMIC_H diff --git a/iguana/exchanges/LP_portfolio.c b/iguana/exchanges/LP_portfolio.c index 23a1d1102..840bc4919 100644 --- a/iguana/exchanges/LP_portfolio.c +++ b/iguana/exchanges/LP_portfolio.c @@ -95,6 +95,12 @@ uint64_t LP_balance(uint64_t *valuep,int32_t iambob,char *symbol,char *coinaddr) cJSON *array,*item; bits256 zero; int32_t i,n; uint64_t valuesum,satoshisum,value; valuesum = satoshisum = 0; memset(zero.bytes,0,sizeof(zero)); +#ifndef NOTETOMIC + struct iguana_info *coin = LP_coinfind(symbol); + if (coin->etomic[0] != 0) { + valuesum = LP_etomic_get_balance(coin, coinaddr); + } else +#endif if ( (array= LP_listunspent(symbol,coinaddr,zero,zero)) != 0 ) { if ( is_cJSON_Array(array) != 0 && (n= cJSON_GetArraySize(array)) > 0 ) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 970839b8e..68c9ea2de 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -628,11 +628,7 @@ cJSON *LP_address_balance(struct iguana_info *coin,char *coinaddr,int32_t electr memset(zero.bytes,0,sizeof(zero)); #ifndef NOTETOMIC if (coin->etomic[0] != 0) { - if (strcmp(coin->symbol, "ETH") == 0) { - balance = getEthBalance(coinaddr); - } else { - balance = getErc20BalanceSatoshi(coinaddr, coin->etomic); - } + balance = LP_etomic_get_balance(coin, coinaddr); } else #endif if ( coin->electrum == 0 )