Browse Source

#82 Use prev ETH/ERC20 balance on portfolio in case of request error.

pass-iguana-arg
Artem Pikulin 7 years ago
parent
commit
437d9b23df
  1. 3
      iguana/exchanges/LP_coins.c
  2. 6
      iguana/exchanges/LP_etomic.c
  3. 2
      iguana/exchanges/LP_etomic.h
  4. 8
      iguana/exchanges/LP_portfolio.c
  5. 3
      iguana/exchanges/LP_rpc.c
  6. 3
      iguana/exchanges/LP_signatures.c
  7. 6
      iguana/exchanges/LP_swap.c
  8. 3
      iguana/exchanges/LP_utxo.c
  9. 8
      iguana/exchanges/etomicswap/etomiclib.cpp
  10. 4
      iguana/exchanges/etomicswap/etomiclib.h

3
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;
}

6
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);
}
}

2
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);

8
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 )

3
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;

3
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));

6
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");
}

3
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 )

8
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<uint64_t>(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<uint64_t>(balance);
} else {
*error = 1;
return 0;
}
}

4
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);

Loading…
Cancel
Save