Skip to content

Conversation

theStack
Copy link
Contributor

This PR cleans up the interfaces of the FundTransaction functions by returning the out-parameters (fee, change output, error) as util::Result with a newly created structure FundedTransactionResult. It can be seen as a late follow-up to #20640 which did a similar operation to the CreateTransaction{Internal} functions. Note that there are actually two functions FundTransaction with the same name:

bool FundTransaction(CWallet& wallet, CMutableTransaction& tx, CAmount& nFeeRet, int& nChangePosInOut, bilingual_str& error, bool lockUnspents, const std::set<int>& setSubtractFeeFromOutputs, CCoinControl);

void FundTransaction(CWallet& wallet, CMutableTransaction& tx, CAmount& fee_out, int& change_position, const UniValue& options, CCoinControl& coinControl, bool override_min_fee)

Only the first returns an error and hence needs to be wrapped into util::Result, the other one can directly return the result structure.

@DrahtBot
Copy link
Contributor

DrahtBot commented Sep 20, 2022

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Reviews

See the guideline for information on the review process.
A summary of reviews will appear here.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #25273 (wallet: Pass through transaction locktime and preset input sequences and scripts to CreateTransaction by achow101)

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.

Copy link

@davidjoshuashelton davidjoshuashelton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

@theStack theStack force-pushed the 202209-refactor-wallet-fundtransaction_return_out_param_in_utilresult branch from b2d3453 to 1cbbbcd Compare November 3, 2022 15:53
int change_pos,
bool lockUnspents,
const std::set<int>& setSubtractFeeFromOutputs,
CCoinControl coinControl)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we are here, coin control could be passed as a ref so we avoid copying it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, done. This is potentially more than just a refactor since the passed in coin control object from the caller is now modified, but as far as I can see this is no problem.

Comment on lines 190 to 216
struct FundedTransactionResult
{
CAmount fee;
int change_pos;

FundedTransactionResult(CAmount _fee, int _change_pos)
: fee(_fee), change_pos(_change_pos) {}
};
Copy link
Member

@furszy furszy Nov 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In 038ed83:

Instead of creating a new struct for this (which duplicates part of what we have in the CreatedTransactionResult struct), I would make a base class for CreatedTransactionResult that only contains the fee, fee calc and change pos fields. Then make CreatedTransactionResult a child of it. And use the new base class directly here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, done.

@theStack theStack force-pushed the 202209-refactor-wallet-fundtransaction_return_out_param_in_utilresult branch from 1cbbbcd to de30125 Compare November 27, 2022 02:00
@theStack
Copy link
Contributor Author

Force-pushed with suggestions from @furszy (thanks for reviewing!) and also rebased on master.

@@ -180,15 +180,22 @@ std::optional<SelectionResult> SelectCoins(const CWallet& wallet, CoinsResult& a
const CAmount& nTargetValue, const CCoinControl& coin_control,
const CoinSelectionParams& coin_selection_params) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet);

struct CreatedTransactionResult
struct FundedTransactionResult
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about naming it TransactionDetails or something similar.

The double "result" wording in stuff like Util::Result<FundedTransactionResult> sounds redundant.

(for the other one, CreatedTransactionResult could do the same and remove the "result" wording too)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the redundancy seems to make sense. Not sure about TransactionDetails -- if one of the two structs is named like this, what would be the name of the other? ({More,Less}TransactionDetails? 😛 )

@theStack theStack force-pushed the 202209-refactor-wallet-fundtransaction_return_out_param_in_utilresult branch from de30125 to d7f6f44 Compare January 3, 2023 01:33
@theStack
Copy link
Contributor Author

theStack commented Jan 3, 2023

Rebased on master. The suggestion in #26129 (comment) is a good improvement idea, but as this PR is only focused on the FundTransaction result output, I decided to use the same naming scheme than the CreateTransaction result output (i.e. CreatedTransactionResult and FundedTransactionResult), and I'm also still not sure which names are proper (is simply CreatedTransaction and FundedTransaction descriptive enough?).

@theStack theStack force-pushed the 202209-refactor-wallet-fundtransaction_return_out_param_in_utilresult branch from d7f6f44 to a065889 Compare January 25, 2023 17:17
@achow101 achow101 closed this Apr 25, 2023
@bitcoin bitcoin locked and limited conversation to collaborators Apr 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants