Browse Source

logging

jl777
dimxy 5 years ago
parent
commit
4cd2814aa8
  1. 24
      src/cc/prices.cpp
  2. 8
      src/komodo_gateway.h

24
src/cc/prices.cpp

@ -144,6 +144,16 @@ 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) {
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;
}
// start of consensus code
CScript prices_betopret(CPubKey mypk,int32_t height,int64_t amount,int16_t leverage,int64_t firstprice,std::vector<uint16_t> vec,uint256 tokenid)
@ -296,7 +306,7 @@ int32_t prices_syntheticvec(std::vector<uint16_t> &vec,std::vector<std::string>
opcode = PRICES_MMM, need = 3;
else if ( opstr == "///" )
opcode = PRICES_DDD, need = 3;
else if ( (ind= komodo_priceind((char *)opstr.c_str())) >= 0 )
else if (!is_weight(opstr) && (ind= komodo_priceind(opstr.c_str())) >= 0 )
opcode = ind, need = 0;
else if ( (weight= atoi(opstr.c_str())) > 0 && weight < KOMODO_MAXPRICES )
{
@ -429,12 +439,18 @@ int64_t prices_syntheticprice(std::vector<uint16_t> vec,int32_t height,int32_t m
if ( errcode != 0 )
break;
}
if ( den == 0 )
if (den == 0) {
std::cerr << "prices_syntheticprice den==0 return err=-11" << std::endl;
return(-11);
else if ( depth != 0 )
}
else if (depth != 0) {
std::cerr << "prices_syntheticprice depth!=0 err=-12" << std::endl;
return(-12);
else if ( errcode != 0 )
}
else if (errcode != 0) {
std::cerr << "prices_syntheticprice err=" << errcode << std::endl;
return(errcode);
}
return(price / den);
}

8
src/komodo_gateway.h

@ -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 i,errs=0; uint32_t price; char *symbol;
std::cerr << "Crypto rates:" << std::endl;
std::cerr << "Crypto binance rates:" << std::endl;
for (i=0; i<n+strvec.size(); i++)
{
@ -2202,7 +2202,7 @@ int32_t get_btcusd(uint32_t pricebits[4])
dbtcusd = (double)pricebits[1]/10000;
dbtcgbp = (double)pricebits[2]/10000;
dbtceur = (double)pricebits[3]/10000;
fprintf(stderr,"BTC/USD %.4f, BTC/GBP %.4f, BTC/EUR %.4f GBPUSD %.6f, EURUSD %.6f EURGBP %.6f\n",dbtcusd,dbtcgbp,dbtceur,dbtcusd/dbtcgbp,dbtcusd/dbtceur,dbtcgbp/dbtceur);
fprintf(stderr,"BTC/USD %.4f, BTC/GBP %.4f, BTC/EUR %.4f not used: GBPUSD %.6f, EURUSD %.6f EURGBP %.6f\n",dbtcusd,dbtcgbp,dbtceur,dbtcusd/dbtcgbp,dbtcusd/dbtceur,dbtcgbp/dbtceur);
return(0);
}
return(-1);
@ -2431,7 +2431,7 @@ char *komodo_pricename(char *name,int32_t ind)
}
// finds index value for its symbol name
int32_t komodo_priceind(char *symbol)
int32_t komodo_priceind(const char *symbol)
{
char name[65]; int32_t i,n = (int32_t)(komodo_cbopretsize(ASSETCHAINS_CBOPRET) / sizeof(uint32_t));
@ -2439,7 +2439,7 @@ int32_t komodo_priceind(char *symbol)
for (i=1; i<n; i++)
{
komodo_pricename(name,i);
std::cerr << "komodo_priceind name=" << name << " i=" << i << std::endl;
//std::cerr << "komodo_priceind name=" << name << " i=" << i << std::endl;
if (strcmp(name, symbol) == 0) {
std::cerr << "komodo_priceind for symbol=" << symbol << " returns=" << i << std::endl;
return(i);

Loading…
Cancel
Save