Skip to content

Commit b721388

Browse files
committed
base64: use new API
1 parent 1b49d43 commit b721388

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

elementsd-tests/src/pset.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,12 @@ fn rtt(base64: &str) -> String {
136136
}
137137

138138
fn psbt_rtt(elementsd: &ElementsD, base64: &str) {
139+
use bitcoin::base64::prelude::{Engine as _, BASE64_STANDARD};
139140
let a = elementsd.decode_psbt(&base64).unwrap();
140141

141142
let b_psbt: PartiallySignedTransaction = base64.parse().unwrap();
142143
let mut b_bytes = serialize(&b_psbt);
143-
let b_base64 = bitcoin::base64::encode(&b_bytes);
144+
let b_base64 = BASE64_STANDARD.encode(&b_bytes);
144145
let b = elementsd.decode_psbt(&b_base64).unwrap();
145146

146147
assert_eq!(a, b);
@@ -152,7 +153,7 @@ fn psbt_rtt(elementsd: &ElementsD, base64: &str) {
152153
// ensuring decode prints all data inside psbt, randomly changing a byte,
153154
// if the results is still decodable it should not be equal to initial value
154155
b_bytes[i] = b_bytes[i].wrapping_add(1);
155-
let base64 = bitcoin::base64::encode(&b_bytes);
156+
let base64 = BASE64_STANDARD.encode(&b_bytes);
156157
if let Some(decoded) = elementsd.decode_psbt(&base64) {
157158
assert_ne!(a, decoded, "{} with changed byte {}", b_bytes.to_hex(), i);
158159
}

src/pset/str.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,18 @@ impl std::str::FromStr for PartiallySignedTransaction {
3232
type Err=ParseError;
3333

3434
fn from_str(s: &str) -> Result<Self, Self::Err> {
35-
let bytes = bitcoin::base64::decode(s).map_err(ParseError::Base64)?;
35+
use bitcoin::base64::prelude::{Engine as _, BASE64_STANDARD};
36+
let bytes = BASE64_STANDARD.decode(s).map_err(ParseError::Base64)?;
3637
crate::encode::deserialize(&bytes).map_err(ParseError::Deserialize)
3738
}
3839
}
3940

4041
impl std::fmt::Display for PartiallySignedTransaction {
4142
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
43+
use bitcoin::base64::prelude::BASE64_STANDARD;
44+
4245
let bytes = crate::encode::serialize(self);
43-
let base64 = bitcoin::base64::encode(bytes);
46+
let base64 = bitcoin::base64::display::Base64Display::new(&bytes, &BASE64_STANDARD);
4447
write!(f, "{}", base64)
4548
}
4649
}

0 commit comments

Comments
 (0)