mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-18 21:01:22 +02:00
util: simplify the interface of serviceFlagToStr()
Don't take two redundant arguments in `serviceFlagToStr()`. As a side effect this fixes an issue introduced in https://github.com/bitcoin/bitcoin/pull/18165 due to which the GUI could print something like `UNKNOWN[1033] & UNKNOWN[1033] & UNKNOWN[2^10]` instead of `NETWORK & WITNESS`.
This commit is contained in:
parent
f2e2c5ebcc
commit
fbacad1880
@ -195,9 +195,10 @@ const std::vector<std::string> &getAllNetMessageTypes()
|
|||||||
return allNetMessageTypesVec;
|
return allNetMessageTypesVec;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string serviceFlagToStr(const uint64_t mask, const int bit)
|
std::string serviceFlagToStr(size_t bit)
|
||||||
{
|
{
|
||||||
switch (ServiceFlags(mask)) {
|
const uint64_t service_flag = 1ULL << bit;
|
||||||
|
switch ((ServiceFlags)service_flag) {
|
||||||
case NODE_NONE: abort(); // impossible
|
case NODE_NONE: abort(); // impossible
|
||||||
case NODE_NETWORK: return "NETWORK";
|
case NODE_NETWORK: return "NETWORK";
|
||||||
case NODE_GETUTXO: return "GETUTXO";
|
case NODE_GETUTXO: return "GETUTXO";
|
||||||
@ -211,7 +212,7 @@ std::string serviceFlagToStr(const uint64_t mask, const int bit)
|
|||||||
stream.imbue(std::locale::classic());
|
stream.imbue(std::locale::classic());
|
||||||
stream << "UNKNOWN[";
|
stream << "UNKNOWN[";
|
||||||
if (bit < 8) {
|
if (bit < 8) {
|
||||||
stream << mask;
|
stream << service_flag;
|
||||||
} else {
|
} else {
|
||||||
stream << "2^" << bit;
|
stream << "2^" << bit;
|
||||||
}
|
}
|
||||||
|
@ -288,7 +288,12 @@ enum ServiceFlags : uint64_t {
|
|||||||
// BIP process.
|
// BIP process.
|
||||||
};
|
};
|
||||||
|
|
||||||
std::string serviceFlagToStr(uint64_t mask, int bit);
|
/**
|
||||||
|
* Convert a service flag (NODE_*) to a human readable string.
|
||||||
|
* It supports unknown service flags which will be returned as "UNKNOWN[...]".
|
||||||
|
* @param[in] bit the service flag is calculated as (1 << bit)
|
||||||
|
*/
|
||||||
|
std::string serviceFlagToStr(size_t bit);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the set of service flags which are "desirable" for a given peer.
|
* Gets the set of service flags which are "desirable" for a given peer.
|
||||||
|
@ -759,7 +759,7 @@ QString formatServicesStr(quint64 mask)
|
|||||||
uint64_t check = 1ull << i;
|
uint64_t check = 1ull << i;
|
||||||
if (mask & check)
|
if (mask & check)
|
||||||
{
|
{
|
||||||
strList.append(QString::fromStdString(serviceFlagToStr(mask, i)));
|
strList.append(QString::fromStdString(serviceFlagToStr(i)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -847,7 +847,7 @@ UniValue GetServicesNames(ServiceFlags services)
|
|||||||
for (int i = 0; i < 64; ++i) {
|
for (int i = 0; i < 64; ++i) {
|
||||||
const uint64_t mask = 1ull << i;
|
const uint64_t mask = 1ull << i;
|
||||||
if (services_n & mask) {
|
if (services_n & mask) {
|
||||||
servicesNames.push_back(serviceFlagToStr(mask, i));
|
servicesNames.push_back(serviceFlagToStr(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user