drt_sc_snippets/interactor_scenario/
interactor_sc_extra.rs1#![allow(deprecated)]
2
3use crate::Interactor;
4use drt_sc_scenario::{
5 api::StaticApi,
6 drt_sc::{
7 abi::TypeAbiFrom,
8 codec::{TopDecodeMulti, TopEncodeMulti},
9 types::{Address, ContractCallBase},
10 },
11 scenario_model::{
12 ScCallStep, ScDeployStep, ScQueryStep, TxResponse, TypedResponse, TypedScCall,
13 TypedScDeploy, TypedScQuery,
14 },
15};
16
17impl Interactor {
18 #[deprecated(
19 since = "0.49.0",
20 note = "Please use the unified transaction syntax instead."
21 )]
22 pub async fn sc_call_use_raw_response<S, F>(
23 &mut self,
24 mut step: S,
25 use_raw_response: F,
26 ) -> &mut Self
27 where
28 S: AsMut<ScCallStep>,
29 F: FnOnce(&TxResponse),
30 {
31 self.sc_call(step.as_mut()).await;
32 let response = unwrap_response(&step.as_mut().response);
33 use_raw_response(response);
34 self
35 }
36
37 #[deprecated(
38 since = "0.49.0",
39 note = "Please use the unified transaction syntax instead."
40 )]
41 pub async fn sc_call_use_result<OriginalResult, RequestedResult, F>(
42 &mut self,
43 step: TypedScCall<OriginalResult>,
44 use_result: F,
45 ) -> &mut Self
46 where
47 OriginalResult: TopEncodeMulti,
48 RequestedResult: TopDecodeMulti + TypeAbiFrom<OriginalResult>,
49 F: FnOnce(TypedResponse<RequestedResult>),
50 {
51 use_result(self.sc_call_get_result(step).await);
52 self
53 }
54
55 #[deprecated(
56 since = "0.49.0",
57 note = "Please use the unified transaction syntax instead."
58 )]
59 pub async fn sc_call_get_result<OriginalResult, RequestedResult>(
60 &mut self,
61 mut step: TypedScCall<OriginalResult>,
62 ) -> TypedResponse<RequestedResult>
63 where
64 OriginalResult: TopEncodeMulti,
65 RequestedResult: TopDecodeMulti + TypeAbiFrom<OriginalResult>,
66 {
67 self.sc_call(step.as_mut()).await;
68 let response = unwrap_response(&step.as_mut().response);
69 TypedResponse::from_raw(response)
70 }
71
72 #[deprecated(
73 since = "0.49.0",
74 note = "Please use the unified transaction syntax instead."
75 )]
76 pub async fn sc_query_use_raw_response<S, F>(
77 &mut self,
78 mut step: S,
79 use_raw_response: F,
80 ) -> &mut Self
81 where
82 S: AsMut<ScQueryStep>,
83 F: FnOnce(&TxResponse),
84 {
85 self.sc_query(step.as_mut()).await;
86 let response = unwrap_response(&step.as_mut().response);
87 use_raw_response(response);
88 self
89 }
90
91 #[deprecated(
92 since = "0.49.0",
93 note = "Please use the unified transaction syntax instead."
94 )]
95 pub async fn sc_query_use_result<OriginalResult, RequestedResult, F>(
96 &mut self,
97 step: TypedScQuery<OriginalResult>,
98 use_result: F,
99 ) -> &mut Self
100 where
101 OriginalResult: TopEncodeMulti,
102 RequestedResult: TopDecodeMulti + TypeAbiFrom<OriginalResult>,
103 F: FnOnce(TypedResponse<RequestedResult>),
104 {
105 use_result(self.sc_query_get_result(step).await);
106 self
107 }
108
109 #[deprecated(
110 since = "0.49.0",
111 note = "Please use the unified transaction syntax instead."
112 )]
113 pub async fn sc_query_get_result<OriginalResult, RequestedResult>(
114 &mut self,
115 mut step: TypedScQuery<OriginalResult>,
116 ) -> TypedResponse<RequestedResult>
117 where
118 OriginalResult: TopEncodeMulti,
119 RequestedResult: TopDecodeMulti + TypeAbiFrom<OriginalResult>,
120 {
121 self.sc_query(step.as_mut()).await;
122 let response = unwrap_response(&step.sc_query_step.response);
123 TypedResponse::from_raw(response)
124 }
125
126 #[deprecated(
127 since = "0.49.0",
128 note = "Please use the unified transaction syntax instead."
129 )]
130 pub async fn quick_query<CC, RequestedResult>(&mut self, contract_call: CC) -> RequestedResult
131 where
132 CC: ContractCallBase<StaticApi>,
133 RequestedResult: TopDecodeMulti + TypeAbiFrom<CC::OriginalResult>,
134 {
135 let mut typed_sc_query = ScQueryStep::new().call(contract_call);
136 self.sc_query(&mut typed_sc_query).await;
137 let response = unwrap_response(&typed_sc_query.sc_query_step.response);
138 let typed_response = TypedResponse::from_raw(response);
139 typed_response.result.unwrap()
140 }
141
142 #[deprecated(
143 since = "0.49.0",
144 note = "Please use the unified transaction syntax instead."
145 )]
146 pub async fn sc_deploy_use_raw_response<S, F>(
147 &mut self,
148 mut step: S,
149 use_raw_response: F,
150 ) -> &mut Self
151 where
152 S: AsMut<ScDeployStep>,
153 F: FnOnce(&TxResponse),
154 {
155 self.sc_deploy(step.as_mut()).await;
156 let response = unwrap_response(&step.as_mut().response);
157 use_raw_response(response);
158 self
159 }
160
161 #[deprecated(
162 since = "0.49.0",
163 note = "Please use the unified transaction syntax instead."
164 )]
165 pub async fn sc_deploy_use_result<OriginalResult, RequestedResult, F>(
166 &mut self,
167 step: TypedScDeploy<OriginalResult>,
168 use_result: F,
169 ) -> &mut Self
170 where
171 OriginalResult: TopEncodeMulti,
172 RequestedResult: TopDecodeMulti + TypeAbiFrom<OriginalResult>,
173 F: FnOnce(Address, TypedResponse<RequestedResult>),
174 {
175 let (new_address, response) = self.sc_deploy_get_result(step).await;
176 use_result(new_address, response);
177 self
178 }
179
180 #[deprecated(
181 since = "0.49.0",
182 note = "Please use the unified transaction syntax instead."
183 )]
184 pub async fn sc_deploy_get_result<OriginalResult, RequestedResult>(
185 &mut self,
186 mut step: TypedScDeploy<OriginalResult>,
187 ) -> (Address, TypedResponse<RequestedResult>)
188 where
189 OriginalResult: TopEncodeMulti,
190 RequestedResult: TopDecodeMulti + TypeAbiFrom<OriginalResult>,
191 {
192 self.sc_deploy(step.as_mut()).await;
193 let response = unwrap_response(&step.sc_deploy_step.response);
194 let new_address = unwrap_new_address(response);
195 let response = TypedResponse::from_raw(response);
196 (new_address, response)
197 }
198}
199
200fn unwrap_response(opt_response: &Option<TxResponse>) -> &TxResponse {
201 opt_response.as_ref().expect("response not processed")
202}
203
204fn unwrap_new_address(response: &TxResponse) -> Address {
205 response
206 .new_deployed_address
207 .clone()
208 .expect("missing new address after deploy")
209}