diff --git a/src/protocol.h b/src/protocol.h index 91d043947b9..321d89532bb 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -245,6 +245,7 @@ const std::vector &getAllNetMessageTypes(); /** nServices flags */ enum ServiceFlags : uint64_t { + // NOTE: When adding here, be sure to update qt/guiutil.cpp's formatServicesStr too // Nothing NODE_NONE = 0, // NODE_NETWORK means that the node is capable of serving the complete block chain. It is currently diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index 54e7a9e0b9b..0130b43c4e5 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -815,6 +815,24 @@ QString formatDurationStr(int secs) return strList.join(" "); } +QString serviceFlagToStr(const quint64 mask, const int bit) +{ + switch (ServiceFlags(mask)) { + case NODE_NONE: abort(); // impossible + case NODE_NETWORK: return "NETWORK"; + case NODE_GETUTXO: return "GETUTXO"; + case NODE_BLOOM: return "BLOOM"; + case NODE_WITNESS: return "WITNESS"; + case NODE_NETWORK_LIMITED: return "NETWORK_LIMITED"; + // Not using default, so we get warned when a case is missing + } + if (bit < 8) { + return QString("%1[%2]").arg("UNKNOWN").arg(mask); + } else { + return QString("%1[2^%2]").arg("UNKNOWN").arg(bit); + } +} + QString formatServicesStr(quint64 mask) { QStringList strList; @@ -823,30 +841,7 @@ QString formatServicesStr(quint64 mask) uint64_t check = 1LL << i; if (mask & check) { - switch (check) - { - case NODE_NETWORK: - strList.append("NETWORK"); - break; - case NODE_GETUTXO: - strList.append("GETUTXO"); - break; - case NODE_BLOOM: - strList.append("BLOOM"); - break; - case NODE_WITNESS: - strList.append("WITNESS"); - break; - case NODE_NETWORK_LIMITED: - strList.append("NETWORK_LIMITED"); - break; - default: - if (i < 8) { - strList.append(QString("%1[%2]").arg("UNKNOWN").arg(check)); - } else { - strList.append(QString("%1[2^%2]").arg("UNKNOWN").arg(i)); - } - } + strList.append(serviceFlagToStr(check, i)); } }