From 44d3ec487db8ab2724af12e07aafb2b42aa05c09 Mon Sep 17 00:00:00 2001 From: sanket1729 Date: Fri, 20 Jan 2023 07:30:29 -0800 Subject: [PATCH] Rename Payload::as_bytes to inner_prog_as_bytes Also make it private --- bitcoin/src/address.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/bitcoin/src/address.rs b/bitcoin/src/address.rs index 4daa0bc1..34a7c87c 100644 --- a/bitcoin/src/address.rs +++ b/bitcoin/src/address.rs @@ -537,8 +537,9 @@ impl Payload { Payload::WitnessProgram(prog) } - /// Returns a byte slice of the payload - pub fn as_bytes(&self) -> &[u8] { + /// Returns a byte slice of the inner program of the payload. If the payload + /// is a script hash or pubkey hash, a reference to the hash is returned. + fn inner_prog_as_bytes(&self) -> &[u8] { match self { Payload::ScriptHash(hash) => hash.as_ref(), Payload::PubkeyHash(hash) => hash.as_ref(), @@ -930,7 +931,7 @@ impl Address { /// given key. For taproot addresses, the supplied key is assumed to be tweaked pub fn is_related_to_pubkey(&self, pubkey: &PublicKey) -> bool { let pubkey_hash = pubkey.pubkey_hash(); - let payload = self.payload.as_bytes(); + let payload = self.payload.inner_prog_as_bytes(); let xonly_pubkey = XOnlyPublicKey::from(pubkey.inner); (*pubkey_hash.as_ref() == *payload) @@ -943,7 +944,7 @@ impl Address { /// This will only work for Taproot addresses. The Public Key is /// assumed to have already been tweaked. pub fn is_related_to_xonly_pubkey(&self, xonly_pubkey: &XOnlyPublicKey) -> bool { - let payload = self.payload.as_bytes(); + let payload = self.payload.inner_prog_as_bytes(); payload == xonly_pubkey.serialize() } }