diff --git a/Jenkinsfile b/Jenkinsfile index 5fca2513d..5415b55c7 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -22,8 +22,8 @@ cmake --build . --target marketmaker-testnet''' sh '''docker-compose build docker-compose up -d ./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) +timeout 600 grep -q "SWAP completed" <(COMPOSE_HTTP_TIMEOUT=600 docker-compose logs -f clientnode) +timeout 600 grep -q "SWAP completed" <(COMPOSE_HTTP_TIMEOUT=600 docker-compose logs -f seednode) docker-compose down''' } } @@ -32,8 +32,8 @@ docker-compose down''' 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) +timeout 600 grep -q "SWAP completed" <(COMPOSE_HTTP_TIMEOUT=600 docker-compose logs -f clientnode) +timeout 600 grep -q "SWAP completed" <(COMPOSE_HTTP_TIMEOUT=600 docker-compose logs -f seednode) docker-compose down''' } } diff --git a/iguana/exchanges/LP_etomic.c b/iguana/exchanges/LP_etomic.c index b211b4c9f..4c6c57f15 100644 --- a/iguana/exchanges/LP_etomic.c +++ b/iguana/exchanges/LP_etomic.c @@ -22,6 +22,9 @@ // Created by artem on 24.01.18. // #include "LP_etomic.h" +#define ALICE_PAYMENT_SENT 1 +#define BOB_DEPOSIT_SENT 1 +#define BOB_PAYMENT_SENT 1 int32_t LP_etomic_wait_for_confirmation(char *txId) { @@ -218,6 +221,10 @@ char *LP_etomicalice_reclaims_payment(struct LP_swap_remember *swap) privkey = LP_privkey(ecoin->symbol, ecoin->smartaddr, ecoin->taddr); uint8arrayToHex(input.dealId, swap->txids[BASILISK_ALICEPAYMENT].bytes, 32); + if (alicePaymentStatus(input.dealId + 2) != ALICE_PAYMENT_SENT) { + printf("Alice payment smart contract status check failed, can't spend\n"); + return NULL; + } satoshisToWei(input.amount, swap->destamount); if (swap->alicetomic[0] != 0) { @@ -266,6 +273,11 @@ char *LP_etomicbob_spends_alice_payment(struct LP_swap_remember *swap) privkey = LP_privkey(ecoin->symbol, ecoin->smartaddr, ecoin->taddr); uint8arrayToHex(input.dealId, swap->txids[BASILISK_ALICEPAYMENT].bytes, 32); + if (alicePaymentStatus(input.dealId + 2) != ALICE_PAYMENT_SENT) { + printf("Alice payment smart contract status check failed, can't spend\n"); + return NULL; + } + satoshisToWei(input.amount, swap->destamount); if (swap->alicetomic[0] != 0) { @@ -417,6 +429,11 @@ char *LP_etomicbob_refunds_deposit(struct LP_swap_remember *swap) return NULL; } uint8arrayToHex(input.depositId, swap->txids[BASILISK_BOBDEPOSIT].bytes, 32); + if (bobDepositStatus(input.depositId + 2) != BOB_DEPOSIT_SENT) { + printf("Bob deposit smart contract status check failed, can't claim\n"); + return NULL; + } + strcpy(input.aliceAddress, swap->etomicdest); bits256 invertedSecret; @@ -567,6 +584,10 @@ char *LP_etomicbob_reclaims_payment(struct LP_swap_remember *swap) return NULL; } uint8arrayToHex(input.paymentId, swap->txids[BASILISK_BOBPAYMENT].bytes, 32); + if (bobPaymentStatus(input.paymentId + 2) != BOB_PAYMENT_SENT) { + printf("Bob payment smart contract status check failed, can't spend\n"); + return NULL; + } strcpy(input.aliceAddress, swap->etomicdest); uint8arrayToHex(input.aliceHash, swap->secretAm, 20); @@ -608,6 +629,10 @@ char *LP_etomicalice_spends_bob_payment(struct LP_swap_remember *swap) privkey = LP_privkey(ecoin->symbol, ecoin->smartaddr, ecoin->taddr); uint8arrayToHex(input.paymentId, swap->txids[BASILISK_BOBPAYMENT].bytes, 32); + if (bobPaymentStatus(input.paymentId + 2) != BOB_PAYMENT_SENT) { + printf("Bob payment smart contract status check failed, can't spend\n"); + return NULL; + } satoshisToWei(input.amount, swap->values[BASILISK_BOBPAYMENT]); if (swap->bobtomic[0] != 0) { @@ -656,6 +681,11 @@ char *LP_etomicalice_claims_bob_deposit(struct LP_swap_remember *swap) privkey = LP_privkey(ecoin->symbol, ecoin->smartaddr, ecoin->taddr); uint8arrayToHex(input.depositId, swap->txids[BASILISK_BOBDEPOSIT].bytes, 32); + if (bobDepositStatus(input.depositId + 2) != BOB_DEPOSIT_SENT) { + printf("Bob deposit smart contract status check failed, can't claim\n"); + return NULL; + } + satoshisToWei(input.amount, swap->values[BASILISK_BOBDEPOSIT]); if (swap->bobtomic[0] != 0) { diff --git a/iguana/exchanges/etomicswap/etomiccurl.c b/iguana/exchanges/etomicswap/etomiccurl.c index 9618eb200..84985f828 100644 --- a/iguana/exchanges/etomicswap/etomiccurl.c +++ b/iguana/exchanges/etomicswap/etomiccurl.c @@ -196,7 +196,7 @@ char *ethCall(char *to, const char *data) cJSON_AddItemToArray(params, cJSON_CreateString("latest")); cJSON *resultJson = sendRpcRequest("eth_call", params); cJSON_Delete(params); - char* result = NULL; + char *result = NULL; if (resultJson != NULL && is_cJSON_String(resultJson) && resultJson->valuestring != NULL) { result = (char *) malloc(strlen(resultJson->valuestring) + 1); strcpy(result, resultJson->valuestring); diff --git a/iguana/exchanges/etomicswap/etomiclib.cpp b/iguana/exchanges/etomicswap/etomiclib.cpp index d5987ae19..50d2e70c0 100644 --- a/iguana/exchanges/etomicswap/etomiclib.cpp +++ b/iguana/exchanges/etomicswap/etomiclib.cpp @@ -758,7 +758,7 @@ char *sendErc20( return result; } -uint8_t verifyAliceErc20FeeData(char* tokenAddress, char *to, char *amount, char *data, uint8_t decimals) +uint8_t verifyAliceErc20FeeData(char *tokenAddress, char *to, char *amount, char *data, uint8_t decimals) { std::stringstream ss = getErc20TransferData(tokenAddress, to, amount, decimals); if (strcmp(ss.str().c_str(), data) != 0) { @@ -767,3 +767,39 @@ uint8_t verifyAliceErc20FeeData(char* tokenAddress, char *to, char *amount, char } return 1; } + +uint8_t alicePaymentStatus(char *paymentId) +{ + char buffer[100]; + memset(buffer, 0, sizeof(buffer)); + strcpy(buffer, "0x81cd872a"); + strcat(buffer, paymentId); + char *hexStatus = ethCall(ETOMIC_ALICECONTRACT, buffer); + auto status = (uint8_t) strtol(hexStatus + 66, NULL, 0); + free(hexStatus); + return status; +} + +uint8_t bobDepositStatus(char *depositId) +{ + char buffer[100]; + memset(buffer, 0, sizeof(buffer)); + strcpy(buffer, "0x3d4dff7b"); + strcat(buffer, depositId); + char *hexStatus = ethCall(ETOMIC_BOBCONTRACT, buffer); + auto status = (uint8_t) strtol(hexStatus + 130, NULL, 0); + free(hexStatus); + return status; +} + +uint8_t bobPaymentStatus(char *paymentId) +{ + char buffer[100]; + memset(buffer, 0, sizeof(buffer)); + strcpy(buffer, "0x0716326d"); + strcat(buffer, paymentId); + char *hexStatus = ethCall(ETOMIC_BOBCONTRACT, buffer); + auto status = (uint8_t) strtol(hexStatus + 130, NULL, 0); + free(hexStatus); + return status; +} diff --git a/iguana/exchanges/etomicswap/etomiclib.h b/iguana/exchanges/etomicswap/etomiclib.h index 97fa29f18..0e981dc1f 100644 --- a/iguana/exchanges/etomicswap/etomiclib.h +++ b/iguana/exchanges/etomicswap/etomiclib.h @@ -200,7 +200,11 @@ char *sendErc20( ); uint8_t verifyAliceErc20FeeData(char* tokenAddress, char *to, char *amount, char *data, uint8_t decimals); -// Your prototype or Definition + +uint8_t alicePaymentStatus(char *paymentId); +uint8_t bobDepositStatus(char *depositId); +uint8_t bobPaymentStatus(char *paymentId); + #ifdef __cplusplus } #endif