1- use crate :: utils:: { config, horizon, print as p, soroban} ;
1+ use crate :: commands:: info;
2+ use crate :: utils:: { config, horizon, print as p} ;
23use anyhow:: Result ;
34use clap:: Args ;
45use colored:: * ;
56use std:: fs;
67use std:: path:: PathBuf ;
8+ use std:: process:: Command ;
79
810const SOROBAN_WASM_LIMIT_KB : f64 = 128.0 ;
911
@@ -21,9 +23,9 @@ pub struct DeployArgs {
2123 /// Skip confirmation prompt
2224 #[ arg( long, default_value = "false" ) ]
2325 pub yes : bool ,
24- /// Simulate the deploy transaction first and show estimated Soroban fee / errors
26+ /// Execute deployment immediately if Stellar CLI is installed
2527 #[ arg( long, default_value = "false" ) ]
26- pub simulate : bool ,
28+ pub execute : bool ,
2729}
2830
2931fn is_wasm_above_size_limit ( wasm_size_kb : f64 ) -> bool {
@@ -46,6 +48,19 @@ fn build_stellar_deploy_command(wasm: &std::path::Path, source: &str, network: &
4648 )
4749}
4850
51+ fn build_stellar_deploy_args ( wasm : & std:: path:: Path , source : & str , network : & str ) -> Vec < String > {
52+ vec ! [
53+ "contract" . to_string( ) ,
54+ "deploy" . to_string( ) ,
55+ "--wasm" . to_string( ) ,
56+ wasm. display( ) . to_string( ) ,
57+ "--source" . to_string( ) ,
58+ source. to_string( ) ,
59+ "--network" . to_string( ) ,
60+ network. to_string( ) ,
61+ ]
62+ }
63+
4964pub fn handle ( args : DeployArgs ) -> Result < ( ) > {
5065 p:: header ( "Deploy Soroban Contract" ) ;
5166
@@ -183,6 +198,36 @@ pub fn handle(args: DeployArgs) -> Result<()> {
183198 println ! ( " {}" , line. cyan( ) ) ;
184199 }
185200 println ! ( ) ;
201+ if args. execute {
202+ let stellar_path = info:: detect_stellar_cli ( ) . ok_or_else ( || {
203+ anyhow:: anyhow!(
204+ "Cannot execute deploy: Stellar CLI not found on PATH.\n Install it from https://developers.stellar.org/docs/tools/stellar-cli"
205+ )
206+ } ) ?;
207+
208+ p:: info ( & format ! (
209+ "Executing with Stellar CLI at {}" ,
210+ stellar_path. display( )
211+ ) ) ;
212+ let cmd_args = build_stellar_deploy_args ( & args. wasm , & wallet. public_key , & args. network ) ;
213+ let output = Command :: new ( stellar_path) . args ( & cmd_args) . output ( ) ?;
214+ if output. status . success ( ) {
215+ p:: success ( "Deployment command executed successfully." ) ;
216+ let stdout = String :: from_utf8_lossy ( & output. stdout ) ;
217+ if !stdout. trim ( ) . is_empty ( ) {
218+ println ! ( "{}" , stdout. trim( ) ) ;
219+ }
220+ } else {
221+ let stderr = String :: from_utf8_lossy ( & output. stderr ) ;
222+ anyhow:: bail!(
223+ "Stellar CLI deployment failed (exit: {}). {}" ,
224+ output. status,
225+ stderr. trim( )
226+ ) ;
227+ }
228+ } else {
229+ p:: info ( "Dry-run mode (default): command not executed. Use --execute to run it." ) ;
230+ }
186231 p:: info ( "Install the Stellar CLI: https://developers.stellar.org/docs/tools/stellar-cli" ) ;
187232 p:: separator ( ) ;
188233
@@ -224,6 +269,28 @@ mod tests {
224269 assert ! ( command. contains( "--network testnet" ) ) ;
225270 }
226271
272+ #[ test]
273+ fn builds_expected_deploy_args ( ) {
274+ let args = build_stellar_deploy_args (
275+ std:: path:: Path :: new ( "target/release/token.wasm" ) ,
276+ "GABCDEF1234567890" ,
277+ "testnet" ,
278+ ) ;
279+ assert_eq ! (
280+ args,
281+ vec![
282+ "contract" ,
283+ "deploy" ,
284+ "--wasm" ,
285+ "target/release/token.wasm" ,
286+ "--source" ,
287+ "GABCDEF1234567890" ,
288+ "--network" ,
289+ "testnet"
290+ ]
291+ ) ;
292+ }
293+
227294 #[ test]
228295 fn flags_large_wasm_sizes ( ) {
229296 assert ! ( !is_wasm_above_size_limit( 127.9 ) ) ;
0 commit comments