Merge rust-bitcoin/rust-bitcoin#1381: Minor improvements to Witness::get_tapscript commit
865fd5ac90
Minor improvements to Witness::get_tapscript commit (sanket1729) Pull request description: ACKs for top commit: apoelstra: ACK865fd5ac90
Kixunil: ACK865fd5ac90
Tree-SHA512: 88d6c02b5b5eeadadf662eebbb40143c2880f8c91a3b0025a81fd4c4a087fc389c4db9e41376936074a9d9545dce5414414517e1059366968ca6e40287b90d20
This commit is contained in:
commit
ecb76320ab
|
@ -16,6 +16,7 @@ use crate::sighash::EcdsaSighashType;
|
|||
use crate::io::{self, Read, Write};
|
||||
use crate::prelude::*;
|
||||
use crate::VarInt;
|
||||
use crate::util::taproot::TAPROOT_ANNEX_PREFIX;
|
||||
|
||||
/// The Witness is the data used to unlock bitcoins since the [segwit upgrade](https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki)
|
||||
///
|
||||
|
@ -302,7 +303,7 @@ impl Witness {
|
|||
/// This does not guarantee that this represents a P2TR [`Witness`].
|
||||
/// It merely gets the second to last or third to last element depending
|
||||
/// on the first byte of the last element being equal to 0x50.
|
||||
pub fn get_tapscript(&self) -> Option<&[u8]> {
|
||||
pub fn tapscript(&self) -> Option<&[u8]> {
|
||||
let len = self.len();
|
||||
self
|
||||
.last()
|
||||
|
@ -311,7 +312,7 @@ impl Witness {
|
|||
// If there are at least two witness elements, and the first byte of
|
||||
// the last element is 0x50, this last element is called annex a
|
||||
// and is removed from the witness stack.
|
||||
if len >= 2 && last_elem.first().filter(|&&v| v == 0x50).is_some() {
|
||||
if len >= 2 && last_elem.first() == Some(&TAPROOT_ANNEX_PREFIX) {
|
||||
// account for the extra item removed from the end
|
||||
3
|
||||
} else {
|
||||
|
@ -602,8 +603,8 @@ mod test {
|
|||
};
|
||||
|
||||
// With or without annex, the tapscript should be returned.
|
||||
assert_eq!(witness.get_tapscript(), Some(&tapscript[..]));
|
||||
assert_eq!(witness_annex.get_tapscript(), Some(&tapscript[..]));
|
||||
assert_eq!(witness.tapscript(), Some(&tapscript[..]));
|
||||
assert_eq!(witness_annex.tapscript(), Some(&tapscript[..]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Reference in New Issue