Browse Source

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	iguana/exchanges/LP_ordermatch.c
pass-iguana-arg
Artem Pikulin 7 years ago
parent
commit
716cd23cf8
  1. 2
      etomic_build/client/buy_BEER_OTHER
  2. 2
      etomic_build/coins
  3. 3
      iguana/exchanges/LP_coins.c
  4. 23
      iguana/exchanges/LP_commands.c
  5. 24
      iguana/exchanges/LP_etomic.c
  6. 2
      iguana/exchanges/LP_etomic.h
  7. 22
      iguana/exchanges/LP_ordermatch.c
  8. 8
      iguana/exchanges/LP_portfolio.c
  9. 3
      iguana/exchanges/LP_rpc.c
  10. 3
      iguana/exchanges/LP_signatures.c
  11. 6
      iguana/exchanges/LP_swap.c
  12. 5
      iguana/exchanges/LP_transaction.c
  13. 14
      iguana/exchanges/LP_utxo.c
  14. 3
      iguana/exchanges/etomicswap/etomiccurl.c
  15. 2
      iguana/exchanges/etomicswap/etomiccurl.h
  16. 34
      iguana/exchanges/etomicswap/etomiclib.cpp
  17. 8
      iguana/exchanges/etomicswap/etomiclib.h
  18. 10
      start_BEER_OTHER_trade.sh
  19. 10
      start_BEER_OTHER_trade_inverted.sh

2
etomic_build/client/buy_BEER_OTHER

@ -1,4 +1,4 @@
#!/bin/bash #!/bin/bash
source userpass source userpass
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"setprice\",\"base\":\"$1\",\"rel\":\"BEER\",\"price\":1}" curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"setprice\",\"base\":\"$1\",\"rel\":\"BEER\",\"price\":1}"
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"sell\",\"base\":\"$1\",\"rel\":\"BEER\",\"basevolume\":0.1,\"price\":1}" curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"buy\",\"base\":\"BEER\",\"rel\":\"$1\",\"relvolume\":0.1,\"price\":1}"

2
etomic_build/coins

File diff suppressed because one or more lines are too long

3
iguana/exchanges/LP_coins.c

@ -251,8 +251,9 @@ cJSON *LP_coinjson(struct iguana_info *coin,int32_t showwif)
} }
#ifndef NOTETOMIC #ifndef NOTETOMIC
else if (coin->etomic[0] != 0) { else if (coin->etomic[0] != 0) {
int error = 0;
if (coin->inactive == 0) { if (coin->inactive == 0) {
balance = LP_etomic_get_balance(coin, coin->smartaddr); balance = LP_etomic_get_balance(coin, coin->smartaddr, &error);
} else { } else {
balance = 0; balance = 0;
} }

23
iguana/exchanges/LP_commands.c

@ -599,19 +599,27 @@ version\n\
} }
#ifndef NOT_ETOMIC #ifndef NOT_ETOMIC
if (strcmp(coin, "ETOMIC") == 0) { if (strcmp(coin, "ETOMIC") == 0) {
char eth_addr[100]; if (get_etomic_from_faucet(ptr->smartaddr) != 1) {
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!\"}")); return(clonestr("{\"error\":\"Could not get ETOMIC from faucet!\"}"));
} }
} }
if (ptr->etomic[0] != 0) { if (ptr->etomic[0] != 0) {
if (isValidAddress(ptr->etomic) == 0) {
return(clonestr("{\"error\":\"'etomic' field is not valid address!\"}"));
}
struct iguana_info *etomic_coin = LP_coinsearch("ETOMIC"); struct iguana_info *etomic_coin = LP_coinsearch("ETOMIC");
if (etomic_coin->inactive != 0) { if (etomic_coin->inactive != 0) {
return(clonestr("{\"error\":\"Enable ETOMIC first to use ETH/ERC20!\"}")); 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 #endif
if ( LP_conflicts_find(ptr) == 0 ) if ( LP_conflicts_find(ptr) == 0 )
@ -685,6 +693,13 @@ version\n\
{ {
if ( (ptr= LP_coinsearch(coin)) != 0 ) if ( (ptr= LP_coinsearch(coin)) != 0 )
{ {
#ifndef NOTETOMIC
if (strcmp(coin, "ETOMIC") == 0) {
if (get_etomic_from_faucet(ptr->smartaddr) != 1) {
return(clonestr("{\"error\":\"Could not get ETOMIC from faucet!\"}"));
}
}
#endif
ptr->inactive = 0; ptr->inactive = 0;
return(jprint(LP_electrumserver(ptr,jstr(argjson,"ipaddr"),juint(argjson,"port")),1)); return(jprint(LP_electrumserver(ptr,jstr(argjson,"ipaddr"),juint(argjson,"port")),1));
} else return(clonestr("{\"error\":\"cant find coind\"}")); } else return(clonestr("{\"error\":\"cant find coind\"}"));

24
iguana/exchanges/LP_etomic.c

@ -60,7 +60,7 @@ uint8_t LP_etomic_verify_alice_fee(struct basilisk_swap *swap)
return(0); return(0);
} }
EthTxData data = getEthTxData(swap->otherfee.I.ethTxid); EthTxData data = getEthTxData(swap->otherfee.I.ethTxid);
if (strcmp(data.from, swap->I.etomicdest) != 0) { if (compareAddresses(data.from, swap->I.etomicdest) == 0) {
printf("Alice fee tx %s was sent from wrong address %s\n", swap->otherfee.I.ethTxid, data.from); printf("Alice fee tx %s was sent from wrong address %s\n", swap->otherfee.I.ethTxid, data.from);
return(0); return(0);
} }
@ -68,7 +68,7 @@ uint8_t LP_etomic_verify_alice_fee(struct basilisk_swap *swap)
char dexaddr[50]; char dexaddr[50];
LP_etomic_pubkeystr_to_addr(INSTANTDEX_PUBKEY, dexaddr); LP_etomic_pubkeystr_to_addr(INSTANTDEX_PUBKEY, dexaddr);
if ( strcmp(swap->I.alicestr,"ETH") == 0 ) { if ( strcmp(swap->I.alicestr,"ETH") == 0 ) {
if (strcmp(data.to, dexaddr) != 0) { if (compareAddresses(data.to, dexaddr) == 0) {
printf("Alice fee %s was sent to wrong address %s\n", swap->otherfee.I.ethTxid, data.to); printf("Alice fee %s was sent to wrong address %s\n", swap->otherfee.I.ethTxid, data.to);
return(0); return(0);
} }
@ -81,7 +81,7 @@ uint8_t LP_etomic_verify_alice_fee(struct basilisk_swap *swap)
} else { } else {
struct iguana_info *alicecoin = LP_coinfind(swap->I.alicestr); struct iguana_info *alicecoin = LP_coinfind(swap->I.alicestr);
if (strcmp(data.to, swap->I.alicetomic) != 0) { if (compareAddresses(data.to, swap->I.alicetomic) == 0) {
printf("Alice ERC20 fee %s token address %s is not equal to expected %s\n", swap->otherfee.I.ethTxid, data.to, swap->I.alicetomic); printf("Alice ERC20 fee %s token address %s is not equal to expected %s\n", swap->otherfee.I.ethTxid, data.to, swap->I.alicetomic);
return(0); return(0);
} }
@ -159,11 +159,11 @@ uint8_t LP_etomic_verify_alice_payment(struct basilisk_swap *swap, char *txId)
return(0); return(0);
} }
EthTxData data = getEthTxData(txId); EthTxData data = getEthTxData(txId);
if (strcmp(data.to, ETOMIC_ALICECONTRACT) != 0) { if (compareAddresses(data.to, ETOMIC_ALICECONTRACT) == 0) {
printf("Alice payment %s was sent to wrong address %s\n", txId, data.to); printf("Alice payment %s was sent to wrong address %s\n", txId, data.to);
return(0); return(0);
} }
if (strcmp(data.from, swap->I.etomicdest) != 0) { if (compareAddresses(data.from, swap->I.etomicdest) == 0) {
printf("Alice payment %s was done from wrong address %s\n", txId, data.from); printf("Alice payment %s was done from wrong address %s\n", txId, data.from);
return(0); return(0);
} }
@ -367,11 +367,11 @@ uint8_t LP_etomic_verify_bob_deposit(struct basilisk_swap *swap, char *txId)
return(0); return(0);
} }
EthTxData data = getEthTxData(txId); EthTxData data = getEthTxData(txId);
if (strcmp(data.to, ETOMIC_BOBCONTRACT) != 0) { if (compareAddresses(data.to, ETOMIC_BOBCONTRACT) == 0) {
printf("Bob deposit txid %s was sent to wrong address %s\n", txId, data.to); printf("Bob deposit txid %s was sent to wrong address %s\n", txId, data.to);
return(0); return(0);
} }
if (strcmp(data.from, swap->I.etomicsrc) != 0) { if (compareAddresses(data.from, swap->I.etomicsrc) == 0) {
printf("Bob deposit txid %s was sent from wrong address %s\n", txId, data.from); printf("Bob deposit txid %s was sent from wrong address %s\n", txId, data.from);
return(0); return(0);
} }
@ -523,10 +523,10 @@ uint8_t LP_etomic_verify_bob_payment(struct basilisk_swap *swap, char *txId)
return 0; return 0;
} }
EthTxData data = getEthTxData(txId); EthTxData data = getEthTxData(txId);
if (strcmp(data.to, ETOMIC_BOBCONTRACT) != 0) { if (compareAddresses(data.to, ETOMIC_BOBCONTRACT) == 0) {
printf("Bob payment %s was sent to wrong address %s\n", txId, data.to); printf("Bob payment %s was sent to wrong address %s\n", txId, data.to);
} }
if (strcmp(data.from, swap->I.etomicsrc) != 0) { if (compareAddresses(data.from, swap->I.etomicsrc) == 0) {
printf("Bob payment %s was sent from wrong address %s\n", txId, data.from); printf("Bob payment %s was sent from wrong address %s\n", txId, data.from);
} }
BobSendsEthPaymentInput input; BobSendsEthPaymentInput input;
@ -773,7 +773,7 @@ uint8_t LP_etomic_is_empty_tx_id(char *txId)
return 0; 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) { if (coin->etomic[0] == 0) {
printf("Trying to get etomic balance for non-etomic coin %s!", coin->symbol); 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) { if (strcmp(coin->symbol, "ETH") == 0) {
return getEthBalance(coinaddr); return getEthBalance(coinaddr, error);
} else { } 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); 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); void LP_etomic_pubkeystr_to_addr(char *pubkey, char *output);

22
iguana/exchanges/LP_ordermatch.c

@ -199,12 +199,12 @@ double LP_quote_validate(struct LP_utxoinfo *autxo,struct LP_utxoinfo *butxo,str
if ( strcmp(autxo->coinaddr,qp->destaddr) != 0 ) if ( strcmp(autxo->coinaddr,qp->destaddr) != 0 )
return(-10); return(-10);
} }
if ( autxo != 0 && destvalue < qp->desttxfee+qp->destsatoshis ) if ( strcmp(destcoin, "ETOMIC") != 0 && autxo != 0 && destvalue < qp->desttxfee+qp->destsatoshis )
{ {
printf("destvalue %.8f destsatoshis %.8f is too small txfee %.8f?\n",dstr(destvalue),dstr(qp->destsatoshis),dstr(qp->desttxfee)); printf("destvalue %.8f destsatoshis %.8f is too small txfee %.8f?\n",dstr(destvalue),dstr(qp->destsatoshis),dstr(qp->desttxfee));
return(-11); return(-11);
} }
if ( butxo != 0 && srcvalue < qp->txfee+qp->satoshis ) if ( strcmp(srccoin, "ETOMIC") != 0 && butxo != 0 && srcvalue < qp->txfee+qp->satoshis )
{ {
printf("srcvalue %.8f [%.8f] satoshis %.8f is too small txfee %.8f?\n",dstr(srcvalue),dstr(srcvalue) - dstr(qp->txfee+qp->satoshis),dstr(qp->satoshis),dstr(qp->txfee)); printf("srcvalue %.8f [%.8f] satoshis %.8f is too small txfee %.8f?\n",dstr(srcvalue),dstr(srcvalue) - dstr(qp->txfee+qp->satoshis),dstr(qp->satoshis),dstr(qp->txfee));
return(-33); return(-33);
@ -222,7 +222,7 @@ double LP_quote_validate(struct LP_utxoinfo *autxo,struct LP_utxoinfo *butxo,str
printf("error -14: txfee %.8f < %.8f or desttxfee %.8f < %.8f\n",dstr(qp->txfee),dstr(LP_REQUIRED_TXFEE*txfee),dstr(qp->desttxfee),dstr(LP_REQUIRED_TXFEE*desttxfee)); printf("error -14: txfee %.8f < %.8f or desttxfee %.8f < %.8f\n",dstr(qp->txfee),dstr(LP_REQUIRED_TXFEE*txfee),dstr(qp->desttxfee),dstr(LP_REQUIRED_TXFEE*desttxfee));
return(-14); return(-14);
} }
if ( butxo != 0 ) if ( butxo != 0 && strcmp(srccoin, "ETOMIC") != 0)
{ {
if ( qp->satoshis < (srcvalue / LP_MINVOL) || srcvalue < qp->txfee*LP_MINSIZE_TXFEEMULT ) if ( qp->satoshis < (srcvalue / LP_MINVOL) || srcvalue < qp->txfee*LP_MINSIZE_TXFEEMULT )
{ {
@ -422,14 +422,22 @@ struct LP_utxoinfo *LP_address_myutxopair(struct LP_utxoinfo *butxo,int32_t iamb
memset(butxo,0,sizeof(*butxo)); memset(butxo,0,sizeof(*butxo));
if ( iambob != 0 ) if ( iambob != 0 )
{ {
if (strcmp(coin->symbol, "ETOMIC") == 0) {
targetval = 100000000 + 3*txfee;
} else {
targetval = LP_basesatoshis(relvolume,price,txfee,desttxfee) + 3*txfee; targetval = LP_basesatoshis(relvolume,price,txfee,desttxfee) + 3*txfee;
}
targetval2 = (targetval / 8) * 9 + 3*txfee; targetval2 = (targetval / 8) * 9 + 3*txfee;
fee = txfee; fee = txfee;
ratio = LP_MINVOL; ratio = LP_MINVOL;
} }
else else
{ {
if (strcmp(coin->symbol, "ETOMIC") == 0) {
targetval = 100000000 + 3*desttxfee;
} else {
targetval = relvolume*SATOSHIDEN + 3*desttxfee; targetval = relvolume*SATOSHIDEN + 3*desttxfee;
}
targetval2 = (targetval / 777) + 3*desttxfee; targetval2 = (targetval / 777) + 3*desttxfee;
fee = desttxfee; fee = desttxfee;
ratio = LP_MINCLIENTVOL; ratio = LP_MINCLIENTVOL;
@ -989,7 +997,7 @@ double LP_trades_pricevalidate(struct LP_quoteinfo *qp,struct iguana_info *coin,
printf("quote %s/%s validate error %.0f\n",qp->srccoin,qp->destcoin,qprice); printf("quote %s/%s validate error %.0f\n",qp->srccoin,qp->destcoin,qprice);
return(-3); return(-3);
} }
if ( qprice < (price - 0.00000001) * 0.998 ) if ( qprice < (price - 0.00000001) * 0.998)
{ {
printf(" quote price %.8f (%llu/%llu %.8f) too low vs %.8f for %s/%s price %.8f %.8f\n",qprice,(long long)qp->destsatoshis,(long long)(qp->satoshis-qp->txfee),(double)qp->destsatoshis/(qp->satoshis-qp->txfee),price,qp->srccoin,qp->destcoin,price,(price - 0.00000001) * 0.998); printf(" quote price %.8f (%llu/%llu %.8f) too low vs %.8f for %s/%s price %.8f %.8f\n",qprice,(long long)qp->destsatoshis,(long long)(qp->satoshis-qp->txfee),(double)qp->destsatoshis/(qp->satoshis-qp->txfee),price,qp->srccoin,qp->destcoin,price,(price - 0.00000001) * 0.998);
return(-77); return(-77);
@ -1096,7 +1104,11 @@ printf("bob %s received REQUEST.(%s) fill.%d gtc.%d\n",bits256_str(str,G.LP_mypu
qp->vout = butxo->payment.vout; qp->vout = butxo->payment.vout;
qp->txid2 = butxo->deposit.txid; qp->txid2 = butxo->deposit.txid;
qp->vout2 = butxo->deposit.vout; qp->vout2 = butxo->deposit.vout;
if (coin->etomic[0] == 0) {
qp->satoshis = butxo->swap_satoshis;// + qp->txfee; qp->satoshis = butxo->swap_satoshis;// + qp->txfee;
} else {
qp->satoshis = LP_basesatoshis(dstr(qp->destsatoshis), price, qp->txfee, qp->desttxfee);
}
qp->quotetime = (uint32_t)time(NULL); qp->quotetime = (uint32_t)time(NULL);
break; break;
} }
@ -1739,7 +1751,7 @@ char *LP_autobuy(void *ctx,int32_t fomoflag,char *myipaddr,int32_t mypubsock,cha
autxo->swap_satoshis = destsatoshis; autxo->swap_satoshis = destsatoshis;
//printf("first path dest %.8f from %.8f\n",dstr(destsatoshis),dstr(autxo->swap_satoshis)); //printf("first path dest %.8f from %.8f\n",dstr(destsatoshis),dstr(autxo->swap_satoshis));
} }
else if ( autxo->swap_satoshis - desttxfee < destsatoshis ) else if ( autxo->swap_satoshis - desttxfee < destsatoshis && relcoin->etomic[0] == 0)
{ {
autxo->swap_satoshis -= desttxfee; autxo->swap_satoshis -= desttxfee;
destsatoshis = autxo->swap_satoshis; destsatoshis = autxo->swap_satoshis;

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 #ifndef NOTETOMIC
struct iguana_info *coin = LP_coinfind(symbol); struct iguana_info *coin = LP_coinfind(symbol);
if (coin->etomic[0] != 0 && coin->inactive == 0) { 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 } else
#endif #endif
if ( (array= LP_listunspent(symbol,coinaddr,zero,zero)) != 0 ) 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 #ifndef NOTETOMIC
if (coin->etomic[0] != 0) { 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 #endif
cJSON *array,*item; char buf[512],*retstr; int32_t i,n; uint64_t valuesum,value; bits256 zero; cJSON *array,*item; char buf[512],*retstr; int32_t i,n; uint64_t valuesum,value; bits256 zero;

3
iguana/exchanges/LP_signatures.c

@ -450,7 +450,8 @@ char *LP_pricepings(void *ctx,char *myipaddr,int32_t pubsock,char *base,char *re
jaddnum(reqjson,"credits",dstr(ap->instantdex_credits)); jaddnum(reqjson,"credits",dstr(ap->instantdex_credits));
#ifndef NOTETOMIC #ifndef NOTETOMIC
if (basecoin->etomic[0] != 0) { 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"); jaddstr(reqjson,"utxocoin","ETH_OR_ERC20");
jaddnum(reqjson,"bal",dstr(etomic_coin_balance)); jaddnum(reqjson,"bal",dstr(etomic_coin_balance));
jaddnum(reqjson,"min",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); alicewaittimeout = LP_calc_waittimeout(alicestr);
#ifndef NOTETOMIC #ifndef NOTETOMIC
if (swap->I.bobtomic[0] != 0 || swap->I.alicetomic[0] != 0) { 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) { if (eth_balance < 500000) {
err = -5000, printf("Bob ETH balance too low, aborting swap!\n"); err = -5000, printf("Bob ETH balance too low, aborting swap!\n");
} }
@ -970,7 +971,8 @@ void LP_aliceloop(void *_swap)
#ifndef NOTETOMIC #ifndef NOTETOMIC
if (swap->I.bobtomic[0] != 0 || swap->I.alicetomic[0] != 0) { 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) { if (eth_balance < 500000) {
err = -5001, printf("Alice ETH balance too low, aborting swap!\n"); err = -5001, printf("Alice ETH balance too low, aborting swap!\n");
} }

5
iguana/exchanges/LP_transaction.c

@ -2136,6 +2136,11 @@ char *LP_eth_withdraw(struct iguana_info *coin,cJSON *argjson)
if (dest_addr == NULL) { if (dest_addr == NULL) {
return(clonestr("{\"error\":\"param 'to' is required!\"}")); return(clonestr("{\"error\":\"param 'to' is required!\"}"));
} }
if (isValidAddress(dest_addr) == 0) {
return(clonestr("{\"error\":\"'to' address is not valid!\"}"));
}
amount = jdouble(argjson, "amount") * 100000000; amount = jdouble(argjson, "amount") * 100000000;
if (amount == 0) { if (amount == 0) {
return(clonestr("{\"error\":\"'amount' is not set or equal to zero!\"}")); return(clonestr("{\"error\":\"'amount' is not set or equal to zero!\"}"));

14
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]); //printf("address balance call LP_listunspent %s electrum.%p etomic.%d\n",coin->symbol,coin->electrum,coin->etomic[0]);
#ifndef NOTETOMIC #ifndef NOTETOMIC
if (coin->etomic[0] != 0) { if (coin->etomic[0] != 0) {
balance = LP_etomic_get_balance(coin, coinaddr); int error = 0;
balance = LP_etomic_get_balance(coin, coinaddr, &error);
} else } else
#endif #endif
if ( coin->electrum == 0 ) if ( coin->electrum == 0 )
@ -787,7 +788,14 @@ cJSON *LP_balances(char *coinaddr)
} }
else else
{ {
if ( (balance= LP_RTsmartbalance(coin)) != 0 ) #ifndef NOTETOMIC
if (coin->etomic[0] == 0 || coin->inactive == 0) {
#endif
balance = LP_RTsmartbalance(coin);
#ifndef NOTETOMIC
}
#endif
if ( balance != 0 )
{ {
item = cJSON_CreateObject(); item = cJSON_CreateObject();
jaddstr(item,"coin",coin->symbol); jaddstr(item,"coin",coin->symbol);
@ -1185,7 +1193,7 @@ int32_t LP_iseligible(uint64_t *valp,uint64_t *val2p,int32_t iambob,char *symbol
return(-1); return(-1);
} }
destaddr[0] = destaddr2[0] = 0; destaddr[0] = destaddr2[0] = 0;
if ( coin != 0 && IAMLP != 0 && coin->inactive != 0 ) if ( coin != 0 && (strcmp(coin->symbol, "ETOMIC") == 0 || (coin->inactive != 0 && IAMLP != 0)))
bypass = 1; bypass = 1;
if ( bypass != 0 ) if ( bypass != 0 )
val = satoshis; val = satoshis;

3
iguana/exchanges/etomicswap/etomiccurl.c

@ -374,11 +374,10 @@ void unlock_send_tx_mutex()
pthread_mutex_unlock(&sendTxMutex); pthread_mutex_unlock(&sendTxMutex);
} }
uint8_t get_etomic_from_faucet(char *eth_addr, char *etomic_addr) uint8_t get_etomic_from_faucet(char *etomic_addr)
{ {
char* string; char* string;
cJSON *request = cJSON_CreateObject(); cJSON *request = cJSON_CreateObject();
cJSON_AddStringToObject(request, "ethAddress", eth_addr);
cJSON_AddStringToObject(request, "etomicAddress", etomic_addr); cJSON_AddStringToObject(request, "etomicAddress", etomic_addr);
string = cJSON_PrintUnformatted(request); string = cJSON_PrintUnformatted(request);
char* requestResult = sendRequest(string, FAUCET_URL); char* requestResult = sendRequest(string, FAUCET_URL);

2
iguana/exchanges/etomicswap/etomiccurl.h

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

34
iguana/exchanges/etomicswap/etomiclib.cpp

@ -4,6 +4,7 @@
#include "etomiclib.h" #include "etomiclib.h"
#include "etomiccurl.h" #include "etomiccurl.h"
#include <iostream> #include <iostream>
#include <regex>
#include <cpp-ethereum/libethcore/Common.h> #include <cpp-ethereum/libethcore/Common.h>
#include <cpp-ethereum/libethcore/CommonJS.h> #include <cpp-ethereum/libethcore/CommonJS.h>
#include <cpp-ethereum/libethcore/TransactionBase.h> #include <cpp-ethereum/libethcore/TransactionBase.h>
@ -543,7 +544,7 @@ char* pubKey2Addr(char* pubKey)
return stringStreamToChar(ss); return stringStreamToChar(ss);
}; };
char* getPubKeyFromPriv(char* privKey) char* getPubKeyFromPriv(char *privKey)
{ {
Public publicKey = toPublic(Secret(privKey)); Public publicKey = toPublic(Secret(privKey));
std::stringstream ss; std::stringstream ss;
@ -551,7 +552,7 @@ char* getPubKeyFromPriv(char* privKey)
return stringStreamToChar(ss); return stringStreamToChar(ss);
} }
uint64_t getEthBalance(char* address) uint64_t getEthBalance(char *address, int *error)
{ {
char* hexBalance = getEthBalanceRequest(address); char* hexBalance = getEthBalanceRequest(address);
if (hexBalance != NULL) { if (hexBalance != NULL) {
@ -560,11 +561,12 @@ uint64_t getEthBalance(char* address)
free(hexBalance); free(hexBalance);
return static_cast<uint64_t>(balance); return static_cast<uint64_t>(balance);
} else { } else {
*error = 1;
return 0; 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; std::stringstream ss;
ss << "0x70a08231" ss << "0x70a08231"
@ -588,6 +590,7 @@ uint64_t getErc20BalanceSatoshi(char *address, char *tokenAddress, uint8_t setDe
free(hexBalance); free(hexBalance);
return static_cast<uint64_t>(balance); return static_cast<uint64_t>(balance);
} else { } else {
*error = 1;
return 0; return 0;
} }
} }
@ -635,6 +638,18 @@ uint8_t getErc20Decimals(char *tokenAddress)
return decimals; 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) void uint8arrayToHex(char *dest, uint8_t *input, int len)
{ {
strcpy(dest, "0x"); strcpy(dest, "0x");
@ -828,3 +843,16 @@ uint8_t bobPaymentStatus(char *paymentId)
free(hexStatus); free(hexStatus);
return status; return status;
} }
uint8_t compareAddresses(char *address1, char *address2)
{
auto addr_bytes_1 = jsToAddress(address1);
auto addr_bytes_2 = jsToAddress(address2);
return static_cast<uint8_t>(addr_bytes_1 == addr_bytes_2);
}
uint8_t isValidAddress(char *address)
{
std::regex r("^(0x|0X)?[a-fA-F0-9]{40}$");
return static_cast<uint8_t>(std::regex_match(address, r));
}

8
iguana/exchanges/etomicswap/etomiclib.h

@ -173,8 +173,8 @@ char* pubKey2Addr(char* pubKey);
char* getPubKeyFromPriv(char* privKey); char* getPubKeyFromPriv(char* privKey);
// returns satoshis, not wei! // returns satoshis, not wei!
uint64_t getEthBalance(char* address); uint64_t getEthBalance(char* address, int *error);
uint64_t getErc20BalanceSatoshi(char *address, char *tokenAddress, uint8_t setDecimals); uint64_t getErc20BalanceSatoshi(char *address, char *tokenAddress, uint8_t setDecimals, int *error);
char *getErc20BalanceHexWei(char* address, char tokenAddress[65]); char *getErc20BalanceHexWei(char* address, char tokenAddress[65]);
uint8_t getErc20Decimals(char *tokenAddress); uint8_t getErc20Decimals(char *tokenAddress);
@ -213,6 +213,10 @@ uint64_t estimate_erc20_gas(
uint8_t decimals uint8_t decimals
); );
uint8_t compareAddresses(char *address1, char *address2);
uint8_t isValidAddress(char *address);
uint8_t getErc20DecimalsZeroOnError(char *tokenAddress);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

10
start_BEER_OTHER_trade.sh

@ -1,12 +1,8 @@
#!/bin/bash #!/bin/bash
docker-compose exec -T clientnode ./setpassphrase
sleep 5
docker-compose exec -T clientnode ./enable docker-compose exec -T clientnode ./enable
sleep 5 sleep 3
docker-compose exec -T seednode ./setpassphrase
sleep 5
docker-compose exec -T seednode ./enable docker-compose exec -T seednode ./enable
sleep 5 sleep 3
docker-compose exec -T seednode ./sell_BEER_OTHER $1 docker-compose exec -T seednode ./sell_BEER_OTHER $1
sleep 5 sleep 3
docker-compose exec -T clientnode ./buy_BEER_OTHER $1 docker-compose exec -T clientnode ./buy_BEER_OTHER $1

10
start_BEER_OTHER_trade_inverted.sh

@ -1,12 +1,8 @@
#!/bin/bash #!/bin/bash
docker-compose exec -T clientnode ./setpassphrase
sleep 5
docker-compose exec -T clientnode ./enable docker-compose exec -T clientnode ./enable
sleep 5 sleep 3
docker-compose exec -T seednode ./setpassphrase
sleep 5
docker-compose exec -T seednode ./enable docker-compose exec -T seednode ./enable
sleep 5 sleep 3
docker-compose exec -T clientnode ./buy_BEER_OTHER $1 docker-compose exec -T clientnode ./buy_BEER_OTHER $1
sleep 5 sleep 3
docker-compose exec -T seednode ./sell_BEER_OTHER $1 docker-compose exec -T seednode ./sell_BEER_OTHER $1
Loading…
Cancel
Save