1
1
//! Signature hashes for Zcash transactions
2
2
3
+ use zcash_transparent:: sighash:: SighashType ;
4
+
3
5
use super :: Transaction ;
4
6
5
7
use crate :: parameters:: NetworkUpgrade ;
@@ -19,6 +21,29 @@ bitflags::bitflags! {
19
21
const SINGLE = Self :: ALL . bits( ) | Self :: NONE . bits( ) ;
20
22
/// Anyone can add inputs to this transaction
21
23
const ANYONECANPAY = 0b1000_0000 ;
24
+
25
+ /// Sign all the outputs and Anyone can add inputs to this transaction
26
+ const ALL_ANYONECANPAY = Self :: ALL . bits( ) | Self :: ANYONECANPAY . bits( ) ;
27
+ /// Sign none of the outputs and Anyone can add inputs to this transaction
28
+ const NONE_ANYONECANPAY = Self :: NONE . bits( ) | Self :: ANYONECANPAY . bits( ) ;
29
+ /// Sign one of the outputs and Anyone can add inputs to this transaction
30
+ const SINGLE_ANYONECANPAY = Self :: SINGLE . bits( ) | Self :: ANYONECANPAY . bits( ) ;
31
+ }
32
+ }
33
+
34
+ impl TryFrom < HashType > for SighashType {
35
+ type Error = ( ) ;
36
+
37
+ fn try_from ( hash_type : HashType ) -> Result < Self , Self :: Error > {
38
+ Ok ( match hash_type {
39
+ HashType :: ALL => Self :: ALL ,
40
+ HashType :: NONE => Self :: NONE ,
41
+ HashType :: SINGLE => Self :: SINGLE ,
42
+ HashType :: ALL_ANYONECANPAY => Self :: ALL_ANYONECANPAY ,
43
+ HashType :: NONE_ANYONECANPAY => Self :: NONE_ANYONECANPAY ,
44
+ HashType :: SINGLE_ANYONECANPAY => Self :: SINGLE_ANYONECANPAY ,
45
+ _other => return Err ( ( ) ) ,
46
+ } )
22
47
}
23
48
}
24
49
0 commit comments