Skip to content

Commit 7562f38

Browse files
committed
fix the serialization issue for next_key
1 parent 830e1be commit 7562f38

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

packages/persistence-std/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "persistence-std"
3-
version = "0.1.5"
3+
version = "0.1.6"
44
edition = "2021"
55
license = "MIT OR Apache-2.0"
66
description = "Standard library for Persistence chain modules with CosmWasm support included"

packages/persistence-std/src/serde/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ pub mod as_map {
3535

3636
match value {
3737
Value::Bytes(b) => Ok(T::from(b)),
38+
Value::Option(o) => match o {
39+
Some(b) => {
40+
// convert this to json string
41+
let s = serde_json_wasm::to_string(&b).unwrap();
42+
Ok(T::from(s.as_bytes().to_vec()))
43+
},
44+
None => Ok(T::from(vec![])),
45+
},
46+
Value::Unit => Ok(T::from(vec![])),
3847
_ => {
3948
// convert this to jsons string
4049
let s = serde_json_wasm::to_string(&value).unwrap();

packages/persistence-std/src/types/cosmos/base/query/v1beta1.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ pub struct PageResponse {
6161
/// query the next page most efficiently. It will be empty if
6262
/// there are no more results.
6363
#[prost(bytes = "vec", tag = "1")]
64+
#[serde(
65+
deserialize_with = "crate::serde::as_map::deserialize"
66+
)]
6467
pub next_key: ::prost::alloc::vec::Vec<u8>,
6568
/// total is total number of results available if PageRequest.count_total
6669
/// was set, its value is undefined otherwise

packages/persistence-std/tests/test.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use persistence_std::{types::{cosmwasm::wasm::v1::MsgExecuteContract, cosmos::gov::v1::{QueryProposalsResponse, QueryProposalRequest, QueryProposalsRequest, ProposalStatus}}, shim::Any};
2+
use serde::de::Error;
23

34

45
#[test]
@@ -33,4 +34,10 @@ pub fn enum_serde_test() {
3334

3435
assert_eq!(query, query2);
3536

37+
38+
let test_json = r#"{"proposals":[{"id":"3","messages":[{"@type":"/cosmwasm.wasm.v1.MsgExecuteContract","sender":"persistence10d07y265gmmuvt4z0w9aw880jnsr700j5w4kch","contract":"persistence1xxx3ps3gm3wceg4g300hvggdv7ga0hmsk64srccffmfy4wvcrugq3skeny","msg":{"resume_create_pool":{"pool_creation_request_id":2}},"funds":[]}],"status":"PROPOSAL_STATUS_DEPOSIT_PERIOD","final_tally_result":{"yes_count":"0","abstain_count":"0","no_count":"0","no_with_veto_count":"0"},"submit_time":"2023-09-06T16:32:52.516964Z","deposit_end_time":"2023-09-08T16:32:52.516964Z","total_deposit":[],"voting_start_time":null,"voting_end_time":null,"metadata":"test","title":"Test Proposal","summary":"test","proposer":"persistence1xxx3ps3gm3wceg4g300hvggdv7ga0hmsk64srccffmfy4wvcrugq3skeny"}],"pagination":{"next_key":null,"total":"1"}}"#;
39+
let val: Result<QueryProposalsResponse, serde_json_wasm::de::Error> = serde_json_wasm::from_str(test_json);
40+
41+
println!("{:?}", val);
42+
3643
}

0 commit comments

Comments
 (0)