示例#1
0
文件: Schema.cpp 项目: ciphrex/mSIGNA
void BlockHeader::fromCoinCore(const Coin::CoinBlockHeader& blockheader, uint32_t height)
{
    hash_ = blockheader.hash();
    height_ = height;
    version_ = blockheader.version();
    prevhash_ = blockheader.prevBlockHash();
    merkleroot_ = blockheader.merkleRoot();
    timestamp_ = blockheader.timestamp();
    bits_ = blockheader.bits();
    nonce_ = blockheader.nonce();
}
示例#2
0
bool CoinQBlockTreeMem::insertHeader(const Coin::CoinBlockHeader& header, bool bCheckProofOfWork, bool bReplaceTip)
{
    if (mHeaderHashMap.size() == 0) throw std::runtime_error("No genesis block.");

    uchar_vector headerHash = header.hash();
    if (hasHeader(headerHash)) return false;

    header_hash_map_t::iterator it = mHeaderHashMap.find(header.prevBlockHash());
    if (it == mHeaderHashMap.end()) throw std::runtime_error("Parent not found.");

    ChainHeader& parent = it->second;

    // TODO: Check version, compute work required.

    // Check timestamp
/*    if (bCheckTimestamp && header.timestamp > time(NULL) + 2 * 60 * 60) {
        throw std::runtime_error("Timestamp too far in the future.");
    }*/

    // Check proof of work
    if (bCheckProofOfWork && BigInt(header.getPOWHashLittleEndian()) > header.getTarget()) throw std::runtime_error("Header hash is too big.");

    ChainHeader& chainHeader = mHeaderHashMap[headerHash] = header;
    chainHeader.height = parent.height + 1;
    chainHeader.chainWork = parent.chainWork + chainHeader.getWork();
    parent.childHashes.insert(headerHash);
    notifyInsert(chainHeader);

    if ((bReplaceTip && chainHeader.chainWork >= mTotalWork) || chainHeader.chainWork > mTotalWork)
    {
        setBestChain(chainHeader);
    }

    bFlushed = false;
    return true;
}