Repository navigation
feat: expose Wallet::try_finalize_psbt outcomes - #1144
Merged
thunderbiscuit merged 1 commit intoNov 17, 2026
Merged
Conversation
thunderbiscuit
requested changes
Oct 15, 2026
Collaborator
There was a problem hiding this comment.
Awesome stuff! Thanks for working on this. I left a bunch of little comments to address or discuss. Of course @reez is the king of this upstream PR so I defer to him in case anything here in my comments/review is wrong.
Annex
I propose a more explicit Kotlin test that showcases a PSBT going from CouldNotSatisfy to Finalized to AlreadyFinalized. Let me know what you think.
@Test
fun tryFinalizePsbtFailsOnUnsignedInputs() {
runBlocking {
val regtestEnv = RegEnv.connectTo(
host = "10.0.2.2",
walletName = "faucet",
username = "regtest",
password = "password",
)
val wallet = Wallet(
descriptor = BIP84_DESCRIPTOR,
changeDescriptor = BIP84_CHANGE_DESCRIPTOR,
network = Network.REGTEST,
persister = Persister.newInMemory()
)
// Fund the wallet and sync it.
val address = wallet.revealNextAddress(KeychainKind.EXTERNAL).address
val txid = Txid.fromString(regtestEnv.send(address.toString(), 0.001, 2.0))
regtestEnv.mine(1)
val esploraClient = EsploraClient(ESPLORA_REGTEST_URL)
// Wait for the Esplora client to see the transaction. Try 5x per second for 20 seconds.
for (i in 0..99) {
if (esploraClient.getTx(txid) != null) break
delay(200.milliseconds)
}
val update = esploraClient.fullScan(wallet.startFullScan().build(), 10uL, 1uL)
wallet.applyUpdate(update)
// Build a transaction but don't sign it.
val recipient = wallet.revealNextAddress(KeychainKind.EXTERNAL).address.scriptPubkey()
val psbt = TxBuilder()
.addRecipient(recipient, Amount.fromSat(10_000uL))
.finish(wallet)
// Every input is ours, but none can be satisfied without a signature.
val unsigned = wallet.tryFinalizePsbt(psbt)
assertFalse(unsigned.isFinalized)
assertTrue(unsigned.outcomes.isNotEmpty())
unsigned.outcomes.values.forEach { assertIs<FinalizeInputOutcome.CouldNotSatisfy>(it) }
// Once signed (without finalizing), the same inputs finalize.
wallet.sign(
psbt,
SignOptions(
trustWitnessUtxo = false,
assumeHeight = null,
allowAllSighashes = false,
tryFinalize = false,
signWithTapInternalKey = true,
allowGrinding = true,
)
)
val signed = wallet.tryFinalizePsbt(psbt)
assertTrue(signed.isFinalized)
assertEquals(unsigned.outcomes.keys, signed.outcomes.keys)
signed.outcomes.values.forEach { assertEquals(FinalizeInputOutcome.Finalized, it) }
// Finalizing again leaves the PSBT finalized, with every input already finalized.
val again = wallet.tryFinalizePsbt(psbt)
assertTrue(again.isFinalized)
assertEquals(signed.outcomes.keys, again.outcomes.keys)
again.outcomes.values.forEach { assertEquals(FinalizeInputOutcome.AlreadyFinalized, it) }
}
}
j-kon
marked this pull request as ready for review
October 16, 2026 04:47
thunderbiscuit
requested changes
Nov 13, 2026
thunderbiscuit
left a comment
Collaborator
There was a problem hiding this comment.
This is ready to go IMO. Please squash all 3 commits into one. Thanks for this!
reez
approved these changes
Nov 13, 2026
Expose detailed per-input finalization outcomes without changing the existing finalize_psbt API. Preserve malformed input index and length errors and cover finalization, failure mapping, output metadata, and Swift/Kotlin binding round trips.
thunderbiscuit
force-pushed
the
feat/1059-try-finalize-psbt
branch
from
November 17, 2026 14:21
527ad97 to
c990031
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Closes #1059. Intended for 3.2.0.
Expose
Wallet::try_finalize_psbtfrom bdk_wallet 3.2.0 without changing the existingfinalize_psbtAPI.FinalizePsbtOutcomerecord containingis_finalizedand an input-indexed map of typed outcomes.MiniscriptErrorforCouldNotSatisfy.FinalizePsbtError::InputIndexOutOfBoundswith both index and length for malformed PSBTs.Notes to the reviewers
Keeping this in draft for API-shape feedback and CI validation.
The method mutates the supplied PSBT in place. Per-input failures are outcomes, not thrown errors. As upstream specifies, timelocks are evaluated from transaction fields and output metadata is not cleared. No
SignOptionsargument is added.The outcome is an FFI record rather than an object;
is_finalizedis a snapshot field and input indices useu64. The existingPsbtFinalizeErrorbelongs toPsbt::finalize; this additive wallet API has its own error type to preserve upstream index/length details without changing existing variants.Validation
cargo test --locked: 86 passed, 6 existing network-dependent tests ignored.cargo fmt --checkandcargo clippy --locked --all-targets -- -D warnings: passed.swift testagainst a locally built macOS-only debug XCFramework: 22 passed. The local linker emitted deployment-target warnings for native dependency objects; this was not a release artifact build.Rust tests cover successful finalization and PSBT mutation, repeated finalization, unchanged output metadata, missing descriptors, unsatisfied inputs, and malformed input-map index details. Binding tests currently cover mixed
MissingDescriptor/AlreadyFinalizedoutcomes.Documentation
Changelog
changelog: added(maintainer label requested).Checklists