Merge pull request #462 from jl777/dPoW
paxprice fixes, no need to update if you dont run pax fiat assetchains
This commit is contained in:
@@ -642,7 +642,7 @@ void jumblr_iteration()
|
||||
biggest = SATOSHIDEN * ((JUMBLR_INCR + 3*fee)*777 + 3*JUMBLR_TXFEE);
|
||||
OS_randombytes((uint8_t *)&r,sizeof(r));
|
||||
s = (r % 3);
|
||||
printf("jumblr_iteration r.%u s.%u\n",r,s);
|
||||
//printf("jumblr_iteration r.%u s.%u\n",r,s);
|
||||
switch ( s )
|
||||
{
|
||||
case 0: // t -> z
|
||||
|
||||
@@ -176,7 +176,21 @@ void pax_rank(uint64_t *ranked,uint32_t *pvals)
|
||||
//printf("sum %llu\n",(long long)sum);
|
||||
};
|
||||
|
||||
int32_t dpow_readprices(uint8_t *data,uint32_t *timestampp,double *KMDBTCp,double *BTCUSDp,double *CNYUSDp,uint32_t *pvals)
|
||||
#define BTCFACTOR_HEIGHT 466266
|
||||
|
||||
double PAX_BTCUSD(int32_t height,uint32_t btcusd)
|
||||
{
|
||||
double btcfactor,BTCUSD;
|
||||
if ( height >= BTCFACTOR_HEIGHT )
|
||||
btcfactor = 100000.;
|
||||
else btcfactor = 1000.;
|
||||
BTCUSD = ((double)btcusd / (1000000000. / btcfactor));
|
||||
if ( height >= BTCFACTOR_HEIGHT && height < 500000 && BTCUSD > 20000 && btcfactor == 100000. )
|
||||
BTCUSD /= 100;
|
||||
return(BTCUSD);
|
||||
}
|
||||
|
||||
int32_t dpow_readprices(int32_t height,uint8_t *data,uint32_t *timestampp,double *KMDBTCp,double *BTCUSDp,double *CNYUSDp,uint32_t *pvals)
|
||||
{
|
||||
uint32_t kmdbtc,btcusd,cnyusd; int32_t i,n,nonz,len = 0;
|
||||
if ( data[0] == 'P' && data[5] == 35 )
|
||||
@@ -192,7 +206,7 @@ int32_t dpow_readprices(uint8_t *data,uint32_t *timestampp,double *KMDBTCp,doubl
|
||||
len += iguana_rwnum(0,&data[len],sizeof(uint32_t),(void *)&btcusd); // *= 1000
|
||||
len += iguana_rwnum(0,&data[len],sizeof(uint32_t),(void *)&cnyusd);
|
||||
*KMDBTCp = ((double)kmdbtc / (1000000000. * 1000.));
|
||||
*BTCUSDp = ((double)btcusd / (1000000000. / 1000.));
|
||||
*BTCUSDp = PAX_BTCUSD(height,btcusd);
|
||||
*CNYUSDp = ((double)cnyusd / 1000000000.);
|
||||
for (i=nonz=0; i<n-3; i++)
|
||||
{
|
||||
@@ -215,7 +229,7 @@ int32_t dpow_readprices(uint8_t *data,uint32_t *timestampp,double *KMDBTCp,doubl
|
||||
return(n);
|
||||
}
|
||||
|
||||
int32_t komodo_pax_opreturn(uint8_t *opret,int32_t maxsize)
|
||||
int32_t komodo_pax_opreturn(int32_t height,uint8_t *opret,int32_t maxsize)
|
||||
{
|
||||
static uint32_t lastcrc;
|
||||
FILE *fp; char fname[512]; uint32_t crc32,check,timestamp; int32_t i,n=0,retval,fsize,len=0; uint8_t data[8192];
|
||||
@@ -238,7 +252,7 @@ int32_t komodo_pax_opreturn(uint8_t *opret,int32_t maxsize)
|
||||
if ( check == crc32 )
|
||||
{
|
||||
double KMDBTC,BTCUSD,CNYUSD; uint32_t pvals[128];
|
||||
if ( dpow_readprices(&data[len],×tamp,&KMDBTC,&BTCUSD,&CNYUSD,pvals) > 0 )
|
||||
if ( dpow_readprices(height,&data[len],×tamp,&KMDBTC,&BTCUSD,&CNYUSD,pvals) > 0 )
|
||||
{
|
||||
if ( 0 && lastcrc != crc32 )
|
||||
{
|
||||
@@ -262,7 +276,7 @@ int32_t komodo_pax_opreturn(uint8_t *opret,int32_t maxsize)
|
||||
} else printf("fread.%d error != fsize.%d\n",retval,fsize);
|
||||
} else printf("fsize.%d > maxsize.%d or data[%d]\n",fsize,maxsize,(int32_t)sizeof(data));
|
||||
fclose(fp);
|
||||
}
|
||||
} //else printf("couldnt open %s\n",fname);
|
||||
return(n);
|
||||
}
|
||||
|
||||
@@ -328,7 +342,7 @@ void komodo_pvals(int32_t height,uint32_t *pvals,uint8_t numpvals)
|
||||
btcusd = pvals[i++];
|
||||
cnyusd = pvals[i++];
|
||||
KMDBTC = ((double)kmdbtc / (1000000000. * 1000.));
|
||||
BTCUSD = ((double)btcusd / (1000000000. / 1000.));
|
||||
BTCUSD = PAX_BTCUSD(height,btcusd);
|
||||
CNYUSD = ((double)cnyusd / 1000000000.);
|
||||
portable_mutex_lock(&komodo_mutex);
|
||||
PVALS = (uint32_t *)realloc(PVALS,(NUM_PRICES+1) * sizeof(*PVALS) * 36);
|
||||
@@ -406,7 +420,7 @@ uint64_t komodo_paxcorrelation(uint64_t *votes,int32_t numvotes,uint64_t seed)
|
||||
|
||||
uint64_t komodo_paxcalc(int32_t height,uint32_t *pvals,int32_t baseid,int32_t relid,uint64_t basevolume,uint64_t refkmdbtc,uint64_t refbtcusd)
|
||||
{
|
||||
uint32_t pvalb,pvalr; uint64_t price,kmdbtc,btcusd,usdvol,baseusd,usdkmd,baserel,ranked[32];
|
||||
uint32_t pvalb,pvalr; double BTCUSD; uint64_t price,kmdbtc,btcusd,usdvol,baseusd,usdkmd,baserel,ranked[32];
|
||||
if ( basevolume > KOMODO_PAXMAX )
|
||||
{
|
||||
printf("paxcalc overflow %.8f\n",dstr(basevolume));
|
||||
@@ -439,9 +453,15 @@ uint64_t komodo_paxcalc(int32_t height,uint32_t *pvals,int32_t baseid,int32_t re
|
||||
usdkmd = ((uint64_t)kmdbtc * 1000000000) / btcusd;
|
||||
if ( height >= 236000-10 )
|
||||
{
|
||||
usdkmd = ((uint64_t)kmdbtc * btcusd) / 1000000000;
|
||||
BTCUSD = PAX_BTCUSD(height,btcusd);
|
||||
if ( height < BTCFACTOR_HEIGHT || (height < 500000 && BTCUSD > 20000) )
|
||||
usdkmd = ((uint64_t)kmdbtc * btcusd) / 1000000000;
|
||||
else usdkmd = ((uint64_t)kmdbtc * btcusd) / 10000000;
|
||||
///if ( height >= BTCFACTOR_HEIGHT && BTCUSD >= 43 )
|
||||
// usdkmd = ((uint64_t)kmdbtc * btcusd) / 10000000;
|
||||
//else usdkmd = ((uint64_t)kmdbtc * btcusd) / 1000000000;
|
||||
price = ((uint64_t)10000000000 * MINDENOMS[USD] / MINDENOMS[baseid]) / komodo_paxvol(usdvol,usdkmd);
|
||||
//fprintf(stderr,"ht.%d kmdbtc.%llu btcusd.%llu base -> USD %llu, usdkmd %llu usdvol %llu -> %llu\n",height,(long long)kmdbtc,(long long)btcusd,(long long)baseusd,(long long)usdkmd,(long long)usdvol,(long long)(MINDENOMS[USD] * komodo_paxvol(usdvol,usdkmd) / (MINDENOMS[baseid]/100)));
|
||||
//fprintf(stderr,"ht.%d %.3f kmdbtc.%llu btcusd.%llu base -> USD %llu, usdkmd %llu usdvol %llu -> %llu\n",height,BTCUSD,(long long)kmdbtc,(long long)btcusd,(long long)baseusd,(long long)usdkmd,(long long)usdvol,(long long)(MINDENOMS[USD] * komodo_paxvol(usdvol,usdkmd) / (MINDENOMS[baseid]/100)));
|
||||
//fprintf(stderr,"usdkmd.%llu basevolume.%llu baseusd.%llu paxvol.%llu usdvol.%llu -> %llu %llu\n",(long long)usdkmd,(long long)basevolume,(long long)baseusd,(long long)komodo_paxvol(basevolume,baseusd),(long long)usdvol,(long long)(MINDENOMS[USD] * komodo_paxvol(usdvol,usdkmd) / (MINDENOMS[baseid]/100)),(long long)price);
|
||||
//fprintf(stderr,"usdkmd.%llu basevolume.%llu baseusd.%llu paxvol.%llu usdvol.%llu -> %llu\n",(long long)usdkmd,(long long)basevolume,(long long)baseusd,(long long)komodo_paxvol(basevolume,baseusd),(long long)usdvol,(long long)(MINDENOMS[USD] * komodo_paxvol(usdvol,usdkmd) / (MINDENOMS[baseid]/100)));
|
||||
} else price = (MINDENOMS[USD] * komodo_paxvol(usdvol,usdkmd) / (MINDENOMS[baseid]/100));
|
||||
@@ -474,7 +494,7 @@ uint64_t komodo_paxcalc(int32_t height,uint32_t *pvals,int32_t baseid,int32_t re
|
||||
|
||||
uint64_t _komodo_paxprice(uint64_t *kmdbtcp,uint64_t *btcusdp,int32_t height,char *base,char *rel,uint64_t basevolume,uint64_t kmdbtc,uint64_t btcusd)
|
||||
{
|
||||
int32_t baseid=-1,relid=-1,i; uint32_t *ptr;
|
||||
int32_t baseid=-1,relid=-1,i; uint32_t *ptr,*pvals;
|
||||
if ( height > 10 )
|
||||
height -= 10;
|
||||
if ( (baseid= komodo_baseid(base)) >= 0 && (relid= komodo_baseid(rel)) >= 0 )
|
||||
@@ -485,14 +505,15 @@ uint64_t _komodo_paxprice(uint64_t *kmdbtcp,uint64_t *btcusdp,int32_t height,cha
|
||||
ptr = &PVALS[36 * i];
|
||||
if ( *ptr < height )
|
||||
{
|
||||
pvals = &ptr[1];
|
||||
if ( kmdbtcp != 0 && btcusdp != 0 )
|
||||
{
|
||||
*kmdbtcp = ptr[MAX_CURRENCIES + 1] / 539;
|
||||
*btcusdp = ptr[MAX_CURRENCIES + 2] / 539;
|
||||
*kmdbtcp = pvals[MAX_CURRENCIES] / 539;
|
||||
*btcusdp = pvals[MAX_CURRENCIES + 1] / 539;
|
||||
}
|
||||
//portable_mutex_unlock(&komodo_mutex);
|
||||
if ( kmdbtc != 0 && btcusd != 0 )
|
||||
return(komodo_paxcalc(height,&ptr[1],baseid,relid,basevolume,kmdbtc,btcusd));
|
||||
return(komodo_paxcalc(height,pvals,baseid,relid,basevolume,kmdbtc,btcusd));
|
||||
else return(0);
|
||||
}
|
||||
}
|
||||
@@ -617,7 +638,7 @@ uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uin
|
||||
if ( ASSETCHAINS_SYMBOL[0] == 0 && chainActive.Tip() != 0 && height > chainActive.Tip()->nHeight )
|
||||
{
|
||||
if ( height < 100000000 )
|
||||
printf("height.%d vs tip.%d\n",height,chainActive.Tip()->nHeight);
|
||||
printf("komodo_paxprice height.%d vs tip.%d\n",height,chainActive.Tip()->nHeight);
|
||||
return(0);
|
||||
}
|
||||
*seedp = komodo_seed(height);
|
||||
@@ -680,10 +701,16 @@ int32_t komodo_paxprices(int32_t *heights,uint64_t *prices,int32_t max,char *bas
|
||||
void komodo_paxpricefeed(int32_t height,uint8_t *pricefeed,int32_t opretlen)
|
||||
{
|
||||
double KMDBTC,BTCUSD,CNYUSD; uint32_t numpvals,timestamp,pvals[128]; uint256 zero;
|
||||
numpvals = dpow_readprices(pricefeed,×tamp,&KMDBTC,&BTCUSD,&CNYUSD,pvals);
|
||||
numpvals = dpow_readprices(height,pricefeed,×tamp,&KMDBTC,&BTCUSD,&CNYUSD,pvals);
|
||||
memset(&zero,0,sizeof(zero));
|
||||
komodo_stateupdate(height,0,0,0,zero,0,0,pvals,numpvals,0,0,0,0,0,0);
|
||||
//printf("komodo_paxpricefeed vout OP_RETURN.%d prices numpvals.%d opretlen.%d\n",height,numpvals,opretlen);
|
||||
if ( 1 )
|
||||
{
|
||||
int32_t i;
|
||||
for (i=0; i<numpvals; i++)
|
||||
printf("%u ",pvals[i]);
|
||||
printf("komodo_paxpricefeed vout OP_RETURN.%d prices numpvals.%d opretlen.%d kmdbtc %.8f BTCUSD %.8f CNYUSD %.8f\n",height,numpvals,opretlen,KMDBTC,BTCUSD,CNYUSD);
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t PAX_fiatdest(uint64_t *seedp,int32_t tokomodo,char *destaddr,uint8_t pubkey33[33],char *coinaddr,int32_t height,char *origbase,int64_t fiatoshis)
|
||||
|
||||
@@ -116,7 +116,7 @@ extern uint8_t NOTARY_PUBKEY33[33];
|
||||
uint32_t Mining_start,Mining_height;
|
||||
int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33);
|
||||
int32_t komodo_is_special(int32_t height,uint8_t pubkey33[33]);
|
||||
int32_t komodo_pax_opreturn(uint8_t *opret,int32_t maxsize);
|
||||
int32_t komodo_pax_opreturn(int32_t height,uint8_t *opret,int32_t maxsize);
|
||||
uint64_t komodo_paxtotal();
|
||||
int32_t komodo_baseid(char *origbase);
|
||||
int32_t komodo_is_issuer();
|
||||
@@ -402,7 +402,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
||||
int32_t i,opretlen; uint8_t opret[256],*ptr;
|
||||
if ( (nHeight % 60) == 0 || komodo_gateway_deposits(&txNew,(char *)"KMD",1) == 0 )
|
||||
{
|
||||
if ( (opretlen= komodo_pax_opreturn(opret,sizeof(opret))) > 0 ) // have pricefeed
|
||||
if ( (opretlen= komodo_pax_opreturn((int32_t)nHeight,opret,sizeof(opret))) > 0 ) // have pricefeed
|
||||
{
|
||||
txNew.vout.resize(2);
|
||||
txNew.vout[1].scriptPubKey.resize(opretlen);
|
||||
@@ -411,7 +411,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
||||
ptr[i] = opret[i];
|
||||
txNew.vout[1].nValue = 0;
|
||||
//fprintf(stderr,"opretlen.%d\n",opretlen);
|
||||
}
|
||||
} //else printf("null opretlen for prices\n");
|
||||
}
|
||||
}
|
||||
else if ( komodo_is_issuer() != 0 )
|
||||
|
||||
Reference in New Issue
Block a user