From 92b30e07f0b792d14cb6ed5007aa264410721029 Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 8 Apr 2019 17:53:09 +0500 Subject: [PATCH] logging --- src/cc/CCPrices.h | 18 +++++++++--------- src/cc/prices.cpp | 31 ++++++++++++++++++------------- src/komodo_gateway.h | 4 ++-- 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/src/cc/CCPrices.h b/src/cc/CCPrices.h index 3dbe6a87c..f88a5fe55 100644 --- a/src/cc/CCPrices.h +++ b/src/cc/CCPrices.h @@ -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_SMOOTHWIDTH 1 #define KOMODO_MAXPRICES 2048 // must be power of 2 and less than 8192 -#define KOMODO_PRICEMASK (~(KOMODO_MAXPRICES - 1)) -#define PRICES_WEIGHT (KOMODO_MAXPRICES * 1) -#define PRICES_MULT (KOMODO_MAXPRICES * 2) -#define PRICES_DIV (KOMODO_MAXPRICES * 3) -#define PRICES_INV (KOMODO_MAXPRICES * 4) -#define PRICES_MDD (KOMODO_MAXPRICES * 5) -#define PRICES_MMD (KOMODO_MAXPRICES * 6) -#define PRICES_MMM (KOMODO_MAXPRICES * 7) -#define PRICES_DDD (KOMODO_MAXPRICES * 8) +#define KOMODO_PRICEMASK (~(KOMODO_MAXPRICES - 1)) // actually 1111 1000 0000 0000 +#define PRICES_WEIGHT (KOMODO_MAXPRICES * 1) // 0000 1000 0000 0000 +#define PRICES_MULT (KOMODO_MAXPRICES * 2) // 0001 0000 0000 0000 +#define PRICES_DIV (KOMODO_MAXPRICES * 3) // 0001 1000 0000 0000 +#define PRICES_INV (KOMODO_MAXPRICES * 4) // 0010 0000 0000 0000 +#define PRICES_MDD (KOMODO_MAXPRICES * 5) // 0010 1000 0000 0000 +#define PRICES_MMD (KOMODO_MAXPRICES * 6) // 0011 0000 0000 0000 +#define PRICES_MMM (KOMODO_MAXPRICES * 7) // 0011 1000 0000 0000 +#define PRICES_DDD (KOMODO_MAXPRICES * 8) // 0100 0000 0000 0000 bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index a2a78c9ed..d1fc1aba9 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -146,11 +146,11 @@ CBOPRET creates trustless oracles, which can be used for making a synthetic cash // helpers: -// returns true if there are only digits and no alphas in 's' -inline bool is_weight(std::string s) { +// returns true if there are only digits and no alphas or slashes in 's' +inline bool is_weight_str(std::string s) { 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::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 &vec,std::vector { int32_t i,need,ind,depth = 0; std::string opstr; uint16_t opcode,weight; if (synthetic.size() == 0) { - std::cerr << "synthetic expression is empty" << std::endl; + std::cerr << "prices_syntheticvec() expression is empty" << std::endl; return(-1); } for (i=0; i &vec,std::vector opcode = PRICES_MMM, need = 3; else if ( opstr == "///" ) 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; else if ( (weight= atoi(opstr.c_str())) > 0 && weight < KOMODO_MAXPRICES ) { @@ -314,30 +314,34 @@ int32_t prices_syntheticvec(std::vector &vec,std::vector need = 1; } else { - std::cerr << "incorrect opcode=" << opstr << std::endl; + std::cerr << "prices_syntheticvec() incorrect opcode=" << opstr << std::endl; return(-2); } 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); } depth -= need; - if ( (opcode & KOMODO_PRICEMASK) != PRICES_WEIGHT ) // weight - depth++; + std::cerr << "opcode=" << opcode << " opstr=" << opstr << " depth-=need=" << depth << std::endl; + if ((opcode & KOMODO_PRICEMASK) != PRICES_WEIGHT) { // skip weight + depth++; // increase operands count + std::cerr << "depth++=" << depth << std::endl; + } 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); } vec.push_back(opcode); } if ( depth != 0 ) { - fprintf(stderr,"depth.%d not empty\n",depth); + fprintf(stderr,"prices_syntheticvec() depth.%d not empty\n",depth); return(-5); } return(0); } +// calculate price for synthetic expression int64_t prices_syntheticprice(std::vector 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; @@ -345,7 +349,7 @@ int64_t prices_syntheticprice(std::vector vec,int32_t height,int32_t m for (i=0; i vec,int32_t height,int32_t m { if ( leverage > 0 ) 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 ) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 204960693..c9e3d0470 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2077,7 +2077,7 @@ uint32_t get_dailyfx(uint32_t *prices) sprintf(url,"https://api.openrates.io/latest?base=USD"); 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 ) { for (i=0; i strvec) { 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