Skip to content

Commit

Permalink
Merge #177: rename pset::str::Error to ParseError and expose it
Browse files Browse the repository at this point in the history
ed066af rename pset::str::Error to ParseError and expose it (Riccardo Casatta)

Pull request description:

  Otherwise the pset decoding from string cannot be used downstream

  fix #175

ACKs for top commit:
  apoelstra:
    ACK ed066af
  sanket1729:
    ACK ed066af

Tree-SHA512: 7ee8346ddea5b6bfa21bdc8fbf0a4fb23ab056821625f0bb67b7b8c271b3c6570f2c431fc0f23f6ee04c025f240d0b7a72a3849e64cd143de4563bfba9634721
  • Loading branch information
sanket1729 committed Sep 22, 2023
2 parents ca1b5c4 + ed066af commit 5d80b94
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
3 changes: 3 additions & 0 deletions src/pset/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ pub mod serialize;
#[cfg(feature = "base64")]
mod str;

#[cfg(feature = "base64")]
pub use self::str::ParseError;

use crate::blind::{BlindAssetProofs, BlindValueProofs};
use crate::confidential;
use crate::encode::{self, Decodable, Encodable};
Expand Down
23 changes: 13 additions & 10 deletions src/pset/str.rs
Original file line number Diff line number Diff line change
@@ -1,36 +1,39 @@
use super::PartiallySignedTransaction;

/// Possible errors when parsing a PSET from a string
#[derive(Debug)]
pub enum Error {
pub enum ParseError {
/// Base64 decoding error
Base64(bitcoin::base64::DecodeError),
/// PSET binary encoding error
Deserialize(crate::encode::Error)
}

impl core::fmt::Display for Error {
impl core::fmt::Display for ParseError {
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"),
ParseError::Base64(_) => write!(f, "Base64 error"),
ParseError::Deserialize(_) => write!(f, "Deserialize error"),
}
}
}

impl std::error::Error for Error {
impl std::error::Error for ParseError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Error::Base64(e) => Some(e),
Error::Deserialize(e) => Some(e),
ParseError::Base64(e) => Some(e),
ParseError::Deserialize(e) => Some(e),
}
}

}

impl std::str::FromStr for PartiallySignedTransaction {
type Err=Error;
type Err=ParseError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
let bytes = bitcoin::base64::decode(s).map_err(Error::Base64)?;
crate::encode::deserialize(&bytes).map_err(Error::Deserialize)
let bytes = bitcoin::base64::decode(s).map_err(ParseError::Base64)?;
crate::encode::deserialize(&bytes).map_err(ParseError::Deserialize)
}
}

Expand Down

0 comments on commit 5d80b94

Please sign in to comment.