Skip to content

Commit

Permalink
Orders runtime api
Browse files Browse the repository at this point in the history
  • Loading branch information
Szegoo committed Aug 13, 2024
1 parent f08db0c commit 49e3f16
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions pallets/orders/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ cumulus-primitives-core = { workspace = true, default-features = false }
frame-benchmarking = { workspace = true, default-features = false, optional = true }
frame-support = { workspace = true, default-features = false }
frame-system = { workspace = true, default-features = false }
sp-api = { workspace = true, default-features = false }
sp-io = { workspace = true, default-features = false }
sp-core = { workspace = true, default-features = false }
sp-runtime = { workspace = true, default-features = false }
Expand All @@ -41,6 +42,7 @@ std = [
"codec/std",
"cumulus-primitives-core/std",
"scale-info/std",
"sp-api/std",
"sp-io/std",
"sp-core/std",
"sp-runtime/std",
Expand Down
2 changes: 2 additions & 0 deletions pallets/orders/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ pub use crate::types::*;
pub mod weights;
pub use weights::WeightInfo;

pub mod runtime_api;

pub type BalanceOf<T> =
<<T as crate::Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;

Expand Down
27 changes: 27 additions & 0 deletions pallets/orders/src/runtime_api.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// This file is part of RegionX.
//
// RegionX 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.
//
// RegionX 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 RegionX. If not, see <https://www.gnu.org/licenses/>.

use codec::Codec;
use order_primitives::OrderId;

sp_api::decl_runtime_apis! {
pub trait OrdersApi<AccountId>
where
AccountId: Codec
{
/// Returns the account of an order.
fn order_account(order_id: OrderId) -> AccountId;
}
}
6 changes: 6 additions & 0 deletions runtime/cocos/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1126,6 +1126,12 @@ impl_runtime_apis! {
}
}

impl pallet_orders::runtime_api::OrdersApi<Block, AccountId> for Runtime {
fn order_account(order_id: OrderId) -> AccountId {
<Runtime as pallet_orders::Config>::OrderToAccountId::convert(order_id)
}
}

#[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for Runtime {
fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) {
Expand Down

0 comments on commit 49e3f16

Please sign in to comment.