-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add to and from base64 string o pset
via standard trait Display and FromStr like it's done in rust-bitcoin PSBT. Reuse rust-bitcoin base64 re-exported
- Loading branch information
Showing
5 changed files
with
54 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use super::PartiallySignedTransaction; | ||
|
||
#[derive(Debug)] | ||
pub enum Error { | ||
Base64(bitcoin::base64::DecodeError), | ||
Deserialize(crate::encode::Error) | ||
} | ||
|
||
impl core::fmt::Display for Error { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
Error::Base64(_) => write!(f, "Base64 error"), | ||
Error::Deserialize(_) => write!(f, "Deserialize error"), | ||
} | ||
} | ||
} | ||
|
||
impl std::error::Error for Error { | ||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { | ||
match self { | ||
Error::Base64(e) => Some(e), | ||
Error::Deserialize(e) => Some(e), | ||
} | ||
} | ||
|
||
} | ||
|
||
impl std::str::FromStr for PartiallySignedTransaction { | ||
type Err=Error; | ||
|
||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
let bytes = bitcoin::base64::decode(s).map_err(|e| Error::Base64(e))?; | ||
Ok(crate::encode::deserialize(&bytes).map_err(|e| Error::Deserialize(e))?) | ||
} | ||
} | ||
|
||
impl std::fmt::Display for PartiallySignedTransaction { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
let bytes = crate::encode::serialize(self); | ||
let base64 = bitcoin::base64::encode(&bytes); | ||
write!(f, "{}", base64) | ||
} | ||
} |