PSBT Display & FromStr using Base64 serialization
This commit is contained in:
parent
2414c5b0a9
commit
072e1d1b86
|
@ -100,7 +100,7 @@ impl fmt::Display for Error {
|
||||||
write!(f, "Preimage {:?} does not match {:?} hash {:?}", preimage, hash_type, hash )
|
write!(f, "Preimage {:?} does not match {:?} hash {:?}", preimage, hash_type, hash )
|
||||||
}
|
}
|
||||||
Error::MergeConflict(ref s) => { write!(f, "Merge conflict: {}", s) }
|
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"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,6 +91,29 @@ impl PartiallySignedTransaction {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "base64")]
|
||||||
|
mod _base64encoding {
|
||||||
|
use super::{PartiallySignedTransaction, Error};
|
||||||
|
use std::fmt::{Display, Formatter, self};
|
||||||
|
use std::str::FromStr;
|
||||||
|
use consensus::encode;
|
||||||
|
use ::base64::display::Base64Display;
|
||||||
|
|
||||||
|
impl Display for PartiallySignedTransaction {
|
||||||
|
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
||||||
|
write!(f, "{}", Base64Display::with_config(&encode::serialize(self), ::base64::STANDARD))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FromStr for PartiallySignedTransaction {
|
||||||
|
type Err = Error;
|
||||||
|
|
||||||
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
|
Ok(encode::deserialize(&::base64::decode(s).map_err(|_| Error::ConsensusEncoding)?)?)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Encodable for PartiallySignedTransaction {
|
impl Encodable for PartiallySignedTransaction {
|
||||||
fn consensus_encode<S: io::Write>(
|
fn consensus_encode<S: io::Write>(
|
||||||
&self,
|
&self,
|
||||||
|
|
Loading…
Reference in New Issue