Skip to content

Commit

Permalink
PSBT Display & FromStr using Base64 serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Feb 19, 2021
1 parent c9c2e45 commit 96f8501
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/util/psbt/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl fmt::Display for Error {
write!(f, "Preimage {:?} does not match {:?} hash {:?}", preimage, hash_type, hash )
}
Error::MergeConflict(ref s) => { write!(f, "Merge conflict: {}", s) }
Error::ConsensusEncoding => f.write_str("bitcoin consensus encoding error"),
Error::ConsensusEncoding => f.write_str("bitcoin consensus or BIP-174 encoding error"),
}
}
}
Expand Down
24 changes: 24 additions & 0 deletions src/util/psbt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,30 @@ impl PartiallySignedTransaction {
}
}

#[cfg(feature = "base64")]
mod _base64encoding {
use super::{PartiallySignedTransaction, Error};
use std::fmt::{Display, Formatter, self};
use std::str::FromStr;

impl Display for PartiallySignedTransaction {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
use consensus::encode::serialize;
use ::base64::display::Base64Display;
write!(f, "{}", Base64Display::with_config(&serialize(self), ::base64::STANDARD))
}
}

impl FromStr for PartiallySignedTransaction {
type Err = Error;

fn from_str(s: &str) -> Result<Self, Self::Err> {
use consensus::encode::deserialize;
Ok(deserialize(&::base64::decode(s).map_err(|_| Error::ConsensusEncoding)?)?)
}
}
}

impl Encodable for PartiallySignedTransaction {
fn consensus_encode<S: io::Write>(
&self,
Expand Down

0 comments on commit 96f8501

Please sign in to comment.