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


C++ CBlock::SetBestChain方法代码示例

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


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

示例1: setbestblockbyheight

Value setbestblockbyheight(const Array& params, bool fHelp)
{
    if (fHelp || params.size() < 1 || params.size() > 2)
        throw runtime_error(
            "setbestblockbyheight <height>\n"
            "Sets the tip of the chain th block at <height>.");

    int nHeight = params[0].get_int();
    if (nHeight < 0 || nHeight > nBestHeight)
        throw runtime_error("Block height out of range.");
    
    if (nNodeMode == NT_THIN)
    {
        throw runtime_error("Must be in full mode.");
    };
    
    CBlock block;
    CBlockIndex* pblockindex = mapBlockIndex[hashBestChain];
    while (pblockindex->nHeight > nHeight)
        pblockindex = pblockindex->pprev;

    uint256 hash = *pblockindex->phashBlock;

    pblockindex = mapBlockIndex[hash];
    block.ReadFromDisk(pblockindex, true);
    
    
    Object result;
    
    CTxDB txdb;
    {
        LOCK(cs_main);
        
        if (!block.SetBestChain(txdb, pblockindex))
            result.push_back(Pair("result", "failure"));
        else
            result.push_back(Pair("result", "success"));
    
    };
    
    return result;
}
开发者ID:perfectcoin-project,项目名称:perfectcoin,代码行数:42,代码来源:rpcblockchain.cpp

示例2: AcceptPendingSyncCheckpoint

    bool AcceptPendingSyncCheckpoint()
    {
        LOCK(cs_hashSyncCheckpoint);
        if (hashPendingCheckpoint != 0 && mapBlockIndex.count(hashPendingCheckpoint))
        {
            if (!ValidateSyncCheckpoint(hashPendingCheckpoint))
            {
                hashPendingCheckpoint = 0;
                checkpointMessagePending.SetNull();
                return false;
            }

            CTxDB txdb;
            CBlockIndex* pindexCheckpoint = mapBlockIndex[hashPendingCheckpoint];
            if (!pindexCheckpoint->IsInMainChain())
            {
                CBlock block;
                if (!block.ReadFromDisk(pindexCheckpoint))
                    return error("AcceptPendingSyncCheckpoint: ReadFromDisk failed for sync checkpoint %s", hashPendingCheckpoint.ToString());
                if (!block.SetBestChain(txdb, pindexCheckpoint))
                {
                    hashInvalidCheckpoint = hashPendingCheckpoint;
                    return error("AcceptPendingSyncCheckpoint: SetBestChain failed for sync checkpoint %s", hashPendingCheckpoint.ToString());
                }
            }

            if (!WriteSyncCheckpoint(hashPendingCheckpoint))
                return error("AcceptPendingSyncCheckpoint(): failed to write sync checkpoint %s", hashPendingCheckpoint.ToString());
            hashPendingCheckpoint = 0;
            checkpointMessage = checkpointMessagePending;
            checkpointMessagePending.SetNull();
            LogPrintf("AcceptPendingSyncCheckpoint : sync-checkpoint at %s\n", hashSyncCheckpoint.ToString());
            // relay the checkpoint
            if (!checkpointMessage.IsNull())
            {
                BOOST_FOREACH(CNode* pnode, vNodes)
                    checkpointMessage.RelayTo(pnode);
            }
            return true;
        }
        return false;
    }
开发者ID:AdvancedStyle,项目名称:bxrewards,代码行数:42,代码来源:checkpoints.cpp

示例3: ResetSyncCheckpoint

    // ppcoin: reset synchronized checkpoint to last hardened checkpoint
    bool ResetSyncCheckpoint()
    {
        LOCK(cs_hashSyncCheckpoint);
        const uint256& hash = mapCheckpoints.rbegin()->second;
        if (mapBlockIndex.count(hash) && !mapBlockIndex[hash]->IsInMainChain())
        {
            // checkpoint block accepted but not yet in main chain
            LogPrintf("ResetSyncCheckpoint: SetBestChain to hardened checkpoint %s\n", hash.ToString());
            CTxDB txdb;
            CBlock block;
            if (!block.ReadFromDisk(mapBlockIndex[hash]))
                return error("ResetSyncCheckpoint: ReadFromDisk failed for hardened checkpoint %s", hash.ToString());
            if (!block.SetBestChain(txdb, mapBlockIndex[hash]))
            {
                return error("ResetSyncCheckpoint: SetBestChain failed for hardened checkpoint %s", hash.ToString());
            }
        }
        else if(!mapBlockIndex.count(hash))
        {
            // checkpoint block not yet accepted
            hashPendingCheckpoint = hash;
            checkpointMessagePending.SetNull();
            LogPrintf("ResetSyncCheckpoint: pending for sync-checkpoint %s\n", hashPendingCheckpoint.ToString());
        }

        BOOST_REVERSE_FOREACH(const MapCheckpoints::value_type& i, mapCheckpoints)
        {
            const uint256& hash = i.second;
            if (mapBlockIndex.count(hash) && mapBlockIndex[hash]->IsInMainChain())
            {
                if (!WriteSyncCheckpoint(hash))
                    return error("ResetSyncCheckpoint: failed to write sync checkpoint %s", hash.ToString());
                LogPrintf("ResetSyncCheckpoint: sync-checkpoint reset to %s\n", hashSyncCheckpoint.ToString());
                return true;
            }
        }

        if (!WriteSyncCheckpoint(Params().HashGenesisBlock()))
            return error("ResetSyncCheckpoint: failed to write sync checkpoint genesis block");
        LogPrintf("ResetSyncCheckpoint: sync-checkpoint reset to genesis block\n");
        return true;
    }
开发者ID:coinkeeper,项目名称:2015-04-19_21-52_cybercoin,代码行数:43,代码来源:checkpoints.cpp

示例4: rewindchain


//.........这里部分代码省略.........
            CAutoFile blkdat(fp, SER_DISK, CLIENT_VERSION);

            if (fseek(blkdat, fpos+foundPos, SEEK_SET) != 0)
            {
                LogPrintf("fseek blkdat failed: %s\n", strerror(errno));
                break;
            };

            unsigned int nSize;
            blkdat >> nSize;
            LogPrintf("nSize %u .\n", nSize);

            if (nSize < 1 || nSize > MAX_BLOCK_SIZE)
            {
                LogPrintf("block size error %u\n", nSize);

            };

            CBlock block;
            blkdat >> block;
            uint256 hashblock = block.GetHash();
            LogPrintf("hashblock %s .\n", hashblock.ToString().c_str());

            std::map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(hashblock);
            if (mi != mapBlockIndex.end() && (*mi).second)
            {
                LogPrintf("block is in main chain.\n");

                if (!mi->second->pprev)
                {
                    LogPrintf("! mi->second.pprev\n");
                } else
                {
                    {
                        CBlock blockPrev; // strange way SetBestChain works, TODO: does it need the full block?
                        if (!blockPrev.ReadFromDisk(mi->second->pprev))
                        {
                            LogPrintf("blockPrev.ReadFromDisk failed %s.\n", mi->second->pprev->GetBlockHash().ToString().c_str());
                            break;
                        };

                        CTxDB txdb;
                        if (!blockPrev.SetBestChain(txdb, mi->second->pprev))
                        {
                            LogPrintf("SetBestChain failed.\n");
                        };
                    }
                    mi->second->pprev->pnext = NULL;
                };

                delete mi->second;
                mapBlockIndex.erase(mi);
            };

            std::map<uint256, COrphanBlock*>::iterator miOph = mapOrphanBlocks.find(hashblock);
            if (miOph != mapOrphanBlocks.end())
            {
                LogPrintf("block is an orphan.\n");
                mapOrphanBlocks.erase(miOph);
            };

            CTxDB txdb;
            for (vector<CTransaction>::iterator it = block.vtx.begin(); it != block.vtx.end(); ++it)
            {
                LogPrintf("EraseTxIndex().\n");
                txdb.EraseTxIndex(*it);
            };

            LogPrintf("EraseBlockIndex().\n");
            txdb.EraseBlockIndex(hashblock);

            errno = 0;
            if (ftruncate(fileno(fp), fpos+foundPos-MESSAGE_START_SIZE) != 0)
            {
                LogPrintf("ftruncate failed: %s\n", strerror(errno));
            };

            LogPrintf("hashBestChain %s, nBestHeight %d\n", hashBestChain.ToString().c_str(), nBestHeight);

            //fclose(fp); // ~CAutoFile() will close the file
            nRemoved++;
        };
    }


    result.push_back(Pair("no. blocks removed", itostr(nRemoved)));

    result.push_back(Pair("hashBestChain", hashBestChain.ToString()));
    result.push_back(Pair("nBestHeight", itostr(nBestHeight)));

    // -- need restart, setStakeSeen etc
    if (nRemoved > 0)
        result.push_back(Pair("Please restart Taurus", ""));

    if (nRemoved == nNumber)
        result.push_back(Pair("result", "success"));
    else
        result.push_back(Pair("result", "failure"));
    return result;
}
开发者ID:tauruscrypto,项目名称:taurus,代码行数:101,代码来源:rpcblockchain.cpp


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