Skip to content

Commit 4341bff

Browse files
committed
GUI: Refactor formatServicesStr to warn when a ServicesFlag is missing
1 parent df77de8 commit 4341bff

File tree

2 files changed

+20
-24
lines changed

2 files changed

+20
-24
lines changed

src/protocol.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ const std::vector<std::string> &getAllNetMessageTypes();
245245

246246
/** nServices flags */
247247
enum ServiceFlags : uint64_t {
248+
// NOTE: When adding here, be sure to update qt/guiutil.cpp's formatServicesStr too
248249
// Nothing
249250
NODE_NONE = 0,
250251
// NODE_NETWORK means that the node is capable of serving the complete block chain. It is currently

src/qt/guiutil.cpp

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,24 @@ QString formatDurationStr(int secs)
815815
return strList.join(" ");
816816
}
817817

818+
QString serviceFlagToStr(const quint64 mask, const int bit)
819+
{
820+
switch (ServiceFlags(mask)) {
821+
case NODE_NONE: abort(); // impossible
822+
case NODE_NETWORK: return "NETWORK";
823+
case NODE_GETUTXO: return "GETUTXO";
824+
case NODE_BLOOM: return "BLOOM";
825+
case NODE_WITNESS: return "WITNESS";
826+
case NODE_NETWORK_LIMITED: return "NETWORK_LIMITED";
827+
// Not using default, so we get warned when a case is missing
828+
}
829+
if (bit < 8) {
830+
return QString("%1[%2]").arg("UNKNOWN").arg(mask);
831+
} else {
832+
return QString("%1[2^%2]").arg("UNKNOWN").arg(bit);
833+
}
834+
}
835+
818836
QString formatServicesStr(quint64 mask)
819837
{
820838
QStringList strList;
@@ -823,30 +841,7 @@ QString formatServicesStr(quint64 mask)
823841
uint64_t check = 1LL << i;
824842
if (mask & check)
825843
{
826-
switch (check)
827-
{
828-
case NODE_NETWORK:
829-
strList.append("NETWORK");
830-
break;
831-
case NODE_GETUTXO:
832-
strList.append("GETUTXO");
833-
break;
834-
case NODE_BLOOM:
835-
strList.append("BLOOM");
836-
break;
837-
case NODE_WITNESS:
838-
strList.append("WITNESS");
839-
break;
840-
case NODE_NETWORK_LIMITED:
841-
strList.append("NETWORK_LIMITED");
842-
break;
843-
default:
844-
if (i < 8) {
845-
strList.append(QString("%1[%2]").arg("UNKNOWN").arg(check));
846-
} else {
847-
strList.append(QString("%1[2^%2]").arg("UNKNOWN").arg(i));
848-
}
849-
}
844+
strList.append(serviceFlagToStr(check, i));
850845
}
851846
}
852847

0 commit comments

Comments
 (0)