1+ use std:: { ops:: Deref , str:: FromStr } ;
2+
3+ /// Pattern.
4+ #[ derive( Clone , Debug , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
5+ pub ( super ) struct Pattern ( Box < str > ) ;
6+
7+ impl Deref for Pattern {
8+ type Target = str ;
9+
10+ fn deref ( & self ) -> & Self :: Target {
11+ & self . 0
12+ }
13+ }
14+
15+ impl Pattern {
16+ pub ( super ) fn into_bytes ( self ) -> Result < Vec < u8 > , hex:: FromHexError > {
17+ let mut string = self . to_string ( ) ;
18+
19+ if self . len ( ) % 2 != 0 {
20+ string += "0"
21+ } ;
22+
23+ hex:: decode ( string)
24+ }
25+ }
26+
27+ /// Pattern errors.
28+ #[ derive( Clone , Copy , Debug , PartialEq , Eq , thiserror:: Error ) ]
29+ pub ( super ) enum PatternError {
30+ #[ error( "the pattern's length exceeds 39 characters or the pattern is empty" ) ]
31+ InvalidPatternLength ,
32+ #[ error( "the pattern is not in hexadecimal format" ) ]
33+ NonHexPattern ,
34+ }
35+
36+ impl FromStr for Pattern {
37+ type Err = PatternError ;
38+
39+ fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
40+ if s. len ( ) >= 40 || s. is_empty ( ) {
41+ return Err ( PatternError :: InvalidPatternLength ) ;
42+ }
43+
44+ if s. chars ( ) . any ( |c| !c. is_ascii_hexdigit ( ) ) {
45+ return Err ( PatternError :: NonHexPattern ) ;
46+ }
47+
48+ Ok ( Self ( s. into ( ) ) )
49+ }
50+ }
51+
52+ #[ derive( Clone , Debug , clap:: Parser ) ]
53+ #[ command( name = "vanity" , about = "Vanity is a fast vanity address miner." ) ]
54+ pub ( super ) enum Vanity {
55+ Move {
56+ #[ clap( long) ]
57+ starts_pattern : Option < String > ,
58+ #[ clap( long) ]
59+ ends_pattern : Option < String > ,
60+ } ,
61+ }
0 commit comments