From 94d31ff7ed054d51ef79e80ec27b49ce86a1bec9 Mon Sep 17 00:00:00 2001 From: Matthew Date: Wed, 12 Jun 2024 20:03:51 -0500 Subject: [PATCH] feat: add display trait to mnemonic --- bdk-ffi/src/bdk.udl | 3 +-- bdk-ffi/src/keys.rs | 7 +++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/bdk-ffi/src/bdk.udl b/bdk-ffi/src/bdk.udl index d01858e8..f172a9a0 100644 --- a/bdk-ffi/src/bdk.udl +++ b/bdk-ffi/src/bdk.udl @@ -454,6 +454,7 @@ interface BumpFeeTxBuilder { // bdk crate - descriptor module // ------------------------------------------------------------------------ +[Traits=(Display)] interface Mnemonic { constructor(WordCount word_count); @@ -462,8 +463,6 @@ interface Mnemonic { [Name=from_entropy, Throws=Bip39Error] constructor(sequence entropy); - - string as_string(); }; interface DerivationPath { diff --git a/bdk-ffi/src/keys.rs b/bdk-ffi/src/keys.rs index f1ee27f8..1e33996b 100644 --- a/bdk-ffi/src/keys.rs +++ b/bdk-ffi/src/keys.rs @@ -1,4 +1,5 @@ use crate::error::{Bip32Error, Bip39Error, DescriptorKeyError}; +use std::fmt::Display; use bdk_wallet::bitcoin::bip32::DerivationPath as BdkDerivationPath; use bdk_wallet::bitcoin::key::Secp256k1; @@ -44,9 +45,11 @@ impl Mnemonic { .map(Mnemonic) .map_err(Bip39Error::from) } +} - pub(crate) fn as_string(&self) -> String { - self.0.to_string() +impl Display for Mnemonic { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.0) } }