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
Add Sapling support to z_getnewaddress and z_listaddresses #3429
Conversation
Regtest addresses are 91 characters, and ZIP 32's Bech32 encoding will be significantly longer.
I am getting a "Permission denied" error when I run |
@Eirik0 try removing the |
It was actually the wallet_addresses.py file. I updated that manually and that fixed the problem. I have seen this before when I have created new rpc tests and done the chmod before pushing. I wasn't sure if this was something that was supposed to be happening automatically. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! I suggested a couple of minor changes.
qa/rpc-tests/wallet_addresses.py
Outdated
assert(res['isvalid']) | ||
assert(res['ismine']) | ||
assert_equal(res['type'], 'sapling') | ||
assert(addr in self.nodes[0].z_listaddresses()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like
types_and_addresses = [
(default_type, self.nodes[0].z_getnewaddress()),
('sprout', self.nodes[0].z_getnewaddress('sprout')),
('sapling', self.nodes[0].z_getnewaddress('sapling'))
]
all_addresses = self.nodes[0].z_listaddresses()
for addr_type, addr in types_and_addresses:
res = self.nodes[0].z_validateaddress(addr)
assert(res['isvalid'])
assert(res['ismine'])
assert_equal(addr_type, res['type'])
assert(addr in all_addresses)
would make it clear we are doing the same for the three scenarios.
@@ -169,7 +169,7 @@ std::pair<std::string, data> Decode(const std::string& str) { | |||
} | |||
if (lower && upper) return {}; | |||
size_t pos = str.rfind('1'); | |||
if (str.size() > 90 || pos == str.npos || pos == 0 || pos + 7 > str.size()) { | |||
if (str.size() > 1023 || pos == str.npos || pos == 0 || pos + 7 > str.size()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where does the number 1023 come from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From BIP 173:
Even though the chosen code performs reasonably well up to 1023 characters, other designs are preferable for lengths above 89 characters (excluding the separator).
We've decided that our addresses are generally small enough that sticking with the established Bech32 encoding for longer encodings is sufficient.
@@ -251,6 +252,19 @@ class CBasicKeyStore : public CKeyStore | |||
virtual bool GetSaplingIncomingViewingKey( | |||
const libzcash::SaplingPaymentAddress &addr, | |||
libzcash::SaplingIncomingViewingKey& ivkOut) const; | |||
void GetSaplingPaymentAddresses(std::set<libzcash::SaplingPaymentAddress> &setAddress) const |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice if void GetPaymentAddresses(std::set<libzcash::SproutPaymentAddress> &setAddress) const
were renamed to reflect that it is now Sprout specific.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That can happen in a later PR, probably after 2.0.0 due to time pressure.
// verify there are two keys | ||
wallet.GetSaplingPaymentAddresses(addrs); | ||
ASSERT_EQ(2, addrs.size()); | ||
ASSERT_EQ(1, addrs.count(address)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about adding ASSERT_EQ(1, addrs.count(sk.default_address()));
?
"\nExamples:\n" | ||
+ HelpExampleCli("z_getnewaddress", "") | ||
+ HelpExampleCli("z_getnewaddress", ADDR_TYPE_SAPLING) | ||
+ HelpExampleRpc("z_getnewaddress", "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we update HelpExampleCli
, but not HelpExampleRpc
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just didn't add an example, because you can conceptually reuse the CLI examples inside the RPC ones (and pretty much everywhere else only one RPC example is given).
@@ -3100,24 +3103,40 @@ UniValue z_getnewaddress(const UniValue& params, bool fHelp) | |||
if (!EnsureWalletIsAvailable(fHelp)) | |||
return NullUniValue; | |||
|
|||
if (fHelp || params.size() > 0) | |||
std::string defaultType = ADDR_TYPE_SPROUT; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not be apposed to either inlining this or making it a constant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was originally where we conditionally set the default based on whether Sapling had activated. We may still want to do that if we decide to make Sapling the default in 2.0.1 (after third parties have had time to test their setups). So I'll leave this as-is.
@@ -3129,7 +3148,7 @@ UniValue z_listaddresses(const UniValue& params, bool fHelp) | |||
if (fHelp || params.size() > 1) | |||
throw runtime_error( | |||
"z_listaddresses ( includeWatchonly )\n" | |||
"\nReturns the list of zaddr belonging to the wallet.\n" | |||
"\nReturns the list of Sprout and Sapling shielded addresses belonging to the wallet.\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the change from "zaddr" to "shielded addresses". Neither here nor there, but we don't really need to say "Sprout and Sapling". Shouldn't that be the default unless we otherwise specify?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just wanted to be clearer for downstream users, given that technically previously they only ever received Sprout addresses from here, whereas now they need to check what type of address they are getting (if they are then doing something Sprout-specific, rather than using our regular APIs for which they will be interchangeable).
src/wallet/rpcwallet.cpp
Outdated
{ | ||
std::set<libzcash::SproutPaymentAddress> addresses; | ||
pwalletMain->GetPaymentAddresses(addresses); | ||
for (auto addr : addresses ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatting: There is an extra space after "addresses".
src/wallet/rpcwallet.cpp
Outdated
pwalletMain->GetSaplingPaymentAddresses(addresses); | ||
libzcash::SaplingIncomingViewingKey ivk; | ||
libzcash::SaplingFullViewingKey fvk; | ||
for (auto addr : addresses ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatting.
Addressed @Eirik0's comments. |
ACK. |
@zkbot r+ |
📌 Commit 4fab49e has been approved by |
⌛ Testing commit 4fab49e with merge d16052757cc7dade3dafe343f9284b8491805c35... |
💔 Test failed - pr-merge |
Pushed fixes for the two test failures - both were bugs in the tests themselves, not the code. @zkbot r+ |
📌 Commit 40dc060 has been approved by |
Add Sapling support to z_getnewaddress and z_listaddresses Closes #3217.
Closes #3217.