本文整理汇总了C++中CBlockIndex::MintedDenomination方法的典型用法代码示例。如果您正苦于以下问题:C++ CBlockIndex::MintedDenomination方法的具体用法?C++ CBlockIndex::MintedDenomination怎么用?C++ CBlockIndex::MintedDenomination使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CBlockIndex
的用法示例。
在下文中一共展示了CBlockIndex::MintedDenomination方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GenerateAccumulatorWitness
bool GenerateAccumulatorWitness(const PublicCoin &coin, Accumulator& accumulator, AccumulatorWitness& witness, int nSecurityLevel, int& nMintsAdded, string& strError)
{
uint256 txid;
if (!zerocoinDB->ReadCoinMint(coin.getValue(), txid)) {
LogPrint("zero","%s failed to read mint from db\n", __func__);
return false;
}
CTransaction txMinted;
uint256 hashBlock;
if (!GetTransaction(txid, txMinted, hashBlock)) {
LogPrint("zero","%s failed to read tx\n", __func__);
return false;
}
int nHeightMintAdded= mapBlockIndex[hashBlock]->nHeight;
uint256 nCheckpointBeforeMint = 0;
CBlockIndex* pindex = chainActive[nHeightMintAdded];
int nChanges = 0;
//find the checksum when this was added to the accumulator officially, which will be two checksum changes later
//reminder that checksums are generated when the block height is a multiple of 10
while (pindex->nHeight < chainActive.Tip()->nHeight - 1) {
if (pindex->nHeight == nHeightMintAdded) {
pindex = chainActive[pindex->nHeight + 1];
continue;
}
//check if the next checksum was generated
if (pindex->nHeight % 10 == 0) {
nChanges++;
if (nChanges == 1) {
nCheckpointBeforeMint = pindex->nAccumulatorCheckpoint;
break;
}
}
pindex = chainActive.Next(pindex);
}
//the height to start accumulating coins to add to witness
int nAccStartHeight = nHeightMintAdded - (nHeightMintAdded % 10);
//If the checkpoint is from the recalculated checkpoint period, then adjust it
int nHeight_LastGoodCheckpoint = Params().Zerocoin_Block_LastGoodCheckpoint();
int nHeight_Recalculate = Params().Zerocoin_Block_RecalculateAccumulators();
if (pindex->nHeight < nHeight_Recalculate - 10 && pindex->nHeight > nHeight_LastGoodCheckpoint) {
//The checkpoint before the mint will be the last good checkpoint
nCheckpointBeforeMint = chainActive[nHeight_LastGoodCheckpoint]->nAccumulatorCheckpoint;
nAccStartHeight = nHeight_LastGoodCheckpoint - 10;
}
//Get the accumulator that is right before the cluster of blocks containing our mint was added to the accumulator
CBigNum bnAccValue = 0;
if (GetAccumulatorValueFromDB(nCheckpointBeforeMint, coin.getDenomination(), bnAccValue)) {
if (bnAccValue > 0) {
accumulator.setValue(bnAccValue);
witness.resetValue(accumulator, coin);
}
}
//security level: this is an important prevention of tracing the coins via timing. Security level represents how many checkpoints
//of accumulated coins are added *beyond* the checkpoint that the mint being spent was added too. If each spend added the exact same
//amounts of checkpoints after the mint was accumulated, then you could know the range of blocks that the mint originated from.
if (nSecurityLevel < 100) {
//add some randomness to the user's selection so that it is not always the same
nSecurityLevel += CBigNum::randBignum(10).getint();
//security level 100 represents adding all available coins that have been accumulated - user did not select this
if (nSecurityLevel >= 100)
nSecurityLevel = 99;
}
//add the pubcoins (zerocoinmints that have been published to the chain) up to the next checksum starting from the block
pindex = chainActive[nAccStartHeight];
int nChainHeight = chainActive.Height();
int nHeightStop = nChainHeight % 10;
nHeightStop = nChainHeight - nHeightStop - 20; // at least two checkpoints deep
int nCheckpointsAdded = 0;
nMintsAdded = 0;
while (pindex->nHeight < nHeightStop + 1) {
if (pindex->nHeight != nAccStartHeight && pindex->pprev->nAccumulatorCheckpoint != pindex->nAccumulatorCheckpoint)
++nCheckpointsAdded;
//if a new checkpoint was generated on this block, and we have added the specified amount of checkpointed accumulators,
//then initialize the accumulator at this point and break
if (!InvalidCheckpointRange(pindex->nHeight) && (pindex->nHeight >= nHeightStop || (nSecurityLevel != 100 && nCheckpointsAdded >= nSecurityLevel))) {
uint32_t nChecksum = ParseChecksum(chainActive[pindex->nHeight + 10]->nAccumulatorCheckpoint, coin.getDenomination());
CBigNum bnAccValue = 0;
if (!zerocoinDB->ReadAccumulatorValue(nChecksum, bnAccValue)) {
LogPrintf("%s : failed to find checksum in database for accumulator\n", __func__);
return false;
}
accumulator.setValue(bnAccValue);
break;
}
// if this block contains mints of the denomination that is being spent, then add them to the witness
if (pindex->MintedDenomination(coin.getDenomination())) {
//grab mints from this block
//.........这里部分代码省略.........