|
|
@ -20,6 +20,7 @@ |
|
|
|
//
|
|
|
|
struct LP_quoteinfo LP_Alicequery; |
|
|
|
double LP_Alicemaxprice; |
|
|
|
bits256 LP_Alicedestpubkey; |
|
|
|
uint32_t Alice_expiration; |
|
|
|
struct { uint64_t aliceid; double bestprice; uint32_t starttime,counter; } Bob_competition[512]; |
|
|
|
|
|
|
@ -455,7 +456,7 @@ int32_t LP_connectstartbob(void *ctx,int32_t pubsock,struct LP_utxoinfo *utxo,cJ |
|
|
|
return(retval); |
|
|
|
} |
|
|
|
|
|
|
|
char *LP_trade(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo *qp,double maxprice,int32_t timeout,int32_t duration,uint32_t tradeid) |
|
|
|
char *LP_trade(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo *qp,double maxprice,int32_t timeout,int32_t duration,uint32_t tradeid,bits256 destpubkey) |
|
|
|
{ |
|
|
|
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;
|
|
|
|
if ( (aliceutxo= LP_utxopairfind(0,qp->desttxid,qp->destvout,qp->feetxid,qp->feevout)) == 0 ) |
|
|
@ -469,14 +470,16 @@ char *LP_trade(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo *q |
|
|
|
qp->aliceid = LP_aliceid_calc(qp->desttxid,qp->destvout,qp->feetxid,qp->feevout); |
|
|
|
qp->tradeid = tradeid; |
|
|
|
LP_query(ctx,myipaddr,mypubsock,"request",qp); |
|
|
|
LP_Alicequery = *qp, LP_Alicemaxprice = maxprice, Alice_expiration = qp->timestamp + timeout; |
|
|
|
printf("LP_trade %s/%s %.8f vol %.8f\n",qp->srccoin,qp->destcoin,dstr(qp->satoshis),dstr(qp->destsatoshis)); |
|
|
|
LP_Alicequery = *qp, LP_Alicemaxprice = maxprice, Alice_expiration = qp->timestamp + timeout, LP_Alicedestpubkey = destpubkey; |
|
|
|
char str[65]; printf("LP_trade %s/%s %.8f vol %.8f dest.(%s)\n",qp->srccoin,qp->destcoin,dstr(qp->satoshis),dstr(qp->destsatoshis),bits256_str(str,LP_Alicedestpubkey)); |
|
|
|
return(LP_recent_swaps(0)); |
|
|
|
} |
|
|
|
|
|
|
|
int32_t LP_quotecmp(struct LP_quoteinfo *qp,struct LP_quoteinfo *qp2) |
|
|
|
{ |
|
|
|
if ( bits256_cmp(qp->desthash,qp2->desthash) == 0 && strcmp(qp->srccoin,qp2->srccoin) == 0 && strcmp(qp->destcoin,qp2->destcoin) == 0 && bits256_cmp(qp->desttxid,qp2->desttxid) == 0 && qp->destvout == qp2->destvout && bits256_cmp(qp->feetxid,qp2->feetxid) == 0 && qp->feevout == qp2->feevout && qp->destsatoshis == qp2->destsatoshis && qp->txfee >= qp2->txfee && qp->desttxfee == qp2->desttxfee ) //bits256_cmp(qp->srchash,qp2->srchash) == 0 &&
|
|
|
|
if ( bits256_nonz(LP_Alicedestpubkey) != 0 && bits256_cmp(LP_Alicedestpubkey,qp->srchash) != 0 ) |
|
|
|
return(-1); |
|
|
|
else if ( bits256_cmp(qp->desthash,qp2->desthash) == 0 && strcmp(qp->srccoin,qp2->srccoin) == 0 && strcmp(qp->destcoin,qp2->destcoin) == 0 && bits256_cmp(qp->desttxid,qp2->desttxid) == 0 && qp->destvout == qp2->destvout && bits256_cmp(qp->feetxid,qp2->feetxid) == 0 && qp->feevout == qp2->feevout && qp->destsatoshis == qp2->destsatoshis && qp->txfee >= qp2->txfee && qp->desttxfee == qp2->desttxfee ) //bits256_cmp(qp->srchash,qp2->srchash) == 0 &&
|
|
|
|
return(0); |
|
|
|
else return(-1); |
|
|
|
} |
|
|
@ -487,6 +490,7 @@ int32_t LP_alice_eligible() |
|
|
|
{ |
|
|
|
printf("time expired for Alice_request\n"); |
|
|
|
memset(&LP_Alicequery,0,sizeof(LP_Alicequery)); |
|
|
|
memset(&LP_Alicedestpubkey,0,sizeof(LP_Alicedestpubkey)); |
|
|
|
LP_Alicemaxprice = 0.; |
|
|
|
Alice_expiration = 0; |
|
|
|
} |
|
|
@ -503,6 +507,7 @@ void LP_reserved(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo |
|
|
|
{ |
|
|
|
qp->tradeid = LP_Alicequery.tradeid; |
|
|
|
memset(&LP_Alicequery,0,sizeof(LP_Alicequery)); |
|
|
|
memset(&LP_Alicedestpubkey,0,sizeof(LP_Alicedestpubkey)); |
|
|
|
LP_Alicemaxprice = 0.; |
|
|
|
Alice_expiration = 0; |
|
|
|
printf("send CONNECT\n"); |
|
|
@ -723,6 +728,11 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, |
|
|
|
//printf("aliceid.%llx price %.8f -> bestprice %.8f\n",(long long)aliceid,qprice,bestprice);
|
|
|
|
if ( LP_Alicemaxprice == 0. ) |
|
|
|
return(retval); |
|
|
|
if ( bits256_nonz(LP_Alicedestpubkey) != 0 && bits256_cmp(LP_Alicedestpubkey,Q.srchash) != 0 ) |
|
|
|
{ |
|
|
|
printf("got reserved response from different node\n"); |
|
|
|
return(retval); |
|
|
|
} |
|
|
|
if ( bits256_cmp(G.LP_mypub25519,Q.desthash) == 0 && bits256_cmp(G.LP_mypub25519,Q.srchash) != 0 && LP_alice_eligible() > 0 ) |
|
|
|
{ |
|
|
|
if ( (qprice= LP_quote_validate(autxo,butxo,&Q,0)) <= SMALLVAL ) |
|
|
@ -801,7 +811,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, |
|
|
|
{ |
|
|
|
char str[65];//,str2[65];
|
|
|
|
recalc = 0; |
|
|
|
if ( bits256_cmp(Q.srchash,G.LP_mypub25519) != 0 || strcmp(butxo->coinaddr,coin->smartaddr) != 0 || bits256_nonz(butxo->payment.txid) == 0 || bits256_nonz(butxo->deposit.txid) == 0 ) |
|
|
|
if ( bits256_nonz(Q.srchash) == 0 || bits256_cmp(Q.srchash,G.LP_mypub25519) != 0 || strcmp(butxo->coinaddr,coin->smartaddr) != 0 || bits256_nonz(butxo->payment.txid) == 0 || bits256_nonz(butxo->deposit.txid) == 0 ) |
|
|
|
{ |
|
|
|
qprice = (double)Q.destsatoshis / Q.satoshis; |
|
|
|
strcpy(Q.gui,G.gui); |
|
|
@ -1132,7 +1142,7 @@ char *LP_autobuy(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel |
|
|
|
return(clonestr("{\"error\":\"cant set ordermatch quote info\"}")); |
|
|
|
int32_t changed; |
|
|
|
LP_mypriceset(&changed,autxo->coin,base,1. / maxprice); |
|
|
|
return(LP_trade(ctx,myipaddr,mypubsock,&Q,maxprice,timeout,duration,tradeid)); |
|
|
|
return(LP_trade(ctx,myipaddr,mypubsock,&Q,maxprice,timeout,duration,tradeid,destpubkey)); |
|
|
|
|
|
|
|
LP_RTmetrics_update(base,rel); |
|
|
|
while ( 1 ) |
|
|
@ -1172,7 +1182,7 @@ char *LP_autobuy(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel |
|
|
|
else return(clonestr("{\"error\":\"cant ordermatch to destpubkey\"}")); |
|
|
|
} |
|
|
|
printf("i.%d maxiters.%d qprice %.8f vs maxprice %.8f\n",i,maxiters,dstr(qprice),dstr(maxprice)); |
|
|
|
return(LP_trade(ctx,myipaddr,mypubsock,&Q,maxprice,timeout,duration,tradeid)); |
|
|
|
return(LP_trade(ctx,myipaddr,mypubsock,&Q,maxprice,timeout,duration,tradeid,destpubkey)); |
|
|
|
} |
|
|
|
return(clonestr("{\"error\":\"cant get here\"}")); |
|
|
|
} |
|
|
|