-
Notifications
You must be signed in to change notification settings - Fork 65
Add reading and writing PSBT files #800
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call, will swap to create new.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool, this looks good otherwise so I'll keep an eye on it and merge when swapped (and rebased if needed)
| 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(), | ||
| } | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding these 👍
| let file = File::create(path)?; | ||
| let mut writer = BufWriter::new(file); | ||
| let psbt = self.0.lock().unwrap(); | ||
| psbt.serialize_to_writer(&mut writer)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
|
Rebased and now using |
reez
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 4f5d092
This is great
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: