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:
-
SERIALIZE_TRANSACTION_NO_WITNESS
- to control whether witnesses should be present or not. -
ADDRv2_FORMAT
(from #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:
0s.SetFlag(SERIALIZE_TRANSACTION_NO_WITNESS)
1s.RemoveFlag(SERIALIZE_TRANSACTION_NO_WITNESS)
2s.IsFlagSet(SERIALIZE_TRANSACTION_NO_WITNESS)