mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-13 12:33:42 +02:00
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.
This commit is contained in:
parent
cea91a1e40
commit
c31bc5bcfd
4 changed files with 35 additions and 30 deletions
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue