wallet, refactor: return out-params of CreateTransaction() as optional struct - #20640
Conversation
6dc88c6 to
8e9266f
Compare
|
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. |
8e9266f to
5865c38
Compare
|
Force-pushed with the proposed changes by @pox (see #20640 (comment)), introducing new constants |
|
reACK 5865c38 |
5865c38 to
c32e2b1
Compare
|
Force-pushed with changes as suggested by practicalswift, using explicit datatype |
c32e2b1 to
3a07695
Compare
|
Rebased on master. |
3a07695 to
5832404
Compare
|
Rebased on master and changed code to return uninitialized values explicitely via |
dc1c6d8 to
5238022
Compare
|
Rebased on master again. |
|
Concept ACK. Returning things is much cleaner for out-only arguments than using mutable arguments (which would ideally be reserved for inout-arguments only). |
furszy
left a comment
There was a problem hiding this comment.
First look, concept ACK.
Wasn't aware of this PR and touched the same piece of code in #24845.
-> PR where I introduced two generic versions of the optional return object called OperationResult and CallResult<T> (basically classes that encapsulate the function result: the result object, or in case of failure, the failure reason), which later can be used everywhere in the sources to cleanup similar boilerplate code where we pass a lot of ref args with a single return optional struct like the one introduced here.
So, combining both PRs, we will just return a CallResult<CreatedTransactionResult> which will cleanup the code further.
Will do a deeper code review soon.
achow101
left a comment
There was a problem hiding this comment.
ACK 5238022161a1ecd361916c6f425439e7c7604758
There was a problem hiding this comment.
In 5238022161a1ecd361916c6f425439e7c7604758 "wallet: CreateTransaction(): return out-params as (optional) struct"
nit: new variables should be snake_case.
Perhaps we should consider changing this to std::optional<int> and get rid of using -1 as a magic number.
There was a problem hiding this comment.
nit: new variables should be snake_case.
Thanks, renamed nChangePos to change_pos in both functions CreateTransaction and CreateTransactionInternal in the latest rebase.
Perhaps we should consider changing this to std::optional and get rid of using -1 as a magic number.
Good idea, I think this would make a good follow-up PR candidate.
5238022 to
4c5ceb0
Compare
There was a problem hiding this comment.
Optional: I stumble a bit on past tense in the Class name here. I think I'd prefer either CreateTransactionResult to emphasize it's the result of a function called CreateTransaction…, or maybe just either CreatedTransaction or TransactionResult, since having both "result" and "created" feels a bit redundant.
|
re-ACK 4c5ceb0 |
The method
CWallet::CreateTransactioncurrently returns several values in the form of out-parameters:CTransactionRef& tx)CAmount& nFeeRate)int& nChangePosInOut) -- as the name suggests, this is both an in- and out-paramBy returning these values in an optional structure (which returns no value a.k.a.
std::nulloptif an error occured), the interfaces is shorter, cleaner (requested change position is now in-param and can be passed by value) and callers don't have to create dummy variables for results that they are not interested in.Note that the names of the replaced out-variables were kept in
CreateTransactionInternalto keep the diff minimal. Also, the fee calculation data (FeeCalculation& fee_calc_out) would be another candidate to put into the structure, butFeeCalculationis currently an opaque data type in the wallet interface and I think it should stay that way.As a potential follow-up, I think it would make sense to also do the same refactoring for
CWallet::FundTransaction, which has a very similar parameter structure.Suggested by laanwj in #20588 (comment).