@@ -188,38 +188,37 @@ impl fmt::Display for AccountMetaRole {
188188 write ! ( f, "{:?}" , self )
189189 }
190190}
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 ( ) ) ,
205208 }
206- _ => Err ( "Transfer hook account must be present as <ADDRESS>:<ROLE>" . to_string ( ) ) ,
207209 }
208210}
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 ) ,
219218 }
220- _ => Err ( "Transfer hook account must be present as <ADDRESS>:<ROLE>" . to_string ( ) ) ,
221219 }
222220}
221+
223222#[ derive( Debug , Clone , PartialEq , EnumIter , EnumString , IntoStaticStr ) ]
224223#[ strum( serialize_all = "kebab-case" ) ]
225224pub enum CliAuthorityType {
@@ -1429,7 +1428,7 @@ pub fn app<'a>(
14291428 . arg (
14301429 Arg :: with_name ( "transfer_hook_account" )
14311430 . long ( "transfer-hook-account" )
1432- . validator ( |s| validate_transfer_hook_account ( s ) )
1431+ . value_parser ( clap :: value_parser! ( TransferHookAccount ) )
14331432 . value_name ( "PUBKEY:ROLE" )
14341433 . takes_value ( true )
14351434 . multiple ( true )
0 commit comments