-
Notifications
You must be signed in to change notification settings - Fork 37.8k
Bech32 addresses in dumpwallet #12315
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
Conversation
|
Actually, this is not good enough. If an uncompressed privkey is being dumped, the address should be a p2pkh one regardless of the global setting. |
Moved the decision as to which address we should output to after
Segwit scriptpubkeys are not created for this uncompressed key on |
I tested this by:
The resulting dump has bech32 output for the old generated address. I assume this wasn't the intention? Here are the dumps. With 0.14.2:
and with this PR:
|
Right, I haven't identified a way of telling whether keys were added before or after the wallet upgrade for bech32. |
You can check which of the corresponding addresses has a label set. Typically this will only be one of the P2PKH, P2SH-P2WPKH, or P2WPKH ones. If so, you could just output that exact one. Unfortunately this won't work for imported keys, as they get the label assigned to all 3. |
Thanks! I'll see what I can do. |
So perhaps the thing to do is to output any of the address types that have a label, and if none have a label output the global type. So up to three addresses per line. |
@devrandom sorry the page didn't auto update with your comment. So you're saying that multiple addresses per entry is better? |
Given Sipa's point, with imported keys you'd outputting the first address type in the |
(sorry for mass pushing, I'll push to a side branch for now) |
I believe this push does things more along the lines that you guys suggested. A couple things :
Here's an example dump : You can see imported compressed and uncompressed keys and keys that were generated by In the gist, the line :
is a result of I'll go over the tests now. It's getting an address entry that looks like Cheers |
src/wallet/rpcdump.cpp
Outdated
std::string strAddr = EncodeDestination(keyid); | ||
std::string strAddr; | ||
std::string strLabel; | ||
bool fLabelFound = false; |
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.
Can fLabelFound
declaration be moved inside the if statement?
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.
Yep, will do.
src/wallet/rpcdump.cpp
Outdated
if (!key.IsCompressed()) { | ||
strAddr = EncodeDestination(keyid); | ||
strLabel = EncodeDumpString(pwallet->mapAddressBook[keyid].name); | ||
fLabelFound = true; |
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.
Should this be set true only if it's found in address book?
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.
Ah good call. The uncompressed key might belong to an internal entry like change.
test/functional/wallet_dump.py
Outdated
# containing multiple addresses if it is the expected p2wsh-p2wpkh | ||
# we added in the test | ||
if len(set(addr.split(","))) > 1 and addr.split(",")[1] == script_addrs[1]: | ||
found_addr += len(set(addr.split(","))) |
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 line seems to be unreached when this test is actually run
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.
Good catch :) the test was passing for because I broke it. I'll set the test to check for the p2sh-p2wpkh address specifically for the key it was added to.
|
src/wallet/rpcdump.cpp
Outdated
CKey key; | ||
if (pwallet->GetKey(keyid, key)) { | ||
bool fLabelFound = false; | ||
if (!key.IsCompressed()) { |
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.
Would make sense to encapsulate this (go from key/keyid to label,addr) out to a function.
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.
Thanks for having a look. I'm not sure what I should be passing to that function though, seems that I would have to pass a pointer to the wallet itself along with the keyid in order to know whether a label exists for an address type for that keyid.
I might be missing something obvious though.
Concept ACK |
Moved things to a function per @laanwj review, I'm not sure if any locks or further wallet availability checks are needed though. |
src/wallet/rpcdump.cpp
Outdated
CScript p2wpkhScr = GetScriptForDestination(WitnessV0KeyHash(keyid)); | ||
CScript p2shScr = GetScriptForDestination(CScriptID(p2wpkhScr)); | ||
ExtractDestination(p2wpkhScr, p2wpkhAddr); | ||
ExtractDestination(p2shScr, p2shAddr); |
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.
You should iterate the result of GetAllDestinationsForKey(key)
here instead of replicating the logic to compute the destinations.
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... makes a lot more sense :)
Actually, per @sipa's suggestion to use |
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.
Lightly tested ACK, needs squashing.
This notably does not report the "correct" address for change addresses created through getrawchangeaddress
or otherwise, though that's hard to deal with regardless as we don't keep a record of which type was used.
src/wallet/rpcdump.cpp
Outdated
pwallet->GetKey(keyid, key); | ||
for (const auto& dest : GetAllDestinationsForKey(key.GetPubKey())) { | ||
if (pwallet->mapAddressBook.count(dest)) { | ||
if (!strAddr.empty()) |
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.
Style nit: braces when indenting.
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.
Fixed
Output bech32 addresses in dumpwallet if address type is not as legacy
b7f99e6
to
45eea40
Compare
One commit now |
Lightly tested ACK 45eea40 |
LGTM, thanks for doing this :) |
utACK 45eea40 |
45eea40 Bech32 addresses in dumpwallet (fivepiece) Pull request description: Output bech32 addresses in dumpwallet if address type is not as legacy Tree-SHA512: f6b6f788293779fe6339b94d9b792180e1d1dcb9c8e826caef8693557e1710213ba57891981c17505ace8d67b407eeca6fd9a8825757dd292cca2aa12575d15c
Output bech32 addresses in dumpwallet if address type is not as legacy Github-Pull: bitcoin#12315 Rebased-From: 45eea40 Tree-SHA512: 3426292ddaeaafebc25fe84802011f5569a0cbb47fcc3209e7f00f64fc6eb1e637732722bbd02dce8d46be87d0f3687ce8370e71e9286bf7d00afc0a895faecb
Output bech32 addresses in dumpwallet if address type is not as legacy