Remove unused code

This commit is contained in:
Duke
2025-08-08 17:36:11 -04:00
parent 701ebf26a7
commit e495bf35b2

View File

@@ -932,12 +932,6 @@ extern std::vector<uint8_t> Mineropret; // opreturn data set by the data gatheri
#define issue_curl(cmdstr) bitcoind_RPC(0,(char *)"CBCOINBASE",cmdstr,0,0,0)
const char *Cryptos[] = { "HUSH", "ETH" };
// "LTC", "BCHABC", "XMR", "IOTA", "ZEC", "WAVES", "LSK", "DCR", "RVN", "DASH", "XEM", "BTS", "ICX", "HOT", "STEEM", "ENJ", "STRAT"
const char *Forex[] =
{ "BGN","NZD","ILS","RUB","CAD","PHP","CHF","AUD","JPY","TRY","HKD","MYR","HRK","CZK","IDR","DKK","NOK","HUF","GBP","MXN","THB","ISK","ZAR","BRL","SGD","PLN","INR","KRW","RON","CNY","SEK","EUR"
}; // must be in ECB list
struct hush_extremeprice
{
uint256 blockhash;
@@ -952,116 +946,35 @@ struct hush_priceinfo
char symbol[64];
} PRICES[HUSH_MAXPRICES];
uint32_t PriceCache[HUSH_LOCALPRICE_CACHESIZE][HUSH_MAXPRICES];//4+sizeof(Cryptos)/sizeof(*Cryptos)+sizeof(Forex)/sizeof(*Forex)];
int64_t PriceMult[HUSH_MAXPRICES];
int32_t hush_cbopretsize(uint64_t flags);
void hush_PriceCache_shift()
{
int32_t i;
for (i=HUSH_LOCALPRICE_CACHESIZE-1; i>0; i--)
memcpy(PriceCache[i],PriceCache[i-1],sizeof(PriceCache[i]));
memcpy(PriceCache[0],Mineropret.data(),Mineropret.size());
}
int32_t _hush_heightpricebits(uint64_t *seedp,uint32_t *heightbits,CBlock *block)
{
CTransaction tx; int32_t numvouts; std::vector<uint8_t> vopret;
tx = block->vtx[0];
numvouts = (int32_t)tx.vout.size();
GetOpReturnData(tx.vout[numvouts-1].scriptPubKey,vopret);
if ( vopret.size() >= PRICES_SIZEBIT0 )
{
if ( seedp != 0 )
memcpy(seedp,&block->hashMerkleRoot,sizeof(*seedp));
memcpy(heightbits,vopret.data(),vopret.size());
return((int32_t)(vopret.size()/sizeof(uint32_t)));
}
return(-1);
}
// hush_heightpricebits() extracts the price data in the coinbase for nHeight
int32_t hush_heightpricebits(uint64_t *seedp,uint32_t *heightbits,int32_t nHeight)
{
CBlockIndex *pindex; CBlock block;
if ( seedp != 0 )
*seedp = 0;
if ( (pindex= hush_chainactive(nHeight)) != 0 )
{
if ( hush_blockload(block,pindex) == 0 )
{
return(_hush_heightpricebits(seedp,heightbits,&block));
}
}
fprintf(stderr,"couldnt get pricebits for %d\n",nHeight);
return(-1);
}
/*
hush_pricenew() is passed in a reference price, the change tolerance and the proposed price. it needs to return a clipped price if it is too big and also set a flag if it is at or above the limit
*/
uint32_t hush_pricenew(char *maxflagp,uint32_t price,uint32_t refprice,int64_t tolerance)
{
uint64_t highprice,lowprice;
if ( refprice < 2 )
return(0);
highprice = ((uint64_t)refprice * (COIN + tolerance)) / COIN; // calc highest acceptable price
lowprice = ((uint64_t)refprice * (COIN - tolerance)) / COIN; // and lowest
if ( highprice == refprice )
highprice++;
if ( lowprice == refprice )
lowprice--;
if ( price >= highprice )
{
//fprintf(stderr,"high %u vs h%llu l%llu tolerance.%llu\n",price,(long long)highprice,(long long)lowprice,(long long)tolerance);
if ( price > highprice ) // return non-zero only if we violate the tolerance
{
*maxflagp = 2;
return(highprice);
}
*maxflagp = 1;
}
else if ( price <= lowprice )
{
//fprintf(stderr,"low %u vs h%llu l%llu tolerance.%llu\n",price,(long long)highprice,(long long)lowprice,(long long)tolerance);
if ( price < lowprice )
{
*maxflagp = -2;
return(lowprice);
}
*maxflagp = -1;
}
return(0);
}
// hush_pricecmp() returns -1 if any of the prices are beyond the tolerance
int32_t hush_pricecmp(int32_t nHeight,int32_t n,char *maxflags,uint32_t *pricebitsA,uint32_t *pricebitsB,int64_t tolerance)
{
int32_t i; uint32_t newprice;
for (i=1; i<n; i++)
{
if ( (newprice= hush_pricenew(&maxflags[i],pricebitsA[i],pricebitsB[i],tolerance)) != 0 )
{
fprintf(stderr,"ht.%d i.%d/%d %u vs %u -> newprice.%u out of tolerance maxflag.%d\n",nHeight,i,n,pricebitsB[i],pricebitsA[i],newprice,maxflags[i]);
return(-1);
}
}
return(0);
}
// hush_priceclamp() clamps any price that is beyond tolerance
int32_t hush_priceclamp(int32_t n,uint32_t *pricebits,uint32_t *refprices,int64_t tolerance)
{
int32_t i; uint32_t newprice; char maxflags[HUSH_MAXPRICES];
memset(maxflags,0,sizeof(maxflags));
for (i=1; i<n; i++)
{
if ( (newprice= hush_pricenew(&maxflags[i],pricebits[i],refprices[i],tolerance)) != 0 )
{
fprintf(stderr,"priceclamped[%d of %d] %u vs %u -> %u\n",i,n,refprices[i],pricebits[i],newprice);
pricebits[i] = newprice;
}
}
return(0);
}
@@ -1110,161 +1023,12 @@ CScript hush_mineropret(int32_t nHeight)
return(opret);
}
/*
hush_opretvalidate() is the entire price validation!
it prints out some useful info for debugging, like the lag from current time and prev block and the prices encoded in the opreturn.
The only way hush_opretvalidate() doesnt return an error is if maxflag is set or it is within tolerance of both the prior block and the local data. The local data validation only happens if it is a recent block and not a block from the past as the local node is only getting the current price data.
*/
void hush_queuelocalprice(int32_t dir,int32_t height,uint32_t timestamp,uint256 blockhash,int32_t ind,uint32_t pricebits)
{
fprintf(stderr,"ExtremePrice dir.%d ht.%d ind.%d cmpbits.%u\n",dir,height,ind,pricebits);
ExtremePrice.dir = dir;
ExtremePrice.height = height;
ExtremePrice.blockhash = blockhash;
ExtremePrice.ind = ind;
ExtremePrice.timestamp = timestamp;
ExtremePrice.pricebits = pricebits;
}
int32_t hush_opretvalidate(const CBlock *block,CBlockIndex * const previndex,int32_t nHeight,CScript scriptPubKey)
{
int32_t testchain_exemption = 0;
std::vector<uint8_t> vopret; char maxflags[HUSH_MAXPRICES]; uint256 bhash; double btcusd,btcgbp,btceur; uint32_t localbits[HUSH_MAXPRICES],pricebits[HUSH_MAXPRICES],prevbits[HUSH_MAXPRICES],newprice; int32_t i,j,prevtime,maxflag,lag,lag2,lag3,n,errflag,iter; uint32_t now;
now = (uint32_t)time(NULL);
if ( ASSETCHAINS_CBOPRET != 0 && nHeight > 0 )
{
bhash = block->GetHash();
GetOpReturnData(scriptPubKey,vopret);
if ( vopret.size() >= PRICES_SIZEBIT0 )
{
n = (int32_t)(vopret.size() / sizeof(uint32_t));
memcpy(pricebits,vopret.data(),Mineropret.size());
memset(maxflags,0,sizeof(maxflags));
if ( nHeight > 2 )
{
prevtime = previndex->nTime;
lag = (int32_t)(now - pricebits[0]);
lag2 = (int32_t)(pricebits[0] - prevtime);
lag3 = (int32_t)(block->nTime - pricebits[0]);
if ( lag < -60 ) // avoid data from future
{
fprintf(stderr,"A ht.%d now.%u htstamp.%u %u - pricebits[0] %u -> lags.%d %d %d\n",nHeight,now,prevtime,block->nTime,pricebits[0],lag,lag2,lag3);
return(-1);
}
if ( lag2 < -60 ) //testchain_exemption ) // must be close to last block timestamp
{
fprintf(stderr,"B ht.%d now.%u htstamp.%u %u - pricebits[0] %u -> lags.%d %d %d vs %d cmp.%d\n",nHeight,now,prevtime,block->nTime,pricebits[0],lag,lag2,lag3,ASSETCHAINS_BLOCKTIME,lag2<-ASSETCHAINS_BLOCKTIME);
if ( nHeight > testchain_exemption )
return(-1);
}
if ( lag3 < -60 || lag3 > ASSETCHAINS_BLOCKTIME )
{
fprintf(stderr,"C ht.%d now.%u htstamp.%u %u - pricebits[0] %u -> lags.%d %d %d\n",nHeight,now,prevtime,block->nTime,pricebits[0],lag,lag2,lag3);
if ( nHeight > testchain_exemption )
return(-1);
}
btcusd = (double)pricebits[1]/10000;
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 ( hush_heightpricebits(0,prevbits,nHeight-1) > 0 )
{
if ( nHeight < testchain_exemption )
{
for (i=0; i<n; i++)
if ( pricebits[i] == 0 )
pricebits[i] = prevbits[i];
}
if ( hush_pricecmp(nHeight,n,maxflags,pricebits,prevbits,PRICES_ERRORRATE) < 0 )
{
for (i=1; i<n; i++)
fprintf(stderr,"%.4f ",(double)prevbits[i]/10000);
fprintf(stderr," oldprices.%d\n",nHeight);
for (i=1; i<n; i++)
fprintf(stderr,"%.4f ",(double)pricebits[i]/10000);
fprintf(stderr," newprices.%d\n",nHeight);
fprintf(stderr,"vs prev maxflag.%d cmp error\n",maxflag);
return(-1);
} // else this is the good case we hope to happen
} else return(-1);
if ( lag < ASSETCHAINS_BLOCKTIME && Mineropret.size() >= PRICES_SIZEBIT0 )
{
memcpy(localbits,Mineropret.data(),Mineropret.size());
if ( nHeight < testchain_exemption )
{
for (i=0; i<n; i++)
if ( localbits[i] == 0 )
localbits[i] = prevbits[i];
}
for (iter=0; iter<2; iter++) // first iter should just refresh prices if out of tolerance
{
for (i=1; i<n; i++)
{
if ( (maxflag= maxflags[i]) != 0 && localbits[i] != 0 )
{
// make sure local price is moving in right direction
fprintf(stderr,"maxflag.%d i.%d localbits.%u vs pricebits.%u prevbits.%u\n",maxflag,i,localbits[i],pricebits[i],prevbits[i]);
if ( maxflag > 0 && localbits[i] < prevbits[i] )
{
if ( iter == 0 )
break;
// second iteration checks recent prices to see if within local volatility
for (j=0; j<HUSH_LOCALPRICE_CACHESIZE; j++)
if ( PriceCache[j][i] >= prevbits[i] )
{
fprintf(stderr,"i.%d within recent localprices[%d] %u >= %u\n",i,j,PriceCache[j][i],prevbits[i]);
break;
}
if ( j == HUSH_LOCALPRICE_CACHESIZE )
{
hush_queuelocalprice(1,nHeight,block->nTime,bhash,i,prevbits[i]);
break;
}
}
else if ( maxflag < 0 && localbits[i] > prevbits[i] )
{
if ( iter == 0 )
break;
for (j=0; j<HUSH_LOCALPRICE_CACHESIZE; j++)
if ( PriceCache[j][i] <= prevbits[i] )
{
fprintf(stderr,"i.%d within recent localprices[%d] %u <= prev %u\n",i,j,PriceCache[j][i],prevbits[i]);
break;
}
if ( j == HUSH_LOCALPRICE_CACHESIZE )
{
hush_queuelocalprice(-1,nHeight,block->nTime,bhash,i,prevbits[i]);
break;
}
}
}
}
if ( i != n )
{
if ( iter == 0 )
{
fprintf(stderr,"force update prices\n");
hush_cbopretupdate(1);
memcpy(localbits,Mineropret.data(),Mineropret.size());
} else return(-1);
}
}
}
}
if ( bhash == ExtremePrice.blockhash )
{
fprintf(stderr,"approved a previously extreme price based on new data ht.%d vs %u vs %u\n",ExtremePrice.height,ExtremePrice.timestamp,(uint32_t)block->nTime);
memset(&ExtremePrice,0,sizeof(ExtremePrice));
}
return(0);
} else fprintf(stderr,"wrong size %d vs %d, scriptPubKey size %d [%02x]\n",(int32_t)vopret.size(),(int32_t)Mineropret.size(),(int32_t)scriptPubKey.size(),scriptPubKey[0]);
return(-1);
}
return(0);
}
@@ -1382,18 +1146,7 @@ cJSON *get_urljson(char *url)
int32_t hush_cbopretsize(uint64_t flags)
{
int32_t size = 0;
if ( (ASSETCHAINS_CBOPRET & 1) != 0 )
{
size = PRICES_SIZEBIT0;
if ( (ASSETCHAINS_CBOPRET & 2) != 0 )
size += (sizeof(Forex)/sizeof(*Forex)) * sizeof(uint32_t);
if ( (ASSETCHAINS_CBOPRET & 4) != 0 )
size += (sizeof(Cryptos)/sizeof(*Cryptos) + ASSETCHAINS_PRICES.size()) * sizeof(uint32_t);
if ( (ASSETCHAINS_CBOPRET & 8) != 0 )
size += (ASSETCHAINS_STOCKS.size() * sizeof(uint32_t));
}
return(size);
return 0;
}
extern uint256 Queued_reconsiderblock;
@@ -1404,110 +1157,9 @@ void hush_cbopretupdate(int32_t forceflag)
int64_t hush_pricemult(int32_t ind)
{
int32_t i,j;
if ( (ASSETCHAINS_CBOPRET & 1) != 0 && ind < HUSH_MAXPRICES )
{
if ( PriceMult[0] == 0 )
{
for (i=0; i<4; i++)
PriceMult[i] = 10000;
if ( (ASSETCHAINS_CBOPRET & 2) != 0 )
{
for (j=0; j<sizeof(Forex)/sizeof(*Forex); j++)
PriceMult[i++] = 10000;
}
if ( (ASSETCHAINS_CBOPRET & 4) != 0 )
{
for (j=0; j<sizeof(Cryptos)/sizeof(*Cryptos)+ASSETCHAINS_PRICES.size(); j++)
PriceMult[i++] = 1;
}
if ( (ASSETCHAINS_CBOPRET & 8) != 0 )
{
for (j=0; j<ASSETCHAINS_STOCKS.size(); j++)
PriceMult[i++] = 1000000;
}
}
return(PriceMult[ind]);
}
return(0);
}
char *hush_pricename(char *name,int32_t ind)
{
strcpy(name,"error");
if ( (ASSETCHAINS_CBOPRET & 1) != 0 && ind < HUSH_MAXPRICES )
{
if ( ind < 4 )
{
switch ( ind )
{
case 0: strcpy(name,"timestamp"); break;
case 1: strcpy(name,"BTC_USD"); break;
case 2: strcpy(name,"BTC_GBP"); break;
case 3: strcpy(name,"BTC_EUR"); break;
default: return(0); break;
}
return(name);
}
else
{
ind -= 4;
if ( (ASSETCHAINS_CBOPRET & 2) != 0 )
{
if ( ind < 0 )
return(0);
if ( ind < sizeof(Forex)/sizeof(*Forex) )
{
name[0] = 'U', name[1] = 'S', name[2] = 'D', name[3] = '_';
strcpy(name+4,Forex[ind]);
return(name);
} else ind -= sizeof(Forex)/sizeof(*Forex);
}
if ( (ASSETCHAINS_CBOPRET & 4) != 0 )
{
if ( ind < 0 )
return(0);
if ( ind < sizeof(Cryptos)/sizeof(*Cryptos) + ASSETCHAINS_PRICES.size() )
{
if ( ind < sizeof(Cryptos)/sizeof(*Cryptos) )
strcpy(name,Cryptos[ind]);
else
{
ind -= (sizeof(Cryptos)/sizeof(*Cryptos));
strcpy(name,ASSETCHAINS_PRICES[ind].c_str());
}
strcat(name,"_BTC");
return(name);
} else ind -= (sizeof(Cryptos)/sizeof(*Cryptos) + ASSETCHAINS_PRICES.size());
}
if ( (ASSETCHAINS_CBOPRET & 8) != 0 )
{
if ( ind < 0 )
return(0);
if ( ind < ASSETCHAINS_STOCKS.size() )
{
strcpy(name,ASSETCHAINS_STOCKS[ind].c_str());
strcat(name,"_USD");
return(name);
} else ind -= ASSETCHAINS_STOCKS.size();
}
}
}
return(0);
}
// finds index for its symbol name
int32_t hush_priceind(const char *symbol)
{
char name[65]; int32_t i,n = (int32_t)(hush_cbopretsize(ASSETCHAINS_CBOPRET) / sizeof(uint32_t));
for (i=1; i<n; i++)
{
hush_pricename(name,i);
if ( strcmp(name,symbol) == 0 )
return(i);
}
return(-1);
}
// returns price value which is in a 10% interval for more than 50% points for the preceding 24 hours
int64_t hush_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int32_t rawskip,uint32_t *nonzprices,int32_t smoothwidth)
{
return(0);