logging
This commit is contained in:
@@ -25,15 +25,15 @@ int32_t komodo_priceget(int64_t *buf64,int32_t ind,int32_t height,int32_t numblo
|
|||||||
#define PRICES_MAXLEVERAGE 777
|
#define PRICES_MAXLEVERAGE 777
|
||||||
#define PRICES_SMOOTHWIDTH 1
|
#define PRICES_SMOOTHWIDTH 1
|
||||||
#define KOMODO_MAXPRICES 2048 // must be power of 2 and less than 8192
|
#define KOMODO_MAXPRICES 2048 // must be power of 2 and less than 8192
|
||||||
#define KOMODO_PRICEMASK (~(KOMODO_MAXPRICES - 1))
|
#define KOMODO_PRICEMASK (~(KOMODO_MAXPRICES - 1)) // actually 1111 1000 0000 0000
|
||||||
#define PRICES_WEIGHT (KOMODO_MAXPRICES * 1)
|
#define PRICES_WEIGHT (KOMODO_MAXPRICES * 1) // 0000 1000 0000 0000
|
||||||
#define PRICES_MULT (KOMODO_MAXPRICES * 2)
|
#define PRICES_MULT (KOMODO_MAXPRICES * 2) // 0001 0000 0000 0000
|
||||||
#define PRICES_DIV (KOMODO_MAXPRICES * 3)
|
#define PRICES_DIV (KOMODO_MAXPRICES * 3) // 0001 1000 0000 0000
|
||||||
#define PRICES_INV (KOMODO_MAXPRICES * 4)
|
#define PRICES_INV (KOMODO_MAXPRICES * 4) // 0010 0000 0000 0000
|
||||||
#define PRICES_MDD (KOMODO_MAXPRICES * 5)
|
#define PRICES_MDD (KOMODO_MAXPRICES * 5) // 0010 1000 0000 0000
|
||||||
#define PRICES_MMD (KOMODO_MAXPRICES * 6)
|
#define PRICES_MMD (KOMODO_MAXPRICES * 6) // 0011 0000 0000 0000
|
||||||
#define PRICES_MMM (KOMODO_MAXPRICES * 7)
|
#define PRICES_MMM (KOMODO_MAXPRICES * 7) // 0011 1000 0000 0000
|
||||||
#define PRICES_DDD (KOMODO_MAXPRICES * 8)
|
#define PRICES_DDD (KOMODO_MAXPRICES * 8) // 0100 0000 0000 0000
|
||||||
|
|
||||||
bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn);
|
bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn);
|
||||||
|
|
||||||
|
|||||||
@@ -146,11 +146,11 @@ CBOPRET creates trustless oracles, which can be used for making a synthetic cash
|
|||||||
|
|
||||||
// helpers:
|
// helpers:
|
||||||
|
|
||||||
// returns true if there are only digits and no alphas in 's'
|
// returns true if there are only digits and no alphas or slashes in 's'
|
||||||
inline bool is_weight(std::string s) {
|
inline bool is_weight_str(std::string s) {
|
||||||
return
|
return
|
||||||
std::count_if(s.begin(), s.end(), [](unsigned char c) { return std::isdigit(c); } ) > 0 &&
|
std::count_if(s.begin(), s.end(), [](unsigned char c) { return std::isdigit(c); } ) > 0 &&
|
||||||
std::count_if(s.begin(), s.end(), [](unsigned char c) { return std::isalpha(c); } ) == 0;
|
std::count_if(s.begin(), s.end(), [](unsigned char c) { return std::isalpha(c) || c == '/'; } ) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -285,7 +285,7 @@ int32_t prices_syntheticvec(std::vector<uint16_t> &vec,std::vector<std::string>
|
|||||||
{
|
{
|
||||||
int32_t i,need,ind,depth = 0; std::string opstr; uint16_t opcode,weight;
|
int32_t i,need,ind,depth = 0; std::string opstr; uint16_t opcode,weight;
|
||||||
if (synthetic.size() == 0) {
|
if (synthetic.size() == 0) {
|
||||||
std::cerr << "synthetic expression is empty" << std::endl;
|
std::cerr << "prices_syntheticvec() expression is empty" << std::endl;
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
for (i=0; i<synthetic.size(); i++)
|
for (i=0; i<synthetic.size(); i++)
|
||||||
@@ -306,7 +306,7 @@ int32_t prices_syntheticvec(std::vector<uint16_t> &vec,std::vector<std::string>
|
|||||||
opcode = PRICES_MMM, need = 3;
|
opcode = PRICES_MMM, need = 3;
|
||||||
else if ( opstr == "///" )
|
else if ( opstr == "///" )
|
||||||
opcode = PRICES_DDD, need = 3;
|
opcode = PRICES_DDD, need = 3;
|
||||||
else if (!is_weight(opstr) && (ind= komodo_priceind(opstr.c_str())) >= 0 )
|
else if (!is_weight_str(opstr) && (ind= komodo_priceind(opstr.c_str())) >= 0 )
|
||||||
opcode = ind, need = 0;
|
opcode = ind, need = 0;
|
||||||
else if ( (weight= atoi(opstr.c_str())) > 0 && weight < KOMODO_MAXPRICES )
|
else if ( (weight= atoi(opstr.c_str())) > 0 && weight < KOMODO_MAXPRICES )
|
||||||
{
|
{
|
||||||
@@ -314,30 +314,34 @@ int32_t prices_syntheticvec(std::vector<uint16_t> &vec,std::vector<std::string>
|
|||||||
need = 1;
|
need = 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
std::cerr << "incorrect opcode=" << opstr << std::endl;
|
std::cerr << "prices_syntheticvec() incorrect opcode=" << opstr << std::endl;
|
||||||
return(-2);
|
return(-2);
|
||||||
}
|
}
|
||||||
if (depth < need) {
|
if (depth < need) {
|
||||||
std::cerr << "incorrect not enough operands for opcode=" << opstr << std::endl;
|
std::cerr << "prices_syntheticvec() incorrect not enough operands for opcode=" << opstr << std::endl;
|
||||||
return(-3);
|
return(-3);
|
||||||
}
|
}
|
||||||
depth -= need;
|
depth -= need;
|
||||||
if ( (opcode & KOMODO_PRICEMASK) != PRICES_WEIGHT ) // weight
|
std::cerr << "opcode=" << opcode << " opstr=" << opstr << " depth-=need=" << depth << std::endl;
|
||||||
depth++;
|
if ((opcode & KOMODO_PRICEMASK) != PRICES_WEIGHT) { // skip weight
|
||||||
|
depth++; // increase operands count
|
||||||
|
std::cerr << "depth++=" << depth << std::endl;
|
||||||
|
}
|
||||||
if (depth > 3) {
|
if (depth > 3) {
|
||||||
std::cerr << "to many operands, last=" << opstr << std::endl;
|
std::cerr << "prices_syntheticvec() to many operands, last=" << opstr << std::endl;
|
||||||
return(-4);
|
return(-4);
|
||||||
}
|
}
|
||||||
vec.push_back(opcode);
|
vec.push_back(opcode);
|
||||||
}
|
}
|
||||||
if ( depth != 0 )
|
if ( depth != 0 )
|
||||||
{
|
{
|
||||||
fprintf(stderr,"depth.%d not empty\n",depth);
|
fprintf(stderr,"prices_syntheticvec() depth.%d not empty\n",depth);
|
||||||
return(-5);
|
return(-5);
|
||||||
}
|
}
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// calculate price for synthetic expression
|
||||||
int64_t prices_syntheticprice(std::vector<uint16_t> vec,int32_t height,int32_t minmax,int16_t leverage)
|
int64_t prices_syntheticprice(std::vector<uint16_t> vec,int32_t height,int32_t minmax,int16_t leverage)
|
||||||
{
|
{
|
||||||
int32_t i,ind,errcode,depth,retval = -1; uint16_t opcode; int64_t pricedata[PRICES_MAXDATAPOINTS],pricestack[4],price,den,a,b,c;
|
int32_t i,ind,errcode,depth,retval = -1; uint16_t opcode; int64_t pricedata[PRICES_MAXDATAPOINTS],pricestack[4],price,den,a,b,c;
|
||||||
@@ -345,7 +349,7 @@ int64_t prices_syntheticprice(std::vector<uint16_t> vec,int32_t height,int32_t m
|
|||||||
for (i=0; i<vec.size(); i++)
|
for (i=0; i<vec.size(); i++)
|
||||||
{
|
{
|
||||||
opcode = vec[i];
|
opcode = vec[i];
|
||||||
ind = (opcode & (KOMODO_MAXPRICES-1));
|
ind = (opcode & (KOMODO_MAXPRICES-1)); // weight value
|
||||||
switch ( opcode & KOMODO_PRICEMASK )
|
switch ( opcode & KOMODO_PRICEMASK )
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
@@ -358,7 +362,8 @@ int64_t prices_syntheticprice(std::vector<uint16_t> vec,int32_t height,int32_t m
|
|||||||
{
|
{
|
||||||
if ( leverage > 0 )
|
if ( leverage > 0 )
|
||||||
pricestack[depth] = (pricedata[1] > pricedata[2]) ? pricedata[1] : pricedata[2]; // MAX
|
pricestack[depth] = (pricedata[1] > pricedata[2]) ? pricedata[1] : pricedata[2]; // MAX
|
||||||
else pricestack[depth] = (pricedata[1] < pricedata[2]) ? pricedata[1] : pricedata[2]; // MIN
|
else
|
||||||
|
pricestack[depth] = (pricedata[1] < pricedata[2]) ? pricedata[1] : pricedata[2]; // MIN
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( pricestack[depth] == 0 )
|
if ( pricestack[depth] == 0 )
|
||||||
|
|||||||
@@ -2077,7 +2077,7 @@ uint32_t get_dailyfx(uint32_t *prices)
|
|||||||
sprintf(url,"https://api.openrates.io/latest?base=USD");
|
sprintf(url,"https://api.openrates.io/latest?base=USD");
|
||||||
if ( (json= get_urljson(url)) != 0 ) //if ( (json= send_curl(url,(char *)"dailyfx")) != 0 )
|
if ( (json= get_urljson(url)) != 0 ) //if ( (json= send_curl(url,(char *)"dailyfx")) != 0 )
|
||||||
{
|
{
|
||||||
std::cerr << "Forex rates:" << std::endl;
|
std::cerr << "Forex USD rates:" << std::endl;
|
||||||
if ( (rates= jobj(json,(char *)"rates")) != 0 )
|
if ( (rates= jobj(json,(char *)"rates")) != 0 )
|
||||||
{
|
{
|
||||||
for (i=0; i<sizeof(Forex)/sizeof(*Forex); i++)
|
for (i=0; i<sizeof(Forex)/sizeof(*Forex); i++)
|
||||||
@@ -2111,7 +2111,7 @@ uint32_t get_binanceprice(const char *symbol)
|
|||||||
int32_t get_cryptoprices(uint32_t *prices,const char *list[],int32_t n,std::vector<std::string> strvec)
|
int32_t get_cryptoprices(uint32_t *prices,const char *list[],int32_t n,std::vector<std::string> strvec)
|
||||||
{
|
{
|
||||||
int32_t i,errs=0; uint32_t price; char *symbol;
|
int32_t i,errs=0; uint32_t price; char *symbol;
|
||||||
std::cerr << "Crypto binance rates:" << std::endl;
|
std::cerr << "Crypto binance BTC rates:" << std::endl;
|
||||||
|
|
||||||
for (i=0; i<n+strvec.size(); i++)
|
for (i=0; i<n+strvec.size(); i++)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user