diff --git a/Cargo.lock b/Cargo.lock index b3781d0854..e49b26a080 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6643,9 +6643,8 @@ name = "oracle-rpc-runtime-api" version = "1.2.0" dependencies = [ "frame-support", + "interbtc-primitives", "parity-scale-codec", - "scale-info", - "serde", "sp-api", "sp-std", ] diff --git a/crates/oracle/rpc/runtime-api/Cargo.toml b/crates/oracle/rpc/runtime-api/Cargo.toml index 2e2f2d2b0d..d4f9af7f02 100644 --- a/crates/oracle/rpc/runtime-api/Cargo.toml +++ b/crates/oracle/rpc/runtime-api/Cargo.toml @@ -5,19 +5,20 @@ authors = ["Interlay Ltd"] edition = "2021" [dependencies] -serde = { version = "1.0.130", default-features = false, optional = true, features = ["derive"] } codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive", "max-encoded-len"] } frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31", default-features = false } sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31", default-features = false } sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31", default-features = false } -scale-info = { version = "2.2.0", default-features = false, features = ["derive"] } + +primitives = { package = "interbtc-primitives", path = "../../../../primitives", default-features = false } [features] default = ["std"] std = [ - "serde", "codec/std", "frame-support/std", "sp-api/std", "sp-std/std", + + "primitives/std", ] diff --git a/crates/oracle/rpc/runtime-api/src/lib.rs b/crates/oracle/rpc/runtime-api/src/lib.rs index 4e44e8bd06..d5066104ef 100644 --- a/crates/oracle/rpc/runtime-api/src/lib.rs +++ b/crates/oracle/rpc/runtime-api/src/lib.rs @@ -2,36 +2,10 @@ #![cfg_attr(not(feature = "std"), no_std)] -use codec::{Codec, Decode, Encode}; +use codec::Codec; use frame_support::dispatch::DispatchError; -use scale_info::TypeInfo; -#[cfg(feature = "std")] -use serde::{Deserialize, Deserializer, Serialize, Serializer}; -#[derive(Eq, PartialEq, Encode, Decode, Default, TypeInfo)] -#[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))] -#[cfg_attr(feature = "std", serde(rename_all = "camelCase"))] -/// a wrapper around a balance, used in RPC to workaround a bug where using u128 -/// in runtime-apis fails. See -pub struct BalanceWrapper { - #[cfg_attr(feature = "std", serde(bound(serialize = "T: std::fmt::Display")))] - #[cfg_attr(feature = "std", serde(serialize_with = "serialize_as_string"))] - #[cfg_attr(feature = "std", serde(bound(deserialize = "T: std::str::FromStr")))] - #[cfg_attr(feature = "std", serde(deserialize_with = "deserialize_from_string"))] - pub amount: T, -} - -#[cfg(feature = "std")] -fn serialize_as_string(t: &T, serializer: S) -> Result { - serializer.serialize_str(&t.to_string()) -} - -#[cfg(feature = "std")] -fn deserialize_from_string<'de, D: Deserializer<'de>, T: std::str::FromStr>(deserializer: D) -> Result { - let s = String::deserialize(deserializer)?; - s.parse::() - .map_err(|_| serde::de::Error::custom("Parse from string failed")) -} +pub use primitives::BalanceWrapper; sp_api::decl_runtime_apis! { pub trait OracleApi where diff --git a/primitives/src/lib.rs b/primitives/src/lib.rs index 2da88406d4..293e2e10ad 100644 --- a/primitives/src/lib.rs +++ b/primitives/src/lib.rs @@ -186,6 +186,19 @@ pub mod issue { } } +#[derive(Eq, PartialEq, Encode, Decode, Default, TypeInfo)] +#[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))] +#[cfg_attr(feature = "std", serde(rename_all = "camelCase"))] +/// a wrapper around a balance, used in RPC to workaround a bug where using u128 +/// in runtime-apis fails. See +pub struct BalanceWrapper { + #[cfg_attr(feature = "std", serde(bound(serialize = "T: std::fmt::Display")))] + #[cfg_attr(feature = "std", serde(serialize_with = "serialize_as_string"))] + #[cfg_attr(feature = "std", serde(bound(deserialize = "T: std::str::FromStr")))] + #[cfg_attr(feature = "std", serde(deserialize_with = "deserialize_from_string"))] + pub amount: T, +} + #[cfg(feature = "std")] fn serialize_as_string(t: &T, serializer: S) -> Result { serializer.serialize_str(&t.to_string())