Browse Source

Rework faucet integration, abort ETH/ERC20 swap if ETH balance < 0.005.

pass-iguana-arg
Artem Pikulin 7 years ago
parent
commit
453fa12d1c
  1. 22
      iguana/exchanges/LP_commands.c
  2. 23
      iguana/exchanges/LP_swap.c
  3. 5
      iguana/exchanges/etomicswap/etomiccurl.c
  4. 2
      iguana/exchanges/etomicswap/etomiccurl.h

22
iguana/exchanges/LP_commands.c

@ -581,24 +581,20 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\
return(jprint(retjson,1));
}
#ifndef NOT_ETOMIC
if (strcmp(coin, "ETOMIC") == 0) {
char eth_addr[100];
bits256 privkey = LP_privkey("ETOMIC", ptr->smartaddr, ptr->taddr);
LP_etomic_priv2addr(eth_addr, privkey);
if (get_etomic_from_faucet(eth_addr, ptr->smartaddr) != 1) {
return(clonestr("{\"error\":\"Could not get ETOMIC from faucet!\"}"));
}
}
if (ptr->etomic[0] != 0) {
struct iguana_info *etomic_coin = LP_coinsearch("ETOMIC");
if (etomic_coin->inactive != 0) {
return(clonestr("{\"error\":\"Enable ETOMIC first to use ETH/ERC20!\"}"));
}
if (ptr->inactive != 0) {
uint64_t balance = LP_etomic_get_balance(ptr, ptr->smartaddr);
uint64_t new_required = G.LP_required_etomic_balance + (balance * 9) / 4;
uint64_t etomic_balance = LP_RTsmartbalance(etomic_coin);
if (etomic_balance < new_required) {
printf("Need additional ETOMIC amount: %" PRIu64 "\n", new_required - etomic_balance);
if (get_etomic_from_faucet(ptr->smartaddr, etomic_coin->smartaddr, ptr->etomic) != 1) {
return(clonestr("{\"error\":\"Could not get ETOMIC from faucet!\"}"));
}
}
G.LP_required_etomic_balance = new_required;
}
}
#endif
if ( LP_conflicts_find(ptr) == 0 )

23
iguana/exchanges/LP_swap.c

@ -854,7 +854,16 @@ void LP_bobloop(void *_swap)
expiration = (uint32_t)time(NULL) + LP_SWAPSTEP_TIMEOUT;
bobwaittimeout = LP_calc_waittimeout(bobstr);
alicewaittimeout = LP_calc_waittimeout(alicestr);
if ( swap != 0 )
#ifndef NOTETOMIC
if (swap->I.bobtomic[0] != 0 || swap->I.alicetomic != 0) {
uint64_t eth_balance = getEthBalance(swap->I.etomicsrc);
if (eth_balance < 500000) {
err = -5000, printf("Bob ETH balance too low, aborting swap!\n");
}
}
#endif
if ( swap != 0 && err == 0)
{
if ( LP_waitsend("pubkeys",120,swap->N.pair,swap,data,maxlen,LP_pubkeys_verify,LP_pubkeys_data) < 0 )
err = -2000, printf("error waitsend pubkeys\n");
@ -947,7 +956,17 @@ void LP_aliceloop(void *_swap)
expiration = (uint32_t)time(NULL) + LP_SWAPSTEP_TIMEOUT;
bobwaittimeout = LP_calc_waittimeout(bobstr);
alicewaittimeout = LP_calc_waittimeout(alicestr);
if ( swap != 0 )
#ifndef NOTETOMIC
if (swap->I.bobtomic[0] != 0 || swap->I.alicetomic != 0) {
uint64_t eth_balance = getEthBalance(swap->I.etomicdest);
if (eth_balance < 500000) {
err = -5001, printf("Alice ETH balance too low, aborting swap!\n");
}
}
#endif
if ( swap != 0 && err == 0)
{
printf("start swap iamalice pair.%d\n",swap->N.pair);
if ( LP_sendwait("pubkeys",120,swap->N.pair,swap,data,maxlen,LP_pubkeys_verify,LP_pubkeys_data) < 0 )

5
iguana/exchanges/etomicswap/etomiccurl.c

@ -373,15 +373,12 @@ void unlock_send_tx_mutex()
pthread_mutex_unlock(&sendTxMutex);
}
uint8_t get_etomic_from_faucet(char *eth_addr, char *etomic_addr, char *token_addr)
uint8_t get_etomic_from_faucet(char *eth_addr, char *etomic_addr)
{
char* string;
cJSON *request = cJSON_CreateObject();
cJSON_AddStringToObject(request, "ethAddress", eth_addr);
cJSON_AddStringToObject(request, "etomicAddress", etomic_addr);
if (strcmp(token_addr, "0x0000000000000000000000000000000000000000") != 0) {
cJSON_AddStringToObject(request, "tokenAddress", token_addr);
}
string = cJSON_PrintUnformatted(request);
char* requestResult = sendRequest(string, FAUCET_URL);
free(string);

2
iguana/exchanges/etomicswap/etomiccurl.h

@ -50,7 +50,7 @@ uint64_t getEthBlockNumber();
uint64_t getGasPriceFromStation(uint8_t defaultOnErr);
int32_t waitForConfirmation(char *txId);
void unlock_send_tx_mutex();
uint8_t get_etomic_from_faucet(char *eth_addr, char *etomic_addr, char *token_addr);
uint8_t get_etomic_from_faucet(char *eth_addr, char *etomic_addr);
#ifdef __cplusplus
}

Loading…
Cancel
Save