Repository: bitcoin/bitcoin
File: src/wallet/migrate.cpp (C++)

Code before:
            throw std::runtime_error("Unsupported BDB data file version number");
        }

        // Page size must be 512 <= pagesize <= 64k, and be a power of 2
        if (pagesize < 512 || pagesize > 65536 || (pagesize & (pagesize - 1)) != 0) {
            throw std::runtime_error("Bad page size");
        }

        // Page type must be the btree type
        if (type != PageType::BTREE_META) {
            throw std::runtime_error("Unexpected page type, should be 9 (BTree Metadata)");
        }

        // Only supported meta-flag is subdatabase
        if (flags != BTreeFlags::SUBDB) {
            throw std::runtime_error("Unexpected database flags, should only be 0x20 (subdatabases)");
        }
    }
};

/** General class for records in a BDB BTree database. Contains common fields. */
class RecordHeader
{
public:
    uint16_t len;    // Key/data item length
    RecordType type; // Page type (BDB has this include a DELETE_FLAG that we track separately)
    bool deleted;    // Whether the DELETE_FLAG was set on type

    static constexpr size_t SIZE = 3; // The record header is 3 bytes

    bool other_endian;

    RecordHeader(bool other_endian) : other_endian(other_endian) {}
    RecordHeader() = delete;

    template <typename Stream>
    void Unserialize(Stream& s)
    {
        s >> len;

        uint8_t uint8_type;
        s >> uint8_type;
        type = static_cast<RecordType>(uint8_type & ~static_cast<uint8_t>(RecordType::DELETE_FLAG));
        deleted = uint8_type & static_cast<uint8_t>(RecordType::DELETE_FLAG);

        if (other_endian) {
            len = internal_bswap_16(len);
        }
    }
};


Review comment (suggestion):
```suggestion
    RecordType type; // Page type (BDB has this; includes a DELETE_FLAG that we track separately)
```

llm typo nit

Code after:
            throw std::runtime_error("Unsupported BDB data file version number");
        }

        // Page size must be 512 <= pagesize <= 64k, and be a power of 2
        if (pagesize < 512 || pagesize > 65536 || (pagesize & (pagesize - 1)) != 0) {
            throw std::runtime_error("Bad page size");
        }

        // Page type must be the btree type
        if (type != PageType::BTREE_META) {
            throw std::runtime_error("Unexpected page type, should be 9 (BTree Metadata)");
        }

        // Only supported meta-flag is subdatabase
        if (flags != BTreeFlags::SUBDB) {
            throw std::runtime_error("Unexpected database flags, should only be 0x20 (subdatabases)");
        }
    }
};

/** General class for records in a BDB BTree database. Contains common fields. */
class RecordHeader
{
public:
    uint16_t len;    // Key/data item length
    RecordType type; // Page type (BDB has this; includes a DELETE_FLAG that we track separately)
    bool deleted;    // Whether the DELETE_FLAG was set on type

    static constexpr size_t SIZE = 3; // The record header is 3 bytes

    bool other_endian;

    RecordHeader(bool other_endian) : other_endian(other_endian) {}
    RecordHeader() = delete;

    template <typename Stream>
    void Unserialize(Stream& s)
    {
        s >> len;

        uint8_t uint8_type;
        s >> uint8_type;
        type = static_cast<RecordType>(uint8_type & ~static_cast<uint8_t>(RecordType::DELETE_FLAG));
        deleted = uint8_type & static_cast<uint8_t>(RecordType::DELETE_FLAG);

        if (other_endian) {
            len = internal_bswap_16(len);
        }
    }
};