|
|
@ -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]); |
|
|
|