@@ -119,7 +119,6 @@ pub mod psbt;
119119mod test_utils;
120120mod util;
121121
122- use core:: str:: FromStr ;
123122use core:: { fmt, hash, str} ;
124123#[ cfg( feature = "std" ) ]
125124use std:: error;
@@ -334,204 +333,6 @@ impl ToPublicKey for bitcoin::secp256k1::XOnlyPublicKey {
334333 }
335334}
336335
337- /// Dummy key which de/serializes to the empty string; useful sometimes for testing
338- #[ derive( Copy , Clone , PartialOrd , Ord , PartialEq , Eq , Debug , Default ) ]
339- pub struct DummyKey ;
340-
341- impl str:: FromStr for DummyKey {
342- type Err = & ' static str ;
343- fn from_str ( x : & str ) -> Result < DummyKey , & ' static str > {
344- if x. is_empty ( ) {
345- Ok ( DummyKey )
346- } else {
347- Err ( "non empty dummy key" )
348- }
349- }
350- }
351-
352- impl MiniscriptKey for DummyKey {
353- type Sha256 = DummySha256Hash ;
354- type Hash256 = DummyHash256Hash ;
355- type Ripemd160 = DummyRipemd160Hash ;
356- type Hash160 = DummyHash160Hash ;
357-
358- fn num_der_paths ( & self ) -> usize {
359- 0
360- }
361- }
362-
363- impl hash:: Hash for DummyKey {
364- fn hash < H : hash:: Hasher > ( & self , state : & mut H ) {
365- "DummyKey" . hash ( state) ;
366- }
367- }
368-
369- impl fmt:: Display for DummyKey {
370- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
371- f. write_str ( "" )
372- }
373- }
374-
375- impl ToPublicKey for DummyKey {
376- fn to_public_key ( & self ) -> bitcoin:: PublicKey {
377- bitcoin:: PublicKey :: from_str (
378- "0250863ad64a87ae8a2fe83c1af1a8403cb53f53e486d8511dad8a04887e5b2352" ,
379- )
380- . unwrap ( )
381- }
382-
383- fn to_sha256 ( _hash : & DummySha256Hash ) -> sha256:: Hash {
384- sha256:: Hash :: from_str ( "50863ad64a87ae8a2fe83c1af1a8403cb53f53e486d8511dad8a04887e5b2352" )
385- . unwrap ( )
386- }
387-
388- fn to_hash256 ( _hash : & DummyHash256Hash ) -> hash256:: Hash {
389- hash256:: Hash :: from_str ( "50863ad64a87ae8a2fe83c1af1a8403cb53f53e486d8511dad8a04887e5b2352" )
390- . unwrap ( )
391- }
392-
393- fn to_ripemd160 ( _: & DummyRipemd160Hash ) -> ripemd160:: Hash {
394- ripemd160:: Hash :: from_str ( "f54a5851e9372b87810a8e60cdd2e7cfd80b6e31" ) . unwrap ( )
395- }
396-
397- fn to_hash160 ( _: & DummyHash160Hash ) -> hash160:: Hash {
398- hash160:: Hash :: from_str ( "f54a5851e9372b87810a8e60cdd2e7cfd80b6e31" ) . unwrap ( )
399- }
400- }
401-
402- /// Dummy keyhash which de/serializes to the empty string; useful sometimes for testing
403- #[ derive( Copy , Clone , PartialOrd , Ord , PartialEq , Eq , Debug , Default ) ]
404- pub struct DummyKeyHash ;
405-
406- impl str:: FromStr for DummyKeyHash {
407- type Err = & ' static str ;
408- fn from_str ( x : & str ) -> Result < DummyKeyHash , & ' static str > {
409- if x. is_empty ( ) {
410- Ok ( DummyKeyHash )
411- } else {
412- Err ( "non empty dummy key" )
413- }
414- }
415- }
416-
417- impl fmt:: Display for DummyKeyHash {
418- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
419- f. write_str ( "" )
420- }
421- }
422-
423- impl hash:: Hash for DummyKeyHash {
424- fn hash < H : hash:: Hasher > ( & self , state : & mut H ) {
425- "DummyKeyHash" . hash ( state) ;
426- }
427- }
428-
429- /// Dummy keyhash which de/serializes to the empty string; useful for testing
430- #[ derive( Copy , Clone , PartialOrd , Ord , PartialEq , Eq , Debug , Default ) ]
431- pub struct DummySha256Hash ;
432-
433- impl str:: FromStr for DummySha256Hash {
434- type Err = & ' static str ;
435- fn from_str ( x : & str ) -> Result < DummySha256Hash , & ' static str > {
436- if x. is_empty ( ) {
437- Ok ( DummySha256Hash )
438- } else {
439- Err ( "non empty dummy hash" )
440- }
441- }
442- }
443-
444- impl fmt:: Display for DummySha256Hash {
445- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
446- f. write_str ( "" )
447- }
448- }
449-
450- impl hash:: Hash for DummySha256Hash {
451- fn hash < H : hash:: Hasher > ( & self , state : & mut H ) {
452- "DummySha256Hash" . hash ( state) ;
453- }
454- }
455-
456- /// Dummy keyhash which de/serializes to the empty string; useful for testing
457- #[ derive( Copy , Clone , PartialOrd , Ord , PartialEq , Eq , Debug , Default ) ]
458- pub struct DummyHash256Hash ;
459-
460- impl str:: FromStr for DummyHash256Hash {
461- type Err = & ' static str ;
462- fn from_str ( x : & str ) -> Result < DummyHash256Hash , & ' static str > {
463- if x. is_empty ( ) {
464- Ok ( DummyHash256Hash )
465- } else {
466- Err ( "non empty dummy hash" )
467- }
468- }
469- }
470-
471- /// Dummy keyhash which de/serializes to the empty string; useful for testing
472- #[ derive( Copy , Clone , PartialOrd , Ord , PartialEq , Eq , Debug , Default ) ]
473- pub struct DummyRipemd160Hash ;
474-
475- impl str:: FromStr for DummyRipemd160Hash {
476- type Err = & ' static str ;
477- fn from_str ( x : & str ) -> Result < DummyRipemd160Hash , & ' static str > {
478- if x. is_empty ( ) {
479- Ok ( DummyRipemd160Hash )
480- } else {
481- Err ( "non empty dummy hash" )
482- }
483- }
484- }
485-
486- impl fmt:: Display for DummyHash256Hash {
487- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
488- f. write_str ( "" )
489- }
490- }
491- impl fmt:: Display for DummyRipemd160Hash {
492- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
493- f. write_str ( "" )
494- }
495- }
496-
497- impl hash:: Hash for DummyHash256Hash {
498- fn hash < H : hash:: Hasher > ( & self , state : & mut H ) {
499- "DummySha256Hash" . hash ( state) ;
500- }
501- }
502-
503- impl hash:: Hash for DummyRipemd160Hash {
504- fn hash < H : hash:: Hasher > ( & self , state : & mut H ) {
505- "DummyRipemd160Hash" . hash ( state) ;
506- }
507- }
508-
509- /// Dummy keyhash which de/serializes to the empty string; useful for testing
510- #[ derive( Copy , Clone , PartialOrd , Ord , PartialEq , Eq , Debug , Default ) ]
511- pub struct DummyHash160Hash ;
512-
513- impl str:: FromStr for DummyHash160Hash {
514- type Err = & ' static str ;
515- fn from_str ( x : & str ) -> Result < DummyHash160Hash , & ' static str > {
516- if x. is_empty ( ) {
517- Ok ( DummyHash160Hash )
518- } else {
519- Err ( "non empty dummy hash" )
520- }
521- }
522- }
523-
524- impl fmt:: Display for DummyHash160Hash {
525- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
526- f. write_str ( "" )
527- }
528- }
529-
530- impl hash:: Hash for DummyHash160Hash {
531- fn hash < H : hash:: Hasher > ( & self , state : & mut H ) {
532- "DummyHash160Hash" . hash ( state) ;
533- }
534- }
535336/// Describes an object that can translate various keys and hashes from one key to the type
536337/// associated with the other key. Used by the [`TranslatePk`] trait to do the actual translations.
537338pub trait Translator < P , Q , E >
@@ -926,6 +727,8 @@ fn hex_script(s: &str) -> bitcoin::Script {
926727
927728#[ cfg( test) ]
928729mod tests {
730+ use core:: str:: FromStr ;
731+
929732 use super :: * ;
930733
931734 #[ test]
0 commit comments