|
|
@ -526,27 +526,33 @@ int32_t LP_connectstartbob(void *ctx,int32_t pubsock,char *base,char *rel,double |
|
|
|
LP_importaddress(qp->destcoin,qp->destaddr); |
|
|
|
LP_otheraddress(qp->srccoin,otheraddr,qp->destcoin,qp->destaddr); |
|
|
|
LP_importaddress(qp->srccoin,otheraddr); |
|
|
|
bits256 zero; |
|
|
|
memset(zero.bytes,0,sizeof(zero)); |
|
|
|
for (i=0; i<1; i++) |
|
|
|
{ |
|
|
|
LP_reserved_msg(1,qp->srccoin,qp->destcoin,qp->desthash,jprint(reqjson,0)); |
|
|
|
break; |
|
|
|
sleep(10); |
|
|
|
if ( swap->received != 0 ) |
|
|
|
bits256 zero; |
|
|
|
memset(zero.bytes,0,sizeof(zero)); |
|
|
|
for (i=0; i<1; i++) |
|
|
|
{ |
|
|
|
printf("swap %u-%u has started t%u\n",swap->I.req.requestid,swap->I.req.quoteid,swap->received); |
|
|
|
LP_reserved_msg(1,qp->srccoin,qp->destcoin,qp->desthash,jprint(reqjson,0)); |
|
|
|
break; |
|
|
|
sleep(10); |
|
|
|
if ( swap->received != 0 ) |
|
|
|
{ |
|
|
|
printf("swap %u-%u has started t%u\n",swap->I.req.requestid,swap->I.req.quoteid,swap->received); |
|
|
|
break; |
|
|
|
} |
|
|
|
printf("bob tries %u-%u again i.%d\n",swap->I.req.requestid,swap->I.req.quoteid,i); |
|
|
|
LP_reserved_msg(1,qp->srccoin,qp->destcoin,zero,jprint(reqjson,0)); |
|
|
|
} |
|
|
|
printf("bob tries %u-%u again i.%d\n",swap->I.req.requestid,swap->I.req.quoteid,i); |
|
|
|
sleep(1); |
|
|
|
printf("send CONNECT for %u-%u\n",qp->R.requestid,qp->R.quoteid); |
|
|
|
LP_reserved_msg(1,qp->srccoin,qp->destcoin,zero,jprint(reqjson,0)); |
|
|
|
if ( IPC_ENDPOINT >= 0 ) |
|
|
|
LP_queuecommand(0,jprint(reqjson,0),IPC_ENDPOINT,-1,0); |
|
|
|
} |
|
|
|
sleep(1); |
|
|
|
printf("send CONNECT for %u-%u\n",qp->R.requestid,qp->R.quoteid); |
|
|
|
LP_reserved_msg(1,qp->srccoin,qp->destcoin,zero,jprint(reqjson,0)); |
|
|
|
if ( IPC_ENDPOINT >= 0 ) |
|
|
|
LP_queuecommand(0,jprint(reqjson,1),IPC_ENDPOINT,-1,0); |
|
|
|
else free_json(reqjson); |
|
|
|
if ( qp->mpnet != 0 && qp->fill != 0 && qp->gtc != 0 ) |
|
|
|
{ |
|
|
|
// send to mpnet
|
|
|
|
} |
|
|
|
free_json(reqjson); |
|
|
|
retval = 0; |
|
|
|
} |
|
|
|
else |
|
|
@ -578,10 +584,16 @@ int32_t LP_connectstartbob(void *ctx,int32_t pubsock,char *base,char *rel,double |
|
|
|
|
|
|
|
void LP_gtc_iteration(void *ctx,char *myipaddr,int32_t mypubsock) |
|
|
|
{ |
|
|
|
struct LP_gtcorder *gtc,*tmp; struct LP_quoteinfo *qp; uint64_t destvalue,destvalue2; |
|
|
|
struct LP_gtcorder *gtc,*tmp; struct LP_quoteinfo *qp; uint64_t destvalue,destvalue2; uint32_t oldest = 0; |
|
|
|
if ( Alice_expiration != 0 ) |
|
|
|
return; |
|
|
|
DL_FOREACH_SAFE(GTCorders,gtc,tmp) |
|
|
|
{ |
|
|
|
qp = >c->Q; |
|
|
|
if ( gtc->cancelled == 0 && (oldest == 0 || gtc->pending < oldest) ) |
|
|
|
oldest = gtc->pending; |
|
|
|
} |
|
|
|
DL_FOREACH_SAFE(GTCorders,gtc,tmp) |
|
|
|
{ |
|
|
|
qp = >c->Q; |
|
|
|
if ( gtc->cancelled == 0 && LP_iseligible(&destvalue,&destvalue2,0,qp->destcoin,qp->desttxid,qp->destvout,qp->destsatoshis,qp->feetxid,qp->feevout) == 0 ) |
|
|
@ -598,9 +610,9 @@ void LP_gtc_iteration(void *ctx,char *myipaddr,int32_t mypubsock) |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
if ( time(NULL) > gtc->pending+LP_AUTOTRADE_TIMEOUT*10 ) |
|
|
|
if ( gtc->pending <= oldest+60 && time(NULL) > gtc->pending+LP_AUTOTRADE_TIMEOUT*10 ) |
|
|
|
{ |
|
|
|
qp->timestamp = (uint32_t)time(NULL); |
|
|
|
gtc->pending = qp->timestamp = (uint32_t)time(NULL); |
|
|
|
LP_query(ctx,myipaddr,mypubsock,"request",qp); |
|
|
|
LP_Alicequery = *qp, LP_Alicemaxprice = gtc->maxprice, Alice_expiration = qp->timestamp + 2*LP_AUTOTRADE_TIMEOUT, LP_Alicedestpubkey = qp->srchash; |
|
|
|
char str[65]; printf("LP_gtc fill.%d gtc.%d %s/%s %.8f vol %.8f dest.(%s) maxprice %.8f etomicdest.(%s) uuid.%s fill.%d gtc.%d\n",qp->fill,qp->gtc,qp->srccoin,qp->destcoin,dstr(qp->satoshis),dstr(qp->destsatoshis),bits256_str(str,LP_Alicedestpubkey),gtc->maxprice,qp->etomicdest,qp->uuidstr,qp->fill,qp->gtc); |
|
|
@ -632,9 +644,15 @@ char *LP_trade(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo *q |
|
|
|
DL_APPEND(GTCorders,gtc); |
|
|
|
portable_mutex_unlock(&LP_gtcmutex); |
|
|
|
} |
|
|
|
LP_query(ctx,myipaddr,mypubsock,"request",qp); |
|
|
|
LP_Alicequery = *qp, LP_Alicemaxprice = maxprice, Alice_expiration = qp->timestamp + timeout, LP_Alicedestpubkey = qp->srchash; |
|
|
|
char str[65]; printf("LP_trade fill.%d gtc.%d %s/%s %.8f vol %.8f dest.(%s) maxprice %.8f etomicdest.(%s) uuid.%s fill.%d gtc.%d\n",qp->fill,qp->gtc,qp->srccoin,qp->destcoin,dstr(qp->satoshis),dstr(qp->destsatoshis),bits256_str(str,LP_Alicedestpubkey),maxprice,qp->etomicdest,qp->uuidstr,qp->fill,qp->gtc); |
|
|
|
{ |
|
|
|
LP_query(ctx,myipaddr,mypubsock,"request",qp); |
|
|
|
LP_Alicequery = *qp, LP_Alicemaxprice = maxprice, Alice_expiration = qp->timestamp + timeout, LP_Alicedestpubkey = qp->srchash; |
|
|
|
} |
|
|
|
if ( qp->mpnet != 0 && qp->gtc != 0 && qp->fill != 0 ) |
|
|
|
{ |
|
|
|
// send to mpnet
|
|
|
|
} |
|
|
|
char str[65]; printf("LP_trade mpnet.%d fill.%d gtc.%d %s/%s %.8f vol %.8f dest.(%s) maxprice %.8f etomicdest.(%s) uuid.%s fill.%d gtc.%d\n",qp->mpnet,qp->fill,qp->gtc,qp->srccoin,qp->destcoin,dstr(qp->satoshis),dstr(qp->destsatoshis),bits256_str(str,LP_Alicedestpubkey),maxprice,qp->etomicdest,qp->uuidstr,qp->fill,qp->gtc); |
|
|
|
return(LP_recent_swaps(0,uuidstr)); |
|
|
|
} |
|
|
|
|
|
|
@ -667,11 +685,17 @@ void LP_alicequery_clear() |
|
|
|
|
|
|
|
int32_t LP_alice_eligible(uint32_t quotetime) |
|
|
|
{ |
|
|
|
int32_t changed; |
|
|
|
if ( Alice_expiration != 0 && quotetime > Alice_expiration ) |
|
|
|
{ |
|
|
|
if ( LP_Alicequery.uuidstr[0] != 0 ) |
|
|
|
LP_failedmsg(LP_Alicequery.R.requestid,LP_Alicequery.R.quoteid,-9999,LP_Alicequery.uuidstr); |
|
|
|
printf("time expired for Alice_request\n"); |
|
|
|
/*if ( LP_Alicequery.srccoin[0] != 0 && LP_Alicequery.destcoin[0] != 0 ) cant do this! myprice is used to validate the order
|
|
|
|
{ |
|
|
|
LP_mypriceset(&changed,LP_Alicequery.destcoin,LP_Alicequery.srccoin,0.); |
|
|
|
LP_mypriceset(&changed,LP_Alicequery.srccoin,LP_Alicequery.destcoin,0.); |
|
|
|
}*/ |
|
|
|
LP_alicequery_clear(); |
|
|
|
} |
|
|
|
return(Alice_expiration == 0 || time(NULL) < Alice_expiration); |
|
|
@ -735,7 +759,7 @@ char *LP_connectedalice(struct LP_quoteinfo *qp,char *pairstr) // alice |
|
|
|
LP_failedmsg(qp->R.requestid,qp->R.quoteid,-4000,qp->uuidstr); |
|
|
|
return(clonestr("{\"result\",\"update stats\"}")); |
|
|
|
} |
|
|
|
printf("CONNECTED fill.%d gtc.%d numpending.%d tradeid.%u requestid.%u quoteid.%u pairstr.%s\n",qp->fill,qp->gtc,G.LP_pendingswaps,qp->tradeid,qp->R.requestid,qp->R.quoteid,pairstr!=0?pairstr:""); |
|
|
|
printf("CONNECTED mpnet.%d fill.%d gtc.%d numpending.%d tradeid.%u requestid.%u quoteid.%u pairstr.%s\n",qp->mpnet,qp->fill,qp->gtc,G.LP_pendingswaps,qp->tradeid,qp->R.requestid,qp->R.quoteid,pairstr!=0?pairstr:""); |
|
|
|
LP_requestinit(&qp->R,qp->srchash,qp->desthash,qp->srccoin,qp->satoshis-qp->txfee,qp->destcoin,qp->destsatoshis-qp->desttxfee,qp->timestamp,qp->quotetime,DEXselector,qp->fill,qp->gtc); |
|
|
|
//printf("calculated requestid.%u quoteid.%u\n",qp->R.requestid,qp->R.quoteid);
|
|
|
|
memset(&LP_Alicereserved,0,sizeof(LP_Alicereserved)); |
|
|
@ -1003,7 +1027,7 @@ struct LP_quoteinfo *LP_trades_gotrequest(void *ctx,struct LP_quoteinfo *qp,stru |
|
|
|
double price=0.,p=0.,qprice,myprice,bestprice,range,bid,ask; uint64_t satoshis; struct iguana_info *coin,*othercoin; struct LP_utxoinfo A,B,*autxo,*butxo; cJSON *reqjson,*retjson; char str[65],*retstr,*txidstr,*hexstr; struct LP_address_utxo *utxos[4096]; int32_t i,j,notarized,r,num,counter,max = (int32_t)(sizeof(utxos)/sizeof(*utxos)); |
|
|
|
*newqp = *qp; |
|
|
|
qp = newqp; |
|
|
|
printf("bob %s received REQUEST.(%s) fill.%d gtc.%d\n",bits256_str(str,G.LP_mypub25519),qp->uuidstr+32,qp->fill,qp->gtc); |
|
|
|
printf("bob %s received REQUEST.(%s) mpnet.%d fill.%d gtc.%d\n",bits256_str(str,G.LP_mypub25519),qp->uuidstr+32,qp->mpnet,qp->fill,qp->gtc); |
|
|
|
if ( (coin= LP_coinfind(qp->srccoin)) == 0 || (othercoin= LP_coinfind(qp->destcoin)) == 0 ) |
|
|
|
return(0); |
|
|
|
if ( (myprice= LP_trades_bobprice(&bid,&ask,qp)) == 0. ) |
|
|
@ -1135,26 +1159,14 @@ printf("bob %s received REQUEST.(%s) fill.%d gtc.%d\n",bits256_str(str,G.LP_mypu |
|
|
|
else if ( qp->fill != 0 || i == priceiters ) |
|
|
|
{ |
|
|
|
printf("i.%d cant find utxopair aliceid.%llu %s/%s %.8f -> relvol %.8f txfee %.8f\n",i,(long long)qp->aliceid,qp->srccoin,qp->destcoin,dstr(LP_basesatoshis(dstr(qp->destsatoshis),price,qp->txfee,qp->desttxfee)),dstr(qp->destsatoshis),dstr(qp->txfee)); |
|
|
|
if ( qp->gtc != 0 && qp->fill != 0 && coin != 0 && LP_getheight(¬arized,coin) > coin->bobfillheight+3 ) |
|
|
|
if ( qp->gtc != 0 && qp->fill != 0 && coin != 0 ) |
|
|
|
{ |
|
|
|
satoshis = LP_basesatoshis(dstr(qp->destsatoshis),price,qp->txfee,qp->desttxfee) + 3*qp->txfee; |
|
|
|
LP_address_utxo_reset(&num,coin); |
|
|
|
if ( (retstr= LP_autofillbob(coin,satoshis*1.02)) != 0 ) |
|
|
|
satoshis = LP_basesatoshis(dstr(qp->destsatoshis),price,qp->txfee,qp->desttxfee) + 3*qp->txfee; |
|
|
|
if ( LP_getheight(¬arized,coin) > coin->bobfillheight+3 && fabs((double)coin->fillsatoshis - satoshis)/satoshis > 0.1 ) |
|
|
|
{ |
|
|
|
if ( (retjson= cJSON_Parse(retstr)) != 0 ) |
|
|
|
{ |
|
|
|
if ( (hexstr= jstr(retjson,"hex")) != 0 ) |
|
|
|
{ |
|
|
|
if ( (txidstr= LP_sendrawtransaction(coin->symbol,hexstr,0)) != 0 ) |
|
|
|
{ |
|
|
|
printf("autofill created %s\n",txidstr); |
|
|
|
free(txidstr); |
|
|
|
coin->bobfillheight = LP_getheight(¬arized,coin); |
|
|
|
} |
|
|
|
} |
|
|
|
free_json(retjson); |
|
|
|
} |
|
|
|
free(retstr); |
|
|
|
printf("queue up do_autofill_merge %.8f\n",dstr(satoshis)); |
|
|
|
coin->do_autofill_merge = satoshis; |
|
|
|
} |
|
|
|
} |
|
|
|
return(0); |
|
|
@ -1177,10 +1189,16 @@ printf("bob %s received REQUEST.(%s) fill.%d gtc.%d\n",bits256_str(str,G.LP_mypu |
|
|
|
jaddnum(reqjson,"quotetime",qp->quotetime); |
|
|
|
jaddnum(reqjson,"pending",qp->timestamp + LP_RESERVETIME); |
|
|
|
jaddstr(reqjson,"method","reserved"); |
|
|
|
LP_reserved_msg(1,qp->srccoin,qp->destcoin,qp->desthash,jprint(reqjson,0)); |
|
|
|
bits256 zero; |
|
|
|
memset(zero.bytes,0,sizeof(zero)); |
|
|
|
LP_reserved_msg(1,qp->srccoin,qp->destcoin,zero,jprint(reqjson,0)); |
|
|
|
{ |
|
|
|
LP_reserved_msg(1,qp->srccoin,qp->destcoin,qp->desthash,jprint(reqjson,0)); |
|
|
|
bits256 zero; |
|
|
|
memset(zero.bytes,0,sizeof(zero)); |
|
|
|
LP_reserved_msg(1,qp->srccoin,qp->destcoin,zero,jprint(reqjson,0)); |
|
|
|
} |
|
|
|
if ( qp->mpnet != 0 && qp->gtc != 0 && qp->fill != 0 ) |
|
|
|
{ |
|
|
|
// send to mpnet
|
|
|
|
} |
|
|
|
free_json(reqjson); |
|
|
|
//printf("Send RESERVED id.%llu\n",(long long)qp->aliceid);
|
|
|
|
return(qp); |
|
|
@ -1191,7 +1209,7 @@ printf("bob %s received REQUEST.(%s) fill.%d gtc.%d\n",bits256_str(str,G.LP_mypu |
|
|
|
struct LP_quoteinfo *LP_trades_gotreserved(void *ctx,struct LP_quoteinfo *qp,struct LP_quoteinfo *newqp) |
|
|
|
{ |
|
|
|
char *retstr; double qprice; |
|
|
|
char str[65]; printf("alice %s received RESERVED.(%s) %.8f fill.%d gtc.%d\n",bits256_str(str,G.LP_mypub25519),qp->uuidstr+32,(double)qp->destsatoshis/(qp->satoshis+1),qp->fill,qp->gtc); |
|
|
|
char str[65]; printf("alice %s received RESERVED.(%s) %.8f mpnet.%d fill.%d gtc.%d\n",bits256_str(str,G.LP_mypub25519),qp->uuidstr+32,(double)qp->destsatoshis/(qp->satoshis+1),qp->mpnet,qp->fill,qp->gtc); |
|
|
|
*newqp = *qp; |
|
|
|
qp = newqp; |
|
|
|
if ( (qprice= LP_trades_alicevalidate(ctx,qp)) > 0. ) |
|
|
@ -1233,7 +1251,7 @@ struct LP_quoteinfo *LP_trades_gotconnect(void *ctx,struct LP_quoteinfo *qp,stru |
|
|
|
struct LP_quoteinfo *LP_trades_gotconnected(void *ctx,struct LP_quoteinfo *qp,struct LP_quoteinfo *newqp,char *pairstr) |
|
|
|
{ |
|
|
|
char *retstr; int32_t changed; double val; |
|
|
|
char str[65]; printf("alice %s received CONNECTED.(%llu) fill.%d gtc.%d\n",bits256_str(str,G.LP_mypub25519),(long long)qp->aliceid,qp->fill,qp->gtc); |
|
|
|
char str[65]; printf("alice %s received CONNECTED.(%llu) mpnet.%d fill.%d gtc.%d\n",bits256_str(str,G.LP_mypub25519),(long long)qp->aliceid,qp->mpnet,qp->fill,qp->gtc); |
|
|
|
*newqp = *qp; |
|
|
|
qp = newqp; |
|
|
|
if ( (val= LP_trades_alicevalidate(ctx,qp)) > 0. ) |
|
|
@ -1775,6 +1793,7 @@ char *LP_autobuy(void *ctx,int32_t fomoflag,char *myipaddr,int32_t mypubsock,cha |
|
|
|
} |
|
|
|
} |
|
|
|
int32_t changed; |
|
|
|
Q.mpnet = 0; |
|
|
|
Q.fill = fillflag; |
|
|
|
Q.gtc = gtcflag; |
|
|
|
LP_mypriceset(&changed,rel,base,1. / maxprice); |
|
|
|