Skip to content

Commit 77ff884

Browse files
authored
fix: assume witness-enabled parsing for version > 2 (#1250)
1 parent 4626e80 commit 77ff884

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

crates/bitcoin/src/parser.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,16 +272,18 @@ pub fn parse_compact_uint(varint: &[u8]) -> Result<(u64, usize), Error> {
272272
pub fn parse_transaction(raw_transaction: &[u8]) -> Result<Transaction, Error> {
273273
let mut parser = BytesParser::new(raw_transaction);
274274
let version: i32 = parser.parse()?;
275+
// For version > 2, treat it as version 2 for parsing behavior
276+
let effective_version = if version > 2 { 2 } else { version };
275277

276-
let allow_witness = (version & SERIALIZE_TRANSACTION_NO_WITNESS) == 0;
278+
let allow_witness = (effective_version & SERIALIZE_TRANSACTION_NO_WITNESS) == 0;
277279

278280
// TODO: bound maximum?
279-
let mut inputs: Vec<TransactionInput> = parser.parse_with(version)?;
281+
let mut inputs: Vec<TransactionInput> = parser.parse_with(effective_version)?;
280282

281283
let mut flags: u8 = 0;
282284
if inputs.is_empty() && allow_witness {
283285
flags = parser.parse()?;
284-
inputs = parser.parse_with(version)?;
286+
inputs = parser.parse_with(effective_version)?;
285287
}
286288

287289
// TODO: bound maximum?

0 commit comments

Comments
 (0)