Browse Source

Test

etomic
jl777 7 years ago
parent
commit
fc3162c5ae
  1. 10
      iguana/exchanges/LP_commands.c
  2. 4
      iguana/exchanges/LP_nativeDEX.c
  3. 55
      iguana/exchanges/LP_ordermatch.c

10
iguana/exchanges/LP_commands.c

@ -404,16 +404,6 @@ dividends(coin, height, <args>)\n\
return(clonestr("{\"result\":\"at least one of coins disabled\"}"));
else if ( IAMLP == 0 && LP_isdisabled(jstr(argjson,"coin"),0) != 0 )
retstr = clonestr("{\"result\":\"coin is disabled\"}");
else if ( strcmp(method,"reserved") == 0 )
{
printf("received RESERVED.(%s)\n",jprint(argjson,0));
retstr = LP_quotereceived(argjson);
}
else if ( strcmp(method,"connected") == 0 )
{
//printf("CONNECTED.(%s)\n",jprint(argjson,0));
retstr = LP_connectedalice(argjson);
}
else if ( strcmp(method,"checktxid") == 0 )
retstr = LP_spentcheck(argjson);
else if ( strcmp(method,"addr_unspents") == 0 )

4
iguana/exchanges/LP_nativeDEX.c

@ -257,14 +257,14 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int
{
if ( jobj(argjson,"method") != 0 && strcmp("connect",jstr(argjson,"method")) == 0 )
printf("self.(%s)\n",str);
portable_mutex_lock(&LP_commandmutex);
if ( LP_tradecommand(ctx,myipaddr,pubsock,argjson,0,0) <= 0 )
{
portable_mutex_lock(&LP_commandmutex);
if ( (retstr= stats_JSON(ctx,myipaddr,pubsock,argjson,remoteaddr,0)) != 0 )
free(retstr);
portable_mutex_unlock(&LP_commandmutex);
}
free_json(argjson);
portable_mutex_unlock(&LP_commandmutex);
}
free(str);
}

55
iguana/exchanges/LP_ordermatch.c

@ -376,9 +376,9 @@ int32_t LP_arrayfind(cJSON *array,bits256 txid,int32_t vout)
return(-1);
}
double LP_query(void *ctx,char *myipaddr,int32_t mypubsock,char *method,struct LP_quoteinfo *qp)
void LP_query(void *ctx,char *myipaddr,int32_t mypubsock,char *method,struct LP_quoteinfo *qp)
{
cJSON *reqjson; bits256 zero; char *msg; int32_t i,flag = 0; double price = 0.; struct LP_utxoinfo *utxo;
cJSON *reqjson; bits256 zero; char *msg; int32_t flag = 0; struct LP_utxoinfo *utxo;
if ( strcmp(method,"request") == 0 )
{
if ( (utxo= LP_utxofind(0,qp->desttxid,qp->destvout)) != 0 && LP_ismine(utxo) > 0 && LP_isavailable(utxo) > 0 )
@ -386,7 +386,7 @@ double LP_query(void *ctx,char *myipaddr,int32_t mypubsock,char *method,struct L
else
{
printf("couldnt find my txid to make request\n");
return(0.);
return;
}
}
reqjson = LP_quotejson(qp);
@ -407,22 +407,6 @@ double LP_query(void *ctx,char *myipaddr,int32_t mypubsock,char *method,struct L
//else LP_broadcast_message(LP_mypubsock,qp->srccoin,qp->destcoin,qp->srchash,msg);
}
portable_mutex_unlock(&LP_reservedmutex);
for (i=0; i<20; i++)
{
if ( (price= LP_pricecache(qp,qp->srccoin,qp->destcoin,qp->txid,qp->vout)) > SMALLVAL )
{
if ( flag == 0 || bits256_nonz(qp->desthash) != 0 )
{
printf("break out of loop.%d price %.8f %s/%s\n",i,price,qp->srccoin,qp->destcoin);
break;
}
}
while ( 1 )
if ( LP_nanomsg_recvs(ctx) <= 0 )
break;
sleep(1);
}
return(price);
}
int32_t LP_nanobind(void *ctx,char *pairstr)
@ -772,11 +756,25 @@ int32_t LP_listunspent_both(char *symbol,char *coinaddr,int32_t fullflag)
int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,uint8_t *data,int32_t datalen)
{
char *method,*msg; uint64_t value,value2; cJSON *retjson; double qprice,price,bid,ask; struct LP_utxoinfo A,B,*autxo,*butxo; struct iguana_info *coin; struct LP_address_utxo *utxos[1000]; struct LP_quoteinfo Q; int32_t retval = -1,max=(int32_t)(sizeof(utxos)/sizeof(*utxos));
char *method,*msg,*retstr; uint64_t value,value2; cJSON *retjson; double qprice,price,bid,ask; struct LP_utxoinfo A,B,*autxo,*butxo; struct iguana_info *coin; struct LP_address_utxo *utxos[1000]; struct LP_quoteinfo Q; int32_t retval = -1,max=(int32_t)(sizeof(utxos)/sizeof(*utxos));
if ( (method= jstr(argjson,"method")) != 0 && (strcmp(method,"request") == 0 ||strcmp(method,"connect") == 0) )
{
printf("LP_tradecommand: check received method %s\n",method);
retval = 1;
if ( strcmp(method,"reserved") == 0 )
{
printf("alice received RESERVED.(%s)\n",jprint(argjson,0));
if ( (retstr= LP_quotereceived(argjson)) != 0 )
free(retstr);
return(1);
}
else if ( strcmp(method,"connected") == 0 )
{
printf("alice received CONNECTED.(%s)\n",jprint(argjson,0));
if ( (retstr= LP_connectedalice(argjson)) != 0 )
free(retstr);
return(1);
}
if ( LP_quoteparse(&Q,argjson) == 0 && bits256_cmp(G.LP_mypub25519,Q.srchash) == 0 && bits256_cmp(G.LP_mypub25519,Q.desthash) != 0 )
{
if ( (coin= LP_coinfind(Q.srccoin)) == 0 || (price= LP_myprice(&bid,&ask,Q.srccoin,Q.destcoin)) <= SMALLVAL || ask <= SMALLVAL )
@ -898,15 +896,26 @@ char *LP_trade(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo *q
char str[65],str2[65]; printf("dest.(%s)/v%d fee.(%s)/v%d\n",bits256_str(str,qp->desttxid),qp->destvout,bits256_str(str2,qp->feetxid),qp->feevout);
return(clonestr("{\"error\":\"cant find alice utxopair\"}"));
}
price = LP_query(ctx,myipaddr,mypubsock,"request",qp);
expiration = (uint32_t)time(NULL) + timeout;
price = 0.;
LP_query(ctx,myipaddr,mypubsock,"request",qp);
while ( time(NULL) < expiration )
{
if ( (price= LP_pricecache(qp,qp->srccoin,qp->destcoin,qp->txid,qp->vout)) > SMALLVAL )
{
printf("break out of price %.8f %s/%s\n",price,qp->srccoin,qp->destcoin);
break;
}
sleep(1);
}
bestitem = LP_quotejson(qp);
if ( LP_pricevalid(price) > 0 )
{
if ( price <= maxprice )
{
price = LP_query(ctx,myipaddr,mypubsock,"connect",qp);
LP_query(ctx,myipaddr,mypubsock,"connect",qp);
//price = LP_pricecache(qp,qp->srccoin,qp->destcoin,qp->txid,qp->vout);
LP_requestinit(&qp->R,qp->srchash,qp->desthash,qp->srccoin,qp->satoshis-2*qp->txfee,qp->destcoin,qp->destsatoshis-2*qp->desttxfee,qp->timestamp,qp->quotetime,DEXselector);
expiration = (uint32_t)time(NULL) + timeout;
while ( time(NULL) < expiration )
{
if ( aliceutxo->S.swap != 0 )

Loading…
Cancel
Save