Browse Source

Merge pull request #595 from artemii235/etomic

Got working ETH swaps. Many additional checks are required.
etomic
jl777 7 years ago
committed by GitHub
parent
commit
fe5da7ef0a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 339
      iguana/exchanges/LP_etomic.c
  2. 4
      iguana/exchanges/LP_include.h
  3. 2
      iguana/exchanges/LP_nativeDEX.c
  4. 86
      iguana/exchanges/LP_remember.c
  5. 62
      iguana/exchanges/LP_swap.c
  6. 14
      iguana/exchanges/LP_transaction.c
  7. 202
      iguana/exchanges/etomicswap/bob.c
  8. 42
      iguana/exchanges/etomicswap/etomiccurl.c
  9. 8
      iguana/exchanges/etomicswap/etomiccurl.h
  10. 18
      iguana/exchanges/etomicswap/etomiclib.cpp
  11. 138
      iguana/exchanges/etomicswap/etomiclib.h
  12. 8
      iguana/exchanges/mm.c

339
iguana/exchanges/LP_etomic.c

@ -22,41 +22,348 @@
// Created by artem on 24.01.18.
//
#include "etomicswap/etomiclib.h"
#include "etomicswap/etomiccurl.h"
#include <inttypes.h>
#define ETOMIC_ALICECONTRACT "0xe1D4236C5774D35Dc47dcc2E5E0CcFc463A3289c"
#define ETOMIC_BOBCONTRACT "0x9387Fd3a016bB0205e4e131Dde886B9d2BC000A2"
#define ETOMIC_SATOSHICAT "0000000000"
int32_t LP_etomicsymbol(char *activesymbol,char *etomic,char *symbol)
{
struct iguana_info *coin;
etomic[0] = activesymbol[0] = 0;
if ( (coin= LP_coinfind(symbol)) != 0 )
{
strcpy(etomic,coin->etomic);
if ( etomic[0] != 0 )
strcpy(activesymbol,"ETOMIC");
else strcpy(activesymbol,symbol);
}
return(etomic[0] != 0);
}
char *LP_etomicalice_start(struct basilisk_swap *swap)
char *LP_etomicalice_send_payment(struct basilisk_swap *swap)
{
AliceSendsEthPaymentInput input; AliceSendsErc20PaymentInput input20; BasicTxData txData;
// set input and txData fields from the swap data structure
memset(&txData,0,sizeof(txData));
if ( strcmp(swap->I.alicestr,"ETH") == 0 )
{
memset(&input,0,sizeof(input));
strcpy(input.bobAddress, swap->I.etomicsrc);
uint8arrayToHex(input.bobHash, swap->I.secretBn, 20);
uint8arrayToHex(input.aliceHash, swap->I.secretAm, 20);
uint8arrayToHex(input.dealId, swap->alicepayment.I.actualtxid.bytes, 32);
strcpy(txData.from, swap->I.etomicdest);
strcpy(txData.to, ETOMIC_ALICECONTRACT);
satoshisToWei(txData.amount, swap->I.alicesatoshis);
uint8arrayToHex(txData.secretKey, swap->persistent_privkey.bytes, 32);
return(aliceSendsEthPayment(input,txData));
}
else
{
memset(&input20,0,sizeof(input20));
strcpy(input20.bobAddress, swap->I.etomicdest);
uint8arrayToHex(input20.bobHash, swap->I.secretBn, 20);
uint8arrayToHex(input20.aliceHash, swap->I.secretAm, 20);
uint8arrayToHex(input20.dealId, swap->alicepayment.utxotxid.bytes, 32);
strcpy(input20.tokenAddress, swap->I.alicetomic);
satoshisToWei(input20.amount, swap->I.alicesatoshis);
strcpy(txData.from, swap->I.etomicsrc);
strcpy(txData.to, ETOMIC_ALICECONTRACT);
strcpy(txData.amount, "0");
uint8arrayToHex(txData.secretKey, swap->persistent_privkey.bytes, 32);
return(aliceSendsErc20Payment(input20,txData));
}
return(0);
}
char *LP_etomicalice_reclaims_payment(struct LP_swap_remember *swap)
{
AliceReclaimsAlicePaymentInput input;
BasicTxData txData;
memset(&txData,0,sizeof(txData));
memset(&input,0,sizeof(input));
struct iguana_info *ecoin;
bits256 privkey;
ecoin = LP_coinfind("ETOMIC");
privkey = LP_privkey(ecoin->symbol, ecoin->smartaddr, ecoin->taddr);
uint8arrayToHex(input.dealId, swap->txids[BASILISK_ALICEPAYMENT].bytes, 32);
satoshisToWei(input.amount, swap->values[BASILISK_ALICEPAYMENT]);
if (swap->alicetomic[0] != 0) {
strcpy(input.tokenAddress, swap->alicetomic);
} else {
strcpy(input.tokenAddress, "0x0000000000000000000000000000000000000000");
}
strcpy(input.bobAddress, swap->etomicdest);
uint8arrayToHex(input.aliceHash, swap->secretAm, 20);
bits256 invertedSecret;
int32_t i;
for (i=0; i<32; i++) {
invertedSecret.bytes[i] = swap->privBn.bytes[31 - i];
}
uint8arrayToHex(input.bobSecret, invertedSecret.bytes, 32);
strcpy(txData.from, swap->etomicsrc);
strcpy(txData.to, ETOMIC_ALICECONTRACT);
strcpy(txData.amount, "0");
uint8arrayToHex(txData.secretKey, privkey.bytes, 32);
return aliceReclaimsAlicePayment(input, txData);
}
char *LP_etomicbob_spends_alice_payment(struct LP_swap_remember *swap)
{
BobSpendsAlicePaymentInput input;
BasicTxData txData;
memset(&txData,0,sizeof(txData));
memset(&input,0,sizeof(input));
struct iguana_info *ecoin;
bits256 privkey;
ecoin = LP_coinfind("ETOMIC");
privkey = LP_privkey(ecoin->symbol, ecoin->smartaddr, ecoin->taddr);
uint8arrayToHex(input.dealId, swap->txids[BASILISK_ALICEPAYMENT].bytes, 32);
satoshisToWei(input.amount, swap->destamount);
if (swap->alicetomic[0] != 0) {
strcpy(input.tokenAddress, swap->alicetomic);
} else {
strcpy(input.tokenAddress, "0x0000000000000000000000000000000000000000");
}
strcpy(input.aliceAddress, swap->etomicdest);
bits256 invertedSecret; int32_t i;
for (i=0; i<32; i++) {
invertedSecret.bytes[i] = swap->privAm.bytes[31 - i];
}
uint8arrayToHex(input.aliceSecret, invertedSecret.bytes, 32);
uint8arrayToHex(input.bobHash, swap->secretBn, 20);
strcpy(txData.from, swap->etomicsrc);
strcpy(txData.to, ETOMIC_ALICECONTRACT);
strcpy(txData.amount, "0");
uint8arrayToHex(txData.secretKey, privkey.bytes, 32);
return bobSpendsAlicePayment(input, txData);
}
char *LP_etomicbob_sends_deposit(struct basilisk_swap *swap)
{
BobSendsEthDepositInput input;
BobSendsErc20DepositInput input20;
BasicTxData txData;
memset(&txData,0,sizeof(txData));
memset(&input,0,sizeof(input));
memset(&input20,0,sizeof(input20));
if ( strcmp(swap->I.bobstr,"ETH") == 0 ) {
uint8arrayToHex(input.depositId, swap->bobdeposit.I.actualtxid.bytes, 32);
strcpy(input.aliceAddress, swap->I.etomicdest);
uint8arrayToHex(input.bobHash, swap->I.secretBn, 20);
strcpy(txData.from, swap->I.etomicsrc);
strcpy(txData.to, ETOMIC_BOBCONTRACT);
satoshisToWei(txData.amount, swap->bobdeposit.I.amount);
uint8arrayToHex(txData.secretKey, swap->persistent_privkey.bytes, 32);
return bobSendsEthDeposit(input, txData);
} else {
uint8arrayToHex(input20.depositId, swap->bobdeposit.I.actualtxid.bytes, 32);
strcpy(input20.aliceAddress, swap->I.etomicdest);
uint8arrayToHex(input20.bobHash, swap->I.secretBn, 20);
satoshisToWei(input20.amount, swap->bobdeposit.I.amount);
strcpy(input20.tokenAddress, swap->I.bobtomic);
strcpy(txData.from, swap->I.etomicsrc);
strcpy(txData.to, ETOMIC_BOBCONTRACT);
strcpy(txData.amount, "0");
uint8arrayToHex(txData.secretKey, swap->persistent_privkey.bytes, 32);
return bobSendsErc20Deposit(input20, txData);
}
}
char *LP_etomicbob_refunds_deposit(struct LP_swap_remember *swap)
{
BobRefundsDepositInput input;
BasicTxData txData;
memset(&txData,0,sizeof(txData));
memset(&input,0,sizeof(input));
struct iguana_info *ecoin;
bits256 privkey;
ecoin = LP_coinfind("ETOMIC");
privkey = LP_privkey(ecoin->symbol, ecoin->smartaddr, ecoin->taddr);
EthTxReceipt receipt = getEthTxReceipt(swap->bobDepositEthTx);
uint8arrayToHex(input.depositId, swap->txids[BASILISK_BOBDEPOSIT].bytes, 32);
strcpy(input.aliceAddress, swap->etomicdest);
sprintf(input.aliceCanClaimAfter, "%" PRIu64, receipt.blockNumber + 960);
bits256 invertedSecret;
int32_t i;
for (i=0; i<32; i++) {
invertedSecret.bytes[i] = swap->privBn.bytes[31 - i];
}
uint8arrayToHex(input.bobSecret, invertedSecret.bytes, 32);
if (swap->bobtomic[0] != 0) {
strcpy(input.tokenAddress, swap->bobtomic);
} else {
strcpy(input.tokenAddress, "0x0000000000000000000000000000000000000000");
}
satoshisToWei(input.amount, swap->values[BASILISK_BOBDEPOSIT]);
strcpy(txData.from, swap->etomicsrc);
strcpy(txData.to, ETOMIC_BOBCONTRACT);
strcpy(txData.amount, "0");
uint8arrayToHex(txData.secretKey, privkey.bytes, 32);
return bobRefundsDeposit(input, txData);
}
char *LP_etomicbob_sends_payment(struct basilisk_swap *swap)
{
BobSendsEthPaymentInput input;
BobSendsErc20PaymentInput input20;
BasicTxData txData;
memset(&txData,0,sizeof(txData));
memset(&input,0,sizeof(input));
memset(&input20,0,sizeof(input20));
if ( strcmp(swap->I.bobstr,"ETH") == 0 ) {
uint8arrayToHex(input.paymentId, swap->bobpayment.I.actualtxid.bytes, 32);
strcpy(input.aliceAddress, swap->I.etomicdest);
uint8arrayToHex(input.aliceHash, swap->I.secretAm, 20);
strcpy(txData.from, swap->I.etomicsrc);
strcpy(txData.to, ETOMIC_BOBCONTRACT);
satoshisToWei(txData.amount, swap->bobpayment.I.amount);
uint8arrayToHex(txData.secretKey, swap->persistent_privkey.bytes, 32);
return bobSendsEthPayment(input, txData);
} else {
uint8arrayToHex(input20.paymentId, swap->bobpayment.I.actualtxid.bytes, 32);
strcpy(input20.aliceAddress, swap->I.etomicdest);
uint8arrayToHex(input20.aliceHash, swap->I.secretAm, 20);
satoshisToWei(input20.amount, swap->bobpayment.I.amount);
strcpy(input20.tokenAddress, swap->I.bobtomic);
strcpy(txData.from, swap->I.etomicsrc);
strcpy(txData.to, ETOMIC_BOBCONTRACT);
strcpy(txData.amount, "0");
uint8arrayToHex(txData.secretKey, swap->persistent_privkey.bytes, 32);
return bobSendsErc20Payment(input20, txData);
}
}
char *LP_etomicbob_reclaims_payment(struct LP_swap_remember *swap)
{
BobReclaimsBobPaymentInput input;
BasicTxData txData;
memset(&txData,0,sizeof(txData));
memset(&input,0,sizeof(input));
struct iguana_info *ecoin;
bits256 privkey;
ecoin = LP_coinfind("ETOMIC");
privkey = LP_privkey(ecoin->symbol, ecoin->smartaddr, ecoin->taddr);
EthTxReceipt receipt = getEthTxReceipt(swap->bobPaymentEthTx);
uint8arrayToHex(input.paymentId, swap->txids[BASILISK_BOBPAYMENT].bytes, 32);
strcpy(input.aliceAddress, swap->etomicdest);
sprintf(input.bobCanClaimAfter, "%" PRIu64, receipt.blockNumber + 480);
uint8arrayToHex(input.aliceHash, swap->secretAm, 20);
if (swap->bobtomic[0] != 0) {
strcpy(input.tokenAddress, swap->bobtomic);
} else {
strcpy(input.tokenAddress, "0x0000000000000000000000000000000000000000");
}
satoshisToWei(input.amount, swap->values[BASILISK_BOBPAYMENT]);
strcpy(txData.from, swap->etomicsrc);
strcpy(txData.to, ETOMIC_BOBCONTRACT);
strcpy(txData.amount, "0");
uint8arrayToHex(txData.secretKey, privkey.bytes, 32);
return bobReclaimsBobPayment(input, txData);
}
char *LP_etomicalice_spends_bob_payment(struct LP_swap_remember *swap)
{
AliceSpendsBobPaymentInput input;
BasicTxData txData;
memset(&txData,0,sizeof(txData));
memset(&input,0,sizeof(input));
EthTxReceipt receipt = getEthTxReceipt(swap->bobPaymentEthTx);
struct iguana_info *ecoin;
bits256 privkey;
ecoin = LP_coinfind("ETOMIC");
privkey = LP_privkey(ecoin->symbol, ecoin->smartaddr, ecoin->taddr);
uint8arrayToHex(input.paymentId, swap->txids[BASILISK_BOBPAYMENT].bytes, 32);
satoshisToWei(input.amount, swap->values[BASILISK_BOBPAYMENT]);
sprintf(input.bobCanClaimAfter, "%" PRIu64, receipt.blockNumber + 480);
if (swap->bobtomic[0] != 0) {
strcpy(input.tokenAddress, swap->bobtomic);
} else {
strcpy(input.tokenAddress, "0x0000000000000000000000000000000000000000");
}
strcpy(input.bobAddress, swap->etomicsrc);
bits256 invertedSecret; int32_t i;
for (i=0; i<32; i++) {
invertedSecret.bytes[i] = swap->privAm.bytes[31 - i];
}
uint8arrayToHex(input.aliceSecret, invertedSecret.bytes, 32);
strcpy(txData.from, swap->etomicdest);
strcpy(txData.to, ETOMIC_BOBCONTRACT);
strcpy(txData.amount, "0");
uint8arrayToHex(txData.secretKey, privkey.bytes, 32);
return aliceSpendsBobPayment(input, txData);
}
char *LP_etomicalice_claims_bob_deposit(struct LP_swap_remember *swap)
{
AliceClaimsBobDepositInput input;
BasicTxData txData;
memset(&txData,0,sizeof(txData));
memset(&input,0,sizeof(input));
EthTxReceipt receipt = getEthTxReceipt(swap->bobDepositEthTx);
struct iguana_info *ecoin;
bits256 privkey;
ecoin = LP_coinfind("ETOMIC");
privkey = LP_privkey(ecoin->symbol, ecoin->smartaddr, ecoin->taddr);
uint8arrayToHex(input.depositId, swap->txids[BASILISK_BOBDEPOSIT].bytes, 32);
satoshisToWei(input.amount, swap->values[BASILISK_BOBDEPOSIT]);
sprintf(input.aliceCanClaimAfter, "%" PRIu64, receipt.blockNumber + 960);
if (swap->bobtomic[0] != 0) {
strcpy(input.tokenAddress, swap->bobtomic);
} else {
strcpy(input.tokenAddress, "0x0000000000000000000000000000000000000000");
}
strcpy(input.bobAddress, swap->etomicsrc);
uint8arrayToHex(input.bobHash, swap->secretBn, 20);
strcpy(txData.from, swap->etomicdest);
strcpy(txData.to, ETOMIC_BOBCONTRACT);
strcpy(txData.amount, "0");
uint8arrayToHex(txData.secretKey, privkey.bytes, 32);
return aliceClaimsBobDeposit(input, txData);
}
char *sendEthTx(struct basilisk_swap *swap, struct basilisk_rawtx *rawtx)
{
if (rawtx == &swap->alicepayment && swap->I.alicetomic[0] != 0) {
return LP_etomicalice_send_payment(swap);
} else if (rawtx == &swap->bobdeposit && swap->I.bobtomic[0] != 0) {
return LP_etomicbob_sends_deposit(swap);
} else if (rawtx == &swap->bobpayment && swap->I.bobtomic[0] != 0) {
return LP_etomicbob_sends_payment(swap);
} else {
char *result = malloc(67);
strcpy(result, "0x0000000000000000000000000000000000000000000000000000000000000000");
return result;
}
}
int32_t LP_etomic_priv2addr(char *coinaddr,bits256 privkey)

4
iguana/exchanges/LP_include.h

@ -202,7 +202,7 @@ struct basilisk_swap;
struct basilisk_rawtxinfo
{
char destaddr[64];
char destaddr[64],ethTxid[75];
bits256 txid,signedtxid,actualtxid;
int64_t amount,change,inputsum;
int32_t redeemlen,datalen,completed,vintype,vouttype,numconfirms,spendlen,secretstart,suppress_pubkeys;
@ -276,7 +276,7 @@ struct LP_swap_remember
uint32_t finishtime,tradeid,requestid,quoteid,plocktime,dlocktime,expiration,state,otherstate;
int32_t iambob,finishedflag,origfinishedflag,Predeemlen,Dredeemlen,sentflags[sizeof(txnames)/sizeof(*txnames)];
uint8_t secretAm[20],secretAm256[32],secretBn[20],secretBn256[32],Predeemscript[1024],Dredeemscript[1024],pubkey33[33],other33[33];
char Agui[65],Bgui[65],gui[65],src[65],dest[65],bobtomic[128],alicetomic[128],etomicsrc[65],etomicdest[65],destaddr[64],Adestaddr[64],Sdestaddr[64],alicepaymentaddr[64],bobpaymentaddr[64],bobdepositaddr[64],alicecoin[65],bobcoin[65],*txbytes[sizeof(txnames)/sizeof(*txnames)];
char Agui[65],Bgui[65],gui[65],src[65],dest[65],bobtomic[128],alicetomic[128],etomicsrc[65],etomicdest[65],destaddr[64],Adestaddr[64],Sdestaddr[64],alicepaymentaddr[64],bobpaymentaddr[64],bobdepositaddr[64],alicecoin[65],bobcoin[65],*txbytes[sizeof(txnames)/sizeof(*txnames)],bobDepositEthTx[75],bobPaymentEthTx[75];
};
struct LP_outpoint

2
iguana/exchanges/LP_nativeDEX.c

@ -174,11 +174,11 @@ char *blocktrail_listtransactions(char *symbol,char *coinaddr,int32_t num,int32_
#include "LP_NXT.c"
#include "LP_cache.c"
#include "LP_RTmetrics.c"
#include "LP_etomic.c"
#include "LP_utxo.c"
#include "LP_prices.c"
#include "LP_scan.c"
#include "LP_transaction.c"
#include "LP_etomic.c"
#include "LP_stats.c"
#include "LP_remember.c"
#include "LP_instantdex.c"

86
iguana/exchanges/LP_remember.c

@ -17,7 +17,6 @@
// LP_remember.c
// marketmaker
//
void basilisk_dontforget_userdata(char *userdataname,FILE *fp,uint8_t *script,int32_t scriptlen)
{
int32_t i; char scriptstr[513];
@ -70,6 +69,13 @@ void basilisk_dontforget(struct basilisk_swap *swap,struct basilisk_rawtx *rawtx
fprintf(fp,",\"bobtomic\":\"%s\"",swap->I.bobtomic);
if ( swap->I.etomicsrc[0] != 0 )
fprintf(fp,",\"etomicsrc\":\"%s\"",swap->I.etomicsrc);
if (swap->bobdeposit.I.ethTxid[0] != 0) {
fprintf(fp,",\"bobDepositEthTx\":\"%s\"", swap->bobdeposit.I.ethTxid);
}
if (swap->bobpayment.I.ethTxid[0] != 0) {
fprintf(fp,",\"bobPaymentEthTx\":\"%s\"", swap->bobpayment.I.ethTxid);
}
fprintf(fp,",\"alicecoin\":\"%s\"",swap->I.alicestr);
if ( swap->I.alicetomic[0] != 0 )
fprintf(fp,",\"alicetomic\":\"%s\"",swap->I.alicetomic);
@ -128,6 +134,7 @@ void basilisk_dontforget(struct basilisk_swap *swap,struct basilisk_rawtx *rawtx
init_hexbytes_noT(secretBn256str,swap->I.secretBn256,32);
fprintf(fp,",\"secretBn256\":\"%s\"",secretBn256str);
}
for (i=0; i<2; i++)
if ( bits256_nonz(swap->I.myprivs[i]) != 0 )
fprintf(fp,",\"myprivs%d\":\"%s\"",i,bits256_str(str,swap->I.myprivs[i]));
@ -845,6 +852,31 @@ int32_t LP_swap_load(struct LP_swap_remember *rswap,int32_t forceflag)
free_json(txobj);
continue;
}
if (jstr(txobj,"etomicsrc") != 0) {
strcpy(rswap->etomicsrc,jstr(txobj,"etomicsrc"));
}
if (jstr(txobj,"etomicdest") != 0) {
strcpy(rswap->etomicdest,jstr(txobj,"etomicdest"));
}
if (jstr(txobj,"bobDepositEthTx") != 0) {
strcpy(rswap->bobDepositEthTx, jstr(txobj,"bobDepositEthTx"));
}
if (jstr(txobj,"bobPaymentEthTx") != 0) {
strcpy(rswap->bobPaymentEthTx, jstr(txobj,"bobPaymentEthTx"));
}
if (jstr(txobj,"bobtomic") != 0) {
strcpy(rswap->bobtomic, jstr(txobj,"bobtomic"));
}
if (jstr(txobj,"alicetomic") != 0) {
strcpy(rswap->alicetomic, jstr(txobj,"alicetomic"));
}
rswap->txids[i] = txid;
if ( jstr(txobj,"Apayment") != 0 )
safecopy(rswap->alicepaymentaddr,jstr(txobj,"Apayment"),sizeof(rswap->alicepaymentaddr));
@ -916,6 +948,7 @@ int32_t LP_swap_load(struct LP_swap_remember *rswap,int32_t forceflag)
//printf("%s %s %.8f\n",txnames[i],bits256_str(str,txid),dstr(value));
}
}
free_json(txobj);
} //else printf("no symbol\n");
free(fstr);
@ -1019,24 +1052,8 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
srcAdest = srcBdest = destAdest = destBdest = 0;
alice = LP_coinfind(rswap.alicecoin);
bob = LP_coinfind(rswap.bobcoin);
if ( alice != 0 )
strcpy(etomicdest,alice->smartaddr);
else etomicdest[0] = 0;
if ( bob != 0 )
strcpy(etomicsrc,bob->smartaddr);
else etomicsrc[0] = 0;
LP_etomicsymbol(bobstr,bobtomic,rswap.src);
if ( bobtomic[0] != 0 )
{
if ( (coin= LP_coinfind(rswap.src)) != 0 )
strcpy(etomicsrc,coin->smartaddr);
}
LP_etomicsymbol(alicestr,alicetomic,rswap.dest);
if ( alicetomic[0] != 0 )
{
if ( (coin= LP_coinfind(rswap.dest)) != 0 )
strcpy(etomicdest,coin->smartaddr);
}
if ( rswap.bobcoin[0] == 0 || rswap.alicecoin[0] == 0 || strcmp(rswap.bobcoin,bobstr) != 0 || strcmp(rswap.alicecoin,alicestr) != 0 )
{
//printf("legacy r%u-q%u DB SWAPS.(%u %u) %llu files BOB.(%s) Alice.(%s) src.(%s) dest.(%s)\n",requestid,quoteid,rswap.requestid,rswap.quoteid,(long long)rswap.aliceid,rswap.bobcoin,rswap.alicecoin,rswap.src,rswap.dest);
@ -1194,7 +1211,10 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
rev.bytes[j] = rswap.myprivs[0].bytes[31 - j];
if ( (rswap.txbytes[BASILISK_ALICESPEND]= basilisk_swap_bobtxspend(&signedtxid,rswap.Btxfee,"alicespend",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[0],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBPAYMENT],0,0,rswap.pubkey33,1,rswap.expiration,&rswap.values[BASILISK_ALICESPEND],0,0,rswap.bobpaymentaddr,1,bob->zcash)) != 0 )
{
//printf("alicespend.(%s)\n",rswap.txbytes[BASILISK_ALICESPEND]);
if (rswap.bobtomic[0] != 0) {
char *aliceSpendEthTxId = LP_etomicalice_spends_bob_payment(&rswap);
free(aliceSpendEthTxId);
}
}
}
LP_txbytes_update("alicespend",rswap.bobcoin,rswap.txbytes[BASILISK_ALICESPEND],&rswap.txids[BASILISK_ALICESPEND],&rswap.paymentspent,&rswap.sentflags[BASILISK_ALICESPEND]);
@ -1220,8 +1240,13 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
if ( redeemlen > 0 )
{
len = basilisk_swapuserdata(userdata,zero,1,rswap.myprivs[0],redeemscript,redeemlen);
if ( (rswap.txbytes[BASILISK_ALICECLAIM]= basilisk_swap_bobtxspend(&signedtxid,rswap.Btxfee,"aliceclaim",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[0],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBDEPOSIT],0,0,rswap.pubkey33,0,claimtime,&rswap.values[BASILISK_ALICECLAIM],0,0,rswap.bobdepositaddr,1,bob->zcash)) != 0 )
printf("claimtime.%u aliceclaim.(%s)\n",claimtime,rswap.txbytes[BASILISK_ALICECLAIM]);
if ( (rswap.txbytes[BASILISK_ALICECLAIM]= basilisk_swap_bobtxspend(&signedtxid,rswap.Btxfee,"aliceclaim",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[0],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBDEPOSIT],0,0,rswap.pubkey33,0,claimtime,&rswap.values[BASILISK_ALICECLAIM],0,0,rswap.bobdepositaddr,1,bob->zcash)) != 0 ) {
printf("claimtime.%u aliceclaim.(%s)\n", claimtime, rswap.txbytes[BASILISK_ALICECLAIM]);
if (rswap.bobtomic[0] != 0) {
char *aliceClaimsEthTxId = LP_etomicalice_claims_bob_deposit(&rswap);
free(aliceClaimsEthTxId);
}
}
}
LP_txbytes_update("aliceclaim",rswap.bobcoin,rswap.txbytes[BASILISK_ALICECLAIM],&rswap.txids[BASILISK_ALICECLAIM],&rswap.depositspent,&rswap.sentflags[BASILISK_ALICECLAIM]);
}
@ -1241,8 +1266,13 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
rswap.privBn = basilisk_swap_privBn_extract(&rswap.txids[BASILISK_BOBREFUND],rswap.bobcoin,rswap.txids[BASILISK_BOBDEPOSIT],rswap.privBn);
if ( bits256_nonz(rswap.txids[BASILISK_ALICEPAYMENT]) != 0 && bits256_nonz(rswap.privAm) != 0 && bits256_nonz(rswap.privBn) != 0 )
{
if ( (rswap.txbytes[BASILISK_ALICERECLAIM]= basilisk_swap_Aspend("alicereclaim",rswap.alicecoin,rswap.Atxfee,alice->wiftaddr,alice->taddr,alice->pubtype,alice->p2shtype,alice->isPoS,alice->wiftype,ctx,rswap.privAm,rswap.privBn,rswap.txids[BASILISK_ALICEPAYMENT],0,rswap.pubkey33,rswap.expiration,&rswap.values[BASILISK_ALICERECLAIM],rswap.alicepaymentaddr,alice->zcash)) != 0 )
printf("alicereclaim.(%s)\n",rswap.txbytes[BASILISK_ALICERECLAIM]);
if ( (rswap.txbytes[BASILISK_ALICERECLAIM]= basilisk_swap_Aspend("alicereclaim",rswap.alicecoin,rswap.Atxfee,alice->wiftaddr,alice->taddr,alice->pubtype,alice->p2shtype,alice->isPoS,alice->wiftype,ctx,rswap.privAm,rswap.privBn,rswap.txids[BASILISK_ALICEPAYMENT],0,rswap.pubkey33,rswap.expiration,&rswap.values[BASILISK_ALICERECLAIM],rswap.alicepaymentaddr,alice->zcash)) != 0 ) {
printf("alicereclaim.(%s)\n", rswap.txbytes[BASILISK_ALICERECLAIM]);
if (rswap.alicetomic[0] != 0) {
char *aliceReclaimEthTx = LP_etomicalice_reclaims_payment(&rswap);
free(aliceReclaimEthTx);
}
}
}
LP_txbytes_update("alicereclaim",rswap.alicecoin,rswap.txbytes[BASILISK_ALICERECLAIM],&rswap.txids[BASILISK_ALICERECLAIM],&rswap.Apaymentspent,&rswap.sentflags[BASILISK_ALICERECLAIM]);
}
@ -1274,6 +1304,10 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
{
if ( (rswap.txbytes[BASILISK_BOBSPEND]= basilisk_swap_Aspend("bobspend",rswap.alicecoin,rswap.Atxfee,alice->wiftaddr,alice->taddr,alice->pubtype,alice->p2shtype,alice->isPoS,alice->wiftype,ctx,rswap.privAm,rswap.privBn,rswap.txids[BASILISK_ALICEPAYMENT],0,rswap.pubkey33,rswap.expiration,&rswap.values[BASILISK_BOBSPEND],rswap.alicepaymentaddr,alice->zcash)) != 0 )
{
if (rswap.alicetomic[0] != 0) {
char *bobSpendEthTx = LP_etomicbob_spends_alice_payment(&rswap);
free(bobSpendEthTx);
}
//printf("bobspend.(%s)\n",rswap.txbytes[BASILISK_BOBSPEND]);
}
}
@ -1299,6 +1333,10 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
len = basilisk_swapuserdata(userdata,zero,1,rswap.myprivs[1],redeemscript,redeemlen);
if ( (rswap.txbytes[BASILISK_BOBRECLAIM]= basilisk_swap_bobtxspend(&signedtxid,rswap.Btxfee,"bobreclaim",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[1],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBPAYMENT],0,0,rswap.pubkey33,0,claimtime,&rswap.values[BASILISK_BOBRECLAIM],0,0,rswap.bobpaymentaddr,1,bob->zcash)) != 0 )
{
if (rswap.bobtomic[0] != 0) {
char *bobReclaimEthTx = LP_etomicbob_reclaims_payment(&rswap);
free(bobReclaimEthTx);
}
//int32_t z;
//for (z=0; z<20; z++)
// printf("%02x",rswap.secretAm[z]);
@ -1333,6 +1371,10 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
len = basilisk_swapuserdata(userdata,rswap.privBn,0,rswap.myprivs[0],redeemscript,redeemlen);
if ( (rswap.txbytes[BASILISK_BOBREFUND]= basilisk_swap_bobtxspend(&signedtxid,rswap.Btxfee,"bobrefund",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[0],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBDEPOSIT],0,0,rswap.pubkey33,1,rswap.expiration,&rswap.values[BASILISK_BOBREFUND],0,0,rswap.bobdepositaddr,1,bob->zcash)) != 0 )
{
if (rswap.bobtomic[0] != 0) {
char *bobRefundsEthTx = LP_etomicbob_refunds_deposit(&rswap);
free(bobRefundsEthTx);
}
//printf("pubB1.(%s) bobrefund.(%s)\n",bits256_str(str,rswap.pubB1),rswap.txbytes[BASILISK_BOBREFUND]);
}
}

62
iguana/exchanges/LP_swap.c

@ -583,6 +583,7 @@ int32_t LP_rawtx_spendscript(struct basilisk_swap *swap,int32_t height,struct ba
otherhash.bytes[i] = recvbuf[offset++];
for (i=0; i<32; i++)
myhash.bytes[i] = recvbuf[offset++];
offset += iguana_rwnum(0,&recvbuf[offset],sizeof(quoteid),&quoteid);
offset += iguana_rwnum(0,&recvbuf[offset],sizeof(msgbits),&msgbits);
datalen = recvbuf[offset++];
@ -593,6 +594,9 @@ int32_t LP_rawtx_spendscript(struct basilisk_swap *swap,int32_t height,struct ba
return(-1);
}
rawtx->I.redeemlen = recvbuf[offset++];
uint8arrayToHex(rawtx->I.ethTxid, &recvbuf[offset], 32);
offset += 32;
printf("ETH txid received: %s\n", rawtx->I.ethTxid);
data = &recvbuf[offset];
if ( rawtx->I.redeemlen > 0 && rawtx->I.redeemlen < 0x100 )
{
@ -625,7 +629,9 @@ int32_t LP_rawtx_spendscript(struct basilisk_swap *swap,int32_t height,struct ba
printf("%s rawtx data compare error, len %d vs %d <<<<<<<<<< warning\n",rawtx->name,rawtx->I.datalen,datalen);
return(-1);
}
if ( recvlen != datalen+rawtx->I.redeemlen+75 )
if ( recvlen != datalen+rawtx->I.redeemlen + 107 )
printf("RECVLEN %d != %d + %d\n",recvlen,datalen,rawtx->I.redeemlen);
txid = bits256_calctxid(coin->symbol,data,datalen);
//char str[65]; printf("rawtx.%s txid %s\n",rawtx->name,bits256_str(str,txid));
@ -691,10 +697,25 @@ uint32_t LP_swapdata_rawtxsend(int32_t pairsock,struct basilisk_swap *swap,uint3
}
if ( bits256_nonz(rawtx->I.actualtxid) != 0 && msgbits != 0 )
{
if (swap->I.bobtomic[0] != 0 || swap->I.alicetomic[0] != 0) {
char *ethTxId = sendEthTx(swap, rawtx);
strcpy(rawtx->I.ethTxid, ethTxId);
free(ethTxId);
}
sendlen = 0;
sendbuf[sendlen++] = rawtx->I.datalen & 0xff;
sendbuf[sendlen++] = (rawtx->I.datalen >> 8) & 0xff;
sendbuf[sendlen++] = rawtx->I.redeemlen;
if (rawtx->I.ethTxid[0] != 0 && strlen(rawtx->I.ethTxid) == 66) {
uint8_t ethTxidBytes[32];
// ETH txid always starts with 0x
decode_hex(ethTxidBytes, 32, rawtx->I.ethTxid + 2);
memcpy(&sendbuf[sendlen], ethTxidBytes, 32);
} else {
// fill with zero bytes to always have fixed message size
memset(&sendbuf[sendlen], 0, 32);
}
sendlen += 32;
//int32_t z; for (z=0; z<rawtx->I.datalen; z++) printf("%02x",rawtx->txbytes[z]); printf(" >>>>>>> send.%d %s\n",rawtx->I.datalen,rawtx->name);
//printf("datalen.%d redeemlen.%d\n",rawtx->I.datalen,rawtx->I.redeemlen);
memcpy(&sendbuf[sendlen],rawtx->txbytes,rawtx->I.datalen), sendlen += rawtx->I.datalen;
@ -703,6 +724,7 @@ uint32_t LP_swapdata_rawtxsend(int32_t pairsock,struct basilisk_swap *swap,uint3
memcpy(&sendbuf[sendlen],rawtx->redeemscript,rawtx->I.redeemlen);
sendlen += rawtx->I.redeemlen;
}
basilisk_dontforget_update(swap,rawtx);
//printf("sendlen.%d datalen.%d redeemlen.%d\n",sendlen,rawtx->datalen,rawtx->redeemlen);
if ( suppress_swapsend == 0 )
@ -792,6 +814,7 @@ void LP_bobloop(void *_swap)
printf("error bobscripts deposit\n");
else
{
uint8_t error = 0;
swap->bobrefund.utxovout = 0;
swap->bobrefund.utxotxid = swap->bobdeposit.I.signedtxid;
basilisk_bobdeposit_refund(swap,swap->I.putduration);
@ -799,12 +822,25 @@ void LP_bobloop(void *_swap)
LP_swapsfp_update(&swap->I.req);
LP_swap_critical = (uint32_t)time(NULL);
if ( LP_waitfor(swap->N.pair,swap,LP_SWAPSTEP_TIMEOUT*10,LP_verify_otherfee) < 0 )
{
error = 1;
printf("error waiting for alicefee\n");
else if ( LP_swapdata_rawtxsend(swap->N.pair,swap,0x200,data,maxlen,&swap->bobdeposit,0x100,0) == 0 )
printf("error sending bobdeposit\n");
else if ( LP_waitfor(swap->N.pair,swap,1800,LP_verify_alicepayment) < 0 )
}
if ( error == 0 ) {
if ( LP_swapdata_rawtxsend(swap->N.pair,swap,0x200,data,maxlen,&swap->bobdeposit,0x100,0) == 0 ) {
error = 1;
printf("error sending bobdeposit\n");
}
}
if ( error == 0 && LP_waitfor(swap->N.pair,swap,1800,LP_verify_alicepayment) < 0 )
{
error = 1;
printf("error waiting for alicepayment\n");
else
}
if (error == 0)
{
LP_swap_critical = (uint32_t)time(NULL);
if ( basilisk_bobscripts_set(swap,0,1) < 0 )
@ -819,8 +855,10 @@ void LP_bobloop(void *_swap)
sleep(10);
}
LP_swap_critical = (uint32_t)time(NULL);
if ( LP_swapdata_rawtxsend(swap->N.pair,swap,0x8000,data,maxlen,&swap->bobpayment,0x4000,0) == 0 )
if ( LP_swapdata_rawtxsend(swap->N.pair,swap,0x8000,data,maxlen,&swap->bobpayment,0x4000,0) == 0 ) {
printf("error sending bobpayment\n");
}
//if ( LP_waitfor(swap->N.pair,swap,10,LP_verify_alicespend) < 0 )
// printf("error waiting for alicespend\n");
//swap->sentflag = 1;
@ -865,20 +903,12 @@ void LP_aliceloop(void *_swap)
{
LP_swapsfp_update(&swap->I.req);
LP_swap_critical = (uint32_t)time(NULL);
if ( swap->I.alicetomic[0] != 0 )
{
// artem: do stuff alice needs to do at the beginning of the swap, before dexfee
}
if ( LP_swapdata_rawtxsend(swap->N.pair,swap,0x80,data,maxlen,&swap->myfee,0x40,0) == 0 )
printf("error sending alicefee\n");
else if ( LP_waitfor(swap->N.pair,swap,1800,LP_verify_bobdeposit) < 0 )
printf("error waiting for bobdeposit\n");
else
{
if ( swap->I.alicetomic[0] != 0 )
{
// artem: do stuff alice needs to do after bobdeposit comes in
}
m = swap->I.bobconfirms;
while ( (n= LP_numconfirms(bobstr,swap->bobdeposit.I.destaddr,swap->bobdeposit.I.signedtxid,0,1)) < m )
{
@ -890,10 +920,6 @@ void LP_aliceloop(void *_swap)
printf("error sending alicepayment\n");
else
{
if ( swap->I.alicetomic[0] != 0 )
{
// artem: do stuff alice needs to do right before alicepayment goes out
}
m = swap->I.aliceconfirms;
while ( (n= LP_numconfirms(alicestr,swap->alicepayment.I.destaddr,swap->alicepayment.I.signedtxid,0,1)) < m )
{

14
iguana/exchanges/LP_transaction.c

@ -1863,6 +1863,20 @@ int32_t basilisk_swapuserdata(uint8_t *userdata,bits256 privkey,int32_t ifpath,b
OP_HASH160 <hash(alice_privM)> OP_EQUALVERIFY <alice_pubA0> OP_CHECKSIG
OP_ENDIF*/
int32_t LP_etomicsymbol(char *activesymbol,char *etomic,char *symbol)
{
struct iguana_info *coin;
etomic[0] = activesymbol[0] = 0;
if ( (coin= LP_coinfind(symbol)) != 0 )
{
strcpy(etomic,coin->etomic);
if ( etomic[0] != 0 )
strcpy(activesymbol,"ETOMIC");
else strcpy(activesymbol,symbol);
}
return(etomic[0] != 0);
}
int32_t basilisk_bobpayment_reclaim(struct basilisk_swap *swap,int32_t delay)
{
static bits256 zero;

202
iguana/exchanges/etomicswap/bob.c

@ -5,7 +5,9 @@
#include <curl/curl.h>
#include <stdlib.h>
#include <inttypes.h>
#include <string.h>
#include "etomiclib.h"
#include "etomiccurl.h"
char* bobContractAddress = "0x9387Fd3a016bB0205e4e131Dde886B9d2BC000A2";
char* aliceAddress = "0x485d2cc2d13a9e12E4b53D606DB1c8adc884fB8a";
@ -26,6 +28,7 @@ int main(int argc, char** argv)
BOB_APPROVES_ERC20,
BOB_ETH_BALANCE,
BOB_ERC20_BALANCE,
TX_RECEIPT
};
if (argc < 2) {
return 1;
@ -36,144 +39,142 @@ int main(int argc, char** argv)
switch (action)
{
case BOB_ETH_DEPOSIT:
txData.amount = "1000000000000000000";
txData.from = bobAddress;
txData.to = bobContractAddress;
txData.secretKey = getenv("BOB_PK");
BobSendsEthDepositInput input = {
.aliceAddress = aliceAddress,
.depositId = argv[2],
.bobHash = argv[3]
};
strcpy(txData.amount, "1000000000000000000");
strcpy(txData.from, bobAddress);
strcpy(txData.to, bobContractAddress);
strcpy(txData.secretKey, getenv("BOB_PK"));
BobSendsEthDepositInput input;
strcpy(input.aliceAddress, aliceAddress);
strcpy(input.depositId, argv[2]);
strcpy(input.bobHash, argv[3]);
result = bobSendsEthDeposit(input, txData);
printf("%s\n", result);
free(result);
break;
case BOB_ERC20_DEPOSIT:
txData.amount = "0";
txData.from = bobAddress;
txData.to = bobContractAddress;
txData.secretKey = getenv("BOB_PK");
strcpy(txData.amount, "0");
strcpy(txData.from, bobAddress);
strcpy(txData.to, bobContractAddress);
strcpy(txData.secretKey, getenv("BOB_PK"));
BobSendsErc20DepositInput input1 = {
.depositId = argv[2],
.amount = "1000000000000000000",
.aliceAddress = aliceAddress,
.bobHash = argv[3],
.tokenAddress = tokenAddress
.amount = "1000000000000000000"
};
strcpy(input1.depositId, argv[2]);
strcpy(input1.aliceAddress, aliceAddress);
strcpy(input1.bobHash, argv[3]);
strcpy(input1.tokenAddress, tokenAddress);
result = bobSendsErc20Deposit(input1, txData);
printf("%s\n", result);
free(result);
break;
case BOB_CLAIMS_DEPOSIT:
txData.amount = "0";
txData.from = bobAddress;
txData.to = bobContractAddress;
txData.secretKey = getenv("BOB_PK");
BobRefundsDepositInput input2 = {
.depositId = argv[2],
.amount = "1000000000000000000",
.aliceAddress = aliceAddress,
.tokenAddress = argv[3],
.aliceCanClaimAfter = argv[4],
.bobSecret = argv[5]
};
strcpy(txData.amount, "0");
strcpy(txData.from, bobAddress);
strcpy(txData.to, bobContractAddress);
strcpy(txData.secretKey, getenv("BOB_PK"));
BobRefundsDepositInput input2;
strcpy(input2.depositId, argv[2]);
strcpy(input2.amount, "1000000000000000000");
strcpy(input2.aliceAddress, aliceAddress);
strcpy(input2.tokenAddress, argv[3]);
strcpy(input2.aliceCanClaimAfter, argv[4]);
strcpy(input2.bobSecret, argv[5]);
result = bobRefundsDeposit(input2, txData);
printf("%s\n", result);
free(result);
break;
case ALICE_CLAIMS_DEPOSIT:
txData.amount = "0";
txData.from = aliceAddress;
txData.to = bobContractAddress;
txData.secretKey = getenv("ALICE_PK");
AliceClaimsBobDepositInput input3 = {
.depositId = argv[2],
.amount = "1000000000000000000",
.bobAddress = bobAddress,
.tokenAddress = argv[3],
.aliceCanClaimAfter = argv[4],
.bobHash = argv[5]
};
strcpy(txData.amount, "0");
strcpy(txData.from, aliceAddress);
strcpy(txData.to, bobContractAddress);
strcpy(txData.secretKey, getenv("ALICE_PK"));
AliceClaimsBobDepositInput input3;
strcpy(input3.depositId, argv[2]);
strcpy(input3.amount, "1000000000000000000");
strcpy(input3.bobAddress, bobAddress);
strcpy(input3.tokenAddress, argv[3]);
strcpy(input3.aliceCanClaimAfter, argv[4]);
strcpy(input3.bobHash, argv[5]);
result = aliceClaimsBobDeposit(input3, txData);
printf("%s\n", result);
free(result);
break;
case BOB_ETH_PAYMENT:
txData.amount = "1000000000000000000";
txData.from = bobAddress;
txData.to = bobContractAddress;
txData.secretKey = getenv("BOB_PK");
BobSendsEthPaymentInput input4 = {
.paymentId = argv[2],
.aliceHash = argv[3],
.aliceAddress = aliceAddress
};
strcpy(txData.amount, "1000000000000000000");
strcpy(txData.from, bobAddress);
strcpy(txData.to, bobContractAddress);
strcpy(txData.secretKey, getenv("BOB_PK"));
BobSendsEthPaymentInput input4;
strcpy(input4.paymentId, argv[2]);
strcpy(input4.aliceHash, argv[3]);
strcpy(input4.aliceAddress, aliceAddress);
result = bobSendsEthPayment(input4, txData);
printf("%s\n", result);
free(result);
break;
case BOB_ERC20_PAYMENT:
txData.amount = "0";
txData.from = bobAddress;
txData.to = bobContractAddress;
txData.secretKey = getenv("BOB_PK");
BobSendsErc20PaymentInput input5 = {
.paymentId = argv[2],
.amount = "1000000000000000000",
.tokenAddress = tokenAddress,
.aliceAddress = aliceAddress,
.aliceHash = argv[3]
};
strcpy(txData.amount, "0");
strcpy(txData.from, bobAddress);
strcpy(txData.to, bobContractAddress);
strcpy(txData.secretKey, getenv("BOB_PK"));
BobSendsErc20PaymentInput input5;
strcpy(input5.paymentId, argv[2]);
strcpy(input5.amount, "1000000000000000000");
strcpy(input5.tokenAddress, tokenAddress);
strcpy(input5.aliceAddress, aliceAddress);
strcpy(input5.aliceHash, argv[3]);
result = bobSendsErc20Payment(input5, txData);
printf("%s\n", result);
free(result);
break;
case BOB_CLAIMS_PAYMENT:
txData.amount = "0";
txData.from = bobAddress;
txData.to = bobContractAddress;
txData.secretKey = getenv("BOB_PK");
BobReclaimsBobPaymentInput input6 = {
.paymentId = argv[2],
.aliceAddress = aliceAddress,
.amount = "1000000000000000000",
.tokenAddress = argv[3],
.bobCanClaimAfter = argv[4],
.aliceHash = argv[5]
};
strcpy(txData.amount, "0");
strcpy(txData.from, bobAddress);
strcpy(txData.to, bobContractAddress);
strcpy(txData.secretKey, getenv("BOB_PK"));
BobReclaimsBobPaymentInput input6;
strcpy(input6.paymentId, argv[2]);
strcpy(input6.aliceAddress, aliceAddress);
strcpy(input6.amount, "1000000000000000000");
strcpy(input6.tokenAddress, argv[3]);
strcpy(input6.bobCanClaimAfter, argv[4]);
strcpy(input6.aliceHash, argv[5]);
result = bobReclaimsBobPayment(input6, txData);
printf("%s\n", result);
free(result);
break;
case ALICE_CLAIMS_PAYMENT:
txData.amount = "0";
txData.from = aliceAddress;
txData.to = bobContractAddress;
txData.secretKey = getenv("ALICE_PK");
AliceSpendsBobPaymentInput input7 = {
.paymentId = argv[2],
.bobAddress = bobAddress,
.amount = "1000000000000000000",
.tokenAddress = argv[3],
.bobCanClaimAfter = argv[4],
.aliceSecret = argv[5]
};
strcpy(txData.amount, "0");
strcpy(txData.from, aliceAddress);
strcpy(txData.to, bobContractAddress);
strcpy(txData.secretKey, getenv("ALICE_PK"));
AliceSpendsBobPaymentInput input7;
strcpy(input7.paymentId, argv[2]);
strcpy(input7.bobAddress, bobAddress);
strcpy(input7.amount, "1000000000000000000");
strcpy(input7.tokenAddress, argv[3]);
strcpy(input7.bobCanClaimAfter, argv[4]);
strcpy(input7.aliceSecret, argv[5]);
result = aliceSpendsBobPayment(input7, txData);
printf("%s\n", result);
@ -195,8 +196,23 @@ int main(int argc, char** argv)
case BOB_ERC20_BALANCE:
printf("%" PRIu64 "\n", getErc20Balance(bobAddress, tokenAddress));
break;
case TX_RECEIPT:
printf("getTxReceipt\n");
EthTxReceipt txReceipt;
txReceipt = getEthTxReceipt("0x82afa1b00f8a63e1a91430162e5cb2d4ebe915831ffd56e6e3227814913e23e6");
printf("%" PRIu64 "\n", txReceipt.blockNumber);
printf("%s\n", txReceipt.blockHash);
break;
default:
return 1;
}
char *pubkey = getPubKeyFromPriv(getenv("BOB_PK"));
printf("pubkey: %s\n", pubkey);
free(pubkey);
uint64_t satoshis = 100000000;
char weiBuffer[100];
satoshisToWei(weiBuffer, satoshis);
printf("wei: %s\n", weiBuffer);
return 0;
}

42
iguana/exchanges/etomicswap/etomiccurl.c

@ -4,7 +4,7 @@
#include <stdlib.h>
#include "../../../includes/cJSON.h"
static char* ethRpcUrl = "https://ropsten.infura.io/y07GHxUyTgeN2mdfOonu";
static char *ethRpcUrl = "https://ropsten.infura.io/y07GHxUyTgeN2mdfOonu";
struct string {
char *ptr;
@ -88,6 +88,7 @@ char* sendRawTx(char* rawTx)
strcpy(txId, tmp);
cJSON_Delete(json);
free(requestResult);
free(string);
return txId;
}
@ -109,6 +110,7 @@ int getNonce(char* address)
int nonce = (int)strtol(cJSON_GetObjectItem(json, "result")->valuestring, NULL, 0);
cJSON_Delete(json);
free(requestResult);
free(string);
return nonce;
}
@ -132,6 +134,7 @@ char* getEthBalanceRequest(char* address)
strcpy(balance, tmp);
cJSON_Delete(json);
free(requestResult);
free(string);
return balance;
}
@ -154,9 +157,40 @@ char* ethCall(char* to, const char* data)
cJSON_Delete(request);
cJSON *json = cJSON_Parse(requestResult);
char* tmp = cJSON_GetObjectItem(json, "result")->valuestring;
char* balance = (char*)malloc(strlen(tmp) + 1);
strcpy(balance, tmp);
char* result = (char*)malloc(strlen(tmp) + 1);
strcpy(result, tmp);
cJSON_Delete(json);
free(requestResult);
return balance;
free(string);
return result;
}
EthTxReceipt getEthTxReceipt(char *txId)
{
EthTxReceipt result;
char* string;
cJSON *request = cJSON_CreateObject();
cJSON *params = cJSON_CreateArray();
cJSON_AddItemToObject(request, "jsonrpc", cJSON_CreateString("2.0"));
cJSON_AddItemToObject(request, "method", cJSON_CreateString("eth_getTransactionReceipt"));
cJSON_AddItemToArray(params, cJSON_CreateString(txId));
cJSON_AddItemToObject(request, "params", params);
cJSON_AddItemToObject(request, "id", cJSON_CreateNumber(2));
string = cJSON_PrintUnformatted(request);
char *requestResult = sendRequest(string);
cJSON_Delete(request);
cJSON *json = cJSON_Parse(requestResult);
cJSON *tmp = cJSON_GetObjectItem(json, "result");
if (is_cJSON_Null(tmp)) {
strcpy(result.blockHash, "0x0000000000000000000000000000000000000000000000000000000000000000");
result.blockNumber = 0;
} else {
strcpy(result.blockHash, cJSON_GetObjectItem(tmp, "blockHash")->valuestring);
result.blockNumber = (uint64_t) strtol(cJSON_GetObjectItem(tmp, "blockNumber")->valuestring, NULL, 0);
}
cJSON_Delete(json);
free(requestResult);
free(string);
return result;
}

8
iguana/exchanges/etomicswap/etomiccurl.h

@ -1,11 +1,19 @@
#include <stdint.h>
#ifdef __cplusplus
extern "C"{
#endif
typedef struct
{
uint64_t blockNumber;
char blockHash[75];
} EthTxReceipt;
char* sendRawTx(char* rawTx);
char* ethCall(char* to, const char* data);
int getNonce(char* address);
char* getEthBalanceRequest(char* address);
EthTxReceipt getEthTxReceipt(char *txId);
#ifdef __cplusplus
}

18
iguana/exchanges/etomicswap/etomiclib.cpp

@ -7,6 +7,8 @@
#include <cpp-ethereum/libethcore/Common.h>
#include <cpp-ethereum/libethcore/CommonJS.h>
#include <cpp-ethereum/libethcore/TransactionBase.h>
#include <inttypes.h>
using namespace dev;
using namespace dev::eth;
@ -355,3 +357,19 @@ uint64_t getErc20Balance(char* address, char* tokenAddress)
free(hexBalance);
return static_cast<uint64_t>(balance);
}
void uint8arrayToHex(char *dest, uint8_t *input, int len)
{
strcpy(dest, "0x");
for (int i = 0; i < len; i++)
{
sprintf(dest + (i + 1) * 2, "%02x", input[i]);
}
dest[(len + 1) * 2] = '\0';
}
void satoshisToWei(char *dest, uint64_t input)
{
sprintf(dest, "%" PRIu64, input);
strcat(dest, "0000000000");
}

138
iguana/exchanges/etomicswap/etomiclib.h

@ -7,111 +7,111 @@
extern "C" {
#endif
typedef struct {
char* from;
char* to;
char* amount;
char* secretKey;
char from[65];
char to[65];
char amount[100];
char secretKey[70];
} BasicTxData;
typedef struct {
char* dealId;
char* bobAddress;
char* aliceHash;
char* bobHash;
char dealId[70];
char bobAddress[65];
char aliceHash[65];
char bobHash[65];
} AliceSendsEthPaymentInput;
typedef struct {
char* dealId;
char* amount;
char* tokenAddress;
char* bobAddress;
char* aliceHash;
char* bobHash;
char dealId[70];
char amount[100];
char tokenAddress[65];
char bobAddress[65];
char aliceHash[65];
char bobHash[65];
} AliceSendsErc20PaymentInput;
typedef struct {
char* dealId;
char* amount;
char* tokenAddress;
char* bobAddress;
char* aliceHash;
char* bobSecret;
char dealId[70];
char amount[100];
char tokenAddress[65];
char bobAddress[65];
char aliceHash[65];
char bobSecret[70];
} AliceReclaimsAlicePaymentInput;
typedef struct {
char* dealId;
char* amount;
char* tokenAddress;
char* aliceAddress;
char* aliceSecret;
char* bobHash;
char dealId[70];
char amount[100];
char tokenAddress[65];
char aliceAddress[65];
char aliceSecret[70];
char bobHash[65];
} BobSpendsAlicePaymentInput;
typedef struct {
char* depositId;
char* aliceAddress;
char* bobHash;
char depositId[70];
char aliceAddress[65];
char bobHash[65];
} BobSendsEthDepositInput;
typedef struct {
char* depositId;
char* amount;
char* tokenAddress;
char* aliceAddress;
char* bobHash;
char depositId[70];
char amount[100];
char tokenAddress[65];
char aliceAddress[65];
char bobHash[65];
} BobSendsErc20DepositInput;
typedef struct {
char* depositId;
char* amount;
char* tokenAddress;
char* aliceAddress;
char* bobSecret;
char* aliceCanClaimAfter;
char depositId[70];
char amount[100];
char tokenAddress[65];
char aliceAddress[65];
char bobSecret[70];
char aliceCanClaimAfter[100];
} BobRefundsDepositInput;
typedef struct {
char* depositId;
char* amount;
char* tokenAddress;
char* bobAddress;
char* bobHash;
char* aliceCanClaimAfter;
char depositId[70];
char amount[100];
char tokenAddress[65];
char bobAddress[65];
char bobHash[65];
char aliceCanClaimAfter[100];
} AliceClaimsBobDepositInput;
typedef struct {
char* paymentId;
char* aliceAddress;
char* aliceHash;
char paymentId[70];
char aliceAddress[65];
char aliceHash[65];
} BobSendsEthPaymentInput;
typedef struct {
char* paymentId;
char* amount;
char* tokenAddress;
char* aliceAddress;
char* aliceHash;
char paymentId[70];
char amount[100];
char tokenAddress[65];
char aliceAddress[65];
char aliceHash[65];
} BobSendsErc20PaymentInput;
typedef struct {
char* paymentId;
char* amount;
char* tokenAddress;
char* aliceAddress;
char* aliceHash;
char* bobCanClaimAfter;
char paymentId[70];
char amount[100];
char tokenAddress[65];
char aliceAddress[65];
char aliceHash[65];
char bobCanClaimAfter[100];
} BobReclaimsBobPaymentInput;
typedef struct {
char* paymentId;
char* amount;
char* tokenAddress;
char* aliceSecret;
char* bobAddress;
char* bobCanClaimAfter;
char paymentId[70];
char amount[100];
char tokenAddress[65];
char aliceSecret[70];
char bobAddress[65];
char bobCanClaimAfter[100];
} AliceSpendsBobPaymentInput;
char* approveErc20(char* amount, char* from, char* secret);
char* approveErc20(char amount[100], char* from, char* secret);
char* aliceSendsEthPayment(AliceSendsEthPaymentInput input, BasicTxData txData);
char* aliceSendsErc20Payment(AliceSendsErc20PaymentInput input, BasicTxData txData);
char* aliceReclaimsAlicePayment(AliceReclaimsAlicePaymentInput input, BasicTxData txData);
@ -128,7 +128,9 @@ char* privKey2Addr(char* privKey);
char* pubKey2Addr(char* pubKey);
char* getPubKeyFromPriv(char* privKey);
uint64_t getEthBalance(char* address);
uint64_t getErc20Balance(char* address, char* tokenAddress);
uint64_t getErc20Balance(char* address, char tokenAddress[65]);
void uint8arrayToHex(char *dest, uint8_t *input, int len);
void satoshisToWei(char *dest, uint64_t input);
// Your prototype or Definition
#ifdef __cplusplus
}

8
iguana/exchanges/mm.c

@ -115,10 +115,10 @@ void LP_main(void *ptr)
void ETH_test()
{
BasicTxData txData; char* ethSignedTx;
txData.amount = "1000000000000000000";
txData.from = "0xA7EF3f65714AE266414C9E58bB4bAa4E6FB82B41";
txData.to = "0x9387Fd3a016bB0205e4e131Dde886B9d2BC000A2";
txData.secretKey = getenv("BOB_PK");
strcpy(txData.amount, "1000000000000000000");
strcpy(txData.from, "0xA7EF3f65714AE266414C9E58bB4bAa4E6FB82B41");
strcpy(txData.to, "0x9387Fd3a016bB0205e4e131Dde886B9d2BC000A2");
strcpy(txData.secretKey, getenv("BOB_PK"));
BobSendsEthDepositInput input = {
.aliceAddress = "0x485d2cc2d13a9e12E4b53D606DB1c8adc884fB8a",
.depositId = "0x28c5a7c25911ef59a577ddf811d0e58edb827efb0646a8a38df6e921ba53f431",

Loading…
Cancel
Save