本文整理汇总了C++中CBigNum::SetHex方法的典型用法代码示例。如果您正苦于以下问题:C++ CBigNum::SetHex方法的具体用法?C++ CBigNum::SetHex怎么用?C++ CBigNum::SetHex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CBigNum
的用法示例。
在下文中一共展示了CBigNum::SetHex方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadCheckpoints
bool LoadCheckpoints(const std::string& strNetwork)
{
UniValue v;
if (strNetwork == "main")
v = read_json(GetMainCheckpoints());
else if (strNetwork == "test")
v = read_json(GetTestCheckpoints());
else if (strNetwork == "regtest")
v = read_json(GetRegTestCheckpoints());
else
return false;
if (v.empty())
return false;
for (unsigned int idx = 0; idx < v.size(); idx++) {
const UniValue &val = v[idx];
const UniValue &o = val.get_obj();
const UniValue &vHeight = find_value(o, "height");
if (!vHeight.isNum())
return false;
int nHeight = vHeight.get_int();
if (nHeight < 0)
return false;
Checkpoint checkpoint;
for (auto denom : libzerocoin::zerocoinDenomList) {
const UniValue& vDenomValue = find_value(o, std::to_string(denom));
if (!vDenomValue.isStr()) {
return false;
}
CBigNum bn = 0;
bn.SetHex(vDenomValue.get_str());
checkpoint.insert(std::make_pair(denom, bn));
}
mapCheckpoints.insert(make_pair(nHeight, checkpoint));
}
return true;
}
示例2: BitcoinMiner2_mineProbableChain
//.........这里部分代码省略.........
mpz_mul_ui(mpzChainOrigin.get_mpz_t(), mpzFinalFixedMultiplier.get_mpz_t(), multiplier);
nChainLengthCunningham1 = 0;
nChainLengthCunningham2 = 0;
nChainLengthBiTwin = 0;
bool canSubmitAsShare = ProbablePrimeChainTestFast2(mpzChainOrigin, testParams, sieveFlags, multiplier);
nProbableChainLength = max(max(nChainLengthCunningham1, nChainLengthCunningham2), nChainLengthBiTwin);
if( nProbableChainLength >= 0x01000000 )
debugStats_primes++;
debugStats_multipliersTested++;
//bool canSubmitAsShare = ProbablePrimeChainTestFast(mpzChainOrigin, testParams);
//CBigNum bnChainOrigin;
//bnChainOrigin.SetHex(mpzChainOrigin.get_str(16));
//bool canSubmitAsShare = ProbablePrimeChainTestBN(bnChainOrigin, block->serverData.nBitsForShare, false, nChainLengthCunningham1, nChainLengthCunningham2, nChainLengthBiTwin);
if( nProbableChainLength >= 0x04000000 )
{
sint32 chainDif = (nProbableChainLength>>24) - 7;
primeStats.nChainHit += pow(8, (float)chainDif);
//primeStats.nChainHit += pow(8, ((float)((double)nProbableChainLength / (double)0x1000000))-7.0);
//primeStats.nChainHit += pow(8, floor((float)((double)nProbableChainLength / (double)0x1000000)) - 7);
nTests = 0;
primeStats.fourChainCount ++;
if (nProbableChainLength >= 0x5000000)
{
primeStats.fiveChainCount ++;
if (nProbableChainLength >= 0x6000000)
{
primeStats.sixChainCount ++;
if (nProbableChainLength >= 0x7000000)
primeStats.sevenChainCount ++;
}
}
}
//if( nBitsGen >= 0x03000000 )
// printf("%08X\n", nBitsGen);
primeStats.primeChainsFound++;
//if( nProbableChainLength > 0x03000000 )
// primeStats.qualityPrimesFound++;
if( nProbableChainLength > primeStats.bestPrimeChainDifficulty )
primeStats.bestPrimeChainDifficulty = nProbableChainLength;
if(nProbableChainLength >= block->serverData.nBitsForShare)
{
// note: mpzPrimeChainMultiplier does not include the blockHash multiplier
mpz_div(block->mpzPrimeChainMultiplier.get_mpz_t(), mpzChainOrigin.get_mpz_t(), mpzHash.get_mpz_t());
//mpz_lsh(block->mpzPrimeChainMultiplier.get_mpz_t(), mpzFixedMultiplier.get_mpz_t(), multiplier);
// update server data
block->serverData.client_shareBits = nProbableChainLength;
// generate block raw data
uint8 blockRawData[256] = {0};
memcpy(blockRawData, block, 80);
uint32 writeIndex = 80;
sint32 lengthBN = 0;
CBigNum bnPrimeChainMultiplier;
bnPrimeChainMultiplier.SetHex(block->mpzPrimeChainMultiplier.get_str(16));
std::vector<unsigned char> bnSerializeData = bnPrimeChainMultiplier.getvch();
lengthBN = bnSerializeData.size();
*(uint8*)(blockRawData+writeIndex) = (uint8)lengthBN; // varInt (we assume it always has a size low enough for 1 byte)
writeIndex += 1;
memcpy(blockRawData+writeIndex, &bnSerializeData[0], lengthBN);
writeIndex += lengthBN;
// switch endianness
for(uint32 f=0; f<256/4; f++)
{
*(uint32*)(blockRawData+f*4) = _swapEndianessU32(*(uint32*)(blockRawData+f*4));
}
time_t now = time(0);
struct tm * timeinfo;
timeinfo = localtime (&now);
char sNow [80];
strftime (sNow, 80, "%x - %X",timeinfo);
printf("%s - SHARE FOUND !!! (Th#: %u Multiplier: %d Layer: %d) --- DIFF: %f %s %s\n",
sNow, threadIndex, multiplier, cSieve->currentSieveLayerIdx, (float)((double)nProbableChainLength / (double)0x1000000),
nProbableChainLength >= 0x6000000 ? ">6":"", nProbableChainLength >= 0x7000000 ? ">7":"");
// submit this share
if (jhMiner_pushShare_primecoin(blockRawData, block))
primeStats.foundShareCount ++;
//printf("Probable prime chain found for block=%s!!\n Target: %s\n Length: (%s %s %s)\n", block.GetHash().GetHex().c_str(),TargetToString(block.nBits).c_str(), TargetToString(nChainLengthCunningham1).c_str(), TargetToString(nChainLengthCunningham2).c_str(), TargetToString(nChainLengthBiTwin).c_str());
//nProbableChainLength = max(max(nChainLengthCunningham1, nChainLengthCunningham2), nChainLengthBiTwin);
// since we are using C structs here we have to make sure the memory for the CBigNum in the block is freed again
//delete *psieve;
//*psieve = NULL;
//block->bnPrimeChainMultiplier = NULL;
RtlZeroMemory(blockRawData, 256);
//delete *psieve;
//*psieve = NULL;
// dont quit if we find a share, there could be other shares in the remaining prime candidates
nTests = 0; // tehere is a good chance to find more shares so search a litle more.
//block->nonce++;
//return true;
//break;
//if (multipleShare)
}
}