Skip to content

Get the account id for a public key#20

Open
ximinez wants to merge 2 commits intomasterfrom
publickey
Open

Get the account id for a public key#20
ximinez wants to merge 2 commits intomasterfrom
publickey

Conversation

@ximinez
Copy link
Copy Markdown
Owner

@ximinez ximinez commented Jan 9, 2026

This change is Reviewable

@ximinez ximinez requested a review from Copilot March 3, 2026 18:57
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +293 to +295
auto const error = [&publicKeyHex]() -> boost::optional<char const*> {
using namespace ripple;
if (auto blob = strUnHex(publicKeyHex))
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

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

doPublicKey introduces boost::optional just to carry an error message, while the rest of this file primarily uses std::optional. Consider switching this to std::optional<std::string> (or similar) and returning owned strings instead of char const* to avoid mixing optional types and to keep error handling consistent.

Copilot uses AI. Check for mistakes.
seed will be used if no <key> is provided on the command line
or from standard input using --stdin.
Miscellaneous:
publickey <hex public key> Get the account id from
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

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

The help text for publickey doesn't mention that --stdin is also accepted (since runCommand supports InputType::readstdin for commands with allowNoInput == false). Either document publickey <hex public key>|--stdin like the other commands, or explicitly reject --stdin for this command if it's not intended.

Suggested change
publickey <hex public key> Get the account id from
publickey <hex public key>|--stdin Get the account id from

Copilot uses AI. Check for mistakes.
Comment on lines +628 to +655
void
testPublicKey()
{
testcase("Get AccountID from Public Key");

std::string const pkHex{
"036F382B723879499B6067B00B241DDF6FBA7599E9F6BF36A422150CEE75FF08F"
"8"};
std::string const account{"rGse36vmL3teKPJwHvKaqgxKkrMKEbATGN"};

auto const [out, err] = [&pkHex, this]() {
CoutRedirect coutRedirect;

std::vector<std::string> args;
args.push_back(pkHex);

auto const exit =
runCommand("publickey", args, {}, {}, InputType::commandline);
BEAST_EXPECT(exit == EXIT_SUCCESS);
return std::make_pair(coutRedirect.out(), coutRedirect.err());
}();

std::string const expected =
"Public key: " + pkHex + "\nAccount ID: " + account + "\n";

BEAST_EXPECTS(err.empty(), err);
BEAST_EXPECTS(out == expected, out);
}
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

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

testPublicKey doesn't currently exercise the failure paths added in doPublicKey (invalid hex and invalid public-key bytes). Adding negative tests here would protect the new error handling and output formatting from regressions.

Copilot uses AI. Check for mistakes.
"8"};
std::string const account{"rGse36vmL3teKPJwHvKaqgxKkrMKEbATGN"};

auto const [out, err] = [&pkHex, this]() {
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

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

Minor: the lambda in testPublicKey captures this but doesn't use it. Dropping the unused capture avoids warnings under stricter compiler flags.

Suggested change
auto const [out, err] = [&pkHex, this]() {
auto const [out, err] = [&pkHex]() {

Copilot uses AI. Check for mistakes.
PublicKey const publicKey(slice);
auto const idSigner = calcAccountID(publicKey);
std::cout << "Public key: " << publicKey
<< "\nAccount ID: " << idSigner << std::endl;
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

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

doPublicKey prints the derived AccountID via the stream operator (<< idSigner). Elsewhere in this codebase, AccountID is consistently rendered using toBase58(calcAccountID(...)) (e.g., doCreateKeyfile and keyfile JSON). To keep the CLI output consistent and ensure the command returns a classic r... account string, format the account with toBase58(idSigner) (or to_string(idSigner) if that is the established base58 helper) instead of relying on operator<<.

Suggested change
<< "\nAccount ID: " << idSigner << std::endl;
<< "\nAccount ID: " << toBase58(idSigner) << std::endl;

Copilot uses AI. Check for mistakes.
throw std::runtime_error("Syntax error: Wrong number of arguments");
};
auto const publickey =
[](auto const& publicKeyHex, auto const&, auto const&) {
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

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

The publickey command action dereferences *publicKeyHex without a BOOST_ASSERT(publicKeyHex) like the other input-required commands (serialize, deserialize, sign, etc.). Even though runCommand should enforce the invariant, adding the assert keeps behavior consistent and avoids undefined behavior if the input dispatch changes later.

Suggested change
[](auto const& publicKeyHex, auto const&, auto const&) {
[](auto const& publicKeyHex, auto const&, auto const&) {
BOOST_ASSERT(publicKeyHex);

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants