1515//! # Addresses
1616//!
1717
18- use std:: convert:: TryFrom as _;
18+ use std:: convert:: { TryFrom as _, TryInto as _ } ;
1919use std:: error;
2020use std:: fmt;
2121use std:: fmt:: Write as _;
2222use std:: str:: FromStr ;
2323
2424use bech32:: { Bech32 , Bech32m , ByteIterExt , Fe32 , Fe32IterExt , Hrp } ;
2525use crate :: blech32:: { Blech32 , Blech32m } ;
26- use crate :: hashes:: Hash ;
2726use bitcoin:: base58;
27+ use bitcoin:: hashes:: Hash as _;
2828use bitcoin:: PublicKey ;
2929use internals:: array:: ArrayExt as _;
3030use internals:: slice:: SliceExt ;
@@ -329,12 +329,12 @@ impl Address {
329329 ) -> Address {
330330 let ws = script:: Builder :: new ( )
331331 . push_int ( 0 )
332- . push_slice ( & WScriptHash :: hash ( & script[ .. ] ) [ .. ] )
332+ . push_slice ( WScriptHash :: hash_script ( script) . as_ref ( ) )
333333 . into_script ( ) ;
334334
335335 Address {
336336 params,
337- payload : Payload :: ScriptHash ( ScriptHash :: hash ( & ws[ .. ] ) ) ,
337+ payload : Payload :: ScriptHash ( ScriptHash :: hash_script ( & ws) ) ,
338338 blinding_pubkey : blinder,
339339 }
340340 }
@@ -386,9 +386,9 @@ impl Address {
386386 ) -> Option < Address > {
387387 Some ( Address {
388388 payload : if script. is_p2pkh ( ) {
389- Payload :: PubkeyHash ( Hash :: from_slice ( & script. as_bytes ( ) [ 3 ..23 ] ) . unwrap ( ) )
389+ Payload :: PubkeyHash ( PubkeyHash :: from_byte_array ( script. as_bytes ( ) [ 3 ..23 ] . try_into ( ) . unwrap ( ) ) )
390390 } else if script. is_p2sh ( ) {
391- Payload :: ScriptHash ( Hash :: from_slice ( & script. as_bytes ( ) [ 2 ..22 ] ) . unwrap ( ) )
391+ Payload :: ScriptHash ( ScriptHash :: from_byte_array ( script. as_bytes ( ) [ 2 ..22 ] . try_into ( ) . unwrap ( ) ) )
392392 } else if script. is_v0_p2wpkh ( ) {
393393 Payload :: WitnessProgram {
394394 version : Fe32 :: Q ,
@@ -418,12 +418,12 @@ impl Address {
418418 Payload :: PubkeyHash ( ref hash) => script:: Builder :: new ( )
419419 . push_opcode ( opcodes:: all:: OP_DUP )
420420 . push_opcode ( opcodes:: all:: OP_HASH160 )
421- . push_slice ( & hash[ .. ] )
421+ . push_slice ( hash. as_ref ( ) )
422422 . push_opcode ( opcodes:: all:: OP_EQUALVERIFY )
423423 . push_opcode ( opcodes:: all:: OP_CHECKSIG ) ,
424424 Payload :: ScriptHash ( ref hash) => script:: Builder :: new ( )
425425 . push_opcode ( opcodes:: all:: OP_HASH160 )
426- . push_slice ( & hash[ .. ] )
426+ . push_slice ( hash. as_byte_array ( ) )
427427 . push_opcode ( opcodes:: all:: OP_EQUAL ) ,
428428 Payload :: WitnessProgram {
429429 version : witver,
@@ -566,12 +566,12 @@ impl fmt::Display for Address {
566566 prefixed[ 0 ] = self . params . blinded_prefix ;
567567 prefixed[ 1 ] = self . params . p2pkh_prefix ;
568568 prefixed[ 2 ..35 ] . copy_from_slice ( & blinder. serialize ( ) ) ;
569- prefixed[ 35 ..] . copy_from_slice ( & hash[ .. ] ) ;
569+ prefixed[ 35 ..] . copy_from_slice ( hash. as_ref ( ) ) ;
570570 base58:: encode_check_to_fmt ( fmt, & prefixed[ ..] )
571571 } else {
572572 let mut prefixed = [ 0 ; 21 ] ;
573573 prefixed[ 0 ] = self . params . p2pkh_prefix ;
574- prefixed[ 1 ..] . copy_from_slice ( & hash[ .. ] ) ;
574+ prefixed[ 1 ..] . copy_from_slice ( hash. as_ref ( ) ) ;
575575 base58:: encode_check_to_fmt ( fmt, & prefixed[ ..] )
576576 }
577577 }
@@ -581,12 +581,12 @@ impl fmt::Display for Address {
581581 prefixed[ 0 ] = self . params . blinded_prefix ;
582582 prefixed[ 1 ] = self . params . p2sh_prefix ;
583583 prefixed[ 2 ..35 ] . copy_from_slice ( & blinder. serialize ( ) ) ;
584- prefixed[ 35 ..] . copy_from_slice ( & hash[ .. ] ) ;
584+ prefixed[ 35 ..] . copy_from_slice ( hash. as_byte_array ( ) ) ;
585585 base58:: encode_check_to_fmt ( fmt, & prefixed[ ..] )
586586 } else {
587587 let mut prefixed = [ 0 ; 21 ] ;
588588 prefixed[ 0 ] = self . params . p2sh_prefix ;
589- prefixed[ 1 ..] . copy_from_slice ( & hash[ .. ] ) ;
589+ prefixed[ 1 ..] . copy_from_slice ( hash. as_byte_array ( ) ) ;
590590 base58:: encode_check_to_fmt ( fmt, & prefixed[ ..] )
591591 }
592592 }
@@ -937,7 +937,7 @@ mod test {
937937 "93c7378d96518a75448821c4f7c8f4bae7ce60f804d03d1f0628dd5dd0f5de51" ,
938938 )
939939 . unwrap ( ) ;
940- let tap_node_hash = TapNodeHash :: all_zeros ( ) ;
940+ let tap_node_hash = TapNodeHash :: from_byte_array ( [ 0 ; 32 ] ) ;
941941
942942 let mut expected = IntoIterator :: into_iter ( [
943943 "2dszRCFv8Ub4ytKo1Q1vXXGgSx7mekNDwSJ" ,
0 commit comments