Skip to content

Commit e04eaab

Browse files
committed
Move Address::payload_as_bytes to Payload::as_bytes
1 parent 4dce111 commit e04eaab

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/util/address.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,15 @@ impl Payload {
468468
program: output_key.as_inner().serialize().to_vec(),
469469
}
470470
}
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+
}
471480
}
472481

473482
/// A utility struct to encode an address payload with the given parameters.
@@ -722,7 +731,7 @@ impl Address {
722731
/// given key. For taproot addresses, the supplied key is assumed to be tweaked
723732
pub fn is_related_to_pubkey(&self, pubkey: &PublicKey) -> bool {
724733
let pubkey_hash = pubkey.pubkey_hash();
725-
let payload = self.payload_as_bytes();
734+
let payload = self.payload.as_bytes();
726735
let xonly_pubkey = XOnlyPublicKey::from(pubkey.inner);
727736

728737
(*pubkey_hash == *payload) || (xonly_pubkey.serialize() == *payload) || (*segwit_redeem_hash(&pubkey_hash) == *payload)
@@ -733,18 +742,9 @@ impl Address {
733742
/// This will only work for Taproot addresses. The Public Key is
734743
/// assumed to have already been tweaked.
735744
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();
737746
payload == xonly_pubkey.serialize()
738747
}
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-
}
748748
}
749749

750750
// Alternate formatting `{:#}` is used to return uppercase version of bech32 addresses which should

0 commit comments

Comments
 (0)