Skip to content

Commit

Permalink
Remove borrows
Browse files Browse the repository at this point in the history
  • Loading branch information
tcharding committed Jul 30, 2024
1 parent 148f486 commit 1a898e0
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/interpreter/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ pub(super) fn from_txdata<'txin>(
let pk = pk_from_stack_elem(&elem, false)?;
if *spk
== bitcoin_primitives::ScriptBuf::new_p2pkh(
&pk.to_pubkeyhash(SigType::Ecdsa).into(),
pk.to_pubkeyhash(SigType::Ecdsa).into(),
)
{
Ok((
Expand All @@ -159,11 +159,11 @@ pub(super) fn from_txdata<'txin>(
Some(elem) => {
let pk = pk_from_stack_elem(&elem, true)?;
let hash160 = pk.to_pubkeyhash(SigType::Ecdsa);
if *spk == bitcoin_primitives::ScriptBuf::new_p2wpkh(&hash160.into()) {
if *spk == bitcoin_primitives::ScriptBuf::new_p2wpkh(hash160.into()) {
Ok((
Inner::PublicKey(pk.into(), PubkeyType::Wpkh),
wit_stack,
Some(bitcoin_primitives::ScriptBuf::new_p2pkh(&hash160.into())), // bip143, why..
Some(bitcoin_primitives::ScriptBuf::new_p2pkh(hash160.into())), // bip143, why..
))
} else {
Err(Error::IncorrectWPubkeyHash)
Expand All @@ -183,7 +183,7 @@ pub(super) fn from_txdata<'txin>(
let script = miniscript.encode();
let miniscript = miniscript.to_no_checks_ms();
let scripthash = sha256::Hash::hash(script.as_bytes());
if *spk == bitcoin_primitives::ScriptBuf::new_p2wsh(&scripthash.into()) {
if *spk == bitcoin_primitives::ScriptBuf::new_p2wsh(scripthash.into()) {
Ok((Inner::Script(miniscript, ScriptType::Wsh), wit_stack, Some(script)))
} else {
Err(Error::IncorrectWScriptHash)
Expand Down Expand Up @@ -255,7 +255,7 @@ pub(super) fn from_txdata<'txin>(
Some(elem) => {
if let stack::Element::Push(slice) = elem {
let scripthash = hash160::Hash::hash(slice);
if *spk != bitcoin_primitives::ScriptBuf::new_p2sh(&scripthash.into()) {
if *spk != bitcoin_primitives::ScriptBuf::new_p2sh(scripthash.into()) {
return Err(Error::IncorrectScriptHash);
}
// ** p2sh-wrapped wpkh **
Expand All @@ -269,15 +269,15 @@ pub(super) fn from_txdata<'txin>(
let hash160 = pk.to_pubkeyhash(SigType::Ecdsa);
if slice
== bitcoin_primitives::ScriptBuf::new_p2wpkh(
&hash160.into(),
hash160.into(),
)
.as_bytes()
{
Ok((
Inner::PublicKey(pk.into(), PubkeyType::ShWpkh),
wit_stack,
Some(bitcoin_primitives::ScriptBuf::new_p2pkh(
&hash160.into(),
hash160.into(),
)), // bip143, why..
))
} else {
Expand All @@ -301,7 +301,7 @@ pub(super) fn from_txdata<'txin>(
let scripthash = sha256::Hash::hash(script.as_bytes());
if slice
== bitcoin_primitives::ScriptBuf::new_p2wsh(
&scripthash.into(),
scripthash.into(),
)
.as_bytes()
{
Expand All @@ -325,7 +325,7 @@ pub(super) fn from_txdata<'txin>(
let miniscript = miniscript.to_no_checks_ms();
if wit_stack.is_empty() {
let scripthash = hash160::Hash::hash(script.as_bytes());
if *spk == bitcoin_primitives::ScriptBuf::new_p2sh(&scripthash.into()) {
if *spk == bitcoin_primitives::ScriptBuf::new_p2sh(scripthash.into()) {
Ok((Inner::Script(miniscript, ScriptType::Sh), ssig_stack, Some(script)))
} else {
Err(Error::IncorrectScriptHash)
Expand Down Expand Up @@ -444,12 +444,12 @@ mod tests {

let pkhash = key.to_pubkeyhash(SigType::Ecdsa).into();
let wpkhash = key.to_pubkeyhash(SigType::Ecdsa).into();
let wpkh_spk = bitcoin_primitives::ScriptBuf::new_p2wpkh(&wpkhash);
let wpkh_spk = bitcoin_primitives::ScriptBuf::new_p2wpkh(wpkhash);
let wpkh_scripthash = hash160::Hash::hash(wpkh_spk.as_bytes()).into();

KeyTestData {
pk_spk: bitcoin_primitives::ScriptBuf::new_p2pk(key),
pkh_spk: bitcoin_primitives::ScriptBuf::new_p2pkh(&pkhash),
pkh_spk: bitcoin_primitives::ScriptBuf::new_p2pkh(pkhash),
pk_sig: script::Builder::new().push_slice(dummy_sig).into_script(),
pkh_sig: script::Builder::new()
.push_slice(dummy_sig)
Expand All @@ -459,7 +459,7 @@ mod tests {
wpkh_spk: wpkh_spk.clone(),
wpkh_stack: Witness::from_slice(&[dummy_sig_vec.clone(), key.to_bytes()]),
wpkh_stack_justkey: Witness::from_slice(&[key.to_bytes()]),
sh_wpkh_spk: bitcoin_primitives::ScriptBuf::new_p2sh(&wpkh_scripthash),
sh_wpkh_spk: bitcoin_primitives::ScriptBuf::new_p2sh(wpkh_scripthash),
sh_wpkh_sig: script::Builder::new()
.push_slice(<&PushBytes>::try_from(wpkh_spk[..].as_bytes()).unwrap())
.into_script(),
Expand Down Expand Up @@ -734,7 +734,7 @@ mod tests {
let (miniscript, redeem_script) = ms_inner_script(&format!("hash160({})", hash));
let rs_hash = hash160::Hash::hash(redeem_script.as_bytes()).into();

let spk = ScriptBuf::new_p2sh(&rs_hash);
let spk = ScriptBuf::new_p2sh(rs_hash);
let script_sig = script::Builder::new()
.push_slice(<&PushBytes>::try_from(redeem_script.as_bytes()).unwrap())
.into_script();
Expand Down Expand Up @@ -770,7 +770,7 @@ mod tests {
let wit_hash = sha256::Hash::hash(witness_script.as_bytes()).into();
let wit_stack = Witness::from_slice(&[witness_script.to_bytes()]);

let spk = ScriptBuf::new_p2wsh(&wit_hash);
let spk = ScriptBuf::new_p2wsh(wit_hash);
let blank_script = bitcoin_primitives::ScriptBuf::new();

// wsh without witness
Expand Down Expand Up @@ -805,14 +805,14 @@ mod tests {
let wit_hash = sha256::Hash::hash(witness_script.as_bytes()).into();
let wit_stack = Witness::from_slice(&[witness_script.to_bytes()]);

let redeem_script = ScriptBuf::new_p2wsh(&wit_hash);
let redeem_script = ScriptBuf::new_p2wsh(wit_hash);
let script_sig = script::Builder::new()
.push_slice(<&PushBytes>::try_from(redeem_script.as_bytes()).unwrap())
.into_script();
let blank_script = bitcoin_primitives::ScriptBuf::new();

let rs_hash = hash160::Hash::hash(redeem_script.as_bytes()).into();
let spk = ScriptBuf::new_p2sh(&rs_hash);
let spk = ScriptBuf::new_p2sh(rs_hash);

// shwsh without witness or scriptsig
let err = from_txdata(&spk, &blank_script, &Witness::default()).unwrap_err();
Expand Down

0 comments on commit 1a898e0

Please sign in to comment.