Skip to content

Commit 783671d

Browse files
committed
feat(stack): Sha256 operator
1 parent f0cd37f commit 783671d

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

stack/src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub use scriptful::prelude::Item;
1919
pub enum MyOperator {
2020
Equal,
2121
Hash160,
22+
Sha256,
2223
CheckMultiSig,
2324
CheckTimeLock,
2425
/// Stop script execution if top-most element of stack is not "true"
@@ -63,6 +64,16 @@ fn hash_160_operator(stack: &mut Stack<MyValue>) {
6364
}
6465
}
6566

67+
fn sha_256_operator(stack: &mut Stack<MyValue>) {
68+
let a = stack.pop();
69+
if let MyValue::Bytes(bytes) = a {
70+
let Sha256(h) = calculate_sha256(&bytes);
71+
stack.push(MyValue::Bytes(h.to_vec()));
72+
} else {
73+
// TODO: hash other types?
74+
}
75+
}
76+
6677
fn check_multisig_operator(stack: &mut Stack<MyValue>) {
6778
let m = stack.pop();
6879
match m {
@@ -191,6 +202,7 @@ fn my_operator_system(
191202
match operator {
192203
MyOperator::Equal => equal_operator(stack),
193204
MyOperator::Hash160 => hash_160_operator(stack),
205+
MyOperator::Sha256 => sha_256_operator(stack),
194206
MyOperator::CheckMultiSig => check_multisig_operator(stack),
195207
MyOperator::CheckTimeLock => check_timelock_operator(stack, context.block_timestamp),
196208
MyOperator::Verify => {

0 commit comments

Comments
 (0)