当前位置: 首页>>代码示例>>C++>>正文


C++ BlockIterator::height方法代码示例

本文整理汇总了C++中BlockIterator::height方法的典型用法代码示例。如果您正苦于以下问题:C++ BlockIterator::height方法的具体用法?C++ BlockIterator::height怎么用?C++ BlockIterator::height使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BlockIterator的用法示例。


在下文中一共展示了BlockIterator::height方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: proofOfWorkLimit

int TestNet3Chain::nextWorkRequired(BlockIterator blk) const {
    const int64_t nTargetTimespan = 14 * 24 * 60 * 60; // two weeks
    const int64_t nTargetSpacing = 10 * 60;
    const int64_t nInterval = nTargetTimespan / nTargetSpacing;
    
    // Genesis block
    int h = blk.height();
    if (h == 0) // trick to test that it is asking for the genesis block
        return proofOfWorkLimit().GetCompact();
    
    // Only change once per interval
    if ((h + 1) % nInterval != 0) {
        // Return the last non-special-min-difficulty-rules-block
        while (blk.height() % nInterval != 0 && blk->bits == proofOfWorkLimit().GetCompact())
            blk--;
        return blk->bits;
    }
    
    // Go back by what we want to be 14 days worth of blocks
    BlockIterator former = blk - (nInterval-1);
    
    // Limit adjustment step
    int nActualTimespan = blk->time - former->time;
    log_debug("  nActualTimespan = %"PRI64d"  before bounds", nActualTimespan);
    if (nActualTimespan < nTargetTimespan/4)
        nActualTimespan = nTargetTimespan/4;
    if (nActualTimespan > nTargetTimespan*4)
        nActualTimespan = nTargetTimespan*4;
    
    // Retarget
    CBigNum bnNew;
    bnNew.SetCompact(blk->bits);
    bnNew *= nActualTimespan;
    bnNew /= nTargetTimespan;
    
    if (bnNew > proofOfWorkLimit())
        bnNew = proofOfWorkLimit();
    
    /// debug print
    log_info("GetNextWorkRequired RETARGET");
    log_info("\tnTargetTimespan = %"PRI64d"    nActualTimespan = %"PRI64d"", nTargetTimespan, nActualTimespan);
    log_info("\tBefore: %08x  %s", blk->bits, CBigNum().SetCompact(blk->bits).getuint256().toString().c_str());
    log_info("\tAfter:  %08x  %s", bnNew.GetCompact(), bnNew.getuint256().toString().c_str());
    
    return bnNew.GetCompact();
}
开发者ID:snowlab,项目名称:libcoin,代码行数:46,代码来源:Chain.cpp

示例2: nextWorkRequired

int LitecoinChain::nextWorkRequired(BlockIterator blk) const {
    const int64_t nTargetTimespan = 3.5 * 24 * 60 * 60; // two weeks
    const int64_t nTargetSpacing = 2.5 * 60;
    const int64_t nInterval = nTargetTimespan / nTargetSpacing;
    
    // Genesis block
    int h = blk.height();
    if (h == 0) // trick to test that it is asking for the genesis block
        return _genesisBlock.getBits(); // proofOfWorkLimit().GetCompact(); Actually not for the genesisblock - here it is 0x1e0ffff0, not 0x1e0fffff
    
    // Only change once per interval
    if ((h + 1) % nInterval != 0)
        return blk->bits;
    
    // Litecoin: This fixes an issue where a 51% attack can change difficulty at will.
    // Go back the full period unless it's the first retarget after genesis. Code courtesy of Art Forz
    int blockstogoback = nInterval-1;
    if ((h + 1) != nInterval)
        blockstogoback = nInterval;
    
    // Go back by what we want to be 3.5 days worth of blocks
    BlockIterator former = blk - blockstogoback;
    
    // Limit adjustment step
    int nActualTimespan = blk->time - former->time;
    log_debug("  nActualTimespan = %"PRI64d"  before bounds", nActualTimespan);
    if (nActualTimespan < nTargetTimespan/4)
        nActualTimespan = nTargetTimespan/4;
    if (nActualTimespan > nTargetTimespan*4)
        nActualTimespan = nTargetTimespan*4;
    
    // Retarget
    CBigNum bnNew;
    bnNew.SetCompact(blk->bits);
    bnNew *= nActualTimespan;
    bnNew /= nTargetTimespan;
    
    if (bnNew > proofOfWorkLimit())
        bnNew = proofOfWorkLimit();
    
    /// debug print
    log_info("GetNextWorkRequired RETARGET");
    log_info("\tnTargetTimespan = %"PRI64d"    nActualTimespan = %"PRI64d"", nTargetTimespan, nActualTimespan);
    log_info("\tBefore: %08x  %s", blk->bits, CBigNum().SetCompact(blk->bits).getuint256().toString().c_str());
    log_info("\tAfter:  %08x  %s", bnNew.GetCompact(), bnNew.getuint256().toString().c_str());
    
    return bnNew.GetCompact();
}
开发者ID:snowlab,项目名称:libcoin,代码行数:48,代码来源:Chain.cpp

示例3: operator

Value GetBlock::operator()(const Array& params, bool fHelp) {
    if (fHelp || params.size() != 1)
        throw RPC::error(RPC::invalid_params, "getblock <hash>\n"
                            "Returns details of a block with given block-hash.");
    
    std::string strHash = params[0].get_str();
    uint256 hash(strHash);
    
    BlockIterator blk = _node.blockChain().iterator(hash);
    
    Block block;
    _node.blockChain().getBlock(hash, block);
    
    if (block.isNull())
        throw RPC::error(RPC::invalid_request,  "Block not found");
        
    Object result;
    result.push_back(Pair("hash", blk->hash.GetHex()));
    result.push_back(Pair("blockcount", blk.height()));
    result.push_back(Pair("version", block.getVersion()));
    result.push_back(Pair("merkleroot", block.getMerkleRoot().GetHex()));
    result.push_back(Pair("time", (boost::int64_t)block.getBlockTime()));
    result.push_back(Pair("nonce", (boost::uint64_t)block.getNonce()));
    result.push_back(Pair("difficulty", _node.blockChain().getDifficulty(blk)));
    Array txhashes;
    BOOST_FOREACH (const Transaction&tx, block.getTransactions())
    txhashes.push_back(tx.getHash().GetHex());
    
    result.push_back(Pair("tx", txhashes));

    BlockIterator prev = blk + 1;
    BlockIterator next = blk - 1;
    if (!!prev)
        result.push_back(Pair("hashprevious", prev->hash.GetHex()));
    if (!!next )
        result.push_back(Pair("hashnext", next->hash.GetHex()));
    
    return result;
}        
开发者ID:JeremyRand2,项目名称:libcoin,代码行数:39,代码来源:NodeRPC.cpp


注:本文中的BlockIterator::height方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。