multiversx_sdk/data/
vm.rs

1use super::sdk_address::SdkAddress;
2use serde::{Deserialize, Serialize};
3use serde_repr::{Deserialize_repr, Serialize_repr};
4use std::collections::HashMap;
5
6#[derive(Serialize_repr, Deserialize_repr, Debug, Clone)]
7#[repr(u8)]
8pub enum CallType {
9    // DirectCall means that the call is an explicit SC invocation originating from a user Transaction
10    DirectCall = 0,
11
12    // AsynchronousCall means that the invocation was performed from within
13    // another SmartContract from another Shard, using asyncCall
14    AsynchronousCall = 1,
15
16    // AsynchronousCallBack means that an AsynchronousCall was performed
17    // previously, and now the control returns to the caller SmartContract's callBack method
18    AsynchronousCallBack = 2,
19
20    // ESDTTransferAndExecute means that there is a smart contract execution after the ESDT transfer
21    // this is needed in order to skip the check whether a contract is payable or not
22    ESDTTransferAndExecute = 3,
23}
24
25// VmValueRequest defines the request struct for values available in a VM
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(rename_all = "camelCase")]
28pub struct VMQueryInput {
29    pub sc_address: SdkAddress,
30    pub func_name: String,
31    pub args: Vec<String>,
32}
33
34// LogEntryApi is a wrapper over vmcommon's LogEntry
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(rename_all = "camelCase")]
37pub struct LogEntryApi {
38    pub identifier: String,
39    pub address: SdkAddress,
40    pub topics: Vec<String>,
41    pub data: String,
42}
43
44// OutputTransferApi is a wrapper over vmcommon's OutputTransfer
45#[derive(Debug, Clone, Serialize, Deserialize)]
46#[serde(rename_all = "camelCase")]
47pub struct OutputTransferApi {
48    pub value: String,
49    pub gas_limit: u64,
50    pub data: String,
51    pub call_type: CallType,
52    pub sender_address: SdkAddress,
53}
54
55// OutputAccountApi is a wrapper over vmcommon's OutputAccount
56#[derive(Debug, Clone, Serialize, Deserialize)]
57#[serde(rename_all = "camelCase")]
58pub struct OutputAccountApi {
59    address: SdkAddress,
60    nonce: u64,
61
62    // TODO: unknow type of data
63    // balance: Option<String>,
64    balance_delta: u64,
65    storage_updates: Option<HashMap<String, StorageUpdateApi>>,
66    code: Option<String>,
67    code_metadata: Option<String>,
68
69    #[serde(default)]
70    output_transfers: Vec<OutputTransferApi>,
71    call_type: CallType,
72}
73
74// StorageUpdateApi is a wrapper over vmcommon's StorageUpdate
75#[derive(Debug, Clone, Serialize, Deserialize)]
76#[serde(rename_all = "camelCase")]
77pub struct StorageUpdateApi {
78    offset: String,
79    data: String,
80}
81
82// VMOutputApi is a wrapper over the vmcommon's VMOutput
83#[derive(Debug, Clone, Serialize, Deserialize)]
84#[serde(rename_all = "camelCase")]
85pub struct VMOutputApi {
86    #[serde(default)]
87    pub return_data: Vec<String>,
88    pub return_code: String,
89    pub return_message: String,
90    pub gas_remaining: u64,
91    pub gas_refund: u64,
92    pub output_accounts: HashMap<String, OutputAccountApi>,
93    pub deleted_accounts: Option<Vec<String>>,
94    pub touched_accounts: Option<Vec<String>>,
95    pub logs: Option<Vec<LogEntryApi>>,
96}
97
98// VmValuesResponseData follows the format of the data field in an API response for a VM values query
99#[derive(Debug, Clone, Serialize, Deserialize)]
100#[serde(rename_all = "camelCase")]
101pub struct VmValuesResponseData {
102    pub data: VMOutputApi,
103}
104
105// ResponseVmValue defines a wrapper over string containing returned data in hex format
106#[derive(Debug, Clone, Serialize, Deserialize)]
107#[serde(rename_all = "camelCase")]
108pub struct ResponseVmValue {
109    pub data: Option<VmValuesResponseData>,
110    pub error: String,
111    pub code: String,
112}