multiversx_sdk/data/
vm.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
use super::sdk_address::SdkAddress;
use serde::{Deserialize, Serialize};
use serde_repr::{Deserialize_repr, Serialize_repr};
use std::collections::HashMap;

#[derive(Serialize_repr, Deserialize_repr, Debug, Clone)]
#[repr(u8)]
pub enum CallType {
    // DirectCall means that the call is an explicit SC invocation originating from a user Transaction
    DirectCall = 0,

    // AsynchronousCall means that the invocation was performed from within
    // another SmartContract from another Shard, using asyncCall
    AsynchronousCall = 1,

    // AsynchronousCallBack means that an AsynchronousCall was performed
    // previously, and now the control returns to the caller SmartContract's callBack method
    AsynchronousCallBack = 2,

    // ESDTTransferAndExecute means that there is a smart contract execution after the ESDT transfer
    // this is needed in order to skip the check whether a contract is payable or not
    ESDTTransferAndExecute = 3,
}

// VmValueRequest defines the request struct for values available in a VM
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct VMQueryInput {
    pub sc_address: SdkAddress,
    pub func_name: String,
    pub args: Vec<String>,
}

// LogEntryApi is a wrapper over vmcommon's LogEntry
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct LogEntryApi {
    pub identifier: String,
    pub address: SdkAddress,
    pub topics: Vec<String>,
    pub data: String,
}

// OutputTransferApi is a wrapper over vmcommon's OutputTransfer
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct OutputTransferApi {
    pub value: String,
    pub gas_limit: u64,
    pub data: String,
    pub call_type: CallType,
    pub sender_address: SdkAddress,
}

// OutputAccountApi is a wrapper over vmcommon's OutputAccount
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct OutputAccountApi {
    address: SdkAddress,
    nonce: u64,

    // TODO: unknow type of data
    // balance: Option<String>,
    balance_delta: u64,
    storage_updates: Option<HashMap<String, StorageUpdateApi>>,
    code: Option<String>,
    code_metadata: Option<String>,

    #[serde(default)]
    output_transfers: Vec<OutputTransferApi>,
    call_type: CallType,
}

// StorageUpdateApi is a wrapper over vmcommon's StorageUpdate
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct StorageUpdateApi {
    offset: String,
    data: String,
}

// VMOutputApi is a wrapper over the vmcommon's VMOutput
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct VMOutputApi {
    #[serde(default)]
    pub return_data: Vec<String>,
    pub return_code: String,
    pub return_message: String,
    pub gas_remaining: u64,
    pub gas_refund: u64,
    pub output_accounts: HashMap<String, OutputAccountApi>,
    pub deleted_accounts: Option<Vec<String>>,
    pub touched_accounts: Option<Vec<String>>,
    pub logs: Option<Vec<LogEntryApi>>,
}

// VmValuesResponseData follows the format of the data field in an API response for a VM values query
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct VmValuesResponseData {
    pub data: VMOutputApi,
}

// ResponseVmValue defines a wrapper over string containing returned data in hex format
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ResponseVmValue {
    pub data: Option<VmValuesResponseData>,
    pub error: String,
    pub code: String,
}