wallet: finalize PsbtManager implementation
#1130
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes #1035 - the old design has evolved here, detailed below.
Initial State: Fragmented and Rigid Methods
In the original monolithic
wallet.Interface, PSBT-related methods (FundPsbt,SignPsbt,FinalizePsbt) were mixed in with general transaction and account management methods. This had several drawbacks:Fund->Decorate->Sign->Combine->Finalize) is a distinct, multi-step process. Scattering these methods obscured this workflow, making it harder for developers to understand the correct sequence of operations.FundPsbttaking explicitminConfs,feeRate,account,keyScope,strategy). This made the API brittle; adding a new funding option (like a specific coin selection strategy or a change output policy) would require breaking changes.CombinePsbtmethod, forcing users to rely on external tools or ad-hoc merging logic for collaborative signing flows (like Multisig or CoinJoin).The Design Evolution: A Cohesive, Extensible Workflow
The
PsbtManagerwas designed to solve these issues by grouping all PSBT operations into a single, cohesive interface and adopting extensible parameter objects.Insight 1: Workflow Cohesion and Discovery
By extracting
PsbtManagerinto its own interface, we elevate PSBTs to a first-class citizen in the wallet API.Fund,Decorate,Sign,Combine, andFinalizetogether makes the intended workflow self-evident.TxPublisherorSigner. While PSBTs involve signing, the high-level coordination of a PSBT packet is conceptually distinct from the low-level cryptographic operations of theSigner.Insight 2: Extensibility via Parameter Objects (
FundIntent)Instead of passing numerous arguments to
FundPsbt, the new design introduces theFundIntentstruct.FundIntentallows the caller to describe what they want (inputs, outputs, fee rate, change source) rather than just passing values.Intentallows for aPolicy(automatic coin selection) or manualInputs(coin control), providing flexibility without changing the method signature.FundIntent(e.g., specific coin selection algorithms, RBF preferences) without breaking existing code. The same pattern is applied toSignPsbtviaSignPsbtParams.Insight 3: The "Combiner" Role
The addition of
CombinePsbtfills a critical gap for collaborative workflows.The Final API: A Complete PSBT Toolkit
The final design provides a robust, extensible, and complete toolkit for managing the PSBT lifecycle.
Why This Design is Superior:
FundIntentensure the API can evolve to support advanced features (like custom coin selection strategies) without breaking changes.CombinePsbtand the support for external input tweakers inSignPsbtParamsmake this interface fully capable of handling complex, multi-party signing scenarios.