drt_sc_snippets/interactor_scenario/
interactor_vm_query.rs1#![allow(deprecated)]
2
3use crate::{address_h256_to_moars, Interactor};
4use log::info;
5use drt_sc_scenario::{
6 api::StaticApi,
7 denali_system::ScenarioRunner,
8 drt_sc::{abi::TypeAbiFrom, codec::TopDecodeMulti, types::ContractCall},
9 scenario_model::{ScQueryStep, TxResponse},
10};
11use drt_sdk::{data::vm::VmValueRequest, utils::base64_decode};
12
13impl Interactor {
14 pub async fn sc_query<S>(&mut self, mut step: S) -> &mut Self
15 where
16 S: AsMut<ScQueryStep>,
17 {
18 self.perform_sc_query(step.as_mut()).await;
19 self
20 }
21
22 pub async fn perform_sc_query(&mut self, step: &mut ScQueryStep) {
23 let sc_address = address_h256_to_moars(&step.tx.to.to_address());
24 let req = VmValueRequest {
25 sc_address: sc_address.clone(),
26 func_name: step.tx.function.clone(),
27 args: step
28 .tx
29 .arguments
30 .iter()
31 .map(|arg| hex::encode(&arg.value))
32 .collect(),
33 caller: sc_address,
34 value: "0".to_string(),
35 };
36 let result = self
37 .proxy
38 .execute_vmquery(&req)
39 .await
40 .expect("error executing VM query");
41
42 info!("{:#?}", result);
43
44 let raw_results: Vec<Vec<u8>> = result.data.return_data.iter().map(base64_decode).collect();
45
46 step.save_response(TxResponse::from_raw_results(raw_results));
47
48 self.pre_runners.run_sc_query_step(step);
49 self.post_runners.run_sc_query_step(step);
50 }
51
52 #[deprecated(since = "0.42.0", note = "Was renamed to `quick_query`.")]
53 pub async fn vm_query<CC, RequestedResult>(&mut self, contract_call: CC) -> RequestedResult
54 where
55 CC: ContractCall<StaticApi>,
56 RequestedResult: TopDecodeMulti + TypeAbiFrom<CC::OriginalResult>,
57 {
58 self.quick_query(contract_call).await
59 }
60}