diff --git a/src/keys/mod.rs b/src/keys/mod.rs index 2f0b8610..f8e36aad 100644 --- a/src/keys/mod.rs +++ b/src/keys/mod.rs @@ -129,15 +129,19 @@ impl DescriptorKey { /// Enum representation of the known valid [`ScriptContext`]s #[derive(Debug, Eq, PartialEq, Copy, Clone)] pub enum ScriptContextEnum { + /// Legacy scripts Legacy, + /// Segwitv0 scripts Segwitv0, } impl ScriptContextEnum { + /// Returns whether the script context is [`ScriptContextEnum::Legacy`] pub fn is_legacy(&self) -> bool { self == &ScriptContextEnum::Legacy } + /// Returns whether the script context is [`ScriptContextEnum::Segwitv0`] pub fn is_segwit_v0(&self) -> bool { self == &ScriptContextEnum::Segwitv0 } @@ -145,12 +149,15 @@ impl ScriptContextEnum { /// Trait that adds extra useful methods to [`ScriptContext`]s pub trait ExtScriptContext: ScriptContext { + /// Returns the [`ScriptContext`] as a [`ScriptContextEnum`] fn as_enum() -> ScriptContextEnum; + /// Returns whether the script context is [`Legacy`](miniscript::Legacy) fn is_legacy() -> bool { Self::as_enum().is_legacy() } + /// Returns whether the script context is [`Segwitv0`](miniscript::Segwitv0) fn is_segwit_v0() -> bool { Self::as_enum().is_segwit_v0() } @@ -345,7 +352,7 @@ pub struct GeneratedKey { } impl GeneratedKey { - pub fn new(key: K, valid_networks: ValidNetworks) -> Self { + fn new(key: K, valid_networks: ValidNetworks) -> Self { GeneratedKey { key, valid_networks, @@ -482,6 +489,7 @@ impl GeneratableKey for bip32::ExtendedPrivKey { /// Defaults to creating compressed keys, which save on-chain bytes and fees #[derive(Debug, Copy, Clone)] pub struct PrivateKeyGenerateOptions { + /// Whether the generated key should be "compressed" or not pub compressed: bool, } @@ -670,12 +678,19 @@ impl ToDescriptorKey for PrivateKey { /// Errors thrown while working with [`keys`](crate::keys) #[derive(Debug)] pub enum KeyError { + /// The key cannot exist in the given script context InvalidScriptContext, + /// The key is not valid for the given network InvalidNetwork, + /// The key has an invalid checksum InvalidChecksum, + + /// Custom error message Message(String), + #[allow(missing_docs)] BIP32(bitcoin::util::bip32::Error), + #[allow(missing_docs)] Miniscript(miniscript::Error), } diff --git a/src/lib.rs b/src/lib.rs index 64d79c42..01b993e2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -256,7 +256,6 @@ pub mod database; pub mod descriptor; #[cfg(feature = "test-md-docs")] mod doctest; -#[allow(missing_docs)] // TODO add missing docs and remove this allow pub mod keys; pub(crate) mod psbt; #[allow(missing_docs)] // TODO add missing docs and remove this allow