Browse Source

Test

etomic
jl777 7 years ago
parent
commit
3a84ed7eb6
  1. 2
      iguana/exchanges/LP_include.h
  2. 11
      iguana/exchanges/LP_ordermatch.c
  3. 37
      iguana/exchanges/LP_remember.c

2
iguana/exchanges/LP_include.h

@ -23,7 +23,7 @@
#define LP_MAJOR_VERSION "0"
#define LP_MINOR_VERSION "1"
#define LP_BUILD_NUMBER "14414"
#define LP_BUILD_NUMBER "14498"
#ifdef FROM_JS
#include <emscripten.h>

11
iguana/exchanges/LP_ordermatch.c

@ -449,6 +449,11 @@ int32_t LP_connectstartbob(void *ctx,int32_t pubsock,cJSON *argjson,char *base,c
if ( bits256_nonz(privkey) != 0 && bits256_cmp(G.LP_mypub25519,qp->srchash) == 0 )
{
LP_requestinit(&qp->R,qp->srchash,qp->desthash,base,qp->satoshis-qp->txfee,rel,qp->destsatoshis-qp->desttxfee,qp->timestamp,qp->quotetime,DEXselector);
if ( LP_pendingswap(qp->R.requestid,qp->R.quoteid) > 0 )
{
printf("requestid.%u quoteid.%u is already in progres\n",qp->R.requestid,qp->R.quoteid);
return(-1);
}
if ( (swap= LP_swapinit(1,0,privkey,&qp->R,qp)) == 0 )
{
printf("cant initialize swap\n");
@ -611,6 +616,12 @@ char *LP_connectedalice(cJSON *argjson) // alice
{
retjson = cJSON_CreateObject();
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);
if ( LP_pendingswap(Q.R.requestid,Q.R.quoteid) > 0 )
{
printf("requestid.%u quoteid.%u is already in progres\n",Q.R.requestid,Q.R.quoteid);
jaddstr(retjson,"error","swap already in progress");
return(jprint(retjson,1));
}
if ( (swap= LP_swapinit(0,0,Q.privkey,&Q.R,&Q)) == 0 )
{
jaddstr(retjson,"error","couldnt swapinit");

37
iguana/exchanges/LP_remember.c

@ -1441,3 +1441,40 @@ char *basilisk_swapentries(char *refbase,char *refrel,int32_t limit)
return(jprint(retarray,1));
}
int32_t LP_pendingswap(uint32_t requestid,uint32_t quoteid)
{
cJSON *retjson,*array,*pending,*item; uint32_t r,q; char *retstr; int32_t i,n,retval = 0;
if ( (retstr= LP_recent_swaps(1000)) != 0 )
{
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{
if ( (array= jarray(&n,retjson,"swaps")) != 0 )
{
for (i=0; i<n; i++)
{
item = jitem(array,i);
r = juint(jitem(item,0),0);
q = juint(jitem(item,1),0);
if ( r == requestid && q == quoteid )
{
retval = 1;
break;
}
}
}
if ( retval == 0 )
{
if ( (pending= jobj(retjson,"pending")) != 0 )
{
r = juint(pending,"requestid");
q = juint(pending,"quoteid");
if ( r == requestid && q == quoteid )
retval = 1;
}
}
free_json(retjson);
}
free(retstr);
}
return(retval);
}

Loading…
Cancel
Save