Skip to content

Commit

Permalink
Add currencies runtime API (#2666)
Browse files Browse the repository at this point in the history
  • Loading branch information
zjb0807 authored Dec 7, 2023
1 parent 13b831d commit 1fd9251
Show file tree
Hide file tree
Showing 12 changed files with 111 additions and 4 deletions.
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ members = [
"node/service",

"modules/*",
"modules/currencies/runtime-api",
"modules/evm-utility/macro",
"primitives",
"rpc",
Expand Down Expand Up @@ -192,14 +193,15 @@ module-cdp-engine = { path = "modules/cdp-engine", default-features = false }
module-cdp-treasury = { path = "modules/cdp-treasury", default-features = false }
module-collator-selection = { path = "modules/collator-selection", default-features = false }
module-currencies = { path = "modules/currencies", default-features = false }
module-currencies-runtime-api = { path = "modules/currencies/runtime-api", default-features = false }
module-dex = { path = "modules/dex", default-features = false }
module-dex-oracle = { path = "modules/dex-oracle", default-features = false }
module-earning = { path = "modules/earning", default-features = false }
module-emergency-shutdown = { path = "modules/emergency-shutdown", default-features = false }
module-evm = { path = "modules/evm", default-features = false }
module-evm-accounts = { path = "modules/evm-accounts", default-features = false }
module-evm-bridge = { path = "modules/evm-bridge", default-features = false }
module-evm-rpc-runtime-api = { path = "modules/evm/rpc/runtime_api", default-features = false }
module-evm-rpc-runtime-api = { path = "modules/evm/rpc/runtime-api", default-features = false }
module-evm-utility = { path = "modules/evm-utility", default-features = false }
module-homa = { path = "modules/homa", default-features = false }
module-honzon = { path = "modules/honzon", default-features = false }
Expand Down
20 changes: 20 additions & 0 deletions modules/currencies/runtime-api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "module-currencies-runtime-api"
version = "2.23.0"
authors = ["Acala Developers"]
edition = "2021"

[dependencies]
sp-runtime = { workspace = true }
sp-api = { workspace = true }
sp-std = { workspace = true }
sp-core = { workspace = true }

[features]
default = ["std"]
std = [
"sp-runtime/std",
"sp-api/std",
"sp-std/std",
"sp-core/std",
]
33 changes: 33 additions & 0 deletions modules/currencies/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// This file is part of Acala.

// Copyright (C) 2020-2023 Acala Foundation.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

#![cfg_attr(not(feature = "std"), no_std)]
#![allow(clippy::all)]

use sp_runtime::codec::Codec;

sp_api::decl_runtime_apis! {
#[api_version(2)]
pub trait CurrenciesApi<CurrencyId, AccountId, Balance> where
CurrencyId: Codec,
AccountId: Codec,
Balance: Codec,
{
fn query_free_balance(currency_id: CurrencyId, who: AccountId) -> Balance;
}
}
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions runtime/acala/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ module-cdp-engine = { workspace = true }
module-cdp-treasury = { workspace = true }
module-collator-selection = { workspace = true }
module-currencies = { workspace = true }
module-currencies-runtime-api = { workspace = true }
module-dex = { workspace = true }
module-dex-oracle = { workspace = true }
module-earning = { workspace = true }
Expand Down Expand Up @@ -235,6 +236,7 @@ std = [
"module-cdp-treasury/std",
"module-collator-selection/std",
"module-currencies/std",
"module-currencies-runtime-api/std",
"module-dex-oracle/std",
"module-dex/std",
"module-earning/std",
Expand Down
13 changes: 12 additions & 1 deletion runtime/acala/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ use frame_support::{
};
use orml_traits::{
create_median_value_data_provider, define_aggregrated_parameters, parameter_type_with_key,
parameters::ParameterStoreAdapter, DataFeeder, DataProviderExtended,
parameters::ParameterStoreAdapter, DataFeeder, DataProviderExtended, MultiCurrency,
};
use orml_utilities::simulate_execution;
use pallet_transaction_payment::RuntimeDispatchInfo;
Expand Down Expand Up @@ -2079,6 +2079,17 @@ sp_api::impl_runtime_apis! {
}
}

impl module_currencies_runtime_api::CurrenciesApi<
Block,
CurrencyId,
AccountId,
Balance,
> for Runtime {
fn query_free_balance(currency_id: CurrencyId, who: AccountId) -> Balance {
Currencies::free_balance(currency_id, &who)
}
}

impl module_evm_rpc_runtime_api::EVMRuntimeRPCApi<Block, Balance> for Runtime {
fn block_limits() -> BlockLimits {
BlockLimits {
Expand Down
2 changes: 2 additions & 0 deletions runtime/karura/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ module-cdp-engine = { workspace = true }
module-cdp-treasury = { workspace = true }
module-collator-selection = { workspace = true }
module-currencies = { workspace = true }
module-currencies-runtime-api = { workspace = true }
module-dex = { workspace = true }
module-dex-oracle = { workspace = true }
module-earning = { workspace = true }
Expand Down Expand Up @@ -236,6 +237,7 @@ std = [
"module-cdp-treasury/std",
"module-collator-selection/std",
"module-currencies/std",
"module-currencies-runtime-api/std",
"module-dex-oracle/std",
"module-dex/std",
"module-earning/std",
Expand Down
13 changes: 12 additions & 1 deletion runtime/karura/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ use module_transaction_payment::TargetedFeeAdjustment;
use cumulus_pallet_parachain_system::RelaychainDataProvider;
use orml_traits::{
create_median_value_data_provider, define_aggregrated_parameters, parameter_type_with_key,
parameters::ParameterStoreAdapter, DataFeeder, DataProviderExtended, GetByKey,
parameters::ParameterStoreAdapter, DataFeeder, DataProviderExtended, GetByKey, MultiCurrency,
};
use orml_utilities::simulate_execution;
use pallet_transaction_payment::RuntimeDispatchInfo;
Expand Down Expand Up @@ -2093,6 +2093,17 @@ impl_runtime_apis! {
}
}

impl module_currencies_runtime_api::CurrenciesApi<
Block,
CurrencyId,
AccountId,
Balance,
> for Runtime {
fn query_free_balance(currency_id: CurrencyId, who: AccountId) -> Balance {
Currencies::free_balance(currency_id, &who)
}
}

impl module_evm_rpc_runtime_api::EVMRuntimeRPCApi<Block, Balance> for Runtime {
fn block_limits() -> BlockLimits {
BlockLimits {
Expand Down
2 changes: 2 additions & 0 deletions runtime/mandala/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ module-cdp-engine = { workspace = true }
module-cdp-treasury = { workspace = true }
module-collator-selection = { workspace = true }
module-currencies = { workspace = true }
module-currencies-runtime-api = { workspace = true }
module-dex = { workspace = true }
module-dex-oracle = { workspace = true }
module-emergency-shutdown = { workspace = true }
Expand Down Expand Up @@ -253,6 +254,7 @@ std = [
"module-cdp-treasury/std",
"module-collator-selection/std",
"module-currencies/std",
"module-currencies-runtime-api/std",
"module-dex-oracle/std",
"module-dex/std",
"module-earning/std",
Expand Down
13 changes: 12 additions & 1 deletion runtime/mandala/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ use scale_info::TypeInfo;
use orml_tokens::CurrencyAdapter;
use orml_traits::{
create_median_value_data_provider, define_aggregrated_parameters, parameter_type_with_key,
parameters::ParameterStoreAdapter, DataFeeder, DataProviderExtended, GetByKey,
parameters::ParameterStoreAdapter, DataFeeder, DataProviderExtended, GetByKey, MultiCurrency,
};
use orml_utilities::simulate_execution;
use pallet_transaction_payment::{FeeDetails, RuntimeDispatchInfo};
Expand Down Expand Up @@ -2286,6 +2286,17 @@ impl_runtime_apis! {
}
}

impl module_currencies_runtime_api::CurrenciesApi<
Block,
CurrencyId,
AccountId,
Balance,
> for Runtime {
fn query_free_balance(currency_id: CurrencyId, who: AccountId) -> Balance {
Currencies::free_balance(currency_id, &who)
}
}

impl module_evm_rpc_runtime_api::EVMRuntimeRPCApi<Block, Balance> for Runtime {
fn block_limits() -> BlockLimits {
BlockLimits {
Expand Down

0 comments on commit 1fd9251

Please sign in to comment.