@@ -286,7 +286,10 @@ where
286
286
Event :: new ( "execute" ) . add_attribute ( CONTRACT_ATTR , & contract_addr) ;
287
287
288
288
let ( res, msgs) = self . build_app_response ( & contract_addr, custom_event, res) ;
289
- self . process_response ( api, router, storage, block, contract_addr, res, msgs)
289
+ let res =
290
+ self . process_response ( api, router, storage, block, contract_addr, res, msgs) ?;
291
+ // res.data = execute_response(res.data);
292
+ Ok ( res)
290
293
}
291
294
WasmMsg :: Instantiate {
292
295
admin,
@@ -345,7 +348,7 @@ where
345
348
res,
346
349
msgs,
347
350
) ?;
348
- init_response ( & mut res, & contract_addr) ;
351
+ res . data = Some ( init_response ( res. data , & contract_addr) ) ;
349
352
Ok ( res)
350
353
}
351
354
WasmMsg :: Migrate {
@@ -381,7 +384,10 @@ where
381
384
. add_attribute ( CONTRACT_ATTR , & contract_addr)
382
385
. add_attribute ( "code_id" , new_code_id. to_string ( ) ) ;
383
386
let ( res, msgs) = self . build_app_response ( & contract_addr, custom_event, res) ;
384
- self . process_response ( api, router, storage, block, contract_addr, res, msgs)
387
+ let res =
388
+ self . process_response ( api, router, storage, block, contract_addr, res, msgs) ?;
389
+ // res.data = execute_response(res.data);
390
+ Ok ( res)
385
391
}
386
392
msg => bail ! ( Error :: UnsupportedWasmMsg ( msg) ) ,
387
393
}
@@ -838,24 +844,42 @@ where
838
844
// TODO: replace with code in cw0
839
845
840
846
#[ derive( Clone , PartialEq , Message ) ]
841
- pub struct InstantiateData {
847
+ struct InstantiateResponse {
842
848
#[ prost( string, tag = "1" ) ]
843
849
pub address : :: prost:: alloc:: string:: String ,
844
- /// Unique ID number for this person.
845
850
#[ prost( bytes, tag = "2" ) ]
846
851
pub data : :: prost:: alloc:: vec:: Vec < u8 > ,
847
852
}
848
853
849
- fn init_response ( res : & mut AppResponse , contact_address : & Addr ) {
850
- let data = res. data . clone ( ) . unwrap_or_default ( ) . to_vec ( ) ;
851
- let init_data = InstantiateData {
854
+ // TODO: encode helpers in cw0
855
+ fn init_response ( data : Option < Binary > , contact_address : & Addr ) -> Binary {
856
+ let data = data. unwrap_or_default ( ) . to_vec ( ) ;
857
+ let init_data = InstantiateResponse {
852
858
address : contact_address. into ( ) ,
853
859
data,
854
860
} ;
855
861
let mut new_data = Vec :: < u8 > :: with_capacity ( init_data. encoded_len ( ) ) ;
856
862
// the data must encode successfully
857
863
init_data. encode ( & mut new_data) . unwrap ( ) ;
858
- res. data = Some ( new_data. into ( ) ) ;
864
+ new_data. into ( )
865
+ }
866
+
867
+ #[ derive( Clone , PartialEq , Message ) ]
868
+ struct ExecuteResponse {
869
+ #[ prost( bytes, tag = "1" ) ]
870
+ pub data : :: prost:: alloc:: vec:: Vec < u8 > ,
871
+ }
872
+
873
+ // empty return if no data present in original
874
+ #[ allow( dead_code) ]
875
+ fn execute_response ( data : Option < Binary > ) -> Option < Binary > {
876
+ data. map ( |d| {
877
+ let exec_data = ExecuteResponse { data : d. to_vec ( ) } ;
878
+ let mut new_data = Vec :: < u8 > :: with_capacity ( exec_data. encoded_len ( ) ) ;
879
+ // the data must encode successfully
880
+ exec_data. encode ( & mut new_data) . unwrap ( ) ;
881
+ new_data. into ( )
882
+ } )
859
883
}
860
884
861
885
#[ cfg( test) ]
0 commit comments