Skip to content

Commit 4dd5614

Browse files
committed
Use tuple as RawRangeEntry
1 parent aeb8ccf commit 4dd5614

File tree

3 files changed

+8
-30
lines changed

3 files changed

+8
-30
lines changed
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
type RawRangeResponse struct {
22
// The key-value pairs
3-
Data Array[RawRangeEntry] `json:"data"`
3+
Data Array[Array[[]byte]] `json:"data"`
44
// `None` if there are no more key-value pairs within the given key range.
55
NextKey []byte `json:"next_key"`
6-
}
7-
type RawRangeEntry struct {
8-
K []byte `json:"k"`
9-
V []byte `json:"v"`
106
}

packages/std/src/query/wasm.rs

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -161,23 +161,7 @@ impl_hidden_constructor!(
161161
next_key: Option<Binary>
162162
);
163163

164-
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
165-
pub struct RawRangeEntry {
166-
// keys renamed to reduce JSON size overhead
167-
#[serde(rename = "k")]
168-
pub key: Binary,
169-
#[serde(rename = "v")]
170-
pub value: Binary,
171-
}
172-
173-
impl RawRangeEntry {
174-
pub fn new(key: impl Into<Binary>, value: impl Into<Binary>) -> Self {
175-
RawRangeEntry {
176-
key: key.into(),
177-
value: value.into(),
178-
}
179-
}
180-
}
164+
pub type RawRangeEntry = (Binary, Binary);
181165

182166
#[cfg(test)]
183167
mod tests {
@@ -284,15 +268,15 @@ mod tests {
284268
fn raw_range_response_serialization() {
285269
let response = RawRangeResponse {
286270
data: vec![
287-
RawRangeEntry::new(b"key", b"value"),
288-
RawRangeEntry::new(b"foo", b"bar"),
271+
(Binary::from(b"key"), Binary::from(b"value")),
272+
(Binary::from(b"foo"), Binary::from(b"bar")),
289273
],
290274
next_key: Some(Binary::from(b"next")),
291275
};
292276
let json = to_json_binary(&response).unwrap();
293277
assert_eq!(
294278
String::from_utf8_lossy(&json),
295-
r#"{"data":[{"k":"a2V5","v":"dmFsdWU="},{"k":"Zm9v","v":"YmFy"}],"next_key":"bmV4dA=="}"#,
279+
r#"{"data":[["a2V5","dmFsdWU="],["Zm9v","YmFy"]],"next_key":"bmV4dA=="}"#,
296280
);
297281
}
298282
}

packages/std/src/testing/mock.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2846,8 +2846,6 @@ mod tests {
28462846
limit,
28472847
order,
28482848
} => {
2849-
use crate::RawRangeEntry;
2850-
28512849
let Ok(addr) = api.addr_validate(contract_addr) else {
28522850
return SystemResult::Err(SystemError::NoSuchContract {
28532851
addr: contract_addr.clone(),
@@ -2861,12 +2859,12 @@ mod tests {
28612859
*order,
28622860
)
28632861
.take(*limit as usize + 1) // take one more entry than limit
2864-
.map(|(key, value)| RawRangeEntry::new(key, value))
2862+
.map(|(key, value)| (Binary::new(key), Binary::new(value)))
28652863
.collect();
28662864

28672865
// if we have more than limit, there are more entries to fetch
28682866
let next_key = if data.len() > *limit as usize {
2869-
data.pop().map(|RawRangeEntry { key, .. }| key)
2867+
data.pop().map(|(key, _)| key)
28702868
} else {
28712869
None
28722870
};
@@ -2966,7 +2964,7 @@ mod tests {
29662964
match result {
29672965
SystemResult::Ok(ContractResult::Ok(value)) => assert_eq!(
29682966
value.as_slice(),
2969-
br#"{"data":[{"k":"dGhlIGtleQ==","v":"dGhlIHZhbHVl"}],"next_key":null}"#
2967+
br#"{"data":[["dGhlIGtleQ==","dGhlIHZhbHVl"]],"next_key":null}"#
29702968
),
29712969
res => panic!("Unexpected result: {res:?}"),
29722970
}

0 commit comments

Comments
 (0)