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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use crate::Binary;
#[cfg(feature = "cosmwasm_1_2")]
use crate::HexBinary;
use super::query_response::QueryResponseType;
#[non_exhaustive]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum WasmQuery {
Smart {
contract_addr: String,
msg: Binary,
},
Raw {
contract_addr: String,
key: Binary,
},
ContractInfo { contract_addr: String },
#[cfg(feature = "cosmwasm_1_2")]
CodeInfo { code_id: u64 },
}
#[non_exhaustive]
#[derive(Serialize, Deserialize, Clone, Default, Debug, PartialEq, Eq, JsonSchema)]
pub struct ContractInfoResponse {
pub code_id: u64,
pub creator: String,
pub admin: Option<String>,
pub pinned: bool,
pub ibc_port: Option<String>,
}
impl QueryResponseType for ContractInfoResponse {}
impl ContractInfoResponse {
#[doc(hidden)]
#[deprecated(
note = "Use ContractInfoResponse::default() and mutate the fields you want to set."
)]
pub fn new(code_id: u64, creator: impl Into<String>) -> Self {
ContractInfoResponse {
code_id,
creator: creator.into(),
..Default::default()
}
}
}
#[non_exhaustive]
#[derive(Serialize, Deserialize, Clone, Default, Debug, PartialEq, Eq, JsonSchema)]
#[cfg(feature = "cosmwasm_1_2")]
pub struct CodeInfoResponse {
pub code_id: u64,
pub creator: String,
pub checksum: HexBinary,
}
#[cfg(feature = "cosmwasm_1_2")]
impl QueryResponseType for CodeInfoResponse {}
#[cfg(test)]
mod tests {
use super::*;
use crate::to_binary;
#[test]
fn wasm_query_contract_info_serialization() {
let query = WasmQuery::ContractInfo {
contract_addr: "aabbccdd456".into(),
};
let json = to_binary(&query).unwrap();
assert_eq!(
String::from_utf8_lossy(&json),
r#"{"contract_info":{"contract_addr":"aabbccdd456"}}"#,
);
}
#[test]
#[cfg(feature = "cosmwasm_1_2")]
fn wasm_query_code_info_serialization() {
let query = WasmQuery::CodeInfo { code_id: 70 };
let json = to_binary(&query).unwrap();
assert_eq!(
String::from_utf8_lossy(&json),
r#"{"code_info":{"code_id":70}}"#,
);
}
#[test]
fn contract_info_response_serialization() {
let response = ContractInfoResponse {
code_id: 67,
creator: "jane".to_string(),
admin: Some("king".to_string()),
pinned: true,
ibc_port: Some("wasm.123".to_string()),
};
let json = to_binary(&response).unwrap();
assert_eq!(
String::from_utf8_lossy(&json),
r#"{"code_id":67,"creator":"jane","admin":"king","pinned":true,"ibc_port":"wasm.123"}"#,
);
}
#[test]
#[cfg(feature = "cosmwasm_1_2")]
fn code_info_response_serialization() {
use crate::HexBinary;
let response = CodeInfoResponse {
code_id: 67,
creator: "jane".to_string(),
checksum: HexBinary::from_hex(
"f7bb7b18fb01bbf425cf4ed2cd4b7fb26a019a7fc75a4dc87e8a0b768c501f00",
)
.unwrap(),
};
let json = to_binary(&response).unwrap();
assert_eq!(
String::from_utf8_lossy(&json),
r#"{"code_id":67,"creator":"jane","checksum":"f7bb7b18fb01bbf425cf4ed2cd4b7fb26a019a7fc75a4dc87e8a0b768c501f00"}"#,
);
}
}