Skip to content

Commit

Permalink
Merge pull request #54 from artemii235/etomic
Browse files Browse the repository at this point in the history
Fix decimals handling in coins config. Put back ETH/ERC20 balance to portfolio.
  • Loading branch information
artemii235 authored May 29, 2018
2 parents 282f88c + 5a5a620 commit 9707c21
Show file tree
Hide file tree
Showing 14 changed files with 61 additions and 36 deletions.
18 changes: 14 additions & 4 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,23 @@ cmake ..
cmake --build . --target marketmaker-testnet'''
}
}
stage('Trade') {
stage('Trade BEER/ETH') {
steps {
sh '''docker-compose build
docker-compose up -d
./start_BEER_ETH_trade.sh
COMPOSE_HTTP_TIMEOUT=601 timeout 600 grep -q "SWAP completed" <(docker-compose logs -f clientnode)
COMPOSE_HTTP_TIMEOUT=601 timeout 600 grep -q "SWAP completed" <(docker-compose logs -f seednode)
./start_BEER_OTHER_trade.sh ETH
timeout 600 grep -q "SWAP completed" <(docker-compose logs -f clientnode)
timeout 600 grep -q "SWAP completed" <(docker-compose logs -f seednode)
docker-compose down'''
}
}
stage('Trade ETH/BEER') {
steps {
sh '''docker-compose build
docker-compose up -d
./start_BEER_OTHER_trade_inverted.sh ETH
timeout 600 grep -q "SWAP completed" <(docker-compose logs -f clientnode)
timeout 600 grep -q "SWAP completed" <(docker-compose logs -f seednode)
docker-compose down'''
}
}
Expand Down
4 changes: 0 additions & 4 deletions etomic_build/client/buy_BEER_ETH

This file was deleted.

4 changes: 4 additions & 0 deletions etomic_build/client/buy_BEER_OTHER
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
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\":\"sell\",\"base\":\"$1\",\"rel\":\"BEER\",\"basevolume\":0.1,\"price\":1}"
3 changes: 2 additions & 1 deletion etomic_build/client/enable
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
source userpass
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"ETOMIC\"}"
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"ETH\"}"
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"KMD\"}"
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"NODEC\"}"
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"JST\"}"
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"BEER\"}"
2 changes: 1 addition & 1 deletion etomic_build/coins

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion etomic_build/seed/enable
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash
source userpass
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"KMD\"}"
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"ETOMIC\"}"
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"ETH\"}"
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"NODEC\"}"
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"JST\"}"
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"BEER\"}"
4 changes: 0 additions & 4 deletions etomic_build/seed/sell_BEER_ETH

This file was deleted.

4 changes: 4 additions & 0 deletions etomic_build/seed/sell_BEER_OTHER
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
source userpass
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"setprice\",\"base\":\"BEER\",\"rel\":\"$1\",\"price\":0.9}"
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"sell\",\"base\":\"BEER\",\"rel\":\"$1\",\"basevolume\":0.1,\"price\":0.9}"
18 changes: 11 additions & 7 deletions iguana/exchanges/LP_coins.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,13 @@ cJSON *LP_coinjson(struct iguana_info *coin,int32_t showwif)
}
#ifndef NOTETOMIC
else if (coin->etomic[0] != 0) {
//balance = LP_etomic_get_balance(coin, coin->smartaddr);
if (coin->inactive == 0) {
balance = LP_etomic_get_balance(coin, coin->smartaddr);
} else {
balance = 0;
}
jaddnum(item,"height",-1);
//jaddnum(item,"balance",dstr(balance));
jaddnum(item,"balance",0);
jaddnum(item,"balance",dstr(balance));
}
#endif
else
Expand Down Expand Up @@ -373,7 +376,7 @@ struct iguana_info *LP_coinadd(struct iguana_info *cdata)
return(coin);
}

uint16_t LP_coininit(struct iguana_info *coin,char *symbol,char *name,char *assetname,int32_t isPoS,uint16_t port,uint8_t pubtype,uint8_t p2shtype,uint8_t wiftype,uint64_t txfee,double estimatedrate,int32_t longestchain,uint8_t wiftaddr,uint8_t taddr,uint16_t busport,char *confpath)
uint16_t LP_coininit(struct iguana_info *coin,char *symbol,char *name,char *assetname,int32_t isPoS,uint16_t port,uint8_t pubtype,uint8_t p2shtype,uint8_t wiftype,uint64_t txfee,double estimatedrate,int32_t longestchain,uint8_t wiftaddr,uint8_t taddr,uint16_t busport,char *confpath,uint8_t decimals)
{
static void *ctx;
char *name2; uint16_t origport = port;
Expand Down Expand Up @@ -429,6 +432,7 @@ uint16_t LP_coininit(struct iguana_info *coin,char *symbol,char *name,char *asse
coin->zcash = LP_IS_BITCOINGOLD;
printf("set coin.%s <- LP_IS_BITCOINGOLD %d\n",symbol,coin->zcash);
}
coin->decimals = decimals;
return(port);
}

Expand Down Expand Up @@ -472,7 +476,7 @@ struct iguana_info *LP_coinfind(char *symbol)
else if ( strcmp(symbol,"KMD") == 0 )
name = "komodo";
else return(0);
port = LP_coininit(&cdata,symbol,name,assetname,isPoS,port,pubtype,p2shtype,wiftype,txfee,estimatedrate,longestchain,0,0,busport,0);
port = LP_coininit(&cdata,symbol,name,assetname,isPoS,port,pubtype,p2shtype,wiftype,txfee,estimatedrate,longestchain,0,0,busport,0,0);
if ( port == 0 )
isinactive = 1;
else isinactive = 0;
Expand Down Expand Up @@ -516,8 +520,8 @@ struct iguana_info *LP_coincreate(cJSON *item)
else if ( (name= jstr(item,"name")) == 0 )
name = symbol;

cdata.decimals = juint(item,"decimals");
if ( LP_coininit(&cdata,symbol,name,assetname==0?"":assetname,isPoS,port,pubtype,p2shtype,wiftype,txfee,estimatedrate,longestchain,juint(item,"wiftaddr"),juint(item,"taddr"),LP_busport(port),jstr(item,"confpath")) < 0 )
uint8_t decimals = juint(item,"decimals");
if ( LP_coininit(&cdata,symbol,name,assetname==0?"":assetname,isPoS,port,pubtype,p2shtype,wiftype,txfee,estimatedrate,longestchain,juint(item,"wiftaddr"),juint(item,"taddr"),LP_busport(port),jstr(item,"confpath"),decimals) < 0 )
{
coin = LP_coinadd(&cdata);
coin->inactive = (uint32_t)time(NULL);
Expand Down
14 changes: 7 additions & 7 deletions iguana/exchanges/LP_etomic.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,10 @@ char *LP_etomicalice_reclaims_payment(struct LP_swap_remember *swap)
memset(&txData,0,sizeof(txData));
memset(&input,0,sizeof(input));

struct iguana_info *ecoin;
struct iguana_info *ecoin, *alice_coin;
bits256 privkey;
ecoin = LP_coinfind("ETOMIC");
alice_coin = LP_coinfind(swap->dest);
privkey = LP_privkey(ecoin->symbol, ecoin->smartaddr, ecoin->taddr);

uint8arrayToHex(input.dealId, swap->txids[BASILISK_ALICEPAYMENT].bytes, 32);
Expand All @@ -233,7 +234,6 @@ char *LP_etomicalice_reclaims_payment(struct LP_swap_remember *swap)
}
uint8arrayToHex(input.bobSecret, invertedSecret.bytes, 32);

struct iguana_info *alice_coin = LP_coinfind(swap->alicecoin);
input.decimals = alice_coin->decimals;

strcpy(txData.from, swap->etomicdest);
Expand Down Expand Up @@ -281,7 +281,7 @@ char *LP_etomicbob_spends_alice_payment(struct LP_swap_remember *swap)
}
uint8arrayToHex(input.aliceSecret, invertedSecret.bytes, 32);
uint8arrayToHex(input.bobHash, swap->secretBn, 20);
struct iguana_info *alice_coin = LP_coinfind(swap->alicecoin);
struct iguana_info *alice_coin = LP_coinfind(swap->dest);
input.decimals = alice_coin->decimals;

strcpy(txData.from, swap->etomicsrc);
Expand Down Expand Up @@ -408,7 +408,7 @@ char *LP_etomicbob_refunds_deposit(struct LP_swap_remember *swap)
struct iguana_info *ecoin, *bobcoin;
bits256 privkey;
ecoin = LP_coinfind("ETOMIC");
bobcoin = LP_coinfind(swap->bobcoin);
bobcoin = LP_coinfind(swap->src);
privkey = LP_privkey(ecoin->symbol, ecoin->smartaddr, ecoin->taddr);

EthTxReceipt receipt = getEthTxReceipt(swap->bobDepositEthTx);
Expand Down Expand Up @@ -558,7 +558,7 @@ char *LP_etomicbob_reclaims_payment(struct LP_swap_remember *swap)
struct iguana_info *ecoin, *bobcoin;
bits256 privkey;
ecoin = LP_coinfind("ETOMIC");
bobcoin = LP_coinfind(swap->bobcoin);
bobcoin = LP_coinfind(swap->src);
privkey = LP_privkey(ecoin->symbol, ecoin->smartaddr, ecoin->taddr);

EthTxReceipt receipt = getEthTxReceipt(swap->bobPaymentEthTx);
Expand Down Expand Up @@ -604,7 +604,7 @@ char *LP_etomicalice_spends_bob_payment(struct LP_swap_remember *swap)
struct iguana_info *ecoin, *bobcoin;
bits256 privkey;
ecoin = LP_coinfind("ETOMIC");
bobcoin = LP_coinfind(swap->bobcoin);
bobcoin = LP_coinfind(swap->src);
privkey = LP_privkey(ecoin->symbol, ecoin->smartaddr, ecoin->taddr);

uint8arrayToHex(input.paymentId, swap->txids[BASILISK_BOBPAYMENT].bytes, 32);
Expand Down Expand Up @@ -652,7 +652,7 @@ char *LP_etomicalice_claims_bob_deposit(struct LP_swap_remember *swap)
struct iguana_info *ecoin, *bobcoin;
bits256 privkey;
ecoin = LP_coinfind("ETOMIC");
bobcoin = LP_coinfind(swap->bobcoin);
bobcoin = LP_coinfind(swap->src);
privkey = LP_privkey(ecoin->symbol, ecoin->smartaddr, ecoin->taddr);

uint8arrayToHex(input.depositId, swap->txids[BASILISK_BOBDEPOSIT].bytes, 32);
Expand Down
4 changes: 1 addition & 3 deletions iguana/exchanges/LP_portfolio.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,12 @@ uint64_t LP_balance(uint64_t *valuep,int32_t iambob,char *symbol,char *coinaddr)
cJSON *array,*item; bits256 zero; int32_t i,n; uint64_t valuesum,satoshisum,value;
valuesum = satoshisum = 0;
memset(zero.bytes,0,sizeof(zero));
/*
#ifndef NOTETOMIC
struct iguana_info *coin = LP_coinfind(symbol);
if (coin->etomic[0] != 0) {
if (coin->etomic[0] != 0 && coin->inactive == 0) {
valuesum = LP_etomic_get_balance(coin, coinaddr);
} else
#endif
*/
if ( (array= LP_listunspent(symbol,coinaddr,zero,zero)) != 0 )
{
if ( is_cJSON_Array(array) != 0 && (n= cJSON_GetArraySize(array)) > 0 )
Expand Down
3 changes: 1 addition & 2 deletions iguana/exchanges/etomicswap/etomiccurl.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ size_t writefunc(void *ptr, size_t size, size_t nmemb, struct string *s)

cJSON *parseEthRpcResponse(char *requestResult)
{
printf("Trying to parse ETH RPC response: %s\n", requestResult);
cJSON *json = cJSON_Parse(requestResult);
if (json == NULL) {
printf("ETH RPC response parse failed!\n");
printf("ETH RPC response parse failed: %s!\n", requestResult);
return NULL;
}
cJSON *tmp = cJSON_GetObjectItem(json, "result");
Expand Down
4 changes: 2 additions & 2 deletions start_BEER_ETH_trade.sh → start_BEER_OTHER_trade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ docker-compose exec -T seednode ./setpassphrase
sleep 5
docker-compose exec -T seednode ./enable
sleep 5
docker-compose exec -T seednode ./sell_BEER_ETH
docker-compose exec -T seednode ./sell_BEER_OTHER $1
sleep 5
docker-compose exec -T clientnode ./buy_BEER_ETH
docker-compose exec -T clientnode ./buy_BEER_OTHER $1
12 changes: 12 additions & 0 deletions start_BEER_OTHER_trade_inverted.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
docker-compose exec -T clientnode ./setpassphrase
sleep 5
docker-compose exec -T clientnode ./enable
sleep 5
docker-compose exec -T seednode ./setpassphrase
sleep 5
docker-compose exec -T seednode ./enable
sleep 5
docker-compose exec -T clientnode ./buy_BEER_OTHER $1
sleep 5
docker-compose exec -T seednode ./sell_BEER_OTHER $1

0 comments on commit 9707c21

Please sign in to comment.