@@ -33,6 +33,8 @@ pub enum MyValue {
3333 String ( String ) ,
3434 /// Bytes.
3535 Bytes ( Vec < u8 > ) ,
36+ /// Signature.
37+ Signature ( Vec < u8 > ) ,
3638}
3739
3840fn equal_operator ( stack : & mut Stack < MyValue > ) {
@@ -43,17 +45,13 @@ fn equal_operator(stack: &mut Stack<MyValue>) {
4345
4446fn hash_160_operator ( stack : & mut Stack < MyValue > ) {
4547 let a = stack. pop ( ) ;
46- match a {
47- MyValue :: Boolean ( _) => { }
48- MyValue :: Float ( _) => { }
49- MyValue :: Integer ( _) => { }
50- MyValue :: String ( _) => { }
51- MyValue :: Bytes ( bytes) => {
52- let mut pkh = [ 0 ; 20 ] ;
53- let Sha256 ( h) = calculate_sha256 ( & bytes) ;
54- pkh. copy_from_slice ( & h[ ..20 ] ) ;
55- stack. push ( MyValue :: Bytes ( pkh. as_ref ( ) . to_vec ( ) ) ) ;
56- }
48+ if let MyValue :: Bytes ( bytes) = a {
49+ let mut pkh = [ 0 ; 20 ] ;
50+ let Sha256 ( h) = calculate_sha256 ( & bytes) ;
51+ pkh. copy_from_slice ( & h[ ..20 ] ) ;
52+ stack. push ( MyValue :: Bytes ( pkh. as_ref ( ) . to_vec ( ) ) ) ;
53+ } else {
54+ // TODO: hash other types?
5755 }
5856}
5957
@@ -94,7 +92,7 @@ fn check_multi_sig(bytes_pkhs: Vec<MyValue>, bytes_keyed_signatures: Vec<MyValue
9492 let mut signed_pkhs = vec ! [ ] ;
9593 for signature in bytes_keyed_signatures {
9694 match signature {
97- MyValue :: Bytes ( bytes) => {
95+ MyValue :: Signature ( bytes) => {
9896 // TODO Handle unwrap
9997 let ks: KeyedSignature = KeyedSignature :: from_pb_bytes ( & bytes) . unwrap ( ) ;
10098 let signed_pkh = ks. public_key . pkh ( ) ;
@@ -364,8 +362,8 @@ mod tests {
364362 let ks_3 = ks_from_pk ( pk_3. clone ( ) ) ;
365363
366364 let witness = vec ! [
367- Item :: Value ( MyValue :: Bytes ( ks_1. to_pb_bytes( ) . unwrap( ) ) ) ,
368- Item :: Value ( MyValue :: Bytes ( ks_2. to_pb_bytes( ) . unwrap( ) ) ) ,
365+ Item :: Value ( MyValue :: Signature ( ks_1. to_pb_bytes( ) . unwrap( ) ) ) ,
366+ Item :: Value ( MyValue :: Signature ( ks_2. to_pb_bytes( ) . unwrap( ) ) ) ,
369367 ] ;
370368 let redeem_script = vec ! [
371369 Item :: Value ( MyValue :: Integer ( 2 ) ) ,
@@ -381,8 +379,8 @@ mod tests {
381379 ) ) ;
382380
383381 let other_valid_witness = vec ! [
384- Item :: Value ( MyValue :: Bytes ( ks_1. to_pb_bytes( ) . unwrap( ) ) ) ,
385- Item :: Value ( MyValue :: Bytes ( ks_3. to_pb_bytes( ) . unwrap( ) ) ) ,
382+ Item :: Value ( MyValue :: Signature ( ks_1. to_pb_bytes( ) . unwrap( ) ) ) ,
383+ Item :: Value ( MyValue :: Signature ( ks_3. to_pb_bytes( ) . unwrap( ) ) ) ,
386384 ] ;
387385 let redeem_script = vec ! [
388386 Item :: Value ( MyValue :: Integer ( 2 ) ) ,
@@ -400,8 +398,8 @@ mod tests {
400398 let pk_4 = PublicKey :: from_bytes ( [ 4 ; 33 ] ) ;
401399 let ks_4 = ks_from_pk ( pk_4) ;
402400 let invalid_witness = vec ! [
403- Item :: Value ( MyValue :: Bytes ( ks_1. to_pb_bytes( ) . unwrap( ) ) ) ,
404- Item :: Value ( MyValue :: Bytes ( ks_4. to_pb_bytes( ) . unwrap( ) ) ) ,
401+ Item :: Value ( MyValue :: Signature ( ks_1. to_pb_bytes( ) . unwrap( ) ) ) ,
402+ Item :: Value ( MyValue :: Signature ( ks_4. to_pb_bytes( ) . unwrap( ) ) ) ,
405403 ] ;
406404 let redeem_script = vec ! [
407405 Item :: Value ( MyValue :: Integer ( 2 ) ) ,
0 commit comments