@@ -8,16 +8,17 @@ use algokit_abi::{ABIReturn, ABIValue, Arc56Contract};
88use crate :: applications:: app_client:: error_transformation:: LogicErrorContext ;
99use crate :: applications:: app_client:: { AppClientMethodCallParams , CompilationParams } ;
1010use crate :: applications:: app_deployer:: { AppLookup , OnSchemaBreak , OnUpdate } ;
11- use crate :: applications:: app_factory;
11+ use crate :: applications:: {
12+ AppDeployMetadata , AppDeployParams , AppDeployResult , CreateParams , DeleteParams , UpdateParams ,
13+ app_factory,
14+ } ;
1215use crate :: clients:: app_manager:: {
1316 DELETABLE_TEMPLATE_NAME , TealTemplateValue , UPDATABLE_TEMPLATE_NAME ,
1417} ;
1518use crate :: transactions:: {
1619 TransactionComposerConfig , TransactionResultError , TransactionSigner ,
1720 composer:: { SendParams as ComposerSendParams , SendTransactionComposerResults } ,
18- sender_results:: {
19- SendAppCallResult , SendAppCreateResult , SendAppUpdateResult , SendTransactionResult ,
20- } ,
21+ sender_results:: SendTransactionResult ,
2122} ;
2223use crate :: { AlgorandClient , AppClient , AppClientParams , AppSourceMaps } ;
2324use app_factory:: types as aftypes;
@@ -78,17 +79,32 @@ impl AppFactory {
7879 let compiled = self . compile_programs_with ( None ) . await ?;
7980 let base = self . to_send_transaction_result ( composer_result) ?;
8081 let last_abi_return = base. abi_returns . as_ref ( ) . and_then ( |v| v. last ( ) ) . cloned ( ) ;
81- let created = SendAppCreateResult :: new (
82- base,
83- last_abi_return. clone ( ) ,
82+ let arc56_return = self . parse_method_return_value ( & last_abi_return) ?;
83+
84+ // Extract app_id from confirmation
85+ let app_id = base
86+ . confirmation
87+ . app_id
88+ . ok_or_else ( || AppFactoryError :: ValidationError {
89+ message : "App creation confirmation missing application-index" . to_string ( ) ,
90+ } ) ?;
91+ let app_address = algokit_transact:: Address :: from_app_id ( & app_id) ;
92+
93+ Ok ( AppFactoryCreateMethodCallResult :: new (
94+ base. transaction ,
95+ base. confirmation ,
96+ base. tx_id ,
97+ base. group_id ,
98+ base. tx_ids ,
99+ base. transactions ,
100+ base. confirmations ,
101+ app_id,
102+ app_address,
84103 Some ( compiled. approval . compiled_base64_to_bytes . clone ( ) ) ,
85104 Some ( compiled. clear . compiled_base64_to_bytes . clone ( ) ) ,
86- )
87- . map_err ( |e| AppFactoryError :: ValidationError {
88- message : e. to_string ( ) ,
89- } ) ?;
90- let arc56_return = self . parse_method_return_value ( & last_abi_return) ?;
91- Ok ( AppFactoryMethodCallResult :: new ( created, arc56_return) )
105+ last_abi_return,
106+ arc56_return,
107+ ) )
92108 }
93109
94110 async fn deploy_update_result (
@@ -98,40 +114,51 @@ impl AppFactory {
98114 let compiled = self . compile_programs_with ( None ) . await ?;
99115 let base = self . to_send_transaction_result ( composer_result) ?;
100116 let last_abi_return = base. abi_returns . as_ref ( ) . and_then ( |v| v. last ( ) ) . cloned ( ) ;
101- let updated = SendAppUpdateResult :: new (
102- base,
103- last_abi_return. clone ( ) ,
117+ let arc56_return = self . parse_method_return_value ( & last_abi_return) ?;
118+
119+ Ok ( AppFactoryUpdateMethodCallResult :: new (
120+ base. transaction ,
121+ base. confirmation ,
122+ base. tx_id ,
123+ base. group_id ,
124+ base. tx_ids ,
125+ base. transactions ,
126+ base. confirmations ,
104127 Some ( compiled. approval . compiled_base64_to_bytes . clone ( ) ) ,
105128 Some ( compiled. clear . compiled_base64_to_bytes . clone ( ) ) ,
106129 compiled. approval . source_map . clone ( ) ,
107130 compiled. clear . source_map . clone ( ) ,
108- ) ;
109- let arc56_return = self . parse_method_return_value ( & last_abi_return ) ? ;
110- Ok ( AppFactoryMethodCallResult :: new ( updated , arc56_return ) )
131+ last_abi_return ,
132+ arc56_return ,
133+ ) )
111134 }
112135
113136 async fn deploy_replace_results (
114137 & self ,
115138 composer_result : & SendTransactionComposerResults ,
116139 ) -> Result <
117140 (
118- Option < AppFactoryCreateMethodCallResult > ,
119- Option < AppFactoryDeleteMethodCallResult > ,
141+ AppFactoryCreateMethodCallResult ,
142+ AppFactoryDeleteMethodCallResult ,
120143 ) ,
121144 AppFactoryError ,
122145 > {
123- if composer_result. confirmations . is_empty ( )
146+ if composer_result. confirmations . len ( ) < 2
124147 || composer_result. confirmations . len ( ) != composer_result. transaction_ids . len ( )
125148 {
126- return Ok ( ( None , None ) ) ;
149+ return Err ( AppFactoryError :: ValidationError {
150+ message : String :: from (
151+ "Invalid replace composer result: expected create and delete confirmations" ,
152+ ) ,
153+ } ) ;
127154 }
128155 let compiled = self . compile_programs_with ( None ) . await ?;
129156 // Create index 0
130157 let create_tx = composer_result. confirmations [ 0 ] . txn . transaction . clone ( ) ;
131158 let create_base = SendTransactionResult :: new (
132159 composer_result. group . map ( hex:: encode) . unwrap_or_default ( ) ,
133160 vec ! [ composer_result. transaction_ids[ 0 ] . clone( ) ] ,
134- vec ! [ create_tx] ,
161+ vec ! [ create_tx. clone ( ) ] ,
135162 vec ! [ composer_result. confirmations[ 0 ] . clone( ) ] ,
136163 if !composer_result. abi_returns . is_empty ( ) {
137164 Some ( vec ! [ composer_result. abi_returns[ 0 ] . clone( ) ] )
@@ -147,49 +174,70 @@ impl AppFactory {
147174 . as_ref ( )
148175 . and_then ( |v| v. last ( ) )
149176 . cloned ( ) ;
150- let created = SendAppCreateResult :: new (
151- create_base,
152- create_abi. clone ( ) ,
177+ let create_arc56 = self . parse_method_return_value ( & create_abi) ?;
178+
179+ // Extract app_id from confirmation
180+ let app_id =
181+ create_base
182+ . confirmation
183+ . app_id
184+ . ok_or_else ( || AppFactoryError :: ValidationError {
185+ message : "App creation confirmation missing application-index" . to_string ( ) ,
186+ } ) ?;
187+ let app_address = algokit_transact:: Address :: from_app_id ( & app_id) ;
188+
189+ let create_result = AppFactoryCreateMethodCallResult :: new (
190+ create_tx,
191+ composer_result. confirmations [ 0 ] . clone ( ) ,
192+ composer_result. transaction_ids [ 0 ] . clone ( ) ,
193+ composer_result. group . map ( hex:: encode) . unwrap_or_default ( ) ,
194+ vec ! [ composer_result. transaction_ids[ 0 ] . clone( ) ] ,
195+ vec ! [ create_base. transaction. clone( ) ] ,
196+ vec ! [ composer_result. confirmations[ 0 ] . clone( ) ] ,
197+ app_id,
198+ app_address,
153199 Some ( compiled. approval . compiled_base64_to_bytes . clone ( ) ) ,
154200 Some ( compiled. clear . compiled_base64_to_bytes . clone ( ) ) ,
201+ create_abi. clone ( ) ,
202+ create_arc56,
203+ ) ;
204+ // Delete uses the final transaction in the replacement group
205+ let delete_index = composer_result. confirmations . len ( ) - 1 ;
206+ let delete_tx = composer_result. confirmations [ delete_index]
207+ . txn
208+ . transaction
209+ . clone ( ) ;
210+ let delete_base = SendTransactionResult :: new (
211+ composer_result. group . map ( hex:: encode) . unwrap_or_default ( ) ,
212+ vec ! [ composer_result. transaction_ids[ delete_index] . clone( ) ] ,
213+ vec ! [ delete_tx. clone( ) ] ,
214+ vec ! [ composer_result. confirmations[ delete_index] . clone( ) ] ,
215+ if composer_result. abi_returns . len ( ) > delete_index {
216+ Some ( vec ! [ composer_result. abi_returns[ delete_index] . clone( ) ] )
217+ } else {
218+ None
219+ } ,
155220 )
156221 . map_err ( |e| AppFactoryError :: ValidationError {
157222 message : e. to_string ( ) ,
158223 } ) ?;
159- let create_arc56 = self . parse_method_return_value ( & create_abi) ?;
160- let create_result = Some ( AppFactoryMethodCallResult :: new ( created, create_arc56) ) ;
161- // Optional delete uses the final transaction in the replacement group
162- let delete_result = if composer_result. confirmations . len ( ) > 1 {
163- let delete_index = composer_result. confirmations . len ( ) - 1 ;
164- let delete_tx = composer_result. confirmations [ delete_index]
165- . txn
166- . transaction
167- . clone ( ) ;
168- let delete_base = SendTransactionResult :: new (
169- composer_result. group . map ( hex:: encode) . unwrap_or_default ( ) ,
170- vec ! [ composer_result. transaction_ids[ delete_index] . clone( ) ] ,
171- vec ! [ delete_tx] ,
172- vec ! [ composer_result. confirmations[ delete_index] . clone( ) ] ,
173- if composer_result. abi_returns . len ( ) > delete_index {
174- Some ( vec ! [ composer_result. abi_returns[ delete_index] . clone( ) ] )
175- } else {
176- None
177- } ,
178- )
179- . map_err ( |e| AppFactoryError :: ValidationError {
180- message : e. to_string ( ) ,
181- } ) ?;
182- let delete_abi = delete_base
183- . abi_returns
184- . as_ref ( )
185- . and_then ( |v| v. last ( ) )
186- . cloned ( ) ;
187- let deleted = SendAppCallResult :: new ( delete_base, delete_abi. clone ( ) ) ;
188- let delete_arc56 = self . parse_method_return_value ( & delete_abi) ?;
189- Some ( AppFactoryMethodCallResult :: new ( deleted, delete_arc56) )
190- } else {
191- None
192- } ;
224+ let delete_abi = delete_base
225+ . abi_returns
226+ . as_ref ( )
227+ . and_then ( |v| v. last ( ) )
228+ . cloned ( ) ;
229+ let delete_arc56 = self . parse_method_return_value ( & delete_abi) ?;
230+ let delete_result = AppFactoryDeleteMethodCallResult :: new (
231+ delete_tx,
232+ composer_result. confirmations [ delete_index] . clone ( ) ,
233+ composer_result. transaction_ids [ delete_index] . clone ( ) ,
234+ composer_result. group . map ( hex:: encode) . unwrap_or_default ( ) ,
235+ vec ! [ composer_result. transaction_ids[ delete_index] . clone( ) ] ,
236+ vec ! [ delete_base. transaction. clone( ) ] ,
237+ vec ! [ composer_result. confirmations[ delete_index] . clone( ) ] ,
238+ delete_abi. clone ( ) ,
239+ delete_arc56,
240+ ) ;
193241 Ok ( ( create_result, delete_result) )
194242 }
195243 /// Convert SendTransactionComposerResults into a rich SendTransactionResult by
@@ -354,9 +402,7 @@ impl AppFactory {
354402 app_spec : self . app_spec . clone ( ) ,
355403 algorand : self . algorand . clone ( ) ,
356404 app_name : Some ( app_name. unwrap_or_else ( || self . app_name . clone ( ) ) ) ,
357- default_sender : Some (
358- default_sender. unwrap_or_else ( || self . default_sender . clone ( ) . unwrap_or_default ( ) ) ,
359- ) ,
405+ default_sender : default_sender. or_else ( || self . default_sender . clone ( ) ) ,
360406 default_signer : default_signer. or_else ( || self . default_signer . clone ( ) ) ,
361407 source_maps : resolved_source_maps,
362408 transaction_composer_config : self . transaction_composer_config . clone ( ) ,
@@ -398,9 +444,7 @@ impl AppFactory {
398444
399445 Ok ( client)
400446 }
401- }
402447
403- impl AppFactory {
404448 pub ( crate ) fn get_sender_address (
405449 & self ,
406450 sender : & Option < String > ,
@@ -553,40 +597,28 @@ impl AppFactory {
553597 let resolved_deploy_time_params = self . deploy_time_params . clone ( ) ;
554598
555599 let create_deploy_params = match args. create_params {
556- Some ( cp) => crate :: applications:: app_deployer:: CreateParams :: AppCreateMethodCall (
557- self . params ( ) . create ( cp) ?,
558- ) ,
559- None => crate :: applications:: app_deployer:: CreateParams :: AppCreateCall (
560- self . params ( ) . bare ( ) . create ( None ) ?,
561- ) ,
600+ Some ( cp) => CreateParams :: AppCreateMethodCall ( self . params ( ) . create ( cp) ?) ,
601+ None => CreateParams :: AppCreateCall ( self . params ( ) . bare ( ) . create ( None ) ?) ,
562602 } ;
563603
564604 let update_deploy_params = match args. update_params {
565- Some ( up) => crate :: applications:: app_deployer:: UpdateParams :: AppUpdateMethodCall (
566- self . params ( ) . deploy_update ( up) ?,
567- ) ,
568- None => crate :: applications:: app_deployer:: UpdateParams :: AppUpdateCall (
569- self . params ( ) . bare ( ) . deploy_update ( None ) ?,
570- ) ,
605+ Some ( up) => UpdateParams :: AppUpdateMethodCall ( self . params ( ) . deploy_update ( up) ?) ,
606+ None => UpdateParams :: AppUpdateCall ( self . params ( ) . bare ( ) . deploy_update ( None ) ?) ,
571607 } ;
572608
573609 let delete_deploy_params = match args. delete_params {
574- Some ( dp) => crate :: applications:: app_deployer:: DeleteParams :: AppDeleteMethodCall (
575- self . params ( ) . deploy_delete ( dp) ?,
576- ) ,
577- None => crate :: applications:: app_deployer:: DeleteParams :: AppDeleteCall (
578- self . params ( ) . bare ( ) . deploy_delete ( None ) ?,
579- ) ,
610+ Some ( dp) => DeleteParams :: AppDeleteMethodCall ( self . params ( ) . deploy_delete ( dp) ?) ,
611+ None => DeleteParams :: AppDeleteCall ( self . params ( ) . bare ( ) . deploy_delete ( None ) ?) ,
580612 } ;
581613
582- let metadata = crate :: applications :: app_deployer :: AppDeployMetadata {
614+ let metadata = AppDeployMetadata {
583615 name : args. app_name . unwrap_or_else ( || self . app_name . clone ( ) ) ,
584616 version : self . version . clone ( ) ,
585617 updatable : resolved_updatable,
586618 deletable : resolved_deletable,
587619 } ;
588620
589- let deploy_params = crate :: applications :: app_deployer :: AppDeployParams {
621+ let deploy_params = AppDeployParams {
590622 metadata,
591623 deploy_time_params : resolved_deploy_time_params,
592624 on_schema_break : args. on_schema_break ,
@@ -608,10 +640,10 @@ impl AppFactory {
608640
609641 // Build AppClient for the resulting app
610642 let app_metadata = match & deploy_result {
611- crate :: applications :: app_deployer :: AppDeployResult :: Create { app, .. }
612- | crate :: applications :: app_deployer :: AppDeployResult :: Update { app, .. }
613- | crate :: applications :: app_deployer :: AppDeployResult :: Replace { app, .. }
614- | crate :: applications :: app_deployer :: AppDeployResult :: Nothing { app } => app,
643+ AppDeployResult :: Create { app, .. }
644+ | AppDeployResult :: Update { app, .. }
645+ | AppDeployResult :: Replace { app, .. }
646+ | AppDeployResult :: Nothing { app } => app,
615647 } ;
616648
617649 // Create AppClient with shared signers from the factory's AlgorandClient
@@ -632,18 +664,18 @@ impl AppFactory {
632664 let mut delete_result: Option < aftypes:: AppFactoryDeleteMethodCallResult > = None ;
633665
634666 match & deploy_result {
635- crate :: applications :: app_deployer :: AppDeployResult :: Create { result, .. } => {
667+ AppDeployResult :: Create { result, .. } => {
636668 create_result = Some ( self . deploy_create_result ( result) . await ?) ;
637669 }
638- crate :: applications :: app_deployer :: AppDeployResult :: Update { result, .. } => {
670+ AppDeployResult :: Update { result, .. } => {
639671 update_result = Some ( self . deploy_update_result ( result) . await ?) ;
640672 }
641- crate :: applications :: app_deployer :: AppDeployResult :: Replace { result, .. } => {
673+ AppDeployResult :: Replace { result, .. } => {
642674 let ( c, d) = self . deploy_replace_results ( result) . await ?;
643- create_result = c ;
644- delete_result = d ;
675+ create_result = Some ( c ) ;
676+ delete_result = Some ( d ) ;
645677 }
646- crate :: applications :: app_deployer :: AppDeployResult :: Nothing { .. } => { }
678+ AppDeployResult :: Nothing { .. } => { }
647679 }
648680
649681 let factory_result = aftypes:: AppFactoryDeployResult {
0 commit comments