prices rpc call stub
This commit is contained in:
@@ -1553,7 +1553,7 @@ extern std::vector<uint8_t> Mineropret; // opreturn data set by the data gatheri
|
||||
#define PRICES_SIZEBIT0 (sizeof(uint32_t) * 4) // 4 uint32_t unixtimestamp, BTCUSD, BTCGBP and BTCEUR
|
||||
|
||||
// komodo_heightpricebits() extracts the price data in the coinbase for nHeight
|
||||
int32_t komodo_heightpricebits(uint32_t prevbits[4],int32_t nHeight)
|
||||
int32_t komodo_heightpricebits(uint32_t *heightbits,int32_t nHeight)
|
||||
{
|
||||
CBlockIndex *pindex; CBlock block; CTransaction tx; int32_t numvouts; std::vector<uint8_t> vopret;
|
||||
if ( (pindex= komodo_chainactive(nHeight)) != 0 )
|
||||
@@ -1565,8 +1565,8 @@ int32_t komodo_heightpricebits(uint32_t prevbits[4],int32_t nHeight)
|
||||
GetOpReturnData(tx.vout[numvouts-1].scriptPubKey,vopret);
|
||||
if ( vopret.size() >= PRICES_SIZEBIT0 )
|
||||
{
|
||||
memcpy(prevbits,vopret.data(),vopret.size());
|
||||
return(0);
|
||||
memcpy(heightbits,vopret.data(),vopret.size());
|
||||
return((int32_t)(vopret.size()/sizeof(uint32_t)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1574,6 +1574,20 @@ int32_t komodo_heightpricebits(uint32_t prevbits[4],int32_t nHeight)
|
||||
return(-1);
|
||||
}
|
||||
|
||||
int32_t komodo_prices(uint32_t *prices,uint32_t *correlated,uint32_t *smoothed,int32_t height)
|
||||
{
|
||||
int32_t i,n;
|
||||
n = komodo_heightpricebits(prices,height);
|
||||
for (i=0; i<n; i++)
|
||||
{
|
||||
correlated[i] = prices[i];
|
||||
}
|
||||
for (i=0; i<n; i++)
|
||||
{
|
||||
smoothed[i] = correlated[i];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
komodo_pricenew() is passed in a reference price, the change tolerance and the proposed price. it needs to return a clipped price if it is too big and also set a flag if it is at or above the limit
|
||||
*/
|
||||
@@ -1659,7 +1673,7 @@ CScript komodo_mineropret(int32_t nHeight)
|
||||
if ( numzero != 0 )
|
||||
fprintf(stderr,"numzero.%d\n",numzero);
|
||||
}
|
||||
if ( komodo_heightpricebits(prevbits,nHeight-1) == 0 )
|
||||
if ( komodo_heightpricebits(prevbits,nHeight-1) > 0 )
|
||||
{
|
||||
memcpy(pricebits,Mineropret.data(),Mineropret.size());
|
||||
memset(maxflags,0,sizeof(maxflags));
|
||||
@@ -1718,7 +1732,7 @@ int32_t komodo_opretvalidate(const CBlock *block,CBlockIndex * const previndex,i
|
||||
fprintf(stderr,"A ht.%d now.%u htstamp.%u %u - pricebits[0] %u -> lags.%d %d %d\n",nHeight,now,prevtime,block->nTime,pricebits[0],lag,lag2,lag3);
|
||||
return(-1);
|
||||
}
|
||||
if ( lag2 < -120 )//-ASSETCHAINS_BLOCKTIME/2 ) // must be close to last block timestamp
|
||||
if ( lag2 < -testchain_exemption ) // must be close to last block timestamp
|
||||
{
|
||||
fprintf(stderr,"B ht.%d now.%u htstamp.%u %u - pricebits[0] %u -> lags.%d %d %d vs %d cmp.%d\n",nHeight,now,prevtime,block->nTime,pricebits[0],lag,lag2,lag3,ASSETCHAINS_BLOCKTIME,lag2<-ASSETCHAINS_BLOCKTIME);
|
||||
if ( nHeight > testchain_exemption )
|
||||
@@ -1734,7 +1748,7 @@ int32_t komodo_opretvalidate(const CBlock *block,CBlockIndex * const previndex,i
|
||||
btcgbp = (double)pricebits[2]/10000;
|
||||
btceur = (double)pricebits[3]/10000;
|
||||
fprintf(stderr,"ht.%d: lag.%d %.4f USD, %.4f GBP, %.4f EUR, GBPUSD %.6f, EURUSD %.6f, EURGBP %.6f [%d]\n",nHeight,lag,btcusd,btcgbp,btceur,btcusd/btcgbp,btcusd/btceur,btcgbp/btceur,lag2);
|
||||
if ( komodo_heightpricebits(prevbits,nHeight-1) == 0 )
|
||||
if ( komodo_heightpricebits(prevbits,nHeight-1) > 0 )
|
||||
{
|
||||
if ( nHeight < testchain_exemption )
|
||||
{
|
||||
|
||||
@@ -1174,38 +1174,80 @@ UniValue paxprice(const UniValue& params, bool fHelp)
|
||||
return ret;
|
||||
}
|
||||
|
||||
UniValue paxprices(const UniValue& params, bool fHelp)
|
||||
int32_t komodo_prices(uint32_t *prices,uint32_t *correlated,uint32_t *smoothed,int32_t height);
|
||||
|
||||
UniValue prices(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if ( fHelp || params.size() != 3 )
|
||||
throw runtime_error("paxprices \"base\" \"rel\" maxsamples\n");
|
||||
if ( fHelp || params.size() != 1 )
|
||||
throw runtime_error("prices maxsamples\n");
|
||||
LOCK(cs_main);
|
||||
UniValue ret(UniValue::VOBJ); uint64_t relvolume,prices[4096]; uint32_t i,n; int32_t heights[sizeof(prices)/sizeof(*prices)];
|
||||
std::string base = params[0].get_str();
|
||||
std::string rel = params[1].get_str();
|
||||
int32_t maxsamples = atoi(params[2].get_str().c_str());
|
||||
UniValue ret(UniValue::VOBJ); uint32_t *prices,*correlated,*smoothed; uint32_t i,firstn=-1,n,nextheight,ht,num=0,daywindow = (3600*24/ASSETCHAINS_BLOCKTIME) + 1;
|
||||
int32_t maxsamples = atoi(params[0].get_str().c_str());
|
||||
if ( maxsamples < 1 )
|
||||
maxsamples = 1;
|
||||
else if ( maxsamples > sizeof(heights)/sizeof(*heights) )
|
||||
maxsamples = sizeof(heights)/sizeof(*heights);
|
||||
ret.push_back(Pair("base", base));
|
||||
ret.push_back(Pair("rel", rel));
|
||||
n = komodo_paxprices(heights,prices,maxsamples,(char *)base.c_str(),(char *)rel.c_str());
|
||||
nextheight = komodo_nextheight();
|
||||
UniValue a(UniValue::VARR);
|
||||
for (i=0; i<n; i++)
|
||||
prices = (uint32_t *)calloc(sizeof(*prices),maxsamples+daywindow);
|
||||
correlated = (uint32_t *)calloc(sizeof(*correlated),maxsamples+daywindow);
|
||||
smoothed = (uint32_t *)calloc(sizeof(*smoothed),maxsamples+daywindow);
|
||||
for (ht=nextheight-1,i=0; i<maxsamples+daywindow&&ht>daywindow+2; i++,ht--)
|
||||
{
|
||||
UniValue item(UniValue::VOBJ);
|
||||
if ( heights[i] < 0 || heights[i] > chainActive.Height() )
|
||||
if ( ht < 0 || ht > chainActive.Height() )
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range");
|
||||
else
|
||||
{
|
||||
CBlockIndex *pblockindex = chainActive[heights[i]];
|
||||
|
||||
item.push_back(Pair("t", (int64_t)pblockindex->nTime));
|
||||
item.push_back(Pair("p", (double)prices[i] / COIN));
|
||||
a.push_back(item);
|
||||
if ( (n= komodo_prices(rawprices,ht)) > 0 )
|
||||
{
|
||||
if ( firstn == -1 )
|
||||
firstn = n;
|
||||
else if ( n != firstn )
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "numprices != first numprices");
|
||||
else
|
||||
{
|
||||
for (j=0; j<n; j++)
|
||||
prices[j*(maxsamples+daywindow) + i] = rawprices[i];
|
||||
}
|
||||
} else throw JSONRPCError(RPC_INVALID_PARAMETER, "no komodo_rawprices found");
|
||||
}
|
||||
}
|
||||
ret.push_back(Pair("array", a));
|
||||
free(prices);
|
||||
free(correlated);
|
||||
free(smoothed);
|
||||
/*for (i=0; i<maxsamples; i++)
|
||||
{
|
||||
UniValue item(UniValue::VOBJ),parr(UniValue::VARR);
|
||||
item.push_back(Pair("height", (int64_t)ht));
|
||||
if ( (n= komodo_prices(prices,correlated,smoothed,ht)) <= 0 )
|
||||
item.push_back(Pair("heighterror",(int64_t)n));
|
||||
else
|
||||
{
|
||||
UniValue timestamps(UniValue::VARR);
|
||||
timestamps.push_back((int64_t)prices[0]);
|
||||
timestamps.push_back((int64_t)correlated[0]);
|
||||
timestamps.push_back((int64_t)smoothed[0]);
|
||||
timestamps.push_back((int64_t)komodo_heightstamp(ht));
|
||||
item.push_back(Pair("timestamps",timestamps));
|
||||
for (j=0; j<n; i++)
|
||||
{
|
||||
UniValue prices(UniValue::VARR);
|
||||
prices.push_back((double)prices[j]/10000.);
|
||||
prices.push_back((double)correlated[j]/10000.);
|
||||
prices.push_back((double)smoothed[j]/10000.);
|
||||
parr.push_back(prices);
|
||||
}
|
||||
item.push_back(Pair("prices",parr));
|
||||
item.push_back(Pair("numprices",n));
|
||||
a.push_back(item);
|
||||
num++;
|
||||
}
|
||||
}*/
|
||||
ret.push_back(Pair("array",a));
|
||||
ret.push_back(Pair("result","success"));
|
||||
ret.push_back(Pair("height",(int64_t)nextheight-1));
|
||||
ret.push_back(Pair("numsamples",(int64_t)num));
|
||||
ret.push_back(Pair("maxsamples",(int64_t)maxsamples));
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -441,6 +441,7 @@ static const CRPCCommand vRPCCommands[] =
|
||||
{ "oracles", "oraclessamples", &oraclessamples, true },
|
||||
|
||||
// Prices
|
||||
{ "prices", "prices", &prices, true },
|
||||
{ "prices", "pricesaddress", &pricesaddress, true },
|
||||
{ "prices", "priceslist", &priceslist, true },
|
||||
{ "prices", "pricesinfo", &pricesinfo, true },
|
||||
|
||||
@@ -486,6 +486,8 @@ extern UniValue paxprices(const UniValue& params, bool fHelp);
|
||||
extern UniValue paxdeposit(const UniValue& params, bool fHelp);
|
||||
extern UniValue paxwithdraw(const UniValue& params, bool fHelp);
|
||||
|
||||
extern UniValue prices(const UniValue& params, bool fHelp);
|
||||
|
||||
// test rpc:
|
||||
extern UniValue test_ac(const UniValue& params, bool fHelp);
|
||||
extern UniValue test_heirmarker(const UniValue& params, bool fHelp);
|
||||
|
||||
Reference in New Issue
Block a user