aboutsummaryrefslogtreecommitdiff
path: root/src/netaddress.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/netaddress.h')
-rw-r--r--src/netaddress.h22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/netaddress.h b/src/netaddress.h
index 143cdd4fa3..a0944c886f 100644
--- a/src/netaddress.h
+++ b/src/netaddress.h
@@ -25,14 +25,6 @@
#include <vector>
/**
- * A flag that is ORed into the protocol version to designate that addresses
- * should be serialized in (unserialized from) v2 format (BIP155).
- * Make sure that this does not collide with any of the values in `version.h`
- * or with `SERIALIZE_TRANSACTION_NO_WITNESS`.
- */
-static constexpr int ADDRV2_FORMAT = 0x20000000;
-
-/**
* A network type.
* @note An address may belong to more than one network, for example `10.0.0.1`
* belongs to both `NET_UNROUTABLE` and `NET_IPV4`.
@@ -220,13 +212,23 @@ public:
return IsIPv4() || IsIPv6() || IsTor() || IsI2P() || IsCJDNS();
}
+ enum class Encoding {
+ V1,
+ V2, //!< BIP155 encoding
+ };
+ struct SerParams {
+ const Encoding enc;
+ };
+ static constexpr SerParams V1{Encoding::V1};
+ static constexpr SerParams V2{Encoding::V2};
+
/**
* Serialize to a stream.
*/
template <typename Stream>
void Serialize(Stream& s) const
{
- if (s.GetVersion() & ADDRV2_FORMAT) {
+ if (s.GetParams().enc == Encoding::V2) {
SerializeV2Stream(s);
} else {
SerializeV1Stream(s);
@@ -239,7 +241,7 @@ public:
template <typename Stream>
void Unserialize(Stream& s)
{
- if (s.GetVersion() & ADDRV2_FORMAT) {
+ if (s.GetParams().enc == Encoding::V2) {
UnserializeV2Stream(s);
} else {
UnserializeV1Stream(s);