diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index eb9d3f16e..236fa8675 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -35,9 +35,9 @@ struct basilisk_request *LP_requestinit(struct basilisk_request *rp,bits256 srch return(rp); } -double LP_pricequery(bits256 *otherpubp,uint32_t *reservedp,uint64_t *txfeep,uint64_t *destsatoshisp,uint64_t *desttxfeep,char *ipaddr,uint16_t port,char *base,char *rel,bits256 txid,int32_t vout) +double LP_pricequery(bits256 *otherpubp,uint32_t *reservedp,uint64_t *txfeep,uint64_t *destsatoshisp,uint64_t *desttxfeep,char *ipaddr,uint16_t port,char *base,char *rel,bits256 txid,int32_t vout,bits256 mypub) { - cJSON *reqjson; struct LP_peerinfo *peer; int32_t i,pushsock = -1; double price = 0.; + cJSON *reqjson; struct LP_peerinfo *peer; int32_t i,flag = 0,pushsock = -1; double price = 0.; if ( ipaddr != 0 && port >= 1000 ) { if ( (peer= LP_peerfind((uint32_t)calc_ipbits(ipaddr),port)) == 0 ) @@ -51,12 +51,22 @@ double LP_pricequery(bits256 *otherpubp,uint32_t *reservedp,uint64_t *txfeep,uin jaddnum(reqjson,"vout",vout); jaddstr(reqjson,"base",base); jaddstr(reqjson,"rel",rel); - jaddstr(reqjson,"method","price"); + if ( bits256_nonz(mypub) == 0 ) + jaddstr(reqjson,"method","price"); + else + { + flag = 1; + jaddstr(reqjson,"method","request"); + jaddbits256(reqjson,"mypub",mypub); + } LP_send(pushsock,jprint(reqjson,1),1); for (i=0; i<10; i++) { if ( (price= LP_pricecache(otherpubp,reservedp,txfeep,destsatoshisp,desttxfeep,base,rel,txid,vout)) != 0. ) - break; + { + if ( flag == 0 || bits256_nonz(*otherpubp) != 0 ) + break; + } usleep(250000); } } else printf("no pushsock for peer.%s:%u\n",ipaddr,port); @@ -137,6 +147,7 @@ cJSON *LP_tradecandidates(struct LP_utxoinfo *myutxo,char *base) cJSON *LP_bestprice(struct LP_utxoinfo *utxo,char *base) { + static bits256 zero; int32_t i,n,besti; cJSON *array,*item,*bestitem=0; double bestmetric,metric,bestprice=0.,price,prices[100]; bits256 otherpubs[100]; uint32_t reserved[100]; uint64_t txfees[100],destsatoshis[100],desttxfees[100]; bestprice = 0.; if ( (array= LP_tradecandidates(utxo,base)) != 0 ) @@ -155,7 +166,7 @@ cJSON *LP_bestprice(struct LP_utxoinfo *utxo,char *base) item = jitem(array,i); if ( (price= jdouble(item,"price")) == 0. ) { - price = LP_pricequery(&otherpubs[i],&reserved[i],&txfees[i],&destsatoshis[i],&desttxfees[i],jstr(item,"ipaddr"),jint(item,"port"),base,utxo->coin,jbits256(item,"txid"),jint(item,"vout")); + price = LP_pricequery(&otherpubs[i],&reserved[i],&txfees[i],&destsatoshis[i],&desttxfees[i],jstr(item,"ipaddr"),jint(item,"port"),base,utxo->coin,jbits256(item,"txid"),jint(item,"vout"),zero); if ( destsatoshis[i] != 0 && (double)j64bits(item,"value")/destsatoshis[i] > price ) price = (double)j64bits(item,"satoshis")/destsatoshis[i]; } @@ -186,6 +197,9 @@ cJSON *LP_bestprice(struct LP_utxoinfo *utxo,char *base) if ( besti >= 0 ) { bestitem = jduplicate(jitem(array,besti)); + i = besti; + item = bestitem; + price = LP_pricequery(&otherpubs[i],&reserved[i],&txfees[i],&destsatoshis[i],&desttxfees[i],jstr(item,"ipaddr"),jint(item,"port"),base,utxo->coin,jbits256(item,"txid"),jint(item,"vout"),myutxo->pubkey); if ( jobj(bestitem,"price") != 0 ) jdelete(bestitem,"price"); jaddnum(bestitem,"reserved",reserved[besti]); diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 240b0a8ca..b970f4dce 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -48,7 +48,7 @@ struct LP_peerinfo struct LP_utxoinfo { UT_hash_handle hh; - bits256 txid,deposittxid,feetxid,otherpubkey; + bits256 txid,deposittxid,feetxid,otherpubkey,mypub; void *swap; uint64_t satoshis,depositsatoshis,feesatoshis; uint8_t key[sizeof(bits256) + sizeof(int32_t)]; @@ -775,7 +775,7 @@ struct iguana_info *LP_coinfind(char *symbol) uint64_t LP_privkey_init(struct LP_peerinfo *mypeer,int32_t mypubsock,char *symbol,char *passphrase,char *wifstr,int32_t amclient) { - char coinaddr[64],*script; cJSON *array,*item,*retjson; bits256 txid,deposittxid; int32_t used,i,n,vout,depositvout; uint64_t *values,satoshis,depositval,targetval,value,total = 0; bits256 privkey,pubkey; uint8_t pubkey33[33],tmptype,rmd160[20]; struct iguana_info *coin = LP_coinfind(symbol); + char coinaddr[64],*script; struct LP_utxoinfo *utxo; cJSON *array,*item,*retjson; bits256 txid,deposittxid; int32_t used,i,n,vout,depositvout; uint64_t *values,satoshis,depositval,targetval,value,total = 0; bits256 privkey,pubkey; uint8_t pubkey33[33],tmptype,rmd160[20]; struct iguana_info *coin = LP_coinfind(symbol); if ( coin == 0 ) { printf("cant add privkey for %s, coin not active\n",symbol); @@ -833,7 +833,11 @@ uint64_t LP_privkey_init(struct LP_peerinfo *mypeer,int32_t mypubsock,char *symb values[i] = 0, used++; if ( amclient == 0 ) LP_addutxo(amclient,mypeer,mypubsock,symbol,txid,vout,value,deposittxid,depositvout,depositval,script,coinaddr,LP_peerinfos[0].ipaddr,LP_peerinfos[0].port,LP_peerinfos[0].profitmargin); - else LP_addutxo(amclient,mypeer,mypubsock,symbol,deposittxid,depositvout,depositval,txid,vout,value,script,coinaddr,"127.0.0.1",0,0); + else + { + if ( (utxo= LP_addutxo(amclient,mypeer,mypubsock,symbol,deposittxid,depositvout,depositval,txid,vout,value,script,coinaddr,"127.0.0.1",0,0)) != 0 ) + utxo->mypub = curve25519(privkey,curve25519_basepoint9()); + } total += value; } }