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

[rpc] Return payment address on z_importkey #3754

Closed
wants to merge 1 commit into from

Conversation

dagurval
Copy link
Contributor

Fixes #3748

BOOST_CHECK_NO_THROW(ret = CallRPC("z_validateaddress " + ret.get_str()));
ret = ret.get_obj();
BOOST_CHECK_EQUAL(true, find_value(ret, "isvalid").get_bool());
BOOST_CHECK_EQUAL(true, find_value(ret, "ismine").get_bool());
Copy link
Contributor

Choose a reason for hiding this comment

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

Excellent test :-)

Copy link
Contributor

Choose a reason for hiding this comment

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

When you support Sapling, please also extend the test to include importing a Sapling key.

Copy link
Contributor

@daira daira left a comment

Choose a reason for hiding this comment

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

Thanks for the PR :-) Please make it support Sapling as well, and then we can probably include it in 2.0.3.

@@ -586,6 +586,7 @@ UniValue z_importkey(const UniValue& params, bool fHelp)
"2. rescan (string, optional, default=\"whenkeyisnew\") Rescan the wallet for transactions - can be \"yes\", \"no\" or \"whenkeyisnew\"\n"
"3. startHeight (numeric, optional, default=0) Block height to start rescan from\n"
"\nNote: This call can take minutes to complete if rescan is true.\n"
"\nResult: Encoded payment address if possible, otherwise nothing.\n"
Copy link
Contributor

Choose a reason for hiding this comment

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

When is it not possible?

auto sproutSpendingKey = boost::get<libzcash::SproutSpendingKey>(&spendingkey);
if (sproutSpendingKey != nullptr) {
return EncodePaymentAddress(sproutSpendingKey->address());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Please also support Sapling keys/addresses.

@daira daira added the A-rpc-interface Area: RPC interface label Dec 29, 2018
@dagurval
Copy link
Contributor Author

Thanks for the feedback @daira. I pushed a commit adding sapling support as well. I'll squash the commits if the changes pass review.

Copy link
Contributor

@daira daira left a comment

Choose a reason for hiding this comment

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

ACK modulo comment.

@dagurval
Copy link
Contributor Author

dagurval commented Jan 2, 2019

Moved and renamed DefaultAddressFromSpendingKey as suggested. Squashed the commits.

Copy link
Contributor

@daira daira left a comment

Choose a reason for hiding this comment

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

ut(ACK+cov). The only place I could see where this could potentially cause a regression would be if the key passed to the DefaultAddressFromSpendingKey visitor were an InvalidEncoding, but that shouldn't be able to happen because we've checked that IsValidSpendingKey(spendingkey) is true. Other reviewers should check my reasoning here.

@daira daira added the C-community-contribution Category: A contribution from the community! label Apr 1, 2019
return NullUniValue;
auto addr = boost::apply_visitor(
libzcash::DefaultAddressFromSpendingKey{}, spendingkey);
return EncodePaymentAddress(addr);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think I'd prefer to return a JSON object that contains a defaultAddress field set to this (or maybe primaryAddress field, since Sprout is supported; alternatively we could use address for Sprout and defaultAddress for Sapling, and have a type field like z_validateaddress has). That makes it clear that this is the default address in the case of Sapling, and also means that we can extend this RPC method in future with additional information if we wanted.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved the address to a defaultAddress field as you suggested.

It looks like the best way to add the type field is to export DescribePaymentAddressVisitor, I suggest that I do that in a separate PR to limit the size of this one. What do you think?

src/zcash/Address.cpp Outdated Show resolved Hide resolved
@zkbot
Copy link
Contributor

zkbot commented Dec 19, 2019

☔ The latest upstream changes (presumably #4270) made this pull request unmergeable. Please resolve the merge conflicts.

@r3ld3v r3ld3v added this to the Core Sprint 2020-03 milestone Jan 13, 2020
@str4d str4d removed the request for review from bitcartel January 21, 2020 19:28
@str4d
Copy link
Contributor

str4d commented Jan 21, 2020

This has been folded into #4220, which I've requested be updated to include appropriate credit for work included from this PR.

@str4d str4d closed this Jan 21, 2020
@str4d str4d added the S-committed Status: Planned work in a sprint label Jan 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rpc-interface Area: RPC interface C-community-contribution Category: A contribution from the community! S-committed Status: Planned work in a sprint
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide a way to obtain the address of a key imported by z_importkey
5 participants