Compiler errors

This commit is contained in:
jl777
2019-04-05 21:17:53 -11:00
parent 50e4a72120
commit 3155223e51
7 changed files with 800 additions and 425 deletions

View File

@@ -1176,19 +1176,58 @@ UniValue paxprice(const UniValue& params, bool fHelp)
int32_t komodo_heightpricebits(uint64_t *seedp,uint32_t *heightbits,int32_t nHeight);
char *komodo_pricename(char *name,int32_t ind);
int64_t komodo_pricesmoothed(int64_t *correlated,int32_t numprices,int64_t *correlated2,int32_t smoothwidth);
int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int32_t numprices,uint32_t *rawprices2,int32_t smoothwidth);
int64_t komodo_pricesmoothed(int64_t *correlated,int32_t cskip,int32_t int64_t *correlated2,int32_t numprices);
int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int32_t skip,int32_t numprices,uint32_t *rawprices2,int32_t smoothwidth);
int32_t komodo_nextheight();
uint32_t komodo_heightstamp(int32_t height);
int64_t komodo_pricemult(int32_t ind);
#define PRICES_SMOOTHWIDTH 1
int32_t prices_extract(int64_t *pricedata,int32_t firstheight,int32_t numblocks,int32_t ind)
{
int32_t height,i,width,numpricefeeds = -1; uint64_t seed,rngval,*correlated2; uint32_t rawprices[1440*6],*ptr;
//daywindow = (3600*24/ASSETCHAINS_BLOCKTIME) + 1;
//pricedata = (uint32_t *)calloc(sizeof(*prices)*3,numblocks + daywindow*2 + PRICES_SMOOTHWIDTH);
width = numblocks+PRICES_DAYWINDOW*2+PRICES_SMOOTHWIDTH;
komodo_heightpricebits(&seed,rawprices,firstheight + numblocks - 1);
if ( firstheight < width )
return(-1);
for (i=0; i<width; i++)
{
if ( (n= komodo_heightpricebits(&ignore,rawprices,firstheight + numblocks - 1 - i)) < 0 )
return(-1);
if ( numpricefeeds < 0 )
numpricefeeds = n;
if ( n != numpricefeeds )
return(-2);
ptr = (uint32_t *)&pricedata[i*3];
ptr[0] = rawprices[ind];
ptr[1] = rawprices[0]; // timestamp
}
rngval = seed;
correlated2 = (int64_t *)calloc(sizeof(*correlated2),width);
for (i=0; i<numblocks+PRICES_DAYWINDOW+PRICES_SMOOTHWIDTH; i++)
{
rngval = (rngval*11109 + 13849);
ptr = (uint32_t *)&pricedata[i*3];
correlated2[i] = ptr[0];
if ( (pricedata[i*3+1]= komodo_pricecorrelated(rngval,ind,(uint32_t)&pricedata[i*3],6,0,PRICES_SMOOTHWIDTH)) < 0 )
{
free(correlated2);
return(-3);
}
}
for (i=0; i<numblocks; i++)
pricedata[i*3+2] = komodo_pricesmoothed(&pricedata[i*3+1],3,correlated2,numblocks+PRICES_DAYWINDOW+PRICES_SMOOTHWIDTH);
return(0);
}
UniValue prices(const UniValue& params, bool fHelp)
{
int32_t smoothwidth = 7;
if ( fHelp || params.size() != 1 )
throw runtime_error("prices maxsamples\n");
LOCK(cs_main);
UniValue ret(UniValue::VOBJ); uint64_t seed,rngval; int64_t smoothed,*correlated,*correlated2; char name[64],*str; uint32_t rawprices[1440*6],*prices,*prices2; uint32_t i,width,j,numpricefeeds=-1,n,numsamples,nextheight,offset,ht,daywindow = (3600*24/ASSETCHAINS_BLOCKTIME) + 1;
UniValue ret(UniValue::VOBJ); uint64_t seed,rngval; int64_t smoothed,*correlated,*correlated2; char name[64],*str; uint32_t rawprices[1440*6],*prices; uint32_t i,width,j,numpricefeeds=-1,n,numsamples,nextheight,offset,ht;
if ( ASSETCHAINS_CBOPRET == 0 )
throw JSONRPCError(RPC_INVALID_PARAMETER, "only -ac_cbopret chains have prices");
@@ -1197,16 +1236,16 @@ UniValue prices(const UniValue& params, bool fHelp)
maxsamples = 1;
nextheight = komodo_nextheight();
UniValue a(UniValue::VARR);
if ( daywindow < 7 )
daywindow = 7;
width = maxsamples+2*daywindow+smoothwidth;
if ( PRICES_DAYWINDOW < 7 )
throw JSONRPCError(RPC_INVALID_PARAMETER, "daywindow is too small");
width = maxsamples+2*PRICES_DAYWINDOW+PRICES_SMOOTHWIDTH;
numpricefeeds = komodo_heightpricebits(&seed,rawprices,nextheight-1);
if ( numpricefeeds <= 0 )
throw JSONRPCError(RPC_INVALID_PARAMETER, "illegal numpricefeeds");
prices = (uint32_t *)calloc(sizeof(*prices),width*numpricefeeds);
correlated = (int64_t *)calloc(sizeof(*correlated),width);
correlated2 = (int64_t *)calloc(sizeof(*correlated2),width);
prices2 = (uint32_t *)calloc(sizeof(*prices2),width);
//prices2 = (uint32_t *)calloc(sizeof(*prices2),width);
i = 0;
for (ht=nextheight-1,i=0; i<width&&ht>2; i++,ht--)
{
@@ -1233,7 +1272,7 @@ UniValue prices(const UniValue& params, bool fHelp)
timestamps.push_back((int64_t)prices[i]);
ret.push_back(Pair("timestamps",timestamps));
rngval = seed;
//for (i=0; i<daywindow; i++)
//for (i=0; i<PRICES_DAYWINDOW; i++)
// fprintf(stderr,"%.4f ",(double)prices[width+i]/10000);
//fprintf(stderr," maxsamples.%d\n",maxsamples);
for (j=1; j<numpricefeeds; j++)
@@ -1244,21 +1283,23 @@ UniValue prices(const UniValue& params, bool fHelp)
item.push_back(Pair("name",str));
if ( numsamples >= width )
{
for (i=0; i<maxsamples+daywindow+smoothwidth&&i<numsamples; i++)
for (i=0; i<maxsamples+PRICES_DAYWINDOW+PRICES_SMOOTHWIDTH&&i<numsamples; i++)
{
offset = j*width + i;
rngval = (rngval*11109 + 13849);
if ( (correlated[i]= komodo_pricecorrelated(rngval,j,&prices[offset],daywindow,prices2,smoothwidth)) < 0 )
correlated2[i] = prices[offset];
if ( (correlated[i]= komodo_pricecorrelated(rngval,j,&prices[offset],1,0,PRICES_SMOOTHWIDTH)) < 0 )
throw JSONRPCError(RPC_INVALID_PARAMETER, "null correlated price");
}
for (i=0; i<maxsamples&&i<numsamples; i++)
{
offset = j*width + i;
smoothed = komodo_pricesmoothed(&correlated[i],daywindow,correlated2,smoothwidth);
smoothed = komodo_pricesmoothed(&correlated[i],1,correlated2,maxsamples+PRICES_DAYWINDOW+PRICES_SMOOTHWIDTH);
UniValue parr(UniValue::VARR);
parr.push_back(ValueFromAmount((int64_t)prices[offset] * komodo_pricemult(j)));
parr.push_back(ValueFromAmount(correlated[i]));
parr.push_back(ValueFromAmount(smoothed));
// compare to alternate method
p.push_back(parr);
}
}
@@ -1282,10 +1323,10 @@ UniValue prices(const UniValue& params, bool fHelp)
ret.push_back(Pair("height",(int64_t)nextheight-1));
ret.push_back(Pair("maxsamples",(int64_t)maxsamples));
ret.push_back(Pair("width",(int64_t)width));
ret.push_back(Pair("daywindow",(int64_t)daywindow));
ret.push_back(Pair("daywindow",(int64_t)PRICES_DAYWINDOW));
ret.push_back(Pair("numpricefeeds",(int64_t)numpricefeeds));
free(prices);
free(prices2);
//free(prices2);
free(correlated);
free(correlated2);
return ret;