Skip to content

Commit 598c937

Browse files
author
ChallengeDev210
committed
Merge rust-bitcoin/rust-bitcoin#978: Make Address::get_payload_bytes public
7ca30b6 Move Address::payload_as_bytes to Payload::as_bytes (Fredrik Meringdal) 525ea00 Make Address::get_payload_bytes public (Fredrik Meringdal) Pull request description: Hi, thanks for the amazing work on this crate. I am trying to upgrade from v0.27 to v0.28, but unable to do so because the `Address::get_payload_bytes` was made private. My use-case is that I have a script hash address and an `Address` and need to compare the two, and in order to do so I need access to the payload bytes of `Address`. I hope you will consider making this function public again 🙏 ACKs for top commit: apoelstra: ACK 7ca30b6 tcharding: ACK 7ca30b6 sanket1729: ACK 7ca30b6. Sorry for the delay and congratz on your first time contribution Tree-SHA512: 02af4565853d93506751ed7cb004f52cb5d8c7936067e06b3e237b448ccdf5716470448eeccbe211958e095b66bb37c7027800c0470c6988dc18d8bd5b48f459
2 parents bb495a2 + e04eaab commit 598c937

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-
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)