本文整理汇总了C++中CBlock::GetHeaderHash方法的典型用法代码示例。如果您正苦于以下问题:C++ CBlock::GetHeaderHash方法的具体用法?C++ CBlock::GetHeaderHash怎么用?C++ CBlock::GetHeaderHash使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CBlock
的用法示例。
在下文中一共展示了CBlock::GetHeaderHash方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: blockToJSON
Object blockToJSON(const CBlock& block, const CBlockIndex* blockindex)
{
Object result;
result.push_back(Pair("hash", block.GetHash().GetHex()));
CMerkleTx txGen(block.vtx[0]);
txGen.SetMerkleBranch(&block);
result.push_back(Pair("confirmations", (int)txGen.GetDepthInMainChain()));
result.push_back(Pair("size", (int)::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION)));
result.push_back(Pair("height", blockindex->nHeight));
result.push_back(Pair("version", block.nVersion));
result.push_back(Pair("headerhash", block.GetHeaderHash().GetHex()));
result.push_back(Pair("merkleroot", block.hashMerkleRoot.GetHex()));
Array txs;
BOOST_FOREACH(const CTransaction&tx, block.vtx)
txs.push_back(tx.GetHash().GetHex());
result.push_back(Pair("tx", txs));
result.push_back(Pair("time", (boost::int64_t)block.GetBlockTime()));
result.push_back(Pair("nonce", (boost::uint64_t)block.nNonce));
result.push_back(Pair("bits", HexBits(block.nBits)));
result.push_back(Pair("difficulty", GetPrimeDifficulty(block.nBits)));
result.push_back(Pair("transition", GetPrimeDifficulty(blockindex->nWorkTransition)));
CBigNum bnPrimeChainOrigin = CBigNum(block.GetHeaderHash()) * block.bnPrimeChainMultiplier;
result.push_back(Pair("primechain", GetPrimeChainName(blockindex->nPrimeChainType, blockindex->nPrimeChainLength).c_str()));
result.push_back(Pair("primeorigin", bnPrimeChainOrigin.ToString().c_str()));
if (blockindex->pprev)
result.push_back(Pair("previousblockhash", blockindex->pprev->GetBlockHash().GetHex()));
if (blockindex->pnext)
result.push_back(Pair("nextblockhash", blockindex->pnext->GetBlockHash().GetHex()));
return result;
}
示例2: listprimerecords
// pNut: list prime chain records within pnut network
Value listprimerecords(const Array& params, bool fHelp)
{
if (fHelp || params.size() < 1 || params.size() > 2)
throw runtime_error(
"listprimerecords <primechain length> [primechain type]\n"
"Returns the list of record prime chains in pnut network.\n"
"<primechain length> is integer like 10, 11, 12 etc.\n"
"[primechain type] is optional type, among 1CC, 2CC and TWN");
int nPrimeChainLength = params[0].get_int();
unsigned int nPrimeChainType = 0;
if (params.size() > 1)
{
std::string strPrimeChainType = params[1].get_str();
if (strPrimeChainType.compare("1CC") == 0)
nPrimeChainType = PRIME_CHAIN_CUNNINGHAM1;
else if (strPrimeChainType.compare("2CC") == 0)
nPrimeChainType = PRIME_CHAIN_CUNNINGHAM2;
else if (strPrimeChainType.compare("TWN") == 0)
nPrimeChainType = PRIME_CHAIN_BI_TWIN;
else
throw runtime_error("Prime chain type must be 1CC, 2CC or TWN.");
}
Array ret;
CBigNum bnPrimeRecord = 0;
for (CBlockIndex* pindex = pindexGenesisBlock; pindex; pindex = pindex->pnext)
{
if (nPrimeChainLength != (int) TargetGetLength(pindex->nPrimeChainLength))
continue; // length not matching, next block
if (nPrimeChainType && nPrimeChainType != pindex->nPrimeChainType)
continue; // type not matching, next block
CBlock block;
block.ReadFromDisk(pindex); // read block
CBigNum bnPrimeChainOrigin = CBigNum(block.GetHeaderHash()) * block.bnPrimeChainMultiplier; // compute prime chain origin
if (bnPrimeChainOrigin > bnPrimeRecord)
{
bnPrimeRecord = bnPrimeChainOrigin; // new record in pnut
Object entry;
entry.push_back(Pair("time", DateTimeStrFormat("%Y-%m-%d %H:%M:%S UTC", pindex->GetBlockTime()).c_str()));
entry.push_back(Pair("epoch", (boost::int64_t) pindex->GetBlockTime()));
entry.push_back(Pair("height", pindex->nHeight));
entry.push_back(Pair("ismine", pwalletMain->IsMine(block.vtx[0])));
CTxDestination address;
entry.push_back(Pair("mineraddress", (block.vtx[0].vout.size() > 1)? "multiple" : ExtractDestination(block.vtx[0].vout[0].scriptPubKey, address)? CBitcoinAddress(address).ToString().c_str() : "invalid"));
entry.push_back(Pair("primedigit", (int) bnPrimeChainOrigin.ToString().length()));
entry.push_back(Pair("primechain", GetPrimeChainName(pindex->nPrimeChainType, pindex->nPrimeChainLength).c_str()));
entry.push_back(Pair("primeorigin", bnPrimeChainOrigin.ToString().c_str()));
entry.push_back(Pair("primorialform", GetPrimeOriginPrimorialForm(bnPrimeChainOrigin).c_str()));
ret.push_back(entry);
}
}
return ret;
}
示例3: HandleRequest
//.........这里部分代码省略.........
etype = proto::Reply::STALE;
break;
}
if(share.length() < mCurrBlock.minshare()){
printf("ERROR: share.length too short.\n");
etype = proto::Reply::INVALID;
break;
}
uint256 merkleRoot;
merkleRoot.SetHex(share.merkle());
unsigned extraNonce = mNonceMap[merkleRoot];
if(!extraNonce){
etype = proto::Reply::STALE;
break;
}
unsigned nCandidateType = share.chaintype();
if(nCandidateType > 2){
printf("ERROR: share.chaintype invalid.\n");
etype = proto::Reply::INVALID;
break;
}
CBlock *pblock = &mBlockTemplate->block;
extraNonce--;
IncrementExtraNonce(pblock, mIndexPrev, extraNonce);
pblock->nTime = share.time();
pblock->nBits = share.bits();
pblock->nNonce = share.nonce();
uint256 headerHash = pblock->GetHeaderHash();
{
uint256 headerHashClient;
headerHashClient.SetHex(share.hash());
if(headerHashClient != headerHash){
printf("ERROR: headerHashClient != headerHash.\n");
etype = proto::Reply::INVALID;
break;
}
}
pblock->bnPrimeChainMultiplier.SetHex(share.multi());
uint256 blockhash = pblock->GetHash();
if(!mShares.insert(blockhash).second){
etype = proto::Reply::DUPLICATE;
break;
}
CBigNum bnChainOrigin = CBigNum(headerHash) * pblock->bnPrimeChainMultiplier;
unsigned int nChainLength = 0;
bool isblock = ProbablePrimeChainTestForMiner(bnChainOrigin, pblock->nBits, nCandidateType+1, nChainLength);
nChainLength = TargetGetLength(nChainLength);
if(nChainLength >= mCurrBlock.minshare()){
if(isblock)
isblock = CheckWork(pblock, *mWallet, mReserveKey);
if(share.length() != nChainLength){
printf("ERROR: share.length() != nChainLength.\n");
etype = proto::Reply::INVALID;
}
示例4: listtopprimes
// pNut: list top prime chain within pnut network
Value listtopprimes(const Array& params, bool fHelp)
{
if (fHelp || params.size() < 1 || params.size() > 2)
throw runtime_error(
"listtopprimes <primechain length> [primechain type]\n"
"Returns the list of top prime chains in pnut network.\n"
"<primechain length> is integer like 10, 11, 12 etc.\n"
"[primechain type] is optional type, among 1CC, 2CC and TWN");
int nPrimeChainLength = params[0].get_int();
unsigned int nPrimeChainType = 0;
if (params.size() > 1)
{
std::string strPrimeChainType = params[1].get_str();
if (strPrimeChainType.compare("1CC") == 0)
nPrimeChainType = PRIME_CHAIN_CUNNINGHAM1;
else if (strPrimeChainType.compare("2CC") == 0)
nPrimeChainType = PRIME_CHAIN_CUNNINGHAM2;
else if (strPrimeChainType.compare("TWN") == 0)
nPrimeChainType = PRIME_CHAIN_BI_TWIN;
else
throw runtime_error("Prime chain type must be 1CC, 2CC or TWN.");
}
// Search for top prime chains
unsigned int nRankingSize = 10; // ranking list size
unsigned int nSortVectorSize = 64; // vector size for sort operation
CBigNum bnPrimeQualify = 0; // minimum qualify value for ranking list
vector<pair<CBigNum, uint256> > vSortedByOrigin;
for (CBlockIndex* pindex = pindexGenesisBlock; pindex; pindex = pindex->pnext)
{
if (nPrimeChainLength != (int) TargetGetLength(pindex->nPrimeChainLength))
continue; // length not matching, next block
if (nPrimeChainType && nPrimeChainType != pindex->nPrimeChainType)
continue; // type not matching, next block
CBlock block;
block.ReadFromDisk(pindex); // read block
CBigNum bnPrimeChainOrigin = CBigNum(block.GetHeaderHash()) * block.bnPrimeChainMultiplier; // compute prime chain origin
if (bnPrimeChainOrigin > bnPrimeQualify)
vSortedByOrigin.push_back(make_pair(bnPrimeChainOrigin, block.GetHash()));
if (vSortedByOrigin.size() >= nSortVectorSize)
{
// Sort prime chain candidates
sort(vSortedByOrigin.begin(), vSortedByOrigin.end());
reverse(vSortedByOrigin.begin(), vSortedByOrigin.end());
// Truncate candidate list
while (vSortedByOrigin.size() > nRankingSize)
vSortedByOrigin.pop_back();
// Update minimum qualify value for top prime chains
bnPrimeQualify = vSortedByOrigin.back().first;
}
}
// Final sort of prime chain candidates
sort(vSortedByOrigin.begin(), vSortedByOrigin.end());
reverse(vSortedByOrigin.begin(), vSortedByOrigin.end());
// Truncate candidate list
while (vSortedByOrigin.size() > nRankingSize)
vSortedByOrigin.pop_back();
// Output top prime chains
Array ret;
BOOST_FOREACH(const PAIRTYPE(CBigNum, uint256)& item, vSortedByOrigin)
{
CBigNum bnPrimeChainOrigin = item.first;
CBlockIndex* pindex = mapBlockIndex[item.second];
CBlock block;
block.ReadFromDisk(pindex); // read block
Object entry;
entry.push_back(Pair("time", DateTimeStrFormat("%Y-%m-%d %H:%M:%S UTC", pindex->GetBlockTime()).c_str()));
entry.push_back(Pair("epoch", (boost::int64_t) pindex->GetBlockTime()));
entry.push_back(Pair("height", pindex->nHeight));
entry.push_back(Pair("ismine", pwalletMain->IsMine(block.vtx[0])));
CTxDestination address;
entry.push_back(Pair("mineraddress", (block.vtx[0].vout.size() > 1)? "multiple" : ExtractDestination(block.vtx[0].vout[0].scriptPubKey, address)? CBitcoinAddress(address).ToString().c_str() : "invalid"));
entry.push_back(Pair("primedigit", (int) bnPrimeChainOrigin.ToString().length()));
entry.push_back(Pair("primechain", GetPrimeChainName(pindex->nPrimeChainType, pindex->nPrimeChainLength).c_str()));
entry.push_back(Pair("primeorigin", bnPrimeChainOrigin.ToString().c_str()));
entry.push_back(Pair("primorialform", GetPrimeOriginPrimorialForm(bnPrimeChainOrigin).c_str()));
ret.push_back(entry);
}
return ret;
}