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 /src/qt | |
parent | df77de8c2157fbb4c0898586dacb2215286745c8 (diff) |
GUI: Refactor formatServicesStr to warn when a ServicesFlag is missing
Diffstat (limited to 'src/qt')
-rw-r--r-- | src/qt/guiutil.cpp | 43 |
1 files changed, 19 insertions, 24 deletions
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)); } } |