Browse Source

Merge pull request #414 from jl777/spvdex

fix RTmetrics crash
etomic
jl777 7 years ago
committed by GitHub
parent
commit
42e8d9fac3
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 19
      iguana/exchanges/LP_RTmetrics.c
  2. 2
      iguana/exchanges/LP_nativeDEX.c
  3. 6
      iguana/exchanges/LP_swap.c

19
iguana/exchanges/LP_RTmetrics.c

@ -20,8 +20,10 @@
struct LP_metricinfo struct LP_metricinfo
{ {
double metric;
double price,balance,minvol;
bits256 pubkey; bits256 pubkey;
double metric,price,balance,minvol,maxvol; double maxvol;
int32_t ind,numutxos,age,pendingswaps; int32_t ind,numutxos,age,pendingswaps;
}; };
@ -181,7 +183,10 @@ double _LP_RTmetric_calc(struct LP_metricinfo *mp,double bestprice,double maxpri
int32_t n; double metric,origmetric = (mp->price / bestprice); int32_t n; double metric,origmetric = (mp->price / bestprice);
metric = origmetric; metric = origmetric;
if ( mp->numutxos == 0 || relvolume == 0. || mp->maxvol == 0. || mp->balance == 0. ) if ( mp->numutxos == 0 || relvolume == 0. || mp->maxvol == 0. || mp->balance == 0. )
{
printf("skip i.%d as no info\n",mp->ind);
return(metric * 100.); return(metric * 100.);
}
if ( relvolume < mp->minvol ) if ( relvolume < mp->minvol )
{ {
metric *= (mp->minvol / relvolume); metric *= (mp->minvol / relvolume);
@ -205,8 +210,8 @@ double _LP_RTmetric_calc(struct LP_metricinfo *mp,double bestprice,double maxpri
if ( (n= mp->pendingswaps) > 0 ) if ( (n= mp->pendingswaps) > 0 )
while ( n-- > 0 ) while ( n-- > 0 )
metric *= 1.1; metric *= 1.1;
if ( metric != origmetric ) //if ( metric != origmetric )
printf("price %.8f orig %.8f -> %.8f relvol %.8f min %.8f max %.8f bal %.8f age.%d pend.%d\n",mp->price,origmetric,metric,relvolume,mp->minvol,mp->maxvol,mp->balance,mp->age,mp->pendingswaps); printf("i.%d price %.8f orig %.8f -> %.8f relvol %.8f min %.8f max %.8f bal %.8f age.%d pend.%d\n",mp->ind,mp->price,origmetric,metric,relvolume,mp->minvol,mp->maxvol,mp->balance,mp->age,mp->pendingswaps);
return(metric); return(metric);
} }
@ -226,7 +231,7 @@ void LP_RTmetric_calc(struct LP_metricinfo *sortbuf,int32_t ind,cJSON *item,doub
cJSON *LP_RTmetrics_sort(char *base,char *rel,cJSON *rawasks,int32_t numasks,double maxprice,double relvolume) cJSON *LP_RTmetrics_sort(char *base,char *rel,cJSON *rawasks,int32_t numasks,double maxprice,double relvolume)
{ {
cJSON *array,*item; int32_t i,num,groupi; double price,prevdepth,bestprice; struct LP_metricinfo *sortbuf; cJSON *array=rawasks,*item; int32_t i,num,groupi; double price,prevdepth,bestprice; struct LP_metricinfo *sortbuf;
groupi = -1; groupi = -1;
bestprice = 0.; bestprice = 0.;
for (num=i=0; i<numasks; i++) for (num=i=0; i<numasks; i++)
@ -241,7 +246,7 @@ cJSON *LP_RTmetrics_sort(char *base,char *rel,cJSON *rawasks,int32_t numasks,dou
groupi = i; groupi = i;
num++; num++;
} }
if ( 0 && groupi > 0 ) if ( groupi > 0 )
{ {
sortbuf = calloc(groupi+1,sizeof(*sortbuf)); sortbuf = calloc(groupi+1,sizeof(*sortbuf));
prevdepth = 0.; prevdepth = 0.;
@ -255,7 +260,7 @@ cJSON *LP_RTmetrics_sort(char *base,char *rel,cJSON *rawasks,int32_t numasks,dou
array = cJSON_CreateArray(); array = cJSON_CreateArray();
for (i=0; i<=groupi; i++) for (i=0; i<=groupi; i++)
{ {
printf("(%d -> %d) ",i,sortbuf[i].ind); printf("(%d -> %d %.3f) ",i,sortbuf[i].ind,sortbuf[i].metric);
item = jitem(rawasks,sortbuf[i].ind); item = jitem(rawasks,sortbuf[i].ind);
jaddi(array,jduplicate(item)); jaddi(array,jduplicate(item));
} }
@ -263,6 +268,6 @@ cJSON *LP_RTmetrics_sort(char *base,char *rel,cJSON *rawasks,int32_t numasks,dou
jaddi(array,jduplicate(jitem(rawasks,i))); jaddi(array,jduplicate(jitem(rawasks,i)));
printf("new ask order for %d of %d, capped at num.%d\n",groupi,numasks,num); printf("new ask order for %d of %d, capped at num.%d\n",groupi,numasks,num);
free(sortbuf); free(sortbuf);
} else array = rawasks; }
return(array); return(array);
} }

2
iguana/exchanges/LP_nativeDEX.c

@ -208,7 +208,7 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock,
} }
else else
{ {
printf("packet not for this node %u\n",crc32); //printf("packet not for this node %u\n",crc32);
} }
} else printf("error (%s) method is %s\n",jsonstr,method); } else printf("error (%s) method is %s\n",jsonstr,method);
} }

6
iguana/exchanges/LP_swap.c

@ -575,10 +575,10 @@ int32_t LP_rawtx_spendscript(struct basilisk_swap *swap,int32_t height,struct ba
if ( rawtx->I.redeemlen > 0 && rawtx->I.redeemlen < 0x100 ) if ( rawtx->I.redeemlen > 0 && rawtx->I.redeemlen < 0x100 )
{ {
memcpy(rawtx->redeemscript,&data[datalen],rawtx->I.redeemlen); memcpy(rawtx->redeemscript,&data[datalen],rawtx->I.redeemlen);
for (i=0; i<rawtx->I.redeemlen; i++) //for (i=0; i<rawtx->I.redeemlen; i++)
printf("%02x",rawtx->redeemscript[i]); // printf("%02x",rawtx->redeemscript[i]);
bitcoin_address(redeemaddr,rawtx->coin->taddr,rawtx->coin->p2shtype,rawtx->redeemscript,rawtx->I.redeemlen); bitcoin_address(redeemaddr,rawtx->coin->taddr,rawtx->coin->p2shtype,rawtx->redeemscript,rawtx->I.redeemlen);
printf(" received redeemscript.(%s) %s taddr.%d\n",redeemaddr,rawtx->coin->symbol,rawtx->coin->taddr); //printf(" received redeemscript.(%s) %s taddr.%d\n",redeemaddr,rawtx->coin->symbol,rawtx->coin->taddr);
LP_swap_coinaddr(rawtx->coin,checkaddr,0,data,datalen,0); LP_swap_coinaddr(rawtx->coin,checkaddr,0,data,datalen,0);
if ( strcmp(redeemaddr,checkaddr) != 0 ) if ( strcmp(redeemaddr,checkaddr) != 0 )
{ {

Loading…
Cancel
Save