From ec26f069ac30776316bb13c2bfaf24e4ad91d66d Mon Sep 17 00:00:00 2001 From: Fuyin Date: Wed, 23 Oct 2024 21:30:22 +0800 Subject: [PATCH] Fix invalid witness program length --- src/wallet/mod.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/wallet/mod.rs b/src/wallet/mod.rs index 494fcd768..271007bf9 100644 --- a/src/wallet/mod.rs +++ b/src/wallet/mod.rs @@ -387,10 +387,12 @@ where let script_pubkey = u.txout.script_pubkey; match script_pubkey.witness_version() { Some(version @ WitnessVersion::V0) => { - let witness_program = WitnessProgram::new(version, script_pubkey.as_bytes()) - .map_err(|e| { - log_error!(self.logger, "Failed to retrieve script payload: {}", e); - })?; + let witness_program = + WitnessProgram::new(version, &script_pubkey.as_bytes()[2..]).map_err( + |e| { + log_error!(self.logger, "Failed to retrieve script payload: {}", e); + }, + )?; let wpkh = WPubkeyHash::from_slice(&witness_program.program().as_bytes()) .map_err(|e| { @@ -400,10 +402,12 @@ where utxos.push(utxo); }, Some(version @ WitnessVersion::V1) => { - let witness_program = WitnessProgram::new(version, script_pubkey.as_bytes()) - .map_err(|e| { - log_error!(self.logger, "Failed to retrieve script payload: {}", e); - })?; + let witness_program = + WitnessProgram::new(version, &script_pubkey.as_bytes()[2..]).map_err( + |e| { + log_error!(self.logger, "Failed to retrieve script payload: {}", e); + }, + )?; XOnlyPublicKey::from_slice(&witness_program.program().as_bytes()).map_err( |e| {