Browse Source

Test

etomic
jl777 7 years ago
parent
commit
ca8852a767
  1. 15
      iguana/exchanges/LP_ordermatch.c
  2. 6
      iguana/exchanges/LP_utxo.c

15
iguana/exchanges/LP_ordermatch.c

@ -776,7 +776,7 @@ char *LP_bestfit(char *rel,double relvolume)
} }
struct LP_quoteinfo LP_Alicequery; struct LP_quoteinfo LP_Alicequery;
double LP_Alicemaxprice; double LP_Alicemaxprice; int32_t Alice_timeout;
char *LP_trade(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo *qp,double maxprice,int32_t timeout,int32_t duration) char *LP_trade(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo *qp,double maxprice,int32_t timeout,int32_t duration)
{ {
struct LP_utxoinfo *aliceutxo; double price; //cJSON *bestitem=0; int32_t DEXselector=0; uint32_t expiration; double price; struct LP_pubkeyinfo *pubp; struct basilisk_swap *swap; struct LP_utxoinfo *aliceutxo; double price; //cJSON *bestitem=0; int32_t DEXselector=0; uint32_t expiration; double price; struct LP_pubkeyinfo *pubp; struct basilisk_swap *swap;
@ -787,7 +787,7 @@ char *LP_trade(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo *q
} }
price = 0.; price = 0.;
LP_query(ctx,myipaddr,mypubsock,"request",qp); LP_query(ctx,myipaddr,mypubsock,"request",qp);
LP_Alicequery = *qp, LP_Alicemaxprice = maxprice; LP_Alicequery = *qp, LP_Alicemaxprice = maxprice, Alice_timeout = timeout;
return(clonestr("{\"result\":\"success\"}")); return(clonestr("{\"result\":\"success\"}"));
} }
@ -801,7 +801,14 @@ int32_t LP_quotecmp(struct LP_quoteinfo *qp,struct LP_quoteinfo *qp2)
void LP_reserved(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo *qp) void LP_reserved(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo *qp)
{ {
double price,maxprice = LP_Alicemaxprice; double price,maxprice = LP_Alicemaxprice;
if ( LP_quotecmp(qp,&LP_Alicequery) == 0 ) if ( time(NULL) > qp->timestamp+Alice_timeout )
{
printf("time expired for Alice_request\n");
memset(&LP_Alicequery,0,sizeof(LP_Alicequery));
LP_Alicemaxprice = 0.;
Alice_timeout = 0;
}
else if ( LP_quotecmp(qp,&LP_Alicequery) == 0 )
{ {
price = LP_pricecache(qp,qp->srccoin,qp->destcoin,qp->txid,qp->vout); price = LP_pricecache(qp,qp->srccoin,qp->destcoin,qp->txid,qp->vout);
if ( LP_pricevalid(price) > 0 && maxprice > SMALLVAL && price <= maxprice ) if ( LP_pricevalid(price) > 0 && maxprice > SMALLVAL && price <= maxprice )
@ -1058,7 +1065,7 @@ char *LP_autobuy(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel
LP_txfees(&txfee,&desttxfee,base,rel); LP_txfees(&txfee,&desttxfee,base,rel);
destsatoshis = SATOSHIDEN * relvolume + 2*desttxfee; destsatoshis = SATOSHIDEN * relvolume + 2*desttxfee;
if ( (autxo= LP_utxo_bestfit(rel,destsatoshis)) == 0 ) if ( (autxo= LP_utxo_bestfit(rel,destsatoshis)) == 0 )
return(clonestr("{\"error\":\"cant find utxo that is big enough\"}")); return(clonestr("{\"error\":\"cant find alice utxo that is big enough\"}"));
if ( destsatoshis < autxo->S.satoshis ) if ( destsatoshis < autxo->S.satoshis )
autxo->S.satoshis = destsatoshis; autxo->S.satoshis = destsatoshis;
while ( 1 ) while ( 1 )

6
iguana/exchanges/LP_utxo.c

@ -157,7 +157,7 @@ int32_t LP_address_utxo_ptrs(int32_t iambob,struct LP_address_utxo **utxos,int32
portable_mutex_lock(&LP_utxomutex); portable_mutex_lock(&LP_utxomutex);
DL_FOREACH_SAFE(ap->utxos,up,tmp) DL_FOREACH_SAFE(ap->utxos,up,tmp)
{ {
//char str[65]; printf("LP_address_utxo_ptrs %s n.%d %.8f %s v%d\n",ap->coinaddr,n,dstr(up->U.value),bits256_str(str,up->U.txid),up->U.vout); char str[65]; printf("LP_address_utxo_ptrs %s n.%d %.8f %s v%d spendheight.%d\n",ap->coinaddr,n,dstr(up->U.value),bits256_str(str,up->U.txid),up->U.vout,up->spendheight);
if ( up->spendheight <= 0 ) if ( up->spendheight <= 0 )
{ {
if ( LP_allocated(up->U.txid,up->U.vout) == 0 ) if ( LP_allocated(up->U.txid,up->U.vout) == 0 )
@ -832,12 +832,12 @@ int32_t LP_iseligible(uint64_t *valp,uint64_t *val2p,int32_t iambob,char *symbol
else val = LP_txvalue(destaddr,symbol,txid,vout); else val = LP_txvalue(destaddr,symbol,txid,vout);
if ( (up= LP_address_utxofind(coin,destaddr,txid,vout)) != 0 && up->spendheight > 0 ) if ( (up= LP_address_utxofind(coin,destaddr,txid,vout)) != 0 && up->spendheight > 0 )
{ {
printf("%s/v%d spent %d\n",bits256_str(str,txid),vout,up->spendheight); //printf("%s/v%d spent %d\n",bits256_str(str,txid),vout,up->spendheight);
return(-2); return(-2);
} }
if ( (up= LP_address_utxofind(coin,destaddr,txid2,vout2)) != 0 && up->spendheight > 0 ) if ( (up= LP_address_utxofind(coin,destaddr,txid2,vout2)) != 0 && up->spendheight > 0 )
{ {
printf("%s/v%d spent %d\n",bits256_str(str,txid2),vout2,up->spendheight); //printf("%s/v%d spent %d\n",bits256_str(str,txid2),vout2,up->spendheight);
return(-3); return(-3);
} }
txfee = LP_txfeecalc(LP_coinfind(symbol),0,0); txfee = LP_txfeecalc(LP_coinfind(symbol),0,0);

Loading…
Cancel
Save