@@ -226,22 +226,41 @@ impl<T: Clone, A: VerificationAlgorithm> Clone for Signed<T, A> {
226226 any( test, feature = "property-test-api" ) ,
227227 derive( test_strategy:: Arbitrary )
228228) ]
229- pub struct Hash ( crypto:: Blake2b256 ) ;
229+ pub struct Hash {
230+ hash : crypto:: Blake2b256 ,
231+ }
232+
230233impl Hash {
234+ pub fn new ( hash : crypto:: Blake2b256 ) -> Self {
235+ Self { hash }
236+ }
237+
238+ pub fn get_hash ( & self ) -> & crypto:: Blake2b256 {
239+ & self . hash
240+ }
241+
231242 /// All 0 hash used as a special hash
232243 pub fn zero_hash ( ) -> Self {
233- Hash ( crypto:: Blake2b256 :: from ( [ 0 ; crypto:: Blake2b256 :: HASH_SIZE ] ) )
244+ Hash {
245+ hash : crypto:: Blake2b256 :: from ( [ 0 ; crypto:: Blake2b256 :: HASH_SIZE ] ) ,
246+ }
234247 }
248+
235249 pub fn hash_bytes ( bytes : & [ u8 ] ) -> Self {
236- Hash ( crypto:: Blake2b256 :: new ( bytes) )
250+ Hash {
251+ hash : crypto:: Blake2b256 :: new ( bytes) ,
252+ }
237253 }
254+
238255 pub fn from_bytes ( bytes : [ u8 ; 32 ] ) -> Self {
239- Hash ( crypto:: Blake2b256 :: from ( bytes) )
256+ Hash {
257+ hash : crypto:: Blake2b256 :: from ( bytes) ,
258+ }
240259 }
241260
242261 #[ inline]
243262 pub fn as_bytes ( & self ) -> & [ u8 ] {
244- self . 0 . as_ref ( )
263+ self . hash . as_ref ( )
245264 }
246265}
247266
@@ -253,63 +272,69 @@ impl From<[u8; 32]> for Hash {
253272
254273impl From < Hash > for [ u8 ; 32 ] {
255274 fn from ( h : Hash ) -> Self {
256- h. 0 . into ( )
275+ h. hash . into ( )
257276 }
258277}
259278
260279impl < ' a > From < & ' a Hash > for & ' a [ u8 ; 32 ] {
261280 fn from ( h : & ' a Hash ) -> Self {
262- ( & h. 0 ) . into ( )
281+ ( & h. hash ) . into ( )
263282 }
264283}
265284
266285impl Serialize for Hash {
267286 fn serialized_size ( & self ) -> usize {
268- self . 0 . as_hash_bytes ( ) . serialized_size ( )
287+ self . hash . as_hash_bytes ( ) . serialized_size ( )
269288 }
270289
271290 fn serialize < W : std:: io:: Write > ( & self , codec : & mut Codec < W > ) -> Result < ( ) , WriteError > {
272- codec. put_bytes ( self . 0 . as_hash_bytes ( ) )
291+ codec. put_bytes ( self . hash . as_hash_bytes ( ) )
273292 }
274293}
275294
276295impl Deserialize for Hash {
277296 fn deserialize < R : std:: io:: Read > ( codec : & mut Codec < R > ) -> Result < Self , ReadError > {
278297 let bytes = <[ u8 ; crypto:: Blake2b256 :: HASH_SIZE ] >:: deserialize ( codec) ?;
279- Ok ( Hash ( crypto:: Blake2b256 :: from ( bytes) ) )
298+ Ok ( Hash {
299+ hash : crypto:: Blake2b256 :: from ( bytes) ,
300+ } )
280301 }
281302}
282303
283304impl BlockId for Hash {
284305 fn zero ( ) -> Hash {
285- Hash ( crypto:: Blake2b256 :: from ( [ 0 ; crypto:: Blake2b256 :: HASH_SIZE ] ) )
306+ Hash {
307+ hash : crypto:: Blake2b256 :: from ( [ 0 ; crypto:: Blake2b256 :: HASH_SIZE ] ) ,
308+ }
286309 }
287310}
288311
289312impl FragmentId for Hash { }
290313
291314impl AsRef < [ u8 ] > for Hash {
292315 fn as_ref ( & self ) -> & [ u8 ] {
293- self . 0 . as_ref ( )
316+ self . hash . as_ref ( )
294317 }
295318}
296319
297320impl From < crypto:: Blake2b256 > for Hash {
298321 fn from ( hash : crypto:: Blake2b256 ) -> Self {
299- Hash ( hash)
322+ Hash { hash }
300323 }
301324}
302325
303326impl std:: fmt:: Display for Hash {
304327 fn fmt ( & self , f : & mut std:: fmt:: Formatter ) -> std:: fmt:: Result {
305- write ! ( f, "{}" , self . 0 )
328+ write ! ( f, "{}" , self . hash )
306329 }
307330}
308331
309332impl FromStr for Hash {
310333 type Err = crypto:: hash:: Error ;
311334 fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
312- Ok ( Hash ( crypto:: Blake2b256 :: from_str ( s) ?) )
335+ Ok ( Hash {
336+ hash : crypto:: Blake2b256 :: from_str ( s) ?,
337+ } )
313338 }
314339}
315340
@@ -408,7 +433,9 @@ mod tests {
408433
409434 impl Arbitrary for Hash {
410435 fn arbitrary < G : Gen > ( g : & mut G ) -> Self {
411- Hash ( Arbitrary :: arbitrary ( g) )
436+ Hash {
437+ hash : Arbitrary :: arbitrary ( g) ,
438+ }
412439 }
413440 }
414441 impl Arbitrary for EitherEd25519SecretKey {
0 commit comments