This commit is contained in:
jl777
2016-10-23 15:36:43 -03:00
parent f09940d8b4
commit a0ae285799
2 changed files with 30 additions and 17 deletions

View File

@@ -67,6 +67,7 @@ uint32_t MINDENOMS[] = { 1000, 1000, 100000, 1000, 1000, 1000, 1000, 1000, // ma
double PAX_val(uint32_t pval,int32_t baseid) double PAX_val(uint32_t pval,int32_t baseid)
{ {
printf("PAX_val baseid.%d pval.%u\n",baseid,pval);
if ( baseid >= 0 && baseid < MAX_CURRENCIES ) if ( baseid >= 0 && baseid < MAX_CURRENCIES )
return(((double)pval / 1000000000.) / MINDENOMS[baseid]); return(((double)pval / 1000000000.) / MINDENOMS[baseid]);
return(0.); return(0.);
@@ -454,22 +455,29 @@ int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *n
void komodo_pvals(int32_t height,uint32_t *pvals,uint8_t numpvals) void komodo_pvals(int32_t height,uint32_t *pvals,uint8_t numpvals)
{ {
int32_t i; double KMDBTC,BTCUSD,CNYUSD; uint32_t kmdbtc,btcusd,cnyusd; int32_t i,nonz; double KMDBTC,BTCUSD,CNYUSD; uint32_t kmdbtc,btcusd,cnyusd;
if ( numpvals >= 35 ) if ( numpvals >= 35 )
{ {
for (i=0; i<32; i++) for (nonz=i=0; i<32; i++)
{
if ( pvals[i] != 0 )
nonz++;
printf("%u ",pvals[i]); printf("%u ",pvals[i]);
kmdbtc = pvals[i++]; }
btcusd = pvals[i++]; if ( nonz == 32 )
cnyusd = pvals[i++]; {
KMDBTC = ((double)kmdbtc / (1000000000. * 1000.)); kmdbtc = pvals[i++];
BTCUSD = ((double)btcusd / (1000000000. / 1000.)); btcusd = pvals[i++];
CNYUSD = ((double)cnyusd / 1000000000.); cnyusd = pvals[i++];
PVALS = (uint32_t *)realloc(PVALS,(NUM_PRICES+1) * sizeof(*PVALS) * 36); KMDBTC = ((double)kmdbtc / (1000000000. * 1000.));
PVALS[36 * NUM_PRICES] = height; BTCUSD = ((double)btcusd / (1000000000. / 1000.));
memcpy(&PVALS[36 * NUM_PRICES + 1],pvals,sizeof(*pvals) * 35); CNYUSD = ((double)cnyusd / 1000000000.);
NUM_PRICES++; PVALS = (uint32_t *)realloc(PVALS,(NUM_PRICES+1) * sizeof(*PVALS) * 36);
printf("OP_RETURN.%d KMD %.8f BTC %.6f CNY %.6f NUM_PRICES.%d\n",height,KMDBTC,BTCUSD,CNYUSD,NUM_PRICES); PVALS[36 * NUM_PRICES] = height;
memcpy(&PVALS[36 * NUM_PRICES + 1],pvals,sizeof(*pvals) * 35);
NUM_PRICES++;
printf("OP_RETURN.%d KMD %.8f BTC %.6f CNY %.6f NUM_PRICES.%d\n",height,KMDBTC,BTCUSD,CNYUSD,NUM_PRICES);
}
} }
} }
@@ -484,7 +492,7 @@ int32_t komodo_baseid(char *base)
uint64_t komodo_paxprice(int32_t height,char *base,char *rel) uint64_t komodo_paxprice(int32_t height,char *base,char *rel)
{ {
int32_t baseid,relid,i,ht; uint32_t pvalb,pvalr,*ptr; int32_t baseid,relid,i,ht; uint32_t pvalb,pvalr,*ptr; double baseval,relval;
if ( (baseid= komodo_baseid(base)) >= 0 && (relid= komodo_baseid(rel)) >= 0 ) if ( (baseid= komodo_baseid(base)) >= 0 && (relid= komodo_baseid(rel)) >= 0 )
{ {
for (i=NUM_PRICES-1; i>=0; i--) for (i=NUM_PRICES-1; i>=0; i--)
@@ -493,11 +501,16 @@ uint64_t komodo_paxprice(int32_t height,char *base,char *rel)
if ( *ptr <= height ) if ( *ptr <= height )
{ {
if ( (pvalb= ptr[baseid]) != 0 && (pvalr= ptr[relid]) != 0 ) if ( (pvalb= ptr[baseid]) != 0 && (pvalr= ptr[relid]) != 0 )
return(COIN * (PAX_val(pvalb,baseid) / PAX_val(pvalr,relid))); {
baseval = PAX_val(pvalb,baseid);
relval = PAX_val(pvalr,relid);
printf("ht.%d [%d] base.(%u %f) rel.(%u %f) -> %llu\n",height,*ptr,pvalb,baseval,pvalr,relval,(long long)(COIN * (baseval / relval)));
return(COIN * (baseval / relval));
}
return(0); return(0);
} }
} }
} } else printf("paxprice invalid base.%s rel.%s\n",base,rel);
return(0); return(0);
} }

View File

@@ -392,7 +392,7 @@ Value paxprice(const Array& params, bool fHelp)
Object ret; uint64_t pricetoshis; Object ret; uint64_t pricetoshis;
std::string base = params[0].get_str(); std::string base = params[0].get_str();
std::string rel = params[1].get_str(); std::string rel = params[1].get_str();
int height = atoi(params[2].get_str().c_str()); int32_t height = atoi(params[2].get_str().c_str());
pricetoshis = komodo_paxprice(height,(char *)base.c_str(),(char *)rel.c_str()); pricetoshis = komodo_paxprice(height,(char *)base.c_str(),(char *)rel.c_str());
ret.push_back(Pair("base", base)); ret.push_back(Pair("base", base));
ret.push_back(Pair("rel", rel)); ret.push_back(Pair("rel", rel));