diff options
author | Luke Dashjr <luke-jr+git@utopios.org> | 2019-11-14 04:50:54 +0000 |
---|---|---|
committer | Luke Dashjr <luke-jr+git@utopios.org> | 2019-11-14 05:02:16 +0000 |
commit | 4341bffb6ef10909f3721329db27c5dc9bc720dd (patch) | |
tree | ceb7cf87af2be848cfc9c6f666343ca4aa75f541 | |
parent | df77de8c2157fbb4c0898586dacb2215286745c8 (diff) | |
download | bitcoin-4341bffb6ef10909f3721329db27c5dc9bc720dd.tar.xz |
GUI: Refactor formatServicesStr to warn when a ServicesFlag is missing
-rw-r--r-- | src/protocol.h | 1 | ||||
-rw-r--r-- | src/qt/guiutil.cpp | 43 |
2 files changed, 20 insertions, 24 deletions
diff --git a/src/protocol.h b/src/protocol.h index 91d043947b..321d89532b 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -245,6 +245,7 @@ const std::vector<std::string> &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 54e7a9e0b9..0130b43c4e 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)); } } |