Skip to content

Commit

Permalink
contract: add convenience to_mnemonic methods for Contract and Attach id
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Jul 25, 2023
1 parent 7755405 commit 68ceba6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/contract/attachment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ impl FromStr for AttachId {
type Err = Baid58ParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> { Self::from_baid58_chunked_str(s, ':', '#') }
}
impl AttachId {
pub fn to_mnemonic(&self) -> String { self.to_baid58().mnemonic() }
}

#[derive(Clone, PartialOrd, Ord, PartialEq, Eq, Hash, Debug)]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
Expand Down Expand Up @@ -145,6 +148,7 @@ mod test {
let id = AttachId::from_raw_array([0x6c; 32]);
assert_eq!(ID, id.to_string());
assert_eq!(ID, id.to_baid58_string());
assert_eq!("juice-empty-joker", id.to_mnemonic());
}

#[test]
Expand Down
3 changes: 3 additions & 0 deletions src/schema/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ impl FromStr for SchemaId {
Self::from_baid58_maybe_chunked_str(s.trim_start_matches("urn:lnp-bp:"), ':', '#')
}
}
impl SchemaId {
pub fn to_mnemonic(&self) -> String { self.to_baid58().mnemonic() }
}

pub trait SchemaRoot: Clone + Eq + StrictType + StrictEncode + StrictDecode + Default {}
impl SchemaRoot for () {}
Expand Down

0 comments on commit 68ceba6

Please sign in to comment.