5
5
use std:: fmt:: { Display , Formatter } ;
6
6
7
7
use anyhow:: { anyhow, Context } ;
8
+ use catalyst_types:: hashes:: Blake2b224Hash ;
8
9
use pallas:: {
9
10
crypto:: hash:: Hash ,
10
11
ledger:: {
@@ -26,8 +27,9 @@ impl StakeAddress {
26
27
/// Creates a new instance from the given parameters.
27
28
#[ allow( clippy:: expect_used, clippy:: missing_panics_doc) ]
28
29
#[ must_use]
29
- pub fn new ( network : Network , is_script : bool , hash : Hash < 28 > ) -> Self {
30
+ pub fn new ( network : Network , is_script : bool , stake_pk_hash : Blake2b224Hash ) -> Self {
30
31
let network = network. into ( ) ;
32
+ let hash = stake_pk_hash. into ( ) ;
31
33
// `pallas::StakeAddress` can only be constructed from `ShelleyAddress`, so we are forced
32
34
// to create a dummy shelley address. The input hash parameter is used to construct both
33
35
// payment and delegation parts, but the payment part isn't used in the stake address
@@ -49,8 +51,8 @@ impl StakeAddress {
49
51
#[ must_use]
50
52
pub fn from_stake_cred ( network : Network , cred : & conway:: StakeCredential ) -> Self {
51
53
match cred {
52
- conway:: StakeCredential :: Scripthash ( h) => Self :: new ( network, true , * h ) ,
53
- conway:: StakeCredential :: AddrKeyhash ( h) => Self :: new ( network, false , * h ) ,
54
+ conway:: StakeCredential :: Scripthash ( h) => Self :: new ( network, true , ( * h ) . into ( ) ) ,
55
+ conway:: StakeCredential :: AddrKeyhash ( h) => Self :: new ( network, false , ( * h ) . into ( ) ) ,
54
56
}
55
57
}
56
58
@@ -111,7 +113,7 @@ impl TryFrom<&[u8]> for StakeAddress {
111
113
v => return Err ( anyhow ! ( "Unexpected type value: {v}, header = {header}" ) ) ,
112
114
} ;
113
115
114
- Ok ( Self :: new ( network, is_script, hash) )
116
+ Ok ( Self :: new ( network, is_script, hash. into ( ) ) )
115
117
}
116
118
}
117
119
@@ -155,7 +157,7 @@ mod tests {
155
157
] ;
156
158
157
159
for ( network, is_script, hash, expected_header) in test_data {
158
- let stake_address = StakeAddress :: new ( network, is_script, hash) ;
160
+ let stake_address = StakeAddress :: new ( network, is_script, hash. into ( ) ) ;
159
161
assert_eq ! ( stake_address. is_script( ) , is_script) ;
160
162
161
163
// Check that conversion to bytes includes the expected header value.
@@ -227,7 +229,7 @@ mod tests {
227
229
// cSpell:enable
228
230
229
231
for ( network, is_script, hash, expected) in test_data {
230
- let address = StakeAddress :: new ( network, is_script, hash) ;
232
+ let address = StakeAddress :: new ( network, is_script, hash. into ( ) ) ;
231
233
assert_eq ! ( expected, format!( "{address}" ) ) ;
232
234
}
233
235
}
0 commit comments