@@ -186,38 +186,37 @@ impl fmt::Display for AccountMetaRole {
186186 write ! ( f, "{:?}" , self )
187187 }
188188}
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 ( ) ) ,
203206 }
204- _ => Err ( "Transfer hook account must be present as <ADDRESS>:<ROLE>" . to_string ( ) ) ,
205207 }
206208}
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 ) ,
217216 }
218- _ => Err ( "Transfer hook account must be present as <ADDRESS>:<ROLE>" . to_string ( ) ) ,
219217 }
220218}
219+
221220#[ derive( Debug , Clone , PartialEq , EnumIter , EnumString , IntoStaticStr ) ]
222221#[ strum( serialize_all = "kebab-case" ) ]
223222pub enum CliAuthorityType {
@@ -1427,7 +1426,7 @@ pub fn app<'a>(
14271426 . arg (
14281427 Arg :: with_name ( "transfer_hook_account" )
14291428 . long ( "transfer-hook-account" )
1430- . validator ( |s| validate_transfer_hook_account ( s ) )
1429+ . value_parser ( clap :: value_parser! ( TransferHookAccount ) )
14311430 . value_name ( "PUBKEY:ROLE" )
14321431 . takes_value ( true )
14331432 . multiple ( true )
0 commit comments