-
Notifications
You must be signed in to change notification settings - Fork 38.7k
RPC: creates possibility to preserve labels on importprivkey #13381
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: creates possibility to preserve labels on importprivkey #13381
Conversation
|
There is no need for a new parameter, check if label is null instead - this means that the default is to preserve if it exists otherwise "". |
|
Concept ACK, a test would be nice. |
|
Thank you, @promag. |
src/wallet/rpcdump.cpp
Outdated
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 was thinking in something like
if (request.params[1].isNull()) {
const auto& it = pwallet->mapAddressBook.find(dest);
if (it != pwallet->mapAddressBook.end()) strLabel = it->second;
}
pwallet->SetAddressBook(dest, strLabel, "receive");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.
Hm, I see. Yeah.. this behavior seems better. Thanks!
Updating this and the test.
|
Updated with the right behavior. |
promag
left a comment
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.
Update PR title.
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.
2018
src/wallet/rpcdump.cpp
Outdated
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.
Comment is inacurate.
|
Tested ACK 74877f3b10072e1975c931bb296212e008cd8c58 . This is exactly the behavior I desired, thanks @marcoagner! |
src/wallet/rpcdump.cpp
Outdated
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.
Is it problematic that this will apply the label for a given destination over all following destinations, provided they aren't found on lookup? I suspect you'll want another destination-specific local to prevent that.
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! Suggestion:
if (it == pwallet->mapAddressBook.end() || !request.params[1].isNull()) {
pwallet->SetAddressBook(dest, strLabel, "receive")
}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.
There should be a test ensuring the correct behaviour.
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.
Yes, makes sense. I will update it and add a test for the correct behaviour as soon as I can.
|
I'm back to this. The new commit keeps the already tested behaviour (passing tests added on this PR et al) and passes new test for the multiple destinations bug spotted by @Empact. |
|
This still changes behaviour: the default is now I don't particularly care what the default is ( |
|
Agree with @luke-jr regarding the behaviour change. |
|
I added a |
|
@marcoagner Thanks for adding the release notes! I thought maybe the behavior change could be described more simply with the addition of a few examples; see below from some proposed text. I also changed the heading so that it's clear that only a small part of the importprivkey API is being changed (I also removed the RPC importprivkey: new label behavior
-------------------------------------
Previously, `importprivkey`automatically added the default empty label
("") to all addresses associated with imported private keys. Now it
defaults to using any existing label for those addresses. For example:
- Old behavior: you import a watch-only address with the label "cold
wallet". Later, you import the corresponding private key using the
default settings. The address's label is changed from "cold wallet"
to "".
- New behavior: you import a watch-only address with the label "cold
wallet". Later, you import the corresponding private key using the
default settings. The address's label remains "cold wallet".
In both the previous and current case, if you directly specify a label
during the import, that label will override whatever previous label the
addresses may have had. Also in both cases, if none of the addresses
previously had a label, they will still receive the default empty label
(""). Examples:
- You import a watch-only address with the label "temporary". Later you
import the corresponding private key with the label "final". The
address's label will be changed to "final".
- You import a private key for an address that was not previously in the
wallet. It's addresses will receive the default empty label (""). |
|
@harding That's much better, thanks. 4,5c4,5
< Previously, `importprivkey`automatically added the default empty label
< ("") to all addresses associated with imported private keys. Now it
---
> Previously, `importprivkey` automatically added the default empty label
> ("") to all addresses associated with the imported private keys. Now it
21c21
< (""). Examples:
---
> ("") as default. Examples:
28c28,29
< wallet. It's addresses will receive the default empty label ("").
---
> wallet using the default settings. Its addresses will receive the
> default empty label ("").Seems good? |
|
@marcoagner LGTM, although the two uses of 'default' in this clause is a tiny bit awkward IMO (but, it's clear, which is all that really matters):
Maybe that second-to-last sentence could have its adverbial phrase "using the default settings" moved next to the verb it modifies, "import", e.g.:
Thanks for updating, and thanks especially for catching my misuse of the apostrophe in the possessive its. 🤦♂️ |
|
@harding I changed both parts pointed in your last comment. Thanks for the attention and help with this; I think we've now nailed this part. :) |
sipa
left a comment
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.
utACK 6115b5231954a38c400fa4808627dbb8e239ea68. Didn't review the tests.
Non-blocking nit only.
src/wallet/rpcdump.cpp
Outdated
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.
Nit: It's slightly confusing to use a reference type here; find returns an iterator by value.
doc/release-notes-pr13381.md
Outdated
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 be ... imported private key. (singular)?
src/wallet/rpcdump.cpp
Outdated
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.
Could drop watch-only since the code below does't validate that, it only checks if the label exists for each associated address. So default=current label if exists, otherwise \"\".
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.
Yes. Just leaving address between if and exists: default=current label if address exists, otherwise \"\". (I know it was probably just a typo; I'm commenting to make sure)
src/wallet/rpcdump.cpp
Outdated
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.
Nit, maybe make it clear that params[1] has precedence — prevents a lookup if it does? Also, updating with the same label could be avoided, or am I missing something? Suggestion:
for (const auto& dest : GetAllDestinationsForKey(pubkey)) {
if (!request.params[1].isNull()) {
pwallet->SetAddressBook(dest, strLabel, "receive")
} else if (pwallet->mapAddressBook.count(dest) == 0) {
pwallet->SetAddressBook(dest, strLabel, "receive");
}
}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.
Yes, it seems right to me. Thank you again!
I thought I had to somehow guarantee purpose was now "receive" for all dests, but it doesn't seem to be the case now I looked.
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.
Drop watch-only?
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 be removed.
|
Thank you all for reviewing again. Updated with 1d4fdb33349a60cac1926f83586826ba62b1a451. |
|
Maybe @harding could re-test? |
sipa
left a comment
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.
utACK 1d4fdb33349a60cac1926f83586826ba62b1a451
src/wallet/rpcdump.cpp
Outdated
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.
Given that the branches for the two if statements are identical, why not write it as a single if (!request.params[1].isNull() || pwallet->mapAddressBook.count(dest)) { ?
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.
Just to try to make it obvious in the code that the request.params[1] has precedence. Bad idea? Both work.
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.
No reason besides it since AFAIK putting the look up as second condition in the || statement (like your suggestion) will not call it if there is a params[1] in the first condition.
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.
The skip-if-no-wallet might have to be added to this test?
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're right. I was not aware, thanks.
|
Lets see what travis says |
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsNo conflicts as of last 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.
Since this is a new file - please run it through black to get it auto-formatted in accordance with PEP-8 :-)
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.
Hm, nice. Didn't know this black, thanks.
I was using Flake8. Besides the double-quotes for strings, it seems that black has a longer default line length, but I'm okay with (actually prefer) that. :)
I will just rebase, re-run tests, and provide a new commit.
- changes importprivkey behavior to overwrite existent label if one is passed and keep existing ones if no label is passed - tests behavior of importprivkey on existing address labels and different same key destination
|
|
|
utACK a6b5ec1 |
|
utACK a6b5ec1 |
|
utACK a6b5ec1 |
|
utACK a6b5ec1 |
…ivkey a6b5ec1 rpc: creates possibility to preserve labels on importprivkey (marcoagner) Pull request description: Closes #13087. As discussed in the issue, this is a feature request instead of a bug report since the behaviour was as intended (i.e. label with default: `''`). With this, the old behaviour is kept while the possibility to achieve the preservation of labels, as expected in the open issue, is added. Tree-SHA512: b33be50e1e7f62f7ddfae953177ba0926e2d848961f9fac7501c2b513322c0cb95787745d07d137488267bad1104ecfdbe800c6747f94162eb07c976835c1386
Summary: - changes importprivkey behavior to overwrite existent label if one is passed and keep existing ones if no label is passed - tests behavior of importprivkey on existing address labels and different same key destination This is a backport of Core [[bitcoin/bitcoin#13381 | PR13381]] . I had to modify heavily the last test to create a P2SH manually. Bitcoin Core does produce a segwit wrapped into P2SH address by default so this isn't a problem for them. Test Plan: ninja all check-all Reviewers: #bitcoin_abc, majcosta Reviewed By: #bitcoin_abc, majcosta Subscribers: majcosta Differential Revision: https://reviews.bitcoinabc.org/D6185
Closes #13087.
As discussed in the issue, this is a feature request instead of a bug report since the behaviour was as intended (i.e. label with default:
''). With this, the old behaviour is kept while the possibility to achieve the preservation of labels, as expected in the open issue, is added.