From 7cdc24096440d4b870e943ef1cc6a76444365f12 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Apr 2019 02:13:20 -1100 Subject: [PATCH] Reverse --- src/komodo_gateway.h | 14 +++++++++----- src/rpc/blockchain.cpp | 12 ++++++------ 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index bbad94c51..293b57367 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1576,9 +1576,11 @@ void komodo_PriceCache_shift() } // komodo_heightpricebits() extracts the price data in the coinbase for nHeight -int32_t komodo_heightpricebits(uint32_t *heightbits,int32_t nHeight) +int32_t komodo_heightpricebits(uint64_t *seedp,uint32_t *heightbits,int32_t nHeight) { CBlockIndex *pindex; CBlock block; CTransaction tx; int32_t numvouts; std::vector vopret; + if ( seedp != 0 ) + *seedp = 0; if ( (pindex= komodo_chainactive(nHeight)) != 0 ) { if ( komodo_blockload(block,pindex) == 0 ) @@ -1588,6 +1590,8 @@ int32_t komodo_heightpricebits(uint32_t *heightbits,int32_t nHeight) GetOpReturnData(tx.vout[numvouts-1].scriptPubKey,vopret); if ( vopret.size() >= PRICES_SIZEBIT0 ) { + if ( seedp != 0 ) + memcpy(seedp,&pindex->hashMerkleRoot,sizeof(*seedp)); memcpy(heightbits,vopret.data(),vopret.size()); return((int32_t)(vopret.size()/sizeof(uint32_t))); } @@ -1682,7 +1686,7 @@ CScript komodo_mineropret(int32_t nHeight) if ( numzero != 0 ) fprintf(stderr,"numzero.%d\n",numzero); } - if ( komodo_heightpricebits(prevbits,nHeight-1) > 0 ) + if ( komodo_heightpricebits(0,prevbits,nHeight-1) > 0 ) { memcpy(pricebits,Mineropret.data(),Mineropret.size()); memset(maxflags,0,sizeof(maxflags)); @@ -1757,7 +1761,7 @@ int32_t komodo_opretvalidate(const CBlock *block,CBlockIndex * const previndex,i btcgbp = (double)pricebits[2]/10000; btceur = (double)pricebits[3]/10000; fprintf(stderr,"ht.%d: lag.%d %.4f USD, %.4f GBP, %.4f EUR, GBPUSD %.6f, EURUSD %.6f, EURGBP %.6f [%d]\n",nHeight,lag,btcusd,btcgbp,btceur,btcusd/btcgbp,btcusd/btceur,btcgbp/btceur,lag2); - if ( komodo_heightpricebits(prevbits,nHeight-1) > 0 ) + if ( komodo_heightpricebits(0,prevbits,nHeight-1) > 0 ) { if ( nHeight < testchain_exemption ) { @@ -2228,14 +2232,14 @@ int64_t komodo_pricesmoothed(int64_t *correlated,int32_t numprices) return(correlated[0]); } -int64_t komodo_pricecorrelated(int32_t ind,uint32_t *rawprices,int32_t numprices) +int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int32_t numprices) { int32_t i; int64_t price,sum = 0; for (i=0; i= 36 ) + if ( ind < 36 ) price *= 10000; sum += price; } diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index eab787f17..1cfcf4eb7 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1174,10 +1174,10 @@ UniValue paxprice(const UniValue& params, bool fHelp) return ret; } -int32_t komodo_heightpricebits(uint32_t *heightbits,int32_t nHeight); +int32_t komodo_heightpricebits(uint64_t *seedp,uint32_t *heightbits,int32_t nHeight); char *komodo_pricename(char *name,int32_t ind); int64_t komodo_pricesmoothed(int64_t *correlated,int32_t numprices); -int64_t komodo_pricecorrelated(int32_t ind,uint32_t *rawprices,int32_t numprices); +int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int32_t numprices); int32_t komodo_nextheight(); uint32_t komodo_heightstamp(int32_t height); @@ -1186,7 +1186,7 @@ UniValue prices(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 1 ) throw runtime_error("prices maxsamples\n"); LOCK(cs_main); - UniValue ret(UniValue::VOBJ); int64_t smoothed,*correlated; char name[64],*str; uint32_t rawprices[2048],*prices; uint32_t i,width,j,numpricefeeds=-1,n,nextheight,offset,ht,num=0,daywindow = (3600*24/ASSETCHAINS_BLOCKTIME) + 1; + UniValue ret(UniValue::VOBJ); uint64_t seed; int64_t smoothed,*correlated; char name[64],*str; uint32_t rawprices[2048],*prices; uint32_t i,width,j,numpricefeeds=-1,n,nextheight,offset,ht,num=0,daywindow = (3600*24/ASSETCHAINS_BLOCKTIME) + 1; if ( ASSETCHAINS_CBOPRET == 0 ) throw JSONRPCError(RPC_INVALID_PARAMETER, "only -ac_cbopret chains have prices"); @@ -1198,7 +1198,7 @@ UniValue prices(const UniValue& params, bool fHelp) if ( daywindow < 7 ) daywindow = 7; width = maxsamples+2*daywindow; - numpricefeeds = komodo_heightpricebits(rawprices,nextheight-1); + numpricefeeds = komodo_heightpricebits(&seed,rawprices,nextheight-1); if ( numpricefeeds <= 0 ) throw JSONRPCError(RPC_INVALID_PARAMETER, "illegal numpricefeeds"); prices = (uint32_t *)calloc(sizeof(*prices),width*numpricefeeds); @@ -1209,7 +1209,7 @@ UniValue prices(const UniValue& params, bool fHelp) throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range"); else { - if ( (n= komodo_heightpricebits(rawprices,ht)) > 0 ) + if ( (n= komodo_heightpricebits(0,rawprices,ht)) > 0 ) { if ( n != numpricefeeds ) throw JSONRPCError(RPC_INVALID_PARAMETER, "numprices != first numprices"); @@ -1238,7 +1238,7 @@ UniValue prices(const UniValue& params, bool fHelp) for (i=0; i