mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-03 09:56:38 -05:00
Merge #18165: Consolidate service flag bit-to-name conversion to a shared serviceFlagToStr function
c31bc5bcfd
Consolidate service flag bit-to-name conversion to a shared serviceFlagToStr function (Luke Dashjr)cea91a1e40
Bugfix: GUI: Use unsigned long long type to avoid implicit conversion of MSB check (Luke Dashjr) Pull request description: 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. ACKs for top commit: jonasschnelli: utACK ~~cea91a1e40e12029140ebfba969ce3ef2965029c~~c31bc5bcfd
Tree-SHA512: 32c7ba8ac7ef2d4087f4f317447ae93a328ec9fb9ad81301df2fbaeeb21a3db7a503187a369552b05a9414251b7cf8e15bcde74c1ea2ef36591ea7ffb6721f60
This commit is contained in:
commit
de369c7ea5
4 changed files with 36 additions and 31 deletions
|
@ -194,3 +194,27 @@ const std::vector<std::string> &getAllNetMessageTypes()
|
||||||
{
|
{
|
||||||
return allNetMessageTypesVec;
|
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();
|
||||||
|
}
|
||||||
|
|
|
@ -257,7 +257,7 @@ const std::vector<std::string>& getAllNetMessageTypes();
|
||||||
|
|
||||||
/** nServices flags */
|
/** nServices flags */
|
||||||
enum ServiceFlags : uint64_t {
|
enum ServiceFlags : uint64_t {
|
||||||
// NOTE: When adding here, be sure to update qt/guiutil.cpp's formatServicesStr too
|
// NOTE: When adding here, be sure to update serviceFlagToStr too
|
||||||
// Nothing
|
// Nothing
|
||||||
NODE_NONE = 0,
|
NODE_NONE = 0,
|
||||||
// NODE_NETWORK means that the node is capable of serving the complete block chain. It is currently
|
// NODE_NETWORK means that the node is capable of serving the complete block chain. It is currently
|
||||||
|
@ -288,6 +288,8 @@ enum ServiceFlags : uint64_t {
|
||||||
// BIP process.
|
// BIP process.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
std::string serviceFlagToStr(uint64_t mask, int 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.
|
||||||
*
|
*
|
||||||
|
|
|
@ -751,33 +751,15 @@ QString formatDurationStr(int secs)
|
||||||
return strList.join(" ");
|
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)
|
QString formatServicesStr(quint64 mask)
|
||||||
{
|
{
|
||||||
QStringList strList;
|
QStringList strList;
|
||||||
|
|
||||||
for (int i = 0; i < 64; i++) {
|
for (int i = 0; i < 64; i++) {
|
||||||
uint64_t check = 1LL << i;
|
uint64_t check = 1ull << i;
|
||||||
if (mask & check)
|
if (mask & check)
|
||||||
{
|
{
|
||||||
strList.append(serviceFlagToStr(check, i));
|
strList.append(QString::fromStdString(serviceFlagToStr(mask, i)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -841,18 +841,15 @@ std::vector<CScript> EvalDescriptorStringOrObject(const UniValue& scanobject, Fl
|
||||||
|
|
||||||
UniValue GetServicesNames(ServiceFlags services)
|
UniValue GetServicesNames(ServiceFlags services)
|
||||||
{
|
{
|
||||||
|
const uint64_t services_n = services;
|
||||||
UniValue servicesNames(UniValue::VARR);
|
UniValue servicesNames(UniValue::VARR);
|
||||||
|
|
||||||
if (services & NODE_NETWORK)
|
for (int i = 0; i < 64; ++i) {
|
||||||
servicesNames.push_back("NETWORK");
|
const uint64_t mask = 1ull << i;
|
||||||
if (services & NODE_GETUTXO)
|
if (services_n & mask) {
|
||||||
servicesNames.push_back("GETUTXO");
|
servicesNames.push_back(serviceFlagToStr(mask, i));
|
||||||
if (services & NODE_BLOOM)
|
}
|
||||||
servicesNames.push_back("BLOOM");
|
}
|
||||||
if (services & NODE_WITNESS)
|
|
||||||
servicesNames.push_back("WITNESS");
|
|
||||||
if (services & NODE_NETWORK_LIMITED)
|
|
||||||
servicesNames.push_back("NETWORK_LIMITED");
|
|
||||||
|
|
||||||
return servicesNames;
|
return servicesNames;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue