-
Notifications
You must be signed in to change notification settings - Fork 37.7k
refactor: wallet: return util::Result from GetReservedDestination
methods
#25656
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
refactor: wallet: return util::Result from GetReservedDestination
methods
#25656
Conversation
src/wallet/scriptpubkeyman.h
Outdated
@@ -179,7 +179,7 @@ class ScriptPubKeyMan | |||
virtual bool CheckDecryptionKey(const CKeyingMaterial& master_key, bool accept_no_keys = false) { return false; } | |||
virtual bool Encrypt(const CKeyingMaterial& master_key, WalletBatch* batch) { return false; } | |||
|
|||
virtual bool GetReservedDestination(const OutputType type, bool internal, CTxDestination& address, int64_t& index, CKeyPool& keypool, bilingual_str& error) { return false; } | |||
virtual BResult<CTxDestination> GetReservedDestination(const OutputType type, bool internal, int64_t& index, CKeyPool& keypool) { return {}; } |
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.
Because CTxDestination default value is CNoDestination
, this will return a succeed BResult
object.
Would be better to do:
return Untranslated("Not supported");
(same as we are doing for the base GetNewDestination
)
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 have expected for {}
to return an empty error message. Is there any way to avoid this confusion at compile time?
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 have expected for
{}
to return an empty error message. Is there any way to avoid this confusion at compile time?
I think the silent conversion of bilingual_str into errors is an anti-feature. Not every translated string is necessarily an error string, and the conversion makes it not possible to use a BResult<bilingual_str>
type that returns a normal translated string. #25665 improves this by adding an explicit error contructor
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 have expected for
{}
to return an empty error message. Is there any way to avoid this confusion at compile time?
Yeah @MarcoFalke, my bad here, I shouldn't had reviewed the PR before sleep...
As we internally use an std::variant
, and the first element is the bilingual_str
. The {}
will indeed initialize the variant with an empty error message.
What I tried to say on the message is that I don't see how empty error strings are useful. The caller cannot know where/why the function failed (which is the main purpose of returning an error string in the first place).
Thinking out loud without test it:
Probably we could prevent this behavior by removing the empty constructor or by asserting that an error string cannot be empty.
I think the silent conversion of bilingual_str into errors is an anti-feature. Not every translated string is necessarily an error string, and the conversion makes it not possible to use a BResult<bilingual_str> type that returns a normal translated string. #25665 improves this by adding an explicit error contructor
You know, the initial version that did for the generic CallResult
was actually implemented in that way. I was using an OperationResult<T, E> ErrorOut(string)
helper function instead of the silent conversion.
I have 25665 on my review list 👍🏼 . The last time that I checked it (brief check, thus why I haven't commented yet), I wasn't so sure about the internal std:.variant removal because every result was going to have the succeed object initialized AND the errors AND warnings in memory. And conceptually, a function can succeed OR fail. Not both.
But.. will comment there soon :). Need to finish up few other reviews first. Been focused on the nice, and long, #24914 lately.
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.
Changed to return return Untranslated("Not supported");
for the sake of being consistent with other methods in the same class (GetNewDestination) right now, as suggested by furszy. The discussion here about general improvements to BResults seem to better fit to #25665, this PR is merely a refactor.
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
d7c37ed
to
224e1e1
Compare
Force-pushed with changes as suggested by @furszy (#25656 (comment), #25656 (comment) (for consistency reasons), #25656 (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.
Code review ACK 224e1e1
GetReservedDestination
methodsGetReservedDestination
methods
224e1e1
to
76b3c37
Compare
Rebased on master, |
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.
ACK 76b3c37
Post-merge ACK |
…eservedDestination` methods
This PR is a follow-up to #25218, as suggested in comment #25218 (comment). The interfaces of the methods
ReserveDestination::GetReservedDestination
,{Legacy,Descriptor,}ScriptPubKeyMan::GetReservedDestination
are improved by returningutil::Result<CTxDestination>
instead ofbool
in order to get rid of the twoCTxDestination&
andbilingual_str&
out-parameters.