Repository: bitcoin/bitcoin
File: src/util/transaction_identifier.h (C/C++)

Code before:
    constexpr const std::byte* end() const { return reinterpret_cast<const std::byte*>(m_wrapped.end()); }
    template <typename Stream> void Serialize(Stream& s) const { m_wrapped.Serialize(s); }
    template <typename Stream> void Unserialize(Stream& s) { m_wrapped.Unserialize(s); }

    /** Conversion function to `uint256`.
     *
     * Note: new code should use `ToUint256`.
     *
     * TODO: This should be removed once the majority of the code has switched
     * to using the Txid and Wtxid types. Until then it makes for a smoother
     * transition to allow this conversion. */
    operator const uint256&() const LIFETIMEBOUND { return m_wrapped; }
};

/** Txid commits to all transaction fields except the witness. */
using Txid = transaction_identifier<false>;
/** Wtxid commits to all transaction fields including the witness. */
using Wtxid = transaction_identifier<true>;

inline Txid TxidFromString(std::string_view str)
{
    return Txid::FromUint256(uint256S(str));
}

#endif // BITCOIN_UTIL_TRANSACTION_IDENTIFIER_H


Review comment (suggestion):
We might as well use the `[[deprecated]]` attribute instead:
```suggestion
[[deprecated("Missing length-check and hex-check, please use the safer SetHex, or FromUint256")]]
```

Resulting in compilation warnings for the remaining usages:

> bitcoin/src/qt/coincontroldialog.cpp:345:25: warning: 'TxidFromString' is deprecated: Missing length-check and hex-check, please use the safer SetHex, or FromUint256 [-Wdeprecated-declarations]
        COutPoint outpt(TxidFromString(item->data(COLUMN_ADDRESS, TxHashRole).toString().toStdString()), item->data(COLUMN_ADDRESS, VOutRole).toUInt());

Code after:
    }
    std::string GetHex() const { return m_wrapped.GetHex(); }
    std::string ToString() const { return m_wrapped.ToString(); }
    static constexpr auto size() { return decltype(m_wrapped)::size(); }
    constexpr const std::byte* data() const { return reinterpret_cast<const std::byte*>(m_wrapped.data()); }
    constexpr const std::byte* begin() const { return reinterpret_cast<const std::byte*>(m_wrapped.begin()); }
    constexpr const std::byte* end() const { return reinterpret_cast<const std::byte*>(m_wrapped.end()); }
    template <typename Stream> void Serialize(Stream& s) const { m_wrapped.Serialize(s); }
    template <typename Stream> void Unserialize(Stream& s) { m_wrapped.Unserialize(s); }

    /** Conversion function to `uint256`.
     *
     * Note: new code should use `ToUint256`.
     *
     * TODO: This should be removed once the majority of the code has switched
     * to using the Txid and Wtxid types. Until then it makes for a smoother
     * transition to allow this conversion. */
    operator const uint256&() const LIFETIMEBOUND { return m_wrapped; }
};

/** Txid commits to all transaction fields except the witness. */
using Txid = transaction_identifier<false>;
/** Wtxid commits to all transaction fields including the witness. */
using Wtxid = transaction_identifier<true>;

/** DEPRECATED due to missing length-check and hex-check, please use the safer FromHex, or FromUint256 */
inline Txid TxidFromString(std::string_view str)
{
    return Txid::FromUint256(uint256S(str));
}

#endif // BITCOIN_UTIL_TRANSACTION_IDENTIFIER_H