@@ -186,38 +186,37 @@ impl fmt::Display for AccountMetaRole {
186
186
write ! ( f, "{:?}" , self )
187
187
}
188
188
}
189
- pub fn parse_transfer_hook_account < T > ( string : T ) -> Result < AccountMeta , String >
190
- where
191
- T : AsRef < str > + fmt:: Display ,
192
- {
193
- match string. as_ref ( ) . split ( ':' ) . collect :: < Vec < _ > > ( ) . as_slice ( ) {
194
- [ address, role] => {
195
- let address = Pubkey :: from_str ( address) . map_err ( |e| format ! ( "{e}" ) ) ?;
196
- let meta = match AccountMetaRole :: from_str ( role) . map_err ( |e| format ! ( "{e}" ) ) ? {
197
- AccountMetaRole :: Readonly => AccountMeta :: new_readonly ( address, false ) ,
198
- AccountMetaRole :: Writable => AccountMeta :: new ( address, false ) ,
199
- AccountMetaRole :: ReadonlySigner => AccountMeta :: new_readonly ( address, true ) ,
200
- AccountMetaRole :: WritableSigner => AccountMeta :: new ( address, true ) ,
201
- } ;
202
- Ok ( meta)
189
+
190
+ #[ derive( Clone , Copy ) ]
191
+ pub ( crate ) struct TransferHookAccount {
192
+ address : Pubkey ,
193
+ role : AccountMetaRole ,
194
+ }
195
+ impl FromStr for TransferHookAccount {
196
+ type Err = String ;
197
+
198
+ fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
199
+ match s. split ( ':' ) . collect :: < Vec < _ > > ( ) . as_slice ( ) {
200
+ [ address, role] => {
201
+ let address = Pubkey :: from_str ( address) . map_err ( |e| format ! ( "{e}" ) ) ?;
202
+ let role = AccountMetaRole :: from_str ( role) . map_err ( |e| format ! ( "{e}" ) ) ?;
203
+ Ok ( Self { address, role } )
204
+ }
205
+ _ => Err ( "Transfer hook account must be present as <ADDRESS>:<ROLE>" . to_string ( ) ) ,
203
206
}
204
- _ => Err ( "Transfer hook account must be present as <ADDRESS>:<ROLE>" . to_string ( ) ) ,
205
207
}
206
208
}
207
- fn validate_transfer_hook_account < T > ( string : T ) -> Result < ( ) , String >
208
- where
209
- T : AsRef < str > + fmt:: Display ,
210
- {
211
- match string. as_ref ( ) . split ( ':' ) . collect :: < Vec < _ > > ( ) . as_slice ( ) {
212
- [ address, role] => {
213
- is_valid_pubkey ( address) ?;
214
- AccountMetaRole :: from_str ( role)
215
- . map ( |_| ( ) )
216
- . map_err ( |e| format ! ( "{e}" ) )
209
+ impl TransferHookAccount {
210
+ pub ( crate ) fn create_account_meta ( & self ) -> AccountMeta {
211
+ match self . role {
212
+ AccountMetaRole :: Readonly => AccountMeta :: new_readonly ( self . address , false ) ,
213
+ AccountMetaRole :: Writable => AccountMeta :: new ( self . address , false ) ,
214
+ AccountMetaRole :: ReadonlySigner => AccountMeta :: new_readonly ( self . address , true ) ,
215
+ AccountMetaRole :: WritableSigner => AccountMeta :: new ( self . address , true ) ,
217
216
}
218
- _ => Err ( "Transfer hook account must be present as <ADDRESS>:<ROLE>" . to_string ( ) ) ,
219
217
}
220
218
}
219
+
221
220
#[ derive( Debug , Clone , PartialEq , EnumIter , EnumString , IntoStaticStr ) ]
222
221
#[ strum( serialize_all = "kebab-case" ) ]
223
222
pub enum CliAuthorityType {
@@ -1427,7 +1426,7 @@ pub fn app<'a>(
1427
1426
. arg (
1428
1427
Arg :: with_name ( "transfer_hook_account" )
1429
1428
. long ( "transfer-hook-account" )
1430
- . validator ( |s| validate_transfer_hook_account ( s ) )
1429
+ . value_parser ( clap :: value_parser! ( TransferHookAccount ) )
1431
1430
. value_name ( "PUBKEY:ROLE" )
1432
1431
. takes_value ( true )
1433
1432
. multiple ( true )
0 commit comments