def check_compactblock_construction_from_block(self, version, header_and_shortids, block_hash, block):
    header_and_shortids.header.calc_sha256()
    assert_equal(header_and_shortids.header.sha256, block_hash)
    assert (len(header_and_shortids.prefilled_txn) >= 1)
    assert_equal(header_and_shortids.prefilled_txn[0].index, 0)
    for entry in header_and_shortids.prefilled_txn:
        entry.tx.calc_sha256()
        assert_equal(entry.tx.sha256, block.vtx[entry.index].sha256)
        wtxid = entry.tx.calc_sha256(True)
        if (version == 2):
            assert_equal(wtxid, block.vtx[entry.index].calc_sha256(True))
        else:
            assert entry.tx.wit.is_null()
    assert_equal((len(header_and_shortids.prefilled_txn) + len(header_and_shortids.shortids)), len(block.vtx))
    [k0, k1] = header_and_shortids.get_siphash_keys()
    index = 0
    while (index < len(block.vtx)):
        if ((len(header_and_shortids.prefilled_txn) > 0) and (header_and_shortids.prefilled_txn[0].index == index)):
            header_and_shortids.prefilled_txn.pop(0)
        else:
            tx_hash = block.vtx[index].sha256
            if (version == 2):
                tx_hash = block.vtx[index].calc_sha256(True)
            shortid = calculate_shortid(k0, k1, tx_hash)
            assert_equal(shortid, header_and_shortids.shortids[0])
            header_and_shortids.shortids.pop(0)
        index += 1
def check_compactblock_construction_from_block(self, version, header_and_shortids, block_hash, block):
    header_and_shortids.header.calc_sha256()
    assert_equal(header_and_shortids.header.sha256, block_hash)
    assert (len(header_and_shortids.prefilled_txn) >= 1)
    assert_equal(header_and_shortids.prefilled_txn[0].index, 0)
    for entry in header_and_shortids.prefilled_txn:
        entry.tx.calc_sha256()
        assert_equal(entry.tx.sha256, block.vtx[entry.index].sha256)
        wtxid = entry.tx.calc_sha256(True)
        if (version == 2):
            assert_equal(wtxid, block.vtx[entry.index].calc_sha256(True))
        else:
            assert entry.tx.wit.is_null()
    assert_equal((len(header_and_shortids.prefilled_txn) + len(header_and_shortids.shortids)), len(block.vtx))
    [k0, k1] = header_and_shortids.get_siphash_keys()
    index = 0
    while (index < len(block.vtx)):
        if ((len(header_and_shortids.prefilled_txn) > 0) and (header_and_shortids.prefilled_txn[0].index == index)):
            header_and_shortids.prefilled_txn.pop(0)
        else:
            tx_hash = block.vtx[index].sha256
            if (version == 2):
                tx_hash = block.vtx[index].calc_sha256(True)
            shortid = calculate_shortid(k0, k1, tx_hash)
            assert_equal(shortid, header_and_shortids.shortids[0])
            header_and_shortids.shortids.pop(0)
        index += 1