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