Browse Source

#80 Set ERC20 decimals upon coin enable to avoid repetitive requests.

pass-iguana-arg
Artem Pikulin 7 years ago
parent
commit
b8890ba2e9
  1. 7
      iguana/exchanges/LP_commands.c
  2. 12
      iguana/exchanges/etomicswap/etomiclib.cpp
  3. 1
      iguana/exchanges/etomicswap/etomiclib.h

7
iguana/exchanges/LP_commands.c

@ -616,6 +616,13 @@ version\n\
if (etomic_coin->inactive != 0) {
return(clonestr("{\"error\":\"Enable ETOMIC first to use ETH/ERC20!\"}"));
}
if (ptr->decimals == 0 && strcmp(coin, "ETH") != 0) {
ptr->decimals = getErc20DecimalsZeroOnError(ptr->etomic);
if (ptr->decimals == 0) {
return(clonestr("{\"error\":\"Could not get token decimals or token has zero decimals which is not supported!\"}"));
}
}
}
#endif
if ( LP_conflicts_find(ptr) == 0 )

12
iguana/exchanges/etomicswap/etomiclib.cpp

@ -636,6 +636,18 @@ uint8_t getErc20Decimals(char *tokenAddress)
return decimals;
}
uint8_t getErc20DecimalsZeroOnError(char *tokenAddress)
{
char* hexDecimals = ethCall(tokenAddress, "0x313ce567");
if (hexDecimals != NULL) {
auto decimals = (uint8_t) strtol(hexDecimals, NULL, 0);
free(hexDecimals);
return decimals;
} else {
return 0;
}
}
void uint8arrayToHex(char *dest, uint8_t *input, int len)
{
strcpy(dest, "0x");

1
iguana/exchanges/etomicswap/etomiclib.h

@ -215,6 +215,7 @@ uint64_t estimate_erc20_gas(
uint8_t compareAddresses(char *address1, char *address2);
uint8_t isValidAddress(char *address);
uint8_t getErc20DecimalsZeroOnError(char *tokenAddress);
#ifdef __cplusplus
}

Loading…
Cancel
Save