@@ -85,53 +85,61 @@ impl Workspace {
8585 } )
8686 }
8787
88- /// New [CommandContext] using the configured upgrade authority keypair.
89- pub fn new_upgrader_context < ' a , ' b > ( & ' a self , cluster : & ' b Cluster ) -> CommandContext < ' a , ' b > {
90- let keypair_path = self . cfg . upgrade_authority_keypair . clone ( ) . unwrap ( ) ;
91- CommandContext {
88+ /// The upgrader.
89+ pub fn get_upgrader_wallet ( & self ) -> Result < String > {
90+ self . cfg
91+ . upgrade_authority_keypair
92+ . clone ( )
93+ . ok_or_else ( || format_err ! ( "upgrade_authority_keypair not found in Goki.toml" ) )
94+ }
95+
96+ /// New [CommandContext] using the specified cluster.
97+ pub fn new_cluster_context < ' a , ' b > (
98+ & ' a self ,
99+ cluster : & ' b Cluster ,
100+ ) -> Result < CommandContext < ' a , ' b > > {
101+ Ok ( CommandContext {
92102 workspace : self ,
93103 cluster,
94- keypair_path,
95- }
104+ } )
96105 }
97106}
98107
99108pub struct CommandContext < ' a , ' b > {
100109 pub workspace : & ' a Workspace ,
101110 pub cluster : & ' b Cluster ,
102- pub keypair_path : String ,
103111}
104112
105113impl < ' a , ' b > CommandContext < ' a , ' b > {
106- fn add_cluster_args ( & self , command : & mut Command ) -> Result < ( ) > {
114+ fn add_cluster_args ( & self , command : & mut Command , wallet : & str ) -> Result < ( ) > {
107115 command
108116 . args ( [
109117 "--url" ,
110118 self . workspace . get_cluster_url ( self . cluster ) ?,
111119 "--keypair" ,
112120 ] )
113- . arg ( & self . keypair_path ) ;
121+ . arg ( wallet ) ;
114122 Ok ( ( ) )
115123 }
116124
117125 /// Executes a command.
118- pub fn exec_command < F > ( & self , mut builder : F ) -> Result < Output >
126+ pub fn exec_command < F > ( & self , mut builder : F , wallet : & str ) -> Result < Output >
119127 where
120128 F : FnMut ( & mut Command ) -> Result < ( ) > ,
121129 {
122130 let cmd = & mut new_solana_cmd ( ) ;
123- self . add_cluster_args ( cmd) ?;
131+ self . add_cluster_args ( cmd, wallet ) ?;
124132 builder ( cmd) ?;
125133 exec_command ( cmd)
126134 }
127135
128136 /// Executes a command.
129- pub fn exec_args < S > ( & self , args : & [ S ] ) -> Result < Output >
137+ pub fn exec_args < S > ( & self , args : & [ S ] , wallet : & str ) -> Result < Output >
130138 where
131139 S : AsRef < OsStr > ,
132140 {
133141 let cmd = & mut new_solana_cmd ( ) ;
134- self . add_cluster_args ( cmd) ?;
142+ self . add_cluster_args ( cmd, wallet ) ?;
135143 args. iter ( ) . for_each ( |arg| {
136144 cmd. arg ( arg. as_ref ( ) ) ;
137145 } ) ;
@@ -141,4 +149,13 @@ impl<'a, 'b> CommandContext<'a, 'b> {
141149 pub fn get_deployer_kp_path ( & self ) -> PathBuf {
142150 self . workspace . get_deployer_kp_path ( self . cluster )
143151 }
152+
153+ pub fn parse_wallet_alias ( & self , alias : & str ) -> Result < String > {
154+ let result = match alias {
155+ "deployer" => Ok ( self . get_deployer_kp_path ( ) . display ( ) . to_string ( ) ) ,
156+ "upgrader" => self . workspace . get_upgrader_wallet ( ) ,
157+ _ => Ok ( alias. to_string ( ) ) ,
158+ } ;
159+ result. map_err ( |err| format_err ! ( "could not parse alias {}: {}" , alias, err) )
160+ }
144161}
0 commit comments