Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added public_key to ValidatorList::getAvailable response #3488

Closed
9 changes: 5 additions & 4 deletions src/ripple/app/misc/impl/ValidatorList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -820,10 +820,11 @@ ValidatorList::getAvailable(boost::beast::string_view const& pubKey)

Json::Value value(Json::objectValue);

value["manifest"] = iter->second.rawManifest;
value["blob"] = iter->second.rawBlob;
value["signature"] = iter->second.rawSignature;
value["version"] = iter->second.rawVersion;
value[jss::public_key] = std::string{pubKey};
value[jss::manifest] = iter->second.rawManifest;
value[jss::blob] = iter->second.rawBlob;
value[jss::signature] = iter->second.rawSignature;
value[jss::version] = iter->second.rawVersion;

return value;
}
Expand Down
1 change: 1 addition & 0 deletions src/ripple/protocol/jss.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ JSS(base_fee_xrp); // out: NetworkOPs
JSS(bids); // out: Subscribe
JSS(binary); // in: AccountTX, LedgerEntry,
// AccountTxOld, Tx LedgerData
JSS(blob); // out: ValidatorList
JSS(books); // in: Subscribe, Unsubscribe
JSS(both); // in: Subscribe, Unsubscribe
JSS(both_sides); // in: Subscribe, Unsubscribe
Expand Down
19 changes: 19 additions & 0 deletions src/test/app/ValidatorList_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,25 @@ class ValidatorList_test : public beast::unit_test::suite
BEAST_EXPECT(trustedKeys->listed(val.signingPublic));
}

const auto hexPublic =
strHex(publisherPublic.begin(), publisherPublic.end());

const auto available = trustedKeys->getAvailable(hexPublic);

BEAST_EXPECT(available);
if (available)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BEAST_EXPECT returns the bool value of the test, so you can write this as if (BEAST_EXPECT(available))

{
BEAST_EXPECT(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're missing an include for the non-unity builds, so jss is unknown. You need #include <ripple/protocol/jss.h>

available->get(jss::public_key, Json::nullValue) == hexPublic);
BEAST_EXPECT(available->get(jss::blob, Json::nullValue) == blob2);
BEAST_EXPECT(
available->get(jss::manifest, Json::nullValue) == manifest1);
BEAST_EXPECT(
available->get(jss::version, Json::nullValue) == version);
BEAST_EXPECT(
available->get(jss::signature, Json::nullValue) == sig2);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get is fine here, but IMHO it's a little easier to read calls using the operator[], mainly because, that default value clutters things up. Since available is an optional, you can dereference it into a local to make things prettier:

auto const& a = *available;
BEAST_EXPECT(a[jss::public_key] == hexPublic);
BEAST_EXPECT(a[jss::blob] == blob2);
BEAST_EXPECT(a[jss::manifest] == manifest1);
BEAST_EXPECT(a[jss::version] == version);
BEAST_EXPECT(a[jss::signature] == sig2);

This is more personal preference, so whether to change it is up to you.

}

// do not re-apply lists with past or current sequence numbers
BEAST_EXPECT(
ListDisposition::stale ==
Expand Down