Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add interchain security protobuf #NTRN-408 #8

Merged
merged 9 commits into from
Nov 27, 2024
21 changes: 20 additions & 1 deletion packages/neutron-std/src/serde/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,19 @@ use std::{
struct StringOrNumberVisitor<T> {
pr0n00gler marked this conversation as resolved.
Show resolved Hide resolved
p: PhantomData<T>,
}

// The Visitor helps deserialize a number, both from its numerical JSON representation and from a string.
// For example, for the struct:
// ```rust
// struct Foo {
// pub bar: i32;
// }
// ```
// Both JSON representations `'{"foo":"12"}'` and `'{"foo":12}'` will give the same result upon deserialization:
// ```json
// {
// "foo": 12
sotnikov-s marked this conversation as resolved.
Show resolved Hide resolved
// }
/// ```
impl<'de, T> de::Visitor<'de> for StringOrNumberVisitor<T>
where
T: Deserialize<'de>,
Expand Down Expand Up @@ -197,6 +209,13 @@ pub mod as_option_base64_encoded_string {
}
}


// NumberOrString is a helper enum that helps us determine which
// JSON numeric representation we are working with. If it's a string,
// we will get the value `NumberOrString::String("-11")`.
// If we are dealing with a numeric representation,
// we will get `NumberOrString::Number(-11i64)`.
// Then, using pattern matching, we can select the appropriate algorithm to work with the data.
#[derive(Deserialize, Debug, PartialEq)]
#[serde(untagged)]
enum NumberOrString<T> {
Expand Down