Add reading and writing PSBT files#800
Merged
reez merged 1 commit intobitcoindevkit:masterfrom Jul 10, 2025
Merged
Conversation
reez
reviewed
Jul 9, 2025
bdk-ffi/src/bitcoin.rs
Outdated
|
|
||
| /// Write the `Psbt` to a file. Note that the file must not yet exist. | ||
| pub(crate) fn write_to_file(&self, path: String) -> Result<(), PsbtError> { | ||
| let file = File::create(path)?; |
Collaborator
There was a problem hiding this comment.
Wondering your thoughts on this: doc comment says "Note that the file must not yet exist." but File::create() "will truncate it if it does" (exist) per docs. Should this use File::create_new() instead to prevent overwrites? Or I could be misunderstanding workflow/behavior too.
Collaborator
Author
There was a problem hiding this comment.
Good call, will swap to create new.
Collaborator
There was a problem hiding this comment.
cool, this looks good otherwise so I'll keep an eye on it and merge when swapped (and rebased if needed)
reez
reviewed
Jul 9, 2025
Comment on lines
+1441
to
+1456
| impl From<std::io::Error> for PsbtError { | ||
| fn from(error: std::io::Error) -> Self { | ||
| PsbtError::Io { | ||
| error_message: error.to_string(), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl From<bdk_wallet::bitcoin::io::Error> for PsbtError { | ||
| fn from(error: bdk_wallet::bitcoin::io::Error) -> Self { | ||
| PsbtError::Io { | ||
| error_message: error.to_string(), | ||
| } | ||
| } | ||
| } | ||
|
|
reez
reviewed
Jul 9, 2025
| let file = File::create(path)?; | ||
| let mut writer = BufWriter::new(file); | ||
| let psbt = self.0.lock().unwrap(); | ||
| psbt.serialize_to_writer(&mut writer)?; |
Collaborator
There was a problem hiding this comment.
The Rust API makes it trivially simple to read and write PSBT to and from files. Bindings users may make use of this in air-gapped signing flows. The `PsbtError` already includes an `Io` variant, so we may make use of that error.
Collaborator
Author
|
Rebased and now using |
reez
approved these changes
Jul 10, 2025
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.
The Rust API makes it trivially simple to read and write PSBT to and from files. Bindings users may make use of this in air-gapped signing flows. The
PsbtErroralready includes anIovariant, so we may make use of that error.Notes to the reviewers
Discovered while working on a desktop app.
Changelog notice
Checklists
All Submissions:
cargo fmtandcargo clippybefore committingNew Features: