Skip to content

Commit 83abd5b

Browse files
committed
maintain provably unspendable semantincs
1 parent 56e03c8 commit 83abd5b

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

src/rest.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ impl TxOutValue {
305305
"fee"
306306
} else if script.is_empty() {
307307
"empty"
308-
} else if script.is_op_return() {
308+
} else if crate::util::provably_unspendable(&script) {
309309
"op_return"
310310
} else if script.is_p2pk() {
311311
"p2pk"
@@ -319,7 +319,7 @@ impl TxOutValue {
319319
"v0_p2wsh"
320320
} else if script.is_p2tr() {
321321
"v1_p2tr"
322-
} else if script.is_op_return() {
322+
} else if crate::util::provably_unspendable(&script) {
323323
"provably_unspendable"
324324
} else {
325325
"unknown"

src/util/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub use self::block::{
1010
BlockHeaderMeta, BlockId, BlockMeta, BlockStatus, HeaderEntry, HeaderList, DEFAULT_BLOCKHASH,
1111
};
1212
pub use self::fees::get_tx_fee;
13+
pub(crate) use self::script::provably_unspendable;
1314
pub use self::script::{get_innerscripts, ScriptToAddr, ScriptToAsm};
1415
pub use self::transaction::{
1516
extract_tx_prevouts, get_prev_outpoints, has_prevout, is_coinbase, is_spendable,

src/util/script.rs

+15
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,18 @@ pub fn get_innerscripts(txin: &TxIn, prevout: &TxOut) -> InnerScripts {
7979
witness_script,
8080
}
8181
}
82+
83+
/// Compatible with Script::is_provably_unspendable on rust-bitcoin v0.31 and before because it checks also IllegalOp class
84+
pub(crate) fn provably_unspendable(script: &Script) -> bool {
85+
use bitcoin::blockdata::opcodes::Class::{IllegalOp, ReturnOp};
86+
87+
match script.as_bytes().first() {
88+
Some(b) => {
89+
let first = bitcoin::Opcode::from(*b);
90+
let class = first.classify(bitcoin::blockdata::opcodes::ClassifyContext::Legacy);
91+
92+
class == ReturnOp || class == IllegalOp
93+
}
94+
None => false,
95+
}
96+
}

src/util/transaction.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pub fn has_prevout(txin: &TxIn) -> bool {
7070

7171
pub fn is_spendable(txout: &TxOut) -> bool {
7272
#[cfg(not(feature = "liquid"))]
73-
return !txout.script_pubkey.is_op_return();
73+
return !crate::util::provably_unspendable(&txout.script_pubkey);
7474
#[cfg(feature = "liquid")]
7575
return !txout.is_fee() && !txout.script_pubkey.is_provably_unspendable();
7676
}

0 commit comments

Comments
 (0)