Browse Source

Stubby release

etomic
jl777 7 years ago
parent
commit
689c63652a
  1. 4
      iguana/exchanges/LP_bitcoin.c
  2. 4
      iguana/exchanges/LP_commands.c
  3. 73
      iguana/exchanges/LP_etomic.c
  4. 4
      iguana/exchanges/LP_include.h
  5. 2
      iguana/exchanges/LP_mmjson.c
  6. 8
      iguana/exchanges/LP_nativeDEX.c
  7. 6
      iguana/exchanges/LP_ordermatch.c
  8. 24
      iguana/exchanges/LP_signatures.c
  9. 34
      iguana/exchanges/LP_swap.c
  10. 2
      iguana/exchanges/coins

4
iguana/exchanges/LP_bitcoin.c

@ -2041,10 +2041,10 @@ bits256 bits256_calcaddrhash(char *symbol,uint8_t *serialized,int32_t len)
else
{
HashGroestl(hash.bytes,serialized,len);
int32_t i; char str[65];
/*int32_t i; char str[65];
for (i=0; i<len; i++)
printf("%02x",serialized[i]);
printf(" HashGroestl %d -> %s\n",len,bits256_str(str,hash));
printf(" HashGroestl %d -> %s\n",len,bits256_str(str,hash));*/
}
return(hash);
}

4
iguana/exchanges/LP_commands.c

@ -184,7 +184,9 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\
jaddstr(retjson,"pubsecp",pub33str);
jadd(retjson,"coins",LP_coinsjson(LP_showwif));
LP_cmdcount++;
return(jprint(retjson,1));
free_json(retjson);
retjson = 0;
//return(jprint(retjson,1));
}
// if passphrase api and passphrase is right, ignore userpass, use hass of passphrase
if ( strcmp(method,"passphrase") == 0 && (passphrase= jstr(argjson,"passphrase")) != 0 )

73
iguana/exchanges/LP_etomic.c

@ -55,7 +55,7 @@ extern "C" {
char* bobAddress;
char* aliceHash;
char* bobSecret;
} AliceClaimsAlicePaymentInput;
} AliceReclaimsAlicePaymentInput;
typedef struct {
char* dealId;
@ -64,7 +64,7 @@ extern "C" {
char* aliceAddress;
char* aliceSecret;
char* bobHash;
} BobClaimsAlicePaymentInput;
} BobSpendsAlicePaymentInput;
typedef struct {
char* depositId;
@ -87,7 +87,7 @@ extern "C" {
char* aliceAddress;
char* bobSecret;
char* aliceCanClaimAfter;
} BobClaimsDepositInput;
} BobRefundsDepositInput;
typedef struct {
char* depositId;
@ -119,7 +119,7 @@ extern "C" {
char* aliceAddress;
char* aliceHash;
char* bobCanClaimAfter;
} BobClaimsBobPaymentInput;
} BobReclaimsBobPaymentInput;
typedef struct {
char* paymentId;
@ -128,22 +128,57 @@ extern "C" {
char* aliceSecret;
char* bobAddress;
char* bobCanClaimAfter;
} AliceClaimsBobPaymentInput;
void approveErc20(char* amount, char* from, char* secret, char* buffer, int nonce);
void aliceInitsEthDeal(AliceInitEthInput input, BasicTxData txData, char* result);
void aliceInitsErc20Deal(AliceInitErc20Input input, BasicTxData txData, char* result);
void aliceClaimsAlicePayment(AliceClaimsAlicePaymentInput input, BasicTxData txData, char* result);
void bobClaimsAlicePayment(BobClaimsAlicePaymentInput input, BasicTxData txData, char* result);
void bobMakesEthDeposit(BobMakesEthDepositInput input, BasicTxData txData, char* result);
void bobMakesErc20Deposit(BobMakesErc20DepositInput input, BasicTxData txData, char* result);
void bobClaimsDeposit(BobClaimsDepositInput input, BasicTxData txData, char* result);
void aliceClaimsBobDeposit(AliceClaimsBobDepositInput input, BasicTxData txData, char* result);
void bobMakesEthPayment(BobMakesEthPaymentInput input, BasicTxData txData, char* result);
void bobMakesErc20Payment(BobMakesErc20PaymentInput input, BasicTxData txData, char* result);
void bobClaimsBobPayment(BobClaimsBobPaymentInput input, BasicTxData txData, char* result);
void aliceClaimsBobPayment(AliceClaimsBobPaymentInput input, BasicTxData txData, char* result);
} AliceSpendsBobPaymentInput;
// Your prototype or Definition
#ifdef __cplusplus
}
#endif
#define ETOMIC_ALICECONTRACT "0xe1D4236C5774D35Dc47dcc2E5E0CcFc463A3289c"
#define ETOMIC_BOBCONTRACT "0x9387Fd3a016bB0205e4e131Dde886B9d2BC000A2"
#define ETOMIC_SATOSHICAT "0000000000"
char *aliceInitsEthDeal(AliceInitEthInput input,BasicTxData txData);
char *aliceInitsErc20Deal(AliceInitErc20Input input,BasicTxData txData);
char *aliceMakesEthPayment(AliceMakesEthPaymentInput input,BasicTxData txData);
char *aliceMakesErc20Payment(AliceMakesErc20PaymentInput input,BasicTxData txData);
char *aliceSpendsBobPayment(AliceSpendsBobPaymentInput input,BasicTxData txData);
char *aliceReclaimsAlicePayment(AliceReclaimsAlicePaymentInput input,BasicTxData txData);
char *aliceClaimsBobDeposit(AliceClaimsBobDepositInput input,BasicTxData txData);
char *bobMakesEthDeposit(BobMakesEthDepositInput input,BasicTxData txData);
char *bobMakesErc20Deposit(BobMakesErc20DepositInput input,BasicTxData txData);
char *bobMakesEthPayment(BobMakesEthPaymentInput input,BasicTxData txData);
char *bobMakesErc20Payment(BobMakesErc20PaymentInput input,BasicTxData txData);
char *bobSpendsAlicePayment(BobSpendsAlicePaymentInput input,BasicTxData txData);
char *bobReclaimsBobPayment(BobReclaimsBobPaymentInput input,BasicTxData txData);
char *bobRefundsDeposit(BobRefundsDepositInput input,BasicTxData txData);
char *approveErc20(char *amount,char *from,char *secret,char *buffer,int32_t nonce);
int32_t LP_etomicsymbol(char *etomic,char *symbol)
{
struct iguana_info *coin;
etomic[0] = 0;
if ( (coin= LP_coinfind(symbol)) != 0 )
strcpy(etomic,coin->etomic);
return(etomic[0] != 0);
}
char *LP_etomicalice_start(struct basilisk_swap *swap)
{
AliceInitEthInput input; AliceInitErc20Input 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));
return(aliceInitsEthDeal(input,txData));
}
else
{
memset(&input20,0,sizeof(input20));
return(aliceInitsErc20Deal(input20,txData));
}
}

4
iguana/exchanges/LP_include.h

@ -232,7 +232,7 @@ struct basilisk_rawtx
struct basilisk_swapinfo
{
struct basilisk_request req;
char bobstr[128],alicestr[128];
char bobstr[128],alicestr[128],bobtomic[64],alicetomic[64];
bits256 myhash,otherhash,orderhash;
uint32_t statebits,otherstatebits,started,expiration,finished,dead,reftime,putduration,callduration;
int32_t bobconfirms,aliceconfirms,iambob,reclaimed,bobspent,alicespent,pad,aliceistrusted,bobistrusted,otheristrusted,otherstrust,alicemaxconfirms,bobmaxconfirms;
@ -302,7 +302,7 @@ struct iguana_info
int32_t numutxos,notarized,longestchain,firstrefht,firstscanht,lastscanht,height; uint16_t busport;
uint32_t txversion,dPoWtime,loadedcache,electrumlist,lastunspent,importedprivkey,lastpushtime,lastutxosync,addr_listunspent_requested,lastutxos,updaterate,counter,inactive,lastmempool,lastgetinfo,ratetime,heighttime,lastmonitor,obooktime;
uint8_t pubtype,p2shtype,isPoS,wiftype,wiftaddr,taddr,noimportprivkey_flag,userconfirms,isassetchain,maxconfirms;
char symbol[128],smartaddr[64],userpass[1024],serverport[128],instantdex_address[64];
char symbol[128],smartaddr[64],etomic[64],userpass[1024],serverport[128],instantdex_address[64];
// portfolio
double price_kmd,force,perc,goal,goalperc,relvolume,rate;
void *electrum; void *ctx;

2
iguana/exchanges/LP_mmjson.c

@ -51,7 +51,7 @@
int32_t MM_numfields;
char *MM_fields[256] =
{
"timestamp", "getdPoW", "dPoW", "aliceid", "src", "base", "basevol", "dest", "rel", "relvol", "price", "requestid", "quoteid", "finished", "expired", "bobdeposit", "alicepayment", "bobpayment", "paymentspent", "Apaymentspent", "depositspent", "ind", "method", "swapstatus", "method2", "gettradestatus", "coin", "rmd160", "pub", "pubsecp", "sig", "session", "notify", "pubkey", "price64", "credits", "utxocoin", "n", "bal", "min", "max", "postprice", "notarized", "notarizedhash", "notarizationtxid", "wantnotify", "isLP", "gui", "nogui", "tradeid", "address", "txid", "vout", "srchash", "txfee", "quotetime", "satoshis", "desthash", "txid2", "vout2", "destaddr", "desttxid", "destvout", "feetxid", "feevout", "desttxfee", "destsatoshis", "pending", "reserved", "broadcast", "ismine", "simplegui", "request", "proof", "connect", "expiration", "iambob", "Bgui", "", "Agui", "bob", "srcamount", "bobtxfee", "alice", "destamount", "alicetxfee", "sentflags", "values", "result", "success", "status", "finishtime", "tradestatus", "pair", "connected", "warning", "critical", "endcritical",
"timestamp", "getdPoW", "dPoW", "aliceid", "src", "base", "basevol", "dest", "rel", "relvol", "price", "requestid", "quoteid", "finished", "expired", "bobdeposit", "alicepayment", "bobpayment", "paymentspent", "Apaymentspent", "depositspent", "ind", "method", "swapstatus", "method2", "gettradestatus", "coin", "rmd160", "pub", "pubsecp", "sig", "session", "notify", "pubkey", "price64", "credits", "utxocoin", "n", "bal", "min", "max", "postprice", "notarized", "notarizedhash", "notarizationtxid", "wantnotify", "isLP", "gui", "nogui", "tradeid", "address", "txid", "vout", "srchash", "txfee", "quotetime", "satoshis", "desthash", "txid2", "vout2", "destaddr", "desttxid", "destvout", "feetxid", "feevout", "desttxfee", "destsatoshis", "pending", "reserved", "broadcast", "ismine", "simplegui", "request", "proof", "connect", "expiration", "iambob", "Bgui", "", "Agui", "bob", "srcamount", "bobtxfee", "alice", "destamount", "alicetxfee", "sentflags", "values", "result", "success", "status", "finishtime", "tradestatus", "pair", "connected", "warning", "critical", "endcritical", "etomic", "esrc", "edest"
};
char *MM_coins[256] =

8
iguana/exchanges/LP_nativeDEX.c

@ -174,6 +174,7 @@ 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"
@ -795,7 +796,7 @@ void bech32_tests()
void LP_initcoins(void *ctx,int32_t pubsock,cJSON *coins)
{
int32_t i,n,notarized; cJSON *item; char *symbol; struct iguana_info *coin;
int32_t i,n,notarized; cJSON *item; char *symbol,*etomic; struct iguana_info *coin;
for (i=0; i<sizeof(activecoins)/sizeof(*activecoins); i++)
{
printf("%s, ",activecoins[i]);
@ -829,10 +830,15 @@ void LP_initcoins(void *ctx,int32_t pubsock,cJSON *coins)
LP_coincreate(item);
LP_priceinfoadd(jstr(item,"coin"));
if ( (coin= LP_coinfind(symbol)) != 0 )
{
if ( (etomic= jstr(item,"etomic")) != 0 )
safecopy(coin->etomic,etomic,sizeof(coin->etomic));
else
{
if ( LP_getheight(&notarized,coin) <= 0 )
coin->inactive = (uint32_t)time(NULL);
else LP_unspents_load(coin->symbol,coin->smartaddr);
}
if ( coin->txfee == 0 && strcmp(coin->symbol,"BTC") != 0 )
coin->txfee = LP_MIN_TXFEE;
if ( 0 && strcmp(coin->symbol,"BCH") == 0 )

6
iguana/exchanges/LP_ordermatch.c

@ -1164,7 +1164,11 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,
char *method,str[65]; int32_t num,DEXselector = 0; uint64_t aliceid; double qprice,bestprice,price,bid,ask; cJSON *proof; struct iguana_info *coin; struct LP_quoteinfo Q,Q2; int32_t counter,retval=-1;
if ( (method= jstr(argjson,"method")) != 0 && (strcmp(method,"reserved") == 0 ||strcmp(method,"connected") == 0 || strcmp(method,"request") == 0 || strcmp(method,"connect") == 0) )
{
LP_quoteparse(&Q,argjson);
if ( LP_quoteparse(&Q,argjson) < 0 )
{
printf("ERROR parsing.(%s)\n",jprint(argjson,0));
return(1);
}
LP_requestinit(&Q.R,Q.srchash,Q.desthash,Q.srccoin,Q.satoshis-Q.txfee,Q.destcoin,Q.destsatoshis-Q.desttxfee,Q.timestamp,Q.quotetime,DEXselector);
LP_tradecommand_log(argjson);
printf("%-4d (%-10u %10u) %12s id.%-20llu %5s/%-5s %12.8f -> %12.8f (%11.8f) | RT.%d %d n%d\n",(uint32_t)time(NULL) % 3600,Q.R.requestid,Q.R.quoteid,method,(long long)Q.aliceid,Q.srccoin,Q.destcoin,dstr(Q.satoshis),dstr(Q.destsatoshis),(double)Q.destsatoshis/Q.satoshis,LP_RTcount,LP_swapscount,G.netid);

24
iguana/exchanges/LP_signatures.c

@ -41,13 +41,17 @@ struct basilisk_request *LP_requestinit(struct basilisk_request *rp,bits256 srch
cJSON *LP_quotejson(struct LP_quoteinfo *qp)
{
double price; cJSON *retjson = cJSON_CreateObject();
double price; char etomic[64]; cJSON *retjson = cJSON_CreateObject();
if ( jobj(retjson,"gui") == 0 )
jaddstr(retjson,"gui",qp->gui[0] != 0 ? qp->gui : LP_gui);
jadd64bits(retjson,"aliceid",qp->aliceid);
jaddnum(retjson,"tradeid",qp->tradeid);
jaddstr(retjson,"base",qp->srccoin);
if ( LP_etomicsymbol(etomic,qp->srccoin) != 0 )
jaddstr(retjson,"esrc",etomic);
jaddstr(retjson,"rel",qp->destcoin);
if ( LP_etomicsymbol(etomic,qp->destcoin) != 0 )
jaddstr(retjson,"edest",etomic);
if ( qp->coinaddr[0] != 0 )
jaddstr(retjson,"address",qp->coinaddr);
if ( qp->timestamp != 0 )
@ -104,12 +108,28 @@ cJSON *LP_quotejson(struct LP_quoteinfo *qp)
int32_t LP_quoteparse(struct LP_quoteinfo *qp,cJSON *argjson)
{
uint32_t rid,qid;
uint32_t rid,qid; char etomic[64],*etomicstr;
memset(qp,0,sizeof(*qp));
safecopy(qp->gui,LP_gui,sizeof(qp->gui));
safecopy(qp->srccoin,jstr(argjson,"base"),sizeof(qp->srccoin));
if ( LP_etomicsymbol(etomic,qp->srccoin) != 0 )
{
if ( (etomicstr= jstr(argjson,"esrc")) == 0 || strcmp(etomicstr,etomic) != 0 )
{
printf("etomic src mismatch (%s) vs (%s)\n",etomicstr!=0?etomicstr:"",etomic);
return(-1);
}
}
safecopy(qp->coinaddr,jstr(argjson,"address"),sizeof(qp->coinaddr));
safecopy(qp->destcoin,jstr(argjson,"rel"),sizeof(qp->destcoin));
if ( LP_etomicsymbol(etomic,qp->destcoin) != 0 )
{
if ( (etomicstr= jstr(argjson,"edest")) == 0 || strcmp(etomicstr,etomic) != 0 )
{
printf("etomic dest mismatch (%s) vs (%s)\n",etomicstr!=0?etomicstr:"",etomic);
return(-1);
}
}
safecopy(qp->destaddr,jstr(argjson,"destaddr"),sizeof(qp->destaddr));
qp->aliceid = j64bits(argjson,"aliceid");
qp->tradeid = juint(argjson,"tradeid");

34
iguana/exchanges/LP_swap.c

@ -861,15 +861,21 @@ 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 ( strcmp(swap->I.bobstr,"BTC") == 0 )
m = 0;
else*/ m = swap->I.bobconfirms;
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(swap->I.bobstr,swap->bobdeposit.I.destaddr,swap->bobdeposit.I.signedtxid,0,1)) < m )
{
LP_swap_critical = (uint32_t)time(NULL);
@ -880,9 +886,11 @@ void LP_aliceloop(void *_swap)
printf("error sending alicepayment\n");
else
{
/*if ( strcmp(swap->I.alicestr,"BTC") == 0 )
m = 0;
else*/ m = swap->I.aliceconfirms;
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(swap->I.alicestr,swap->alicepayment.I.destaddr,swap->alicepayment.I.signedtxid,0,1)) < m )
{
LP_swap_critical = (uint32_t)time(NULL);
@ -895,22 +903,20 @@ void LP_aliceloop(void *_swap)
printf("error waiting for bobpayment\n");
else
{
if ( swap->I.alicetomic[0] != 0 )
{
// artem: do stuff alice needs to do after bobpayment comes in
}
LP_swap_endcritical = (uint32_t)time(NULL);
while ( (n= LP_numconfirms(swap->I.bobstr,swap->bobpayment.I.destaddr,swap->bobpayment.I.signedtxid,0,1)) < swap->I.bobconfirms )
{
char str[65];printf("%d wait for bobpayment %s numconfs.%d %s %s\n",n,swap->bobpayment.I.destaddr,swap->I.bobconfirms,swap->I.bobstr,bits256_str(str,swap->bobpayment.I.signedtxid));
sleep(10);
}
/*if ( LP_swapdata_rawtxsend(swap->N.pair,swap,0x20000,data,maxlen,&swap->alicespend,0x40000,0) == 0 )
printf("error sending alicespend\n");
while ( (n= LP_numconfirms(swap->I.alicestr,swap->alicespend.I.destaddr,swap->alicespend.I.signedtxid,0,1)) < swap->I.aliceconfirms )
{
char str[65];printf("%d wait for alicespend %s numconfs.%d %s %s\n",n,swap->alicespend.I.destaddr,swap->I.aliceconfirms,swap->I.bobstr,bits256_str(str,swap->alicespend.I.signedtxid));
sleep(LP_SWAPSTEP_TIMEOUT);
}*/
if ( swap->N.pair >= 0 )
nn_close(swap->N.pair), swap->N.pair = -1;
LP_swap_endcritical = (uint32_t)time(NULL);
// spending is done in LP_remember.c
LP_swapwait(swap,swap->I.req.requestid,swap->I.req.quoteid,LP_atomic_locktime(swap->I.bobstr,swap->I.alicestr)*2,swap->I.aliceconfirms == 0 ? 3 : 30);
}
}
@ -1040,6 +1046,8 @@ struct basilisk_swap *bitcoin_swapinit(bits256 privkey,uint8_t *pubkey33,bits256
uint8_t *alicepub33=0,*bobpub33=0; int32_t jumblrflag=-2,x = -1; struct iguana_info *bobcoin,*alicecoin;
strcpy(swap->I.bobstr,swap->I.req.src);
strcpy(swap->I.alicestr,swap->I.req.dest);
LP_etomicsymbol(swap->I.bobtomic,swap->I.bobstr);
LP_etomicsymbol(swap->I.alicetomic,swap->I.bobstr);
if ( (alicecoin= LP_coinfind(swap->I.alicestr)) == 0 )
{
printf("missing alicecoin src.%p dest.%p\n",LP_coinfind(swap->I.req.src),LP_coinfind(swap->I.req.dest));

2
iguana/exchanges/coins

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save