diff --git a/iguana/exchanges/LP_coins.c b/iguana/exchanges/LP_coins.c index e413ffa64..ce948fa95 100644 --- a/iguana/exchanges/LP_coins.c +++ b/iguana/exchanges/LP_coins.c @@ -251,8 +251,9 @@ cJSON *LP_coinjson(struct iguana_info *coin,int32_t showwif) } #ifndef NOTETOMIC else if (coin->etomic[0] != 0) { + int error = 0; if (coin->inactive == 0) { - balance = LP_etomic_get_balance(coin, coin->smartaddr); + balance = LP_etomic_get_balance(coin, coin->smartaddr, &error); } else { balance = 0; } diff --git a/iguana/exchanges/LP_etomic.c b/iguana/exchanges/LP_etomic.c index 8c03e7810..3b7c7aa8f 100644 --- a/iguana/exchanges/LP_etomic.c +++ b/iguana/exchanges/LP_etomic.c @@ -773,7 +773,7 @@ uint8_t LP_etomic_is_empty_tx_id(char *txId) return 0; } -uint64_t LP_etomic_get_balance(struct iguana_info *coin, char *coinaddr) +uint64_t LP_etomic_get_balance(struct iguana_info *coin, char *coinaddr, int *error) { if (coin->etomic[0] == 0) { printf("Trying to get etomic balance for non-etomic coin %s!", coin->symbol); @@ -781,8 +781,8 @@ uint64_t LP_etomic_get_balance(struct iguana_info *coin, char *coinaddr) } if (strcmp(coin->symbol, "ETH") == 0) { - return getEthBalance(coinaddr); + return getEthBalance(coinaddr, error); } else { - return getErc20BalanceSatoshi(coinaddr, coin->etomic, coin->decimals); + return getErc20BalanceSatoshi(coinaddr, coin->etomic, coin->decimals, error); } } diff --git a/iguana/exchanges/LP_etomic.h b/iguana/exchanges/LP_etomic.h index af5de5f63..8a744cb3d 100644 --- a/iguana/exchanges/LP_etomic.h +++ b/iguana/exchanges/LP_etomic.h @@ -49,7 +49,7 @@ 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); +uint64_t LP_etomic_get_balance(struct iguana_info *coin, char *coinaddr, int *error); void LP_etomic_pubkeystr_to_addr(char *pubkey, char *output); diff --git a/iguana/exchanges/LP_portfolio.c b/iguana/exchanges/LP_portfolio.c index b38a08c89..dda09ec54 100644 --- a/iguana/exchanges/LP_portfolio.c +++ b/iguana/exchanges/LP_portfolio.c @@ -98,7 +98,13 @@ uint64_t LP_balance(uint64_t *valuep,int32_t iambob,char *symbol,char *coinaddr) #ifndef NOTETOMIC struct iguana_info *coin = LP_coinfind(symbol); if (coin->etomic[0] != 0 && coin->inactive == 0) { - valuesum = LP_etomic_get_balance(coin, coinaddr); + int error = 0; + uint64_t etomic_balance = LP_etomic_get_balance(coin, coinaddr, &error); + if (error == 0) { + valuesum = etomic_balance; + } else { + valuesum = *valuep; + } } else #endif if ( (array= LP_listunspent(symbol,coinaddr,zero,zero)) != 0 ) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 9c1bca6c2..800214ba4 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -139,7 +139,8 @@ uint64_t LP_RTsmartbalance(struct iguana_info *coin) { #ifndef NOTETOMIC if (coin->etomic[0] != 0) { - return LP_etomic_get_balance(coin, coin->smartaddr); + int error = 0; + return LP_etomic_get_balance(coin, coin->smartaddr, &error); } #endif cJSON *array,*item; char buf[512],*retstr; int32_t i,n; uint64_t valuesum,value; bits256 zero; diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index 2d8e45750..a280ae9d4 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -444,7 +444,8 @@ char *LP_pricepings(void *ctx,char *myipaddr,int32_t pubsock,char *base,char *re jaddnum(reqjson,"credits",dstr(ap->instantdex_credits)); #ifndef NOTETOMIC if (basecoin->etomic[0] != 0) { - uint64_t etomic_coin_balance = LP_etomic_get_balance(basecoin, basecoin->smartaddr); + int error = 0; + uint64_t etomic_coin_balance = LP_etomic_get_balance(basecoin, basecoin->smartaddr, &error); jaddstr(reqjson,"utxocoin","ETH_OR_ERC20"); jaddnum(reqjson,"bal",dstr(etomic_coin_balance)); jaddnum(reqjson,"min",dstr(etomic_coin_balance)); diff --git a/iguana/exchanges/LP_swap.c b/iguana/exchanges/LP_swap.c index 5c7af583e..8a1efb9bf 100644 --- a/iguana/exchanges/LP_swap.c +++ b/iguana/exchanges/LP_swap.c @@ -856,7 +856,8 @@ void LP_bobloop(void *_swap) alicewaittimeout = LP_calc_waittimeout(alicestr); #ifndef NOTETOMIC if (swap->I.bobtomic[0] != 0 || swap->I.alicetomic[0] != 0) { - uint64_t eth_balance = getEthBalance(swap->I.etomicsrc); + int error = 0; + uint64_t eth_balance = getEthBalance(swap->I.etomicsrc, &error); if (eth_balance < 500000) { err = -5000, printf("Bob ETH balance too low, aborting swap!\n"); } @@ -960,7 +961,8 @@ void LP_aliceloop(void *_swap) #ifndef NOTETOMIC if (swap->I.bobtomic[0] != 0 || swap->I.alicetomic[0] != 0) { - uint64_t eth_balance = getEthBalance(swap->I.etomicdest); + int error = 0; + uint64_t eth_balance = getEthBalance(swap->I.etomicdest, &error); if (eth_balance < 500000) { err = -5001, printf("Alice ETH balance too low, aborting swap!\n"); } diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 944876a90..f241e73c5 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -699,7 +699,8 @@ cJSON *LP_address_balance(struct iguana_info *coin,char *coinaddr,int32_t electr //printf("address balance call LP_listunspent %s electrum.%p etomic.%d\n",coin->symbol,coin->electrum,coin->etomic[0]); #ifndef NOTETOMIC if (coin->etomic[0] != 0) { - balance = LP_etomic_get_balance(coin, coinaddr); + int error = 0; + balance = LP_etomic_get_balance(coin, coinaddr, &error); } else #endif if ( coin->electrum == 0 ) diff --git a/iguana/exchanges/etomicswap/etomiclib.cpp b/iguana/exchanges/etomicswap/etomiclib.cpp index ab60510fd..f80ba22f4 100644 --- a/iguana/exchanges/etomicswap/etomiclib.cpp +++ b/iguana/exchanges/etomicswap/etomiclib.cpp @@ -544,7 +544,7 @@ char* pubKey2Addr(char* pubKey) return stringStreamToChar(ss); }; -char* getPubKeyFromPriv(char* privKey) +char* getPubKeyFromPriv(char *privKey) { Public publicKey = toPublic(Secret(privKey)); std::stringstream ss; @@ -552,7 +552,7 @@ char* getPubKeyFromPriv(char* privKey) return stringStreamToChar(ss); } -uint64_t getEthBalance(char* address) +uint64_t getEthBalance(char *address, int *error) { char* hexBalance = getEthBalanceRequest(address); if (hexBalance != NULL) { @@ -561,11 +561,12 @@ uint64_t getEthBalance(char* address) free(hexBalance); return static_cast(balance); } else { + *error = 1; return 0; } } -uint64_t getErc20BalanceSatoshi(char *address, char *tokenAddress, uint8_t setDecimals) +uint64_t getErc20BalanceSatoshi(char *address, char *tokenAddress, uint8_t setDecimals, int *error) { std::stringstream ss; ss << "0x70a08231" @@ -589,6 +590,7 @@ uint64_t getErc20BalanceSatoshi(char *address, char *tokenAddress, uint8_t setDe free(hexBalance); return static_cast(balance); } else { + *error = 1; return 0; } } diff --git a/iguana/exchanges/etomicswap/etomiclib.h b/iguana/exchanges/etomicswap/etomiclib.h index 3557e4191..6075124a5 100644 --- a/iguana/exchanges/etomicswap/etomiclib.h +++ b/iguana/exchanges/etomicswap/etomiclib.h @@ -173,8 +173,8 @@ char* pubKey2Addr(char* pubKey); char* getPubKeyFromPriv(char* privKey); // returns satoshis, not wei! -uint64_t getEthBalance(char* address); -uint64_t getErc20BalanceSatoshi(char *address, char *tokenAddress, uint8_t setDecimals); +uint64_t getEthBalance(char* address, int *error); +uint64_t getErc20BalanceSatoshi(char *address, char *tokenAddress, uint8_t setDecimals, int *error); char *getErc20BalanceHexWei(char* address, char tokenAddress[65]); uint8_t getErc20Decimals(char *tokenAddress);