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
use std::collections::BTreeMap;

use crate::{
    keymanager::SignedPublicKey,
    types::transaction::{CallResult, CallerAddress, Transaction},
};

/// Key in the versions map used for the global state version.
pub const VERSION_GLOBAL_KEY: &str = "";

/// Basic per-module metadata; tracked in core module's state.
#[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)]
pub struct Metadata {
    /// A set of state versions for all supported modules.
    pub versions: BTreeMap<String, u32>,
}

/// Arguments for the EstimateGas query.
#[derive(Clone, Debug, cbor::Encode, cbor::Decode)]
#[cbor(no_default)]
pub struct EstimateGasQuery {
    /// The address of the caller for which to do estimation. If not specified the authentication
    /// information from the passed transaction is used.
    #[cbor(optional)]
    pub caller: Option<CallerAddress>,
    /// The unsigned transaction to estimate.
    pub tx: Transaction,
    /// If the estimate gas query should fail in case of transaction failures.
    /// If true, the query will return the transaction error and not the gas estimation.
    /// Defaults to false.
    #[cbor(optional)]
    pub propagate_failures: bool,
}

/// Response to the call data public key query.
#[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)]
pub struct CallDataPublicKeyQueryResponse {
    /// Public key used for deriving the shared secret for encrypting call data.
    pub public_key: SignedPublicKey,
    /// Epoch of the ephemeral runtime key.
    pub epoch: u64,
}

#[derive(Debug, Copy, Clone, cbor::Encode, cbor::Decode)]
#[cfg_attr(test, derive(PartialEq, Eq))]
pub enum MethodHandlerKind {
    #[cbor(rename = "call")]
    Call,
    // `Prefetch` is omitted because it is an implementation detail of handling `Call`s.
    #[cbor(rename = "query")]
    Query,
    #[cbor(rename = "message_result")]
    MessageResult,
}

#[derive(Debug, Clone, cbor::Encode, cbor::Decode)]
#[cfg_attr(test, derive(PartialEq, Eq))]
#[cbor(no_default)]
pub struct MethodHandlerInfo {
    pub kind: MethodHandlerKind,
    pub name: String,
}

/// Metadata for an individual module.
#[derive(Clone, Debug, cbor::Encode, cbor::Decode)]
#[cfg_attr(test, derive(PartialEq, Eq))]
#[cbor(no_default)]
pub struct ModuleInfo {
    pub version: u32,
    pub params: cbor::Value,
    pub methods: Vec<MethodHandlerInfo>,
}

/// Response to the RuntimeInfo query.
#[derive(Clone, Debug, cbor::Encode, cbor::Decode)]
#[cfg_attr(test, derive(PartialEq, Eq))]
#[cbor(no_default)]
pub struct RuntimeInfoResponse {
    pub runtime_version: oasis_core_runtime::common::version::Version,
    pub state_version: u32,
    pub modules: BTreeMap<String, ModuleInfo>,
}

/// Arguments for the ExecuteReadOnlyTx query.
#[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)]
pub struct ExecuteReadOnlyTxQuery {
    pub tx: Vec<u8>,
}

/// Response to the ExecuteReadOnlyTx query.
#[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)]
pub struct ExecuteReadOnlyTxResponse {
    pub result: CallResult,
}