aboutsummaryrefslogtreecommitdiff
path: root/src/protocol.cpp
diff options
context:
space:
mode:
authorLuke Dashjr <luke-jr+git@utopios.org>2020-02-17 01:53:13 +0000
committerLuke Dashjr <luke-jr+git@utopios.org>2020-02-21 19:10:04 +0000
commitc31bc5bcfddf440e9a1713f7ba2ca2bf9cfa8e2e (patch)
tree7d04a6ac6765a3591963d9420d68d2c64620cbd3 /src/protocol.cpp
parentcea91a1e40e12029140ebfba969ce3ef2965029c (diff)
downloadbitcoin-c31bc5bcfddf440e9a1713f7ba2ca2bf9cfa8e2e.tar.xz
Consolidate service flag bit-to-name conversion to a shared serviceFlagToStr function
Side effect: this results in the RPC showing unknown service bits as "UNKNOWN[n]" like the GUI. Note that there is no common mask-to-vector<string> function because both GUI and RPC would need to iterate through it to convert to their desired target formats.
Diffstat (limited to 'src/protocol.cpp')
-rw-r--r--src/protocol.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/protocol.cpp b/src/protocol.cpp
index e49e5523ac..816b3ead0c 100644
--- a/src/protocol.cpp
+++ b/src/protocol.cpp
@@ -199,3 +199,27 @@ const std::vector<std::string> &getAllNetMessageTypes()
{
return allNetMessageTypesVec;
}
+
+std::string serviceFlagToStr(const uint64_t 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
+ }
+
+ std::ostringstream stream;
+ stream.imbue(std::locale::classic());
+ stream << "UNKNOWN[";
+ if (bit < 8) {
+ stream << mask;
+ } else {
+ stream << "2^" << bit;
+ }
+ stream << "]";
+ return stream.str();
+}