Skip to content

Commit

Permalink
reuse utxo extract_secret_v2 in legacy extract_secret
Browse files Browse the repository at this point in the history
  • Loading branch information
laruh committed Nov 8, 2024
1 parent 9449cca commit 2e65abf
Showing 1 changed file with 1 addition and 19 deletions.
20 changes: 1 addition & 19 deletions mm2src/coins/utxo/utxo_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2584,25 +2584,7 @@ pub async fn get_taker_watcher_reward<T: UtxoCommonOps + SwapOps + MarketCoinOps
/// Note spender could generate the spend with several inputs where the only one input is the p2sh script.
pub fn extract_secret(secret_hash: &[u8], spend_tx: &[u8]) -> Result<Vec<u8>, String> {
let spend_tx: UtxoTx = try_s!(deserialize(spend_tx).map_err(|e| ERRL!("{:?}", e)));
let expected_secret_hash = if secret_hash.len() == 32 {
ripemd160(secret_hash)
} else {
H160::from(secret_hash)
};
for input in spend_tx.inputs.into_iter() {
let script: Script = input.script_sig.clone().into();
for instruction in script.iter().flatten() {
if instruction.opcode == Opcode::OP_PUSHBYTES_32 {
if let Some(secret) = instruction.data {
let actual_secret_hash = dhash160(secret);
if actual_secret_hash == expected_secret_hash {
return Ok(secret.to_vec());
}
}
}
}
}
ERR!("Couldn't extract secret")
extract_secret_v2(secret_hash, &spend_tx)
}

/// Extract a secret from the `spend_tx`.
Expand Down

0 comments on commit 2e65abf

Please sign in to comment.