Skip to content

Commit a5ca3c0

Browse files
committed
Rename to HashChallenge
1 parent a70db5a commit a5ca3c0

File tree

7 files changed

+31
-31
lines changed

7 files changed

+31
-31
lines changed

mintscript/src/checker/hashlock.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
use crypto::hash::{self, hash};
1717

18-
use crate::script::HashType;
18+
use crate::script::HashChallenge;
1919

2020
#[derive(thiserror::Error, Debug, PartialEq, Eq, Clone)]
2121
pub enum HashlockError {
@@ -37,7 +37,7 @@ pub trait HashlockChecker {
3737

3838
fn check_hashlock(
3939
&mut self,
40-
hash_type: &HashType,
40+
hash_challenge: &HashChallenge,
4141
preimage: &[u8; 32],
4242
) -> Result<(), Self::Error>;
4343
}
@@ -49,7 +49,7 @@ impl HashlockChecker for NoOpHashlockChecker {
4949

5050
fn check_hashlock(
5151
&mut self,
52-
_hash_type: &HashType,
52+
_hash_challenge: &HashChallenge,
5353
_preimage: &[u8; 32],
5454
) -> Result<(), Self::Error> {
5555
Ok(())
@@ -63,19 +63,19 @@ impl HashlockChecker for StandardHashlockChecker {
6363

6464
fn check_hashlock(
6565
&mut self,
66-
hash_type: &HashType,
66+
hash_challenge: &HashChallenge,
6767
preimage: &[u8; 32],
6868
) -> Result<(), Self::Error> {
69-
match hash_type {
70-
HashType::HASH160(expected_hash) => {
69+
match hash_challenge {
70+
HashChallenge::HASH160(expected_hash) => {
7171
let actual_hash = hash::<hash::Ripemd160, _>(hash::<hash::Sha256, _>(preimage));
7272

7373
ensure_hashes_equal(actual_hash.as_slice(), expected_hash)?;
7474
}
75-
HashType::RIPEMD160(_)
76-
| HashType::SHA1(_)
77-
| HashType::SHA256(_)
78-
| HashType::HASH256(_) => {
75+
HashChallenge::RIPEMD160(_)
76+
| HashChallenge::SHA1(_)
77+
| HashChallenge::SHA256(_)
78+
| HashChallenge::HASH256(_) => {
7979
unimplemented!()
8080
}
8181
}

mintscript/src/checker/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ where
125125

126126
fn visit_hashlock(
127127
&mut self,
128-
hash_type: &crate::script::HashType,
128+
hash_challenge: &crate::script::HashChallenge,
129129
preimage: &[u8; 32],
130130
) -> Result<(), Self::HashlockError> {
131-
self.hashlock_checker.check_hashlock(hash_type, preimage)
131+
self.hashlock_checker.check_hashlock(hash_challenge, preimage)
132132
}
133133
}

mintscript/src/script/display.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use std::fmt;
1818
use common::chain::timelock::OutputTimeLock;
1919
use serialization::hex_encoded::HexEncoded;
2020

21-
use crate::script::HashType;
21+
use crate::script::HashChallenge;
2222

2323
use super::{DissatisfiedScript, ScriptCondition, Threshold, WitnessScript};
2424

@@ -69,20 +69,20 @@ impl WitnessScript {
6969
OutputTimeLock::ForSeconds(s) => write!(f, "after_seconds({s})"),
7070
},
7171
WitnessScript::HashLock {
72-
hash_type,
72+
hash_challenge,
7373
preimage,
7474
} => {
7575
let preimage = HexEncoded::new(preimage);
7676
let mut write_fn = |algo: &str, hash: &[u8]| {
7777
let hash = HexEncoded::new(hash);
7878
write!(f, "{algo}(0x{hash}, 0x{preimage})")
7979
};
80-
match hash_type {
81-
HashType::RIPEMD160(hash) => write_fn("RIPEMD160", hash.as_slice()),
82-
HashType::SHA1(hash) => write_fn("SHA1", hash.as_slice()),
83-
HashType::SHA256(hash) => write_fn("SHA256", hash.as_slice()),
84-
HashType::HASH160(hash) => write_fn("HASH160", hash.as_slice()),
85-
HashType::HASH256(hash) => write_fn("HASH256", hash.as_slice()),
80+
match hash_challenge {
81+
HashChallenge::RIPEMD160(hash) => write_fn("RIPEMD160", hash.as_slice()),
82+
HashChallenge::SHA1(hash) => write_fn("SHA1", hash.as_slice()),
83+
HashChallenge::SHA256(hash) => write_fn("SHA256", hash.as_slice()),
84+
HashChallenge::HASH160(hash) => write_fn("HASH160", hash.as_slice()),
85+
HashChallenge::HASH256(hash) => write_fn("HASH256", hash.as_slice()),
8686
}
8787
}
8888
}

mintscript/src/script/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl Threshold {
123123
}
124124

125125
#[derive(Clone, PartialEq, Eq, Debug)]
126-
pub enum HashType {
126+
pub enum HashChallenge {
127127
RIPEMD160([u8; 20]),
128128
SHA1([u8; 20]),
129129
SHA256([u8; 32]),
@@ -138,7 +138,7 @@ pub enum WitnessScript {
138138
Signature(Destination, InputWitness),
139139
Timelock(OutputTimeLock),
140140
HashLock {
141-
hash_type: HashType,
141+
hash_challenge: HashChallenge,
142142
preimage: [u8; 32],
143143
},
144144
}
@@ -158,9 +158,9 @@ impl WitnessScript {
158158
}
159159

160160
/// Construct a hashlock condition
161-
pub const fn hashlock(hash_type: HashType, preimage: [u8; 32]) -> Self {
161+
pub const fn hashlock(hash_challenge: HashChallenge, preimage: [u8; 32]) -> Self {
162162
Self::HashLock {
163-
hash_type,
163+
hash_challenge,
164164
preimage,
165165
}
166166
}

mintscript/src/script/verify.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
1818
use common::chain::{signature::inputsig::InputWitness, timelock::OutputTimeLock, Destination};
1919

20-
use super::{HashType, WitnessScript};
20+
use super::{HashChallenge, WitnessScript};
2121

2222
/// A script processing object
2323
///
@@ -48,7 +48,7 @@ pub trait ScriptVisitor {
4848
///Check hashlock
4949
fn visit_hashlock(
5050
&mut self,
51-
hash_type: &HashType,
51+
hash_challenge: &HashChallenge,
5252
preimage: &[u8; 32],
5353
) -> Result<(), Self::HashlockError>;
5454
}
@@ -107,10 +107,10 @@ impl WitnessScript {
107107
eval_stack.extend(thresh.collect_satisfied()?.into_iter().rev());
108108
}
109109
Self::HashLock {
110-
hash_type,
110+
hash_challenge,
111111
preimage,
112112
} => {
113-
v.visit_hashlock(hash_type, preimage).map_err(ScriptError::Hashlock)?;
113+
v.visit_hashlock(hash_challenge, preimage).map_err(ScriptError::Hashlock)?;
114114
}
115115
}
116116
}

mintscript/src/tests/hashlock_checker.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ fn check_hashlock_160_ok(#[case] preimage: &str, #[case] hash: &str) {
7676
let hash = hex::decode(hash).unwrap().try_into().unwrap();
7777
let preimage = hex::decode(preimage).unwrap().try_into().unwrap();
7878

79-
let script = WitnessScript::hashlock(HashType::HASH160(hash), preimage);
79+
let script = WitnessScript::hashlock(HashChallenge::HASH160(hash), preimage);
8080

8181
let context = EmptyContext;
8282
let mut checker = crate::ScriptChecker::full(context);
@@ -91,7 +91,7 @@ fn check_hashlock_160_random_values_mismatch(#[case] seed: Seed) {
9191
let preimage: [u8; 32] = std::array::from_fn(|_| rng.gen::<u8>());
9292
let hash: [u8; 20] = std::array::from_fn(|_| rng.gen::<u8>());
9393

94-
let script = WitnessScript::hashlock(HashType::HASH160(hash), preimage);
94+
let script = WitnessScript::hashlock(HashChallenge::HASH160(hash), preimage);
9595

9696
let context = EmptyContext;
9797
let mut checker = crate::ScriptChecker::full(context);

mintscript/src/tests/script.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ fn visit_order(#[case] script: WS) {
139139

140140
fn visit_hashlock(
141141
&mut self,
142-
_hash_type: &crate::script::HashType,
142+
_hash_challenge: &crate::script::HashChallenge,
143143
_preimage: &[u8; 32],
144144
) -> Result<(), Self::HashlockError> {
145145
unreachable!("Not used in this test")

0 commit comments

Comments
 (0)