File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ pub use scriptful::prelude::Item;
1919pub 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+
6677fn 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 => {
You can’t perform that action at this time.
0 commit comments