diff --git a/Cargo.dev.toml b/Cargo.dev.toml index 988e00465..a1fb52b79 100644 --- a/Cargo.dev.toml +++ b/Cargo.dev.toml @@ -7,11 +7,9 @@ members = [ "currencies", "gradually-update", "oracle", - "oracle/rpc", - "oracle/rpc/runtime-api", + "oracle/runtime-api", "tokens", - "tokens/rpc", - "tokens/rpc/runtime-api", + "tokens/runtime-api", "traits", "utilities", "vesting", diff --git a/oracle/rpc/Cargo.toml b/oracle/rpc/Cargo.toml deleted file mode 100644 index fb8a70d20..000000000 --- a/oracle/rpc/Cargo.toml +++ /dev/null @@ -1,19 +0,0 @@ -[package] -name = "orml-oracle-rpc" -version = "0.4.1-dev" -authors = ["Laminar Developers "] -edition = "2021" -license = "Apache-2.0" -description = "RPC module for orml-oracle." - -[dependencies] -codec = { package = "parity-scale-codec", version = "3.4.0" } -jsonrpsee = { version = "0.16.2", features = ["client", "server", "macros"] } -tracing = "0.1.29" -tracing-core = "0.1.28" - -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } -sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } -sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } - -orml-oracle-rpc-runtime-api = { path = "runtime-api", version = "0.4.1-dev" } diff --git a/oracle/rpc/src/lib.rs b/oracle/rpc/src/lib.rs deleted file mode 100644 index bad779ff9..000000000 --- a/oracle/rpc/src/lib.rs +++ /dev/null @@ -1,102 +0,0 @@ -use std::sync::Arc; - -use codec::Codec; -use jsonrpsee::{ - core::{async_trait, RpcResult}, - proc_macros::rpc, - types::error::{CallError, ErrorObject}, -}; -use sp_api::ProvideRuntimeApi; -use sp_blockchain::HeaderBackend; -use sp_runtime::traits::Block as BlockT; - -pub use orml_oracle_rpc_runtime_api::OracleApi as OracleRuntimeApi; - -#[rpc(client, server)] -pub trait OracleApi { - #[method(name = "oracle_getValue")] - fn get_value(&self, provider_id: ProviderId, key: Key, at: Option) -> RpcResult>; - #[method(name = "oracle_getAllValues")] - fn get_all_values(&self, provider_id: ProviderId, at: Option) -> RpcResult)>>; -} - -/// Provides RPC methods to query oracle value. -#[deprecated(note = "please use `state_call` instead of RPC")] -pub struct Oracle { - /// Shared reference to the client. - client: Arc, - _marker: std::marker::PhantomData, -} - -#[allow(deprecated)] -impl Oracle { - /// Creates a new instance of the `Oracle` helper. - pub fn new(client: Arc) -> Self { - Self { - client, - _marker: Default::default(), - } - } -} - -pub enum Error { - RuntimeError, -} - -impl From for i32 { - fn from(e: Error) -> i32 { - match e { - Error::RuntimeError => 1, - } - } -} - -#[async_trait] -#[allow(deprecated)] -impl OracleApiServer<::Hash, ProviderId, Key, Value> - for Oracle -where - Block: BlockT, - C: ProvideRuntimeApi + HeaderBackend + Send + Sync + 'static, - C::Api: OracleRuntimeApi, - ProviderId: Codec, - Key: Codec, - Value: Codec, -{ - fn get_value( - &self, - provider_id: ProviderId, - key: Key, - at: Option<::Hash>, - ) -> RpcResult> { - let api = self.client.runtime_api(); - let at = at.unwrap_or_else(|| self.client.info().best_hash); - - api.get_value(at, provider_id, key).map_err(|e| { - CallError::Custom(ErrorObject::owned( - Error::RuntimeError.into(), - "Unable to get value.", - Some(e.to_string()), - )) - .into() - }) - } - - fn get_all_values( - &self, - provider_id: ProviderId, - at: Option<::Hash>, - ) -> RpcResult)>> { - let api = self.client.runtime_api(); - let at = at.unwrap_or_else(|| self.client.info().best_hash); - - api.get_all_values(at, provider_id).map_err(|e| { - CallError::Custom(ErrorObject::owned( - Error::RuntimeError.into(), - "Unable to get all values.", - Some(e.to_string()), - )) - .into() - }) - } -} diff --git a/oracle/rpc/runtime-api/Cargo.toml b/oracle/runtime-api/Cargo.toml similarity index 85% rename from oracle/rpc/runtime-api/Cargo.toml rename to oracle/runtime-api/Cargo.toml index 7484afc7d..7eb8bb62e 100644 --- a/oracle/rpc/runtime-api/Cargo.toml +++ b/oracle/runtime-api/Cargo.toml @@ -1,10 +1,10 @@ [package] -name = "orml-oracle-rpc-runtime-api" +name = "orml-oracle-runtime-api" version = "0.4.1-dev" authors = ["Laminar Developers "] edition = "2021" license = "Apache-2.0" -description = "Runtime API module for orml-oracle-rpc." +description = "Runtime API module for orml-oracle." [dependencies] codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } diff --git a/oracle/rpc/runtime-api/src/lib.rs b/oracle/runtime-api/src/lib.rs similarity index 100% rename from oracle/rpc/runtime-api/src/lib.rs rename to oracle/runtime-api/src/lib.rs diff --git a/tokens/rpc/Cargo.toml b/tokens/rpc/Cargo.toml deleted file mode 100644 index 06562c907..000000000 --- a/tokens/rpc/Cargo.toml +++ /dev/null @@ -1,22 +0,0 @@ -[package] -name = "orml-tokens-rpc" -description = "orml tokens rpc interface." -license = "Apache-2.0" -version = "0.4.1-dev" -authors = ["Laminar Developers "] -edition = "2021" - -[dependencies] -codec = { package = "parity-scale-codec", version = "3.4.0" } -jsonrpsee = { version = "0.16.2", features = ["client", "server", "macros"] } -tracing = "0.1.29" -tracing-core = "0.1.28" - -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } -sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } -sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } -sp-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } - -orml-tokens-rpc-runtime-api = { version = "0.4.1-dev", path = "./runtime-api" } diff --git a/tokens/rpc/src/lib.rs b/tokens/rpc/src/lib.rs deleted file mode 100644 index df10d8692..000000000 --- a/tokens/rpc/src/lib.rs +++ /dev/null @@ -1,94 +0,0 @@ -//! RPC interface for the orml-tokens pallet. -use std::sync::Arc; - -use codec::Codec; -use jsonrpsee::{ - core::{async_trait, Error as JsonRpseeError, RpcResult}, - proc_macros::rpc, - types::error::{CallError, ErrorCode, ErrorObject}, -}; -use sp_api::ProvideRuntimeApi; -use sp_blockchain::HeaderBackend; -use sp_rpc::number::NumberOrHex; -use sp_runtime::traits::{Block as BlockT, MaybeDisplay}; - -pub use orml_tokens_rpc_runtime_api::TokensApi as TokensRuntimeApi; - -#[rpc(client, server)] -pub trait TokensApi { - #[method(name = "tokens_queryExistentialDeposit")] - fn query_existential_deposit(&self, currency_id: CurrencyId, at: Option) -> RpcResult; -} - -/// Provides RPC methods to query existential deposit of currency. -#[deprecated(note = "please use `state_call` instead of RPC")] -pub struct Tokens { - /// Shared reference to the client. - client: Arc, - _marker: std::marker::PhantomData

, -} - -#[allow(deprecated)] -impl Tokens { - /// Creates a new instance of the `Tokens` helper. - pub fn new(client: Arc) -> Self { - Self { - client, - _marker: Default::default(), - } - } -} - -/// Error type of this RPC api. -pub enum Error { - /// The call to runtime failed. - RuntimeError, -} - -impl From for i32 { - fn from(e: Error) -> i32 { - match e { - Error::RuntimeError => 1, - } - } -} - -#[async_trait] -#[allow(deprecated)] -impl TokensApiServer<::Hash, CurrencyId, Balance> for Tokens -where - Block: BlockT, - C: ProvideRuntimeApi + HeaderBackend + Send + Sync + 'static, - C::Api: TokensRuntimeApi, - Balance: Codec + MaybeDisplay + Copy + TryInto + Send + Sync + 'static, - CurrencyId: Codec, -{ - fn query_existential_deposit( - &self, - currency_id: CurrencyId, - at: Option<::Hash>, - ) -> RpcResult { - let api = self.client.runtime_api(); - let at = at.unwrap_or_else(|| self.client.info().best_hash); - - let balance = api.query_existential_deposit(at, currency_id).map_err(|e| { - CallError::Custom(ErrorObject::owned( - Error::RuntimeError.into(), - "Unable to query existential deposit.", - Some(e.to_string()), - )) - }); - - let try_into_rpc_balance = |value: Balance| { - value.try_into().map_err(|_| { - JsonRpseeError::Call(CallError::Custom(ErrorObject::owned( - ErrorCode::InvalidParams.code(), - format!("{} doesn't fit in NumberOrHex representation", value), - None::<()>, - ))) - }) - }; - - try_into_rpc_balance(balance?) - } -} diff --git a/tokens/rpc/runtime-api/Cargo.toml b/tokens/runtime-api/Cargo.toml similarity index 81% rename from tokens/rpc/runtime-api/Cargo.toml rename to tokens/runtime-api/Cargo.toml index 840b5a487..c9523b213 100644 --- a/tokens/rpc/runtime-api/Cargo.toml +++ b/tokens/runtime-api/Cargo.toml @@ -1,17 +1,16 @@ [package] -name = "orml-tokens-rpc-runtime-api" -description = "orml tokens rpc interface." -license = "Apache-2.0" +name = "orml-tokens-runtime-api" version = "0.4.1-dev" authors = ["Laminar Developers "] edition = "2021" +license = "Apache-2.0" +description = "Runtime API module for orml-tokens." [dependencies] codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v1.0.0" } sp-api = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v1.0.0" } sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v1.0.0" } -orml-tokens = { default-features = false, path = "../../../tokens" } [features] default = ["std"] @@ -20,5 +19,4 @@ std = [ "frame-support/std", "sp-api/std", "sp-runtime/std", - "orml-tokens/std", ] diff --git a/tokens/rpc/runtime-api/src/lib.rs b/tokens/runtime-api/src/lib.rs similarity index 100% rename from tokens/rpc/runtime-api/src/lib.rs rename to tokens/runtime-api/src/lib.rs