feat(addresses): Add hex and bech32 for Shelley parts (#181)

This commit is contained in:
Harper 2022-09-11 20:05:52 +01:00 committed by GitHub
parent 070b33114f
commit 98d0087cd9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -143,6 +143,20 @@ impl ShelleyPaymentPart {
Self::Script(x) => x.to_vec(),
}
}
pub fn to_hex(&self) -> String {
let bytes = self.to_vec();
hex::encode(bytes)
}
pub fn to_bech32(&self) -> Result<String, Error> {
let hrp = match self {
Self::Key(_) => "addr_vkh",
Self::Script(_) => "addr_shared_vkh"
};
let bytes = self.to_vec();
encode_bech32(&bytes, hrp)
}
/// Indicates if this is the hash of a script
pub fn is_script(&self) -> bool {
@ -191,6 +205,21 @@ impl ShelleyDelegationPart {
Self::Null => vec![],
}
}
pub fn to_hex(&self) -> String {
let bytes = self.to_vec();
hex::encode(bytes)
}
pub fn to_bech32(&self) -> Result<String, Error> {
let hrp = match self {
Self::Key(_) => "stake_vkh",
Self::Script(_) => "stake_shared_vkh",
_ => todo!(),
};
let bytes = self.to_vec();
encode_bech32(&bytes, hrp)
}
pub fn is_script(&self) -> bool {
matches!(self, ShelleyDelegationPart::Script(_))