Browse Source

Test

etomic
jl777 8 years ago
parent
commit
c032065398
  1. 2
      iguana/exchanges/LP_include.h
  2. 29
      iguana/exchanges/LP_ordermatch.c
  3. 19
      iguana/exchanges/LP_utxos.c

2
iguana/exchanges/LP_include.h

@ -47,6 +47,8 @@
#define LP_MIN_TXFEE 10000
#define LP_MINVOL 20
#define LP_MINCLIENTVOL 100
#define LP_MINSIZE_TXFEEMULT 10
#define LP_REQUIRED_TXFEE 0.95
#define LP_DEXFEE(destsatoshis) ((destsatoshis) / INSTANTDEX_INSURANCEDIV)
#define LP_DEPOSITSATOSHIS(satoshis) ((satoshis) + (satoshis >> 3))

29
iguana/exchanges/LP_ordermatch.c

@ -268,19 +268,19 @@ double LP_quote_validate(struct LP_utxoinfo **autxop,struct LP_utxoinfo **butxop
return(-11);
}
qprice = ((double)qp->destsatoshis / qp->satoshis);
if ( qp->satoshis < (srcvalue / LP_MINVOL) )
if ( qp->satoshis < (srcvalue / LP_MINVOL) || srcvalue < qp->txfee*LP_MINSIZE_TXFEEMULT )
{
printf("utxo payment %.8f is less than %f covered by Q %.8f\n",dstr(srcvalue),1./LP_MINVOL,dstr(qp->satoshis));
printf("utxo payment %.8f is less than %f covered by Q %.8f or <10x txfee %.8f\n",dstr(srcvalue),1./LP_MINVOL,dstr(qp->satoshis),dstr(qp->txfee));
return(-12);
}
if ( qp->destsatoshis < (destvalue / LP_MINCLIENTVOL) )
if ( qp->destsatoshis < (destvalue / LP_MINCLIENTVOL) || destvalue < qp->desttxfee*LP_MINSIZE_TXFEEMULT )
{
printf("destsatoshis %.8f is less than %f of value %.8f\n",dstr(qp->destsatoshis),1./LP_MINCLIENTVOL,dstr(destvalue));
printf("destsatoshis %.8f is less than %f of value %.8f or < 10x txfee %.8f\n",dstr(qp->destsatoshis),1./LP_MINCLIENTVOL,dstr(destvalue),dstr(qp->desttxfee));
return(-13);
}
LP_txfees(&txfee,&desttxfee,qp->srccoin,qp->destcoin);
printf("qprice %.8f <- %.8f/%.8f txfees.(%.8f %.8f) vs (%.8f %.8f)\n",qprice,dstr(qp->destsatoshis),dstr(qp->satoshis),dstr(qp->txfee),dstr(qp->desttxfee),dstr(txfee),dstr(desttxfee));
if ( qp->txfee < 0.95*txfee || qp->desttxfee < 0.95*desttxfee )
if ( qp->txfee < LP_REQUIRED_TXFEE*txfee || qp->desttxfee < LP_REQUIRED_TXFEE*desttxfee )
return(-14);
return(qprice);
}
@ -313,19 +313,6 @@ double LP_query(void *ctx,char *myipaddr,int32_t mypubsock,char *method,struct L
reqjson = LP_quotejson(qp);
if ( bits256_nonz(qp->desthash) != 0 )
flag = 1;
/*if ( IAMLP != 0 )
{
jaddstr(reqjson,"method",method);
msg = jprint(reqjson,1);
/LP_send(LP_mypubsock,msg,(int32_t)strlen(msg)+1,1);
}
else
{
jaddstr(reqjson,"method2",method);
jaddstr(reqjson,"method","forward");
jaddbits256(reqjson,"pubkey",qp->srchash);
/LP_forward(ctx,myipaddr,mypubsock,qp->srchash,jprint(reqjson,1),1);
}*/
jaddbits256(reqjson,"pubkey",qp->srchash);
jaddstr(reqjson,"method",method);
msg = jprint(reqjson,1);
@ -600,7 +587,7 @@ struct LP_utxoinfo *LP_bestutxo(double *ordermatchpricep,int64_t *bestdestsatosh
{
if ( bestprice == 0. ) // assumes price ordered asks
bestprice = price;
printf("item.[%d] %s\n",i,jprint(item,0));
//printf("item.[%d] %s\n",i,jprint(item,0));
txid = jbits256(item,"txid");
vout = jint(item,"vout");
vol = jdouble(item,"volume");
@ -610,10 +597,6 @@ struct LP_utxoinfo *LP_bestutxo(double *ordermatchpricep,int64_t *bestdestsatosh
if ( LP_iseligible(&val,&val2,butxo->iambob,butxo->coin,butxo->payment.txid,butxo->payment.vout,butxo->S.satoshis,butxo->deposit.txid,butxo->deposit.vout) > 0 )
{
destsatoshis = ((butxo->S.satoshis - txfee) * price);
/*if ( destsatoshis > autxo->payment.value-desttxfee-1 )
destsatoshis = autxo->payment.value-desttxfee-1;
if ( maxdestsatoshis != 0 && destsatoshis > maxdestsatoshis-desttxfee-1 )
destsatoshis = maxdestsatoshis-desttxfee-1;*/
satoshis = (destsatoshis / price + 0.49) - txfee;
if ( satoshis <= 0 )
continue;

19
iguana/exchanges/LP_utxos.c

@ -288,14 +288,15 @@ cJSON *LP_utxojson(struct LP_utxoinfo *utxo)
int32_t LP_iseligible(uint64_t *valp,uint64_t *val2p,int32_t iambob,char *symbol,bits256 txid,int32_t vout,uint64_t satoshis,bits256 txid2,int32_t vout2)
{
uint64_t val,val2=0,threshold=0; int32_t iter,bypass = 0; char destaddr[64],destaddr2[64]; struct LP_utxoinfo *utxo; struct iguana_info *coin = LP_coinfind(symbol);
uint64_t val,val2=0,txfee,threshold=0; int32_t iter,bypass = 0; char destaddr[64],destaddr2[64]; struct LP_utxoinfo *utxo; struct iguana_info *coin = LP_coinfind(symbol);
destaddr[0] = destaddr2[0] = 0;
if ( coin != 0 && IAMLP != 0 && coin->inactive != 0 )
bypass = 1;
if ( bypass != 0 )
val = satoshis;
else val = LP_txvalue(destaddr,symbol,txid,vout);
if ( val >= satoshis )
txfee = LP_txfeecalc(symbol,0);
if ( val >= satoshis && val > 10*txfee )
{
threshold = (iambob != 0) ? LP_DEPOSITSATOSHIS(satoshis) : LP_DEXFEE(satoshis);
if ( bypass != 0 )
@ -315,7 +316,7 @@ int32_t LP_iseligible(uint64_t *valp,uint64_t *val2p,int32_t iambob,char *symbol
}
} // else printf("no val2\n");
}
char str[65],str2[65]; printf("spent.%d %s txid or value %.8f < %.8f or val2 %.8f < %.8f, %s/v%d %s/v%d\n",iambob,symbol,dstr(val),dstr(satoshis),dstr(val2),dstr(threshold),bits256_str(str,txid),vout,bits256_str(str2,txid2),vout2);
char str[65],str2[65]; printf("spent.%d %s txid or value %.8f < %.8f or val2 %.8f < %.8f, %s/v%d %s/v%d or < 10x txfee %.8f\n",iambob,symbol,dstr(val),dstr(satoshis),dstr(val2),dstr(threshold),bits256_str(str,txid),vout,bits256_str(str2,txid2),vout2,dstr(txfee));
for (iter=0; iter<2; iter++)
{
if ( (utxo= LP_utxofind(iter,txid,vout)) != 0 )
@ -793,7 +794,7 @@ int32_t LP_nearestvalue(int32_t iambob,uint64_t *values,int32_t n,uint64_t targe
uint64_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 myprivkey,bits256 mypub)
{
char *script; struct LP_utxoinfo *utxo; cJSON *array,*item; bits256 txid,deposittxid; int32_t used,i,n,iambob,vout,depositvout; uint64_t *values=0,satoshis,depositval,targetval,value,total = 0;
char *script; struct LP_utxoinfo *utxo; cJSON *array,*item; bits256 txid,deposittxid; int32_t used,i,n,iambob,vout,depositvout; uint64_t *values=0,satoshis,txfee,depositval,targetval,value,total = 0;
if ( coin == 0 )
{
printf("coin not active\n");
@ -802,6 +803,7 @@ uint64_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypr
//printf("privkey init.(%s) %s\n",coin->symbol,coin->smartaddr);
if ( coin->inactive == 0 && (array= LP_listunspent(coin->symbol,coin->smartaddr)) != 0 )
{
txfee = LP_txfeecalc(coin->symbol,0);
if ( is_cJSON_Array(array) != 0 && (n= cJSON_GetArraySize(array)) > 0 )
{
for (iambob=0; iambob<=1; iambob++)
@ -835,10 +837,17 @@ uint64_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypr
values[i] = 0, used++;
if ( iambob == 0 )
targetval = (depositval / 776) + 100000;
else targetval = (depositval / 9) * 8 + 100000;
else
{
if ( depositval < LP_MINSIZE_TXFEEMULT*txfee )
continue;
targetval = (depositval / 9) * 8 + 100000;
}
//printf("i.%d %.8f target %.8f\n",i,dstr(depositval),dstr(targetval));
if ( (i= LP_nearestvalue(iambob,values,n,targetval)) < 0 && iambob != 0 )
targetval /= 4;
if ( iambob != 0 && targetval < txfee*LP_MINSIZE_TXFEEMULT )
continue;
if ( (i= LP_nearestvalue(iambob,values,n,targetval)) >= 0 )
{
item = jitem(array,i);

Loading…
Cancel
Save