From 57b31d92d732a962200c34c380de197a372b9cf6 Mon Sep 17 00:00:00 2001 From: kaimen-sano Date: Sat, 6 Jan 2024 21:23:38 +1300 Subject: [PATCH] fix(white-whale package): use shim for CosmwasmExt `osmosis-std-derive` expects a shim package at `::crate::shim` which has an `Any` struct (https://github.com/osmosis-labs/osmosis-rust/blob/01affba52765e50f43cf52bbc12355fa2dc379f2/packages/osmosis-std-derive/src/lib.rs#L75-L81). We create a shim file for this. --- packages/white-whale/Cargo.toml | 6 ++- packages/white-whale/src/lib.rs | 3 ++ packages/white-whale/src/shim.rs | 89 ++++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 packages/white-whale/src/shim.rs diff --git a/packages/white-whale/Cargo.toml b/packages/white-whale/Cargo.toml index 0d76e866..6f5c0a6e 100644 --- a/packages/white-whale/Cargo.toml +++ b/packages/white-whale/Cargo.toml @@ -17,7 +17,9 @@ documentation = "https://whitewhale.money" backtraces = ["cosmwasm-std/backtraces"] injective = ["token_factory"] token_factory = ["cosmwasm-std/stargate", "cosmwasm-std/cosmwasm_1_1"] -osmosis_token_factory = ["token_factory"] # this is for the osmosis token factory proto definitions, which defer from the standard token factory :) +osmosis_token_factory = [ + "token_factory", +] # this is for the osmosis token factory proto definitions, which defer from the standard token factory :) [dependencies] cosmwasm-std.workspace = true @@ -30,4 +32,4 @@ protobuf.workspace = true uint.workspace = true osmosis-std-derive.workspace = true prost.workspace = true -prost-types.workspace = true \ No newline at end of file +prost-types.workspace = true diff --git a/packages/white-whale/src/lib.rs b/packages/white-whale/src/lib.rs index 5b326434..3c904b55 100644 --- a/packages/white-whale/src/lib.rs +++ b/packages/white-whale/src/lib.rs @@ -7,3 +7,6 @@ pub mod pool_network; pub mod traits; pub mod vault_network; pub mod whale_lair; + +// used in `denom.rs` for `CosmwasmExt` +mod shim; diff --git a/packages/white-whale/src/shim.rs b/packages/white-whale/src/shim.rs new file mode 100644 index 00000000..ac7f653a --- /dev/null +++ b/packages/white-whale/src/shim.rs @@ -0,0 +1,89 @@ +// osmosis-std-derive needs a `::crate::shim` to work +// we rip this file from `osmosis-std` package: +// https://github.com/osmosis-labs/osmosis-rust/blob/main/packages/osmosis-std/src/shim.rs +#[derive(Clone, PartialEq, Eq, ::prost::Message, schemars::JsonSchema)] +pub struct Any { + /// A URL/resource name that uniquely identifies the type of the serialized + /// protocol buffer message. This string must contain at least + /// one "/" character. The last segment of the URL's path must represent + /// the fully qualified name of the type (as in + /// `path/google.protobuf.Duration`). The name should be in a canonical form + /// (e.g., leading "." is not accepted). + /// + /// In practice, teams usually precompile into the binary all types that they + /// expect it to use in the context of Any. However, for URLs which use the + /// scheme `http`, `https`, or no scheme, one can optionally set up a type + /// server that maps type URLs to message definitions as follows: + /// + /// * If no scheme is provided, `https` is assumed. + /// * An HTTP GET on the URL must yield a \[google.protobuf.Type][\] + /// value in binary format, or produce an error. + /// * Applications are allowed to cache lookup results based on the + /// URL, or have them precompiled into a binary to avoid any + /// lookup. Therefore, binary compatibility needs to be preserved + /// on changes to types. (Use versioned type names to manage + /// breaking changes.) + /// + /// Note: this functionality is not currently available in the official + /// protobuf release, and it is not used for type URLs beginning with + /// type.googleapis.com. + /// + /// Schemes other than `http`, `https` (or the empty scheme) might be + /// used with implementation specific semantics. + /// + #[prost(string, tag = "1")] + pub type_url: ::prost::alloc::string::String, + /// Must be a valid serialized protocol buffer of the above specified type. + #[prost(bytes = "vec", tag = "2")] + pub value: ::prost::alloc::vec::Vec, +} + +macro_rules! impl_prost_types_exact_conversion { + ($t:ident | $($arg:ident),*) => { + impl From<$t> for prost_types::$t { + fn from(src: $t) -> Self { + prost_types::$t { + $( + $arg: src.$arg, + )* + } + } + } + + impl From for $t { + fn from(src: prost_types::$t) -> Self { + $t { + $( + $arg: src.$arg, + )* + } + } + } + }; +} + +impl_prost_types_exact_conversion! { Any | type_url, value } + +// depended on by cosmwasm.rs +pub mod as_str { + use serde::{de, Deserialize, Deserializer, Serializer}; + use std::{fmt::Display, str::FromStr}; + + pub fn deserialize<'de, T, D>(deserializer: D) -> Result + where + T: FromStr, + T::Err: Display, + D: Deserializer<'de>, + { + let s = String::deserialize(deserializer)?; + T::from_str(&s).map_err(de::Error::custom) + } + + pub fn serialize(value: &T, serializer: S) -> Result + where + S: Serializer, + T: Display, + { + serializer.serialize_str(&value.to_string()) + } +}