Skip to content

Commit 9bc67df

Browse files
committed
Encode taddrs in compat mode with bech32
1 parent dde7c8b commit 9bc67df

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

crates/core/src/address.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,20 @@ impl Address {
278278
string_encoding::Format::encode(self)
279279
}
280280

281+
/// Encode an address in compatibility mode (i.e. with the legacy Bech32
282+
/// encoding)
283+
pub fn encode_compat(&self) -> String {
284+
use crate::string_encoding::Format;
285+
286+
bech32::encode::<bech32::Bech32>(Self::HRP, self.to_bytes().as_ref())
287+
.unwrap_or_else(|_| {
288+
panic!(
289+
"The human-readable part {} should never cause a failure",
290+
Self::HRP
291+
)
292+
})
293+
}
294+
281295
/// Decode an address from Bech32m encoding
282296
pub fn decode(string: impl AsRef<str>) -> Result<Self> {
283297
string_encoding::Format::decode(string)

0 commit comments

Comments
 (0)