feat(traverse): Integrate address library (#149)

This commit is contained in:
Santiago Carmuega 2022-07-04 18:06:14 -03:00 committed by GitHub
parent a26773a94c
commit 9e22c842cd
5 changed files with 42 additions and 22 deletions

View file

@ -1,5 +1,6 @@
use std::{borrow::Cow, ops::Deref};
use pallas_addresses::{Address, ByronAddress, Error as AddressError};
use pallas_codec::minicbor;
use pallas_primitives::{alonzo, babbage, byron};
@ -18,13 +19,14 @@ impl<'b> MultiEraOutput<'b> {
Self::Babbage(Box::new(Cow::Borrowed(output)))
}
pub fn address(&self, hrp: &str) -> String {
pub fn to_address(&self) -> Result<Address, AddressError> {
match self {
MultiEraOutput::AlonzoCompatible(x) => {
x.to_bech32_address(hrp).expect("invalid address value")
}
MultiEraOutput::Babbage(x) => x.to_bech32_address(hrp).expect("invalid address value"),
MultiEraOutput::Byron(x) => x.address.to_addr_string().expect("invalid address value"),
MultiEraOutput::AlonzoCompatible(x) => Address::from_bytes(&x.address),
MultiEraOutput::Babbage(x) => match x.deref().deref() {
babbage::TransactionOutput::Legacy(x) => Address::from_bytes(&x.address),
babbage::TransactionOutput::PostAlonzo(x) => Address::from_bytes(&x.address),
},
MultiEraOutput::Byron(x) => Ok(ByronAddress::new(x.address.clone()).into()),
}
}