33#![ allow( dead_code) ]
44
55use crate :: hash:: Hash ;
6+ use crate :: serialization:: Bech32Conversion ;
67use crate :: {
78 address:: { Address , ShelleyAddress , StakeAddress } ,
89 declare_hash_type, declare_hash_type_with_bech32, protocol_params,
@@ -439,9 +440,13 @@ impl Default for UTXODelta {
439440 }
440441}
441442
443+ /// Key hash
442444pub type KeyHash = Hash < 28 > ;
443445
446+ /// Script hash
444447pub type ScriptHash = KeyHash ;
448+
449+ /// Address key hash
445450pub type AddrKeyhash = KeyHash ;
446451
447452/// Script identifier
@@ -451,8 +456,11 @@ declare_hash_type!(BlockHash, 32);
451456declare_hash_type ! ( TxHash , 32 ) ;
452457declare_hash_type_with_bech32 ! ( VrfKeyHash , 32 , "vrf_vk" ) ;
453458declare_hash_type_with_bech32 ! ( PoolId , 28 , "pool" ) ;
454- // declare_hash_type_with_bech32!(DrepKey, 28, "drep");
455- // declare_hash_type_with_bech32!(DrepScriptKey, 28, "drep_script");
459+
460+ declare_hash_type_with_bech32 ! ( ConstitutionalCommitteeKeyHash , 28 , "cc_hot" ) ;
461+ declare_hash_type_with_bech32 ! ( ConstitutionalCommitteeScriptHash , 28 , "cc_hot_script" ) ;
462+ declare_hash_type_with_bech32 ! ( DrepKeyHash , 28 , "drep" ) ;
463+ declare_hash_type_with_bech32 ! ( DRepScriptHash , 28 , "drep_script" ) ;
456464
457465/// Data hash used for metadata, anchors (SHA256)
458466pub type DataHash = Vec < u8 > ;
@@ -641,10 +649,10 @@ pub struct PotDelta {
641649) ]
642650pub enum Credential {
643651 /// Script hash. NOTE: Order matters when parsing Haskell Node Snapshot data.
644- ScriptHash ( #[ serde_as( as = "Hex" ) ] KeyHash ) ,
652+ ScriptHash ( #[ serde_as( as = "Hex" ) ] ScriptHash ) ,
645653
646654 /// Address key hash
647- AddrKeyHash ( #[ serde_as( as = "Hex" ) ] KeyHash ) ,
655+ AddrKeyHash ( #[ serde_as( as = "Hex" ) ] AddrKeyhash ) ,
648656}
649657
650658impl Credential {
@@ -1663,33 +1671,26 @@ impl GovernanceAction {
16631671 serde:: Serialize , serde:: Deserialize , Debug , PartialEq , PartialOrd , Eq , Ord , Clone , Hash ,
16641672) ]
16651673pub enum Voter {
1666- ConstitutionalCommitteeKey ( AddrKeyhash ) ,
1667- ConstitutionalCommitteeScript ( ScriptHash ) ,
1668- DRepKey ( AddrKeyhash ) ,
1669- DRepScript ( ScriptHash ) ,
1674+ ConstitutionalCommitteeKey ( ConstitutionalCommitteeKeyHash ) ,
1675+ ConstitutionalCommitteeScript ( ConstitutionalCommitteeScriptHash ) ,
1676+ DRepKey ( DrepKeyHash ) ,
1677+ DRepScript ( DRepScriptHash ) ,
16701678 StakePoolKey ( PoolId ) ,
16711679}
16721680
1673- impl Voter {
1674- pub fn to_bech32 ( & self , hrp : & str , buf : & [ u8 ] ) -> String {
1675- let voter_hrp: Hrp = Hrp :: parse ( hrp) . unwrap ( ) ;
1676- bech32:: encode :: < Bech32 > ( voter_hrp, buf)
1677- . unwrap_or_else ( |e| format ! ( "Cannot convert {:?} to bech32: {e}" , self ) )
1678- }
1679- }
1680-
16811681impl Display for Voter {
1682- fn fmt ( & self , f : & mut Formatter < ' _ > ) -> std:: fmt:: Result {
1683- match self {
1684- Voter :: ConstitutionalCommitteeKey ( h) => {
1685- write ! ( f, "{}" , self . to_bech32( "cc_hot" , h. as_ref( ) ) )
1686- }
1687- Voter :: ConstitutionalCommitteeScript ( s) => {
1688- write ! ( f, "{}" , self . to_bech32( "cc_hot_script" , s. as_ref( ) ) )
1689- }
1690- Voter :: DRepKey ( k) => write ! ( f, "{}" , self . to_bech32( "drep" , k. as_ref( ) ) ) ,
1691- Voter :: DRepScript ( s) => write ! ( f, "{}" , self . to_bech32( "drep_script" , s. as_ref( ) ) ) ,
1692- Voter :: StakePoolKey ( k) => write ! ( f, "{}" , self . to_bech32( "pool" , k. as_ref( ) ) ) ,
1682+ fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
1683+ let bech32 = match self {
1684+ Voter :: ConstitutionalCommitteeKey ( h) => h. to_bech32 ( ) ,
1685+ Voter :: ConstitutionalCommitteeScript ( s) => s. to_bech32 ( ) ,
1686+ Voter :: DRepKey ( k) => k. to_bech32 ( ) ,
1687+ Voter :: DRepScript ( s) => s. to_bech32 ( ) ,
1688+ Voter :: StakePoolKey ( k) => k. to_bech32 ( ) ,
1689+ } ;
1690+
1691+ match bech32 {
1692+ Ok ( s) => write ! ( f, "{}" , s) ,
1693+ Err ( e) => write ! ( f, "<invalid: {}>" , e) ,
16931694 }
16941695 }
16951696}
0 commit comments