Skip to content

Add "flags" capability to streams #19477

@vasild

Description

@vasild

Is your feature request related to a problem? Please describe.

Currently the streams (e.g. CDataStream, CVectorWriter) classes use a "protocol version" which defines how something should be written to or read from the stream.

This is not flexible enough because in some cases the content does not depend on the protocol, but depends on other things. In order to workaround this limitation the code is sneaking some constants into the "protocol version" to tune the (un)serialize behavior. Two examples:

  1. SERIALIZE_TRANSACTION_NO_WITNESS - to control whether witnesses should be present or not.

  2. ADDRv2_FORMAT (from Implement ADDRv2 support (part of BIP155) #19031, not yet merged at the time of writing) to control whether addresses should be (un)serialized in ADDRv2/BIP155 format.

This is problematic because once such a constant is bitwise-OR-ed into the protocol version then code that checks for a particular version becomes invalid, e.g. version == SENDHEADERS_VERSION or version > CADDR_TIME_VERSION. Also, it is outright confusing.

Describe the solution you'd like

Introduce "flags" to the streams, mimicking iostream::setf(), independent from the "protocol version". And manipulate them like:

s.SetFlag(SERIALIZE_TRANSACTION_NO_WITNESS)
s.RemoveFlag(SERIALIZE_TRANSACTION_NO_WITNESS)
s.IsFlagSet(SERIALIZE_TRANSACTION_NO_WITNESS)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions