f - Define method for legacy format rather than using From
authorJeffrey Czyz <jkczyz@gmail.com>
Fri, 30 Jul 2021 23:13:20 +0000 (18:13 -0500)
committerJeffrey Czyz <jkczyz@gmail.com>
Sat, 31 Jul 2021 03:49:30 +0000 (22:49 -0500)
lightning/src/ln/script.rs

index 69b09e958d9f08507529f4da890710b585a77d97..c2987f7393ff5d90e10de8229de1869af456d325 100644 (file)
@@ -9,7 +9,6 @@ use bitcoin::secp256k1::key::PublicKey;
 
 use ln::features::InitFeatures;
 
-use std::convert::From;
 use std::convert::TryFrom;
 
 /// A script pubkey for shutting down a channel as defined by [BOLT #2].
@@ -31,6 +30,11 @@ enum ShutdownScriptImpl {
 }
 
 impl ShutdownScript {
+       /// Generates a P2WPKH script pubkey from the given [`PublicKey`].
+       pub fn new_p2wpkh_from_pubkey(pubkey: PublicKey) -> Self {
+               Self(ShutdownScriptImpl::Legacy(pubkey))
+       }
+
        /// Generates a P2PKH script pubkey from the given [`PubkeyHash`].
        pub fn new_p2pkh(pubkey_hash: &PubkeyHash) -> Self {
                Self(ShutdownScriptImpl::Bolt2(Script::new_p2pkh(pubkey_hash)))
@@ -67,12 +71,6 @@ impl ShutdownScript {
        }
 }
 
-impl From<PublicKey> for ShutdownScript {
-       fn from(pubkey: PublicKey) -> Self {
-               Self(ShutdownScriptImpl::Legacy(pubkey))
-       }
-}
-
 impl TryFrom<Script> for ShutdownScript {
        type Error = InvalidShutdownScript;
 
@@ -138,7 +136,7 @@ mod shutdown_script_tests {
                let pubkey_hash = pubkey.wpubkey_hash().unwrap();
                let p2wpkh_script = Script::new_v0_wpkh(&pubkey_hash);
 
-               let shutdown_script = ShutdownScript::from(pubkey.key);
+               let shutdown_script = ShutdownScript::new_p2wpkh_from_pubkey(pubkey.key);
                assert_eq!(shutdown_script.into_inner(), p2wpkh_script);
        }