From ffe63b6209ca92ee70ec7649e555af71d6911e0b Mon Sep 17 00:00:00 2001 From: b-yap <2826165+b-yap@users.noreply.github.com> Date: Tue, 4 Apr 2023 19:46:40 +0800 Subject: [PATCH] added the oracle api in the node, foucoco runtime, and amplitude runtime --- Cargo.lock | 14 ++++++++++++++ node/Cargo.toml | 1 + node/src/rpc.rs | 5 ++++- runtime/amplitude/src/lib.rs | 12 ++++++++++++ runtime/foucoco/src/lib.rs | 12 ++++++++++++ 5 files changed, 43 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index a2da614cf..4cd999b73 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5228,6 +5228,19 @@ dependencies = [ "sp-std", ] +[[package]] +name = "module-oracle-rpc" +version = "1.2.0" +source = "git+https://github.com/pendulum-chain/spacewalk?rev=5183e8730a3a10492d0be80720f68e236e0dee10#5183e8730a3a10492d0be80720f68e236e0dee10" +dependencies = [ + "jsonrpsee", + "module-oracle-rpc-runtime-api", + "parity-scale-codec", + "sp-api", + "sp-blockchain", + "sp-runtime", +] + [[package]] name = "module-oracle-rpc-runtime-api" version = "1.2.0" @@ -7271,6 +7284,7 @@ dependencies = [ "jsonrpsee", "log", "module-issue-rpc", + "module-oracle-rpc", "module-redeem-rpc", "module-replace-rpc", "module-vault-registry-rpc", diff --git a/node/Cargo.toml b/node/Cargo.toml index 422f9a883..a589058d7 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -16,6 +16,7 @@ serde = { version = "1.0.145", features = ["derive"] } jsonrpsee = { version = "0.16.2", features = ["server"] } module-issue-rpc = { git = "https://github.com/pendulum-chain/spacewalk", rev = "5183e8730a3a10492d0be80720f68e236e0dee10"} +module-oracle-rpc = { git = "https://github.com/pendulum-chain/spacewalk", rev = "5183e8730a3a10492d0be80720f68e236e0dee10"} module-redeem-rpc = { git = "https://github.com/pendulum-chain/spacewalk", rev = "5183e8730a3a10492d0be80720f68e236e0dee10"} module-replace-rpc = { git = "https://github.com/pendulum-chain/spacewalk", rev = "5183e8730a3a10492d0be80720f68e236e0dee10"} module-vault-registry-rpc = { git = "https://github.com/pendulum-chain/spacewalk", rev = "5183e8730a3a10492d0be80720f68e236e0dee10"} diff --git a/node/src/rpc.rs b/node/src/rpc.rs index b656e67ce..d92520e2c 100644 --- a/node/src/rpc.rs +++ b/node/src/rpc.rs @@ -103,10 +103,12 @@ where H256, RedeemRequest, >, + C::Api: module_oracle_rpc::OracleRuntimeApi, C::Api: BlockBuilder, P: TransactionPool + Sync + Send + 'static, { use module_issue_rpc::{Issue, IssueApiServer}; + use module_oracle_rpc::{Oracle, OracleApiServer}; use module_redeem_rpc::{Redeem, RedeemApiServer}; use module_replace_rpc::{Replace, ReplaceApiServer}; use module_vault_registry_rpc::{VaultRegistry, VaultRegistryApiServer}; @@ -121,7 +123,8 @@ where module.merge(Issue::new(client.clone()).into_rpc())?; module.merge(Redeem::new(client.clone()).into_rpc())?; module.merge(Replace::new(client.clone()).into_rpc())?; - module.merge(VaultRegistry::new(client).into_rpc())?; + module.merge(VaultRegistry::new(client.clone()).into_rpc())?; + module.merge(Oracle::new(client).into_rpc())?; Ok(module) } diff --git a/runtime/amplitude/src/lib.rs b/runtime/amplitude/src/lib.rs index 440c5b320..1ef07ba29 100644 --- a/runtime/amplitude/src/lib.rs +++ b/runtime/amplitude/src/lib.rs @@ -1659,6 +1659,18 @@ impl_runtime_apis! { } } + impl module_oracle_rpc_runtime_api::OracleApi for Runtime { + fn currency_to_usd(amount:BalanceWrapper, currency_id: CurrencyId) -> Result, DispatchError> { + let result = Oracle::currency_to_usd(amount.amount, currency_id)?; + Ok(BalanceWrapper{amount:result}) + } + + fn usd_to_currency(amount:BalanceWrapper, currency_id: CurrencyId) -> Result, DispatchError> { + let result = Oracle::usd_to_currency(amount.amount, currency_id)?; + Ok(BalanceWrapper{amount:result}) + } + } + } struct CheckInherents; diff --git a/runtime/foucoco/src/lib.rs b/runtime/foucoco/src/lib.rs index 30d1d3994..afc30adc2 100644 --- a/runtime/foucoco/src/lib.rs +++ b/runtime/foucoco/src/lib.rs @@ -2080,6 +2080,18 @@ impl_runtime_apis! { } } + impl module_oracle_rpc_runtime_api::OracleApi for Runtime { + fn currency_to_usd(amount:BalanceWrapper, currency_id: CurrencyId) -> Result, DispatchError> { + let result = Oracle::currency_to_usd(amount.amount, currency_id)?; + Ok(BalanceWrapper{amount:result}) + } + + fn usd_to_currency(amount:BalanceWrapper, currency_id: CurrencyId) -> Result, DispatchError> { + let result = Oracle::usd_to_currency(amount.amount, currency_id)?; + Ok(BalanceWrapper{amount:result}) + } + } + } struct CheckInherents;