Exemplo n.º 1
0
CBlock ThinBlockBuilder::finishBlock() {
    if (numTxsMissing())
        throw thinblock_error("TXs missing. Can't build thin block.");

    for (size_t i = 0; i < thinBlock.vtx.size(); ++i)
        assert(!thinBlock.vtx[i].IsNull());

    bool dummy;
    const uint256& root = thinBlock.BuildMerkleTree(&dummy);


    if (root != thinBlock.hashMerkleRoot) {
        std::stringstream ss;
        ss << "Consistency check failure on attempt to reconstruct thin block. "
            << "Expected merkele root hash " << thinBlock.hashMerkleRoot.ToString()
            << ", got " << root.ToString();
        throw thinblock_error(ss.str());
    }

    LogPrintf("reassembled thin block for %s (%d bytes)\n",
            thinBlock.GetHash().ToString(),
            thinBlock.GetSerializeSize(SER_NETWORK, CBlock::CURRENT_VERSION));


    CBlock block = thinBlock;
    reset();
    return block;
}
Exemplo n.º 2
0
std::vector<uint256> ThinBlockBuilder::getHashes(const CMerkleBlock& m) const {

    std::vector<uint256> txHashes;
    // FIXME: Calculate a sane number of max
    // transactions here, or skip the check.
    uint256 merkleRoot = CMerkleBlock(m).txn.ExtractMatches(txHashes);
    if (m.header.hashMerkleRoot != merkleRoot)
        throw thinblock_error("Failed to match Merkle root or bad tree in thin block");

    return txHashes;
}
Exemplo n.º 3
0
std::vector<ThinTx> ThinBloomStub::allTransactions() const {
    std::vector<uint256> txHashes;

    // Has a side effect of validating the MerkeleBlock hash
    // and can throw a thinblock_error
    uint256 merkleRoot = CMerkleBlock(merkleblock).txn.ExtractMatches(txHashes);
    if (merkleblock.header.hashMerkleRoot != merkleRoot)
        throw thinblock_error("Failed to match Merkle root or bad tree in thin block");

    return std::vector<ThinTx>(txHashes.begin(), txHashes.end());
}