@@ -468,6 +468,15 @@ impl Payload {
468
468
program : output_key. as_inner ( ) . serialize ( ) . to_vec ( ) ,
469
469
}
470
470
}
471
+
472
+ /// Returns a byte slice of the payload
473
+ pub fn as_bytes ( & self ) -> & [ u8 ] {
474
+ match self {
475
+ Payload :: ScriptHash ( hash) => hash,
476
+ Payload :: PubkeyHash ( hash) => hash,
477
+ Payload :: WitnessProgram { program, .. } => program,
478
+ }
479
+ }
471
480
}
472
481
473
482
/// A utility struct to encode an address payload with the given parameters.
@@ -722,7 +731,7 @@ impl Address {
722
731
/// given key. For taproot addresses, the supplied key is assumed to be tweaked
723
732
pub fn is_related_to_pubkey ( & self , pubkey : & PublicKey ) -> bool {
724
733
let pubkey_hash = pubkey. pubkey_hash ( ) ;
725
- let payload = self . payload_as_bytes ( ) ;
734
+ let payload = self . payload . as_bytes ( ) ;
726
735
let xonly_pubkey = XOnlyPublicKey :: from ( pubkey. inner ) ;
727
736
728
737
( * pubkey_hash == * payload) || ( xonly_pubkey. serialize ( ) == * payload) || ( * segwit_redeem_hash ( & pubkey_hash) == * payload)
@@ -733,18 +742,9 @@ impl Address {
733
742
/// This will only work for Taproot addresses. The Public Key is
734
743
/// assumed to have already been tweaked.
735
744
pub fn is_related_to_xonly_pubkey ( & self , xonly_pubkey : & XOnlyPublicKey ) -> bool {
736
- let payload = self . payload_as_bytes ( ) ;
745
+ let payload = self . payload . as_bytes ( ) ;
737
746
payload == xonly_pubkey. serialize ( )
738
747
}
739
-
740
- /// Return the address payload as a byte slice
741
- pub fn payload_as_bytes ( & self ) -> & [ u8 ] {
742
- match & self . payload {
743
- Payload :: ScriptHash ( hash) => hash,
744
- Payload :: PubkeyHash ( hash) => hash,
745
- Payload :: WitnessProgram { program, .. } => program,
746
- }
747
- }
748
748
}
749
749
750
750
// Alternate formatting `{:#}` is used to return uppercase version of bech32 addresses which should
0 commit comments