multiversx_sdk/data/
vm.rs1use multiversx_chain_core::std::Bech32Address;
2use serde::{Deserialize, Serialize};
3use serde_repr::{Deserialize_repr, Serialize_repr};
4use std::collections::HashMap;
5
6use crate::utils::base64_decode;
7
8#[derive(Serialize_repr, Deserialize_repr, Debug, Clone)]
9#[repr(u8)]
10pub enum CallType {
11 DirectCall = 0,
13
14 AsynchronousCall = 1,
17
18 AsynchronousCallBack = 2,
21
22 ESDTTransferAndExecute = 3,
25}
26
27#[derive(Debug, Clone, Serialize, Deserialize)]
29#[serde(rename_all = "camelCase")]
30pub struct VMQueryInput {
31 pub sc_address: Bech32Address,
32 pub func_name: String,
33 pub args: Vec<String>,
34}
35
36#[derive(Debug, Clone, Serialize, Deserialize)]
38#[serde(rename_all = "camelCase")]
39pub struct LogEntryApi {
40 pub identifier: String,
41 pub address: Bech32Address,
42 pub topics: Vec<String>,
43 pub data: String,
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(rename_all = "camelCase")]
49pub struct OutputTransferApi {
50 pub value: String,
51 pub gas_limit: u64,
52 pub data: String,
53 pub call_type: CallType,
54 pub sender_address: Bech32Address,
55}
56
57#[derive(Debug, Clone, Serialize, Deserialize)]
59#[serde(rename_all = "camelCase")]
60pub struct OutputAccountApi {
61 address: Bech32Address,
62 nonce: u64,
63
64 balance_delta: u64,
67 storage_updates: Option<HashMap<String, StorageUpdateApi>>,
68 code: Option<String>,
69 code_metadata: Option<String>,
70
71 #[serde(default)]
72 output_transfers: Vec<OutputTransferApi>,
73 call_type: CallType,
74}
75
76#[derive(Debug, Clone, Serialize, Deserialize)]
78#[serde(rename_all = "camelCase")]
79pub struct StorageUpdateApi {
80 offset: String,
81 data: String,
82}
83
84#[derive(Debug, Clone, Serialize, Deserialize)]
86#[serde(rename_all = "camelCase")]
87pub struct VMOutputApi {
88 #[serde(default)]
89 pub return_data: Option<Vec<String>>,
90 pub return_code: String,
91 pub return_message: String,
92 pub gas_remaining: u64,
93 pub gas_refund: u64,
94 pub output_accounts: HashMap<String, OutputAccountApi>,
95 pub deleted_accounts: Option<Vec<String>>,
96 pub touched_accounts: Option<Vec<String>>,
97 pub logs: Option<Vec<LogEntryApi>>,
98}
99
100impl VMOutputApi {
101 pub fn return_data(&self) -> &[String] {
102 if let Some(return_data) = &self.return_data {
103 return_data
104 } else {
105 &[]
106 }
107 }
108
109 pub fn return_data_base64_decode(&self) -> Vec<Vec<u8>> {
110 self.return_data().iter().map(base64_decode).collect()
111 }
112
113 pub fn is_ok(&self) -> bool {
114 self.return_code == "ok"
115 }
116}
117
118#[derive(Debug, Clone, Serialize, Deserialize)]
120#[serde(rename_all = "camelCase")]
121pub struct VmValuesResponseData {
122 pub data: VMOutputApi,
123}
124
125#[derive(Debug, Clone, Serialize, Deserialize)]
127#[serde(rename_all = "camelCase")]
128pub struct ResponseVmValue {
129 pub data: Option<VmValuesResponseData>,
130 pub error: String,
131 pub code: String,
132}