Skip to content

Commit

Permalink
United Polkadot&Kusama parachain runtime
Browse files Browse the repository at this point in the history
* Remove SUDO from polkadot parachain runtime
* Added XcmInfo pallet for fine tune XCM settings
  • Loading branch information
akru committed Oct 10, 2024
1 parent 492b059 commit 11ec1ec
Show file tree
Hide file tree
Showing 8 changed files with 181 additions and 402 deletions.
35 changes: 23 additions & 12 deletions Cargo.lock

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

6 changes: 2 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ homepage.workspace = true
repository.workspace = true

[workspace.package]
version = "3.1.0"
version = "3.2.0"
edition = "2021"
authors = ["Airalab <research@robonomics.network>"]
license = "Apache-2.0"
Expand Down Expand Up @@ -51,6 +51,7 @@ members = [
"frame/liability",
"frame/lighthouse",
"frame/digital-twin",
"frame/xcm-info",
"primitives",
"runtime/dev",
"runtime/main",
Expand All @@ -70,9 +71,6 @@ scale-info = { version = "2.5.0", default-features = false, features = [
"derive",
] }
smallvec = { version = "1.11", default-features = false }
lazy_static = { version = "1.4", default-features = false, features = [
"spin_no_std",
] }
log = { version = "0.4.19", default-features = false }

# (native)
Expand Down
29 changes: 29 additions & 0 deletions frame/xcm-info/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[package]
name = "pallet-xcm-info"
description = "XCM setup & information pallet"
version = "0.1.0"
authors.workspace = true
edition.workspace = true
homepage.workspace = true
repository.workspace = true

[dependencies]
frame-support = { workspace = true }
frame-system = { workspace = true }
parity-scale-codec = { workspace = true }
scale-info = { workspace = true }
sp-runtime = { workspace = true }
sp-std = { workspace = true }
xcm = { workspace = true }

[features]
default = ["std"]
std = [
"frame-support/std",
"frame-system/std",
"parity-scale-codec/std",
"scale-info/std",
"sp-runtime/std",
"sp-std/std",
"xcm/std",
]
109 changes: 109 additions & 0 deletions frame/xcm-info/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
///////////////////////////////////////////////////////////////////////////////
//
// Copyright 2018-2024 Robonomics Network <research@robonomics.network>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
///////////////////////////////////////////////////////////////////////////////
//! On-chain XCM setup & information.
#![cfg_attr(not(feature = "std"), no_std)]

pub use pallet::*;

#[frame_support::pallet]
pub mod pallet {
use super::*;
use frame_support::pallet_prelude::*;
use frame_system::{ensure_root, pallet_prelude::*};
use sp_runtime::traits::MaybeEquivalence;
use xcm::latest::prelude::*;

#[pallet::config]
pub trait Config: frame_system::Config {
/// AssetId type for asset<>location linkage setup.
type AssetId: Parameter + Copy + Default + MaxEncodedLen;
/// The overarching event type.
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
}

#[pallet::error]
pub enum Error<T> {}

#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
/// Updated Relay XCM identifier.
RelayNetworkChanged(NetworkId),
/// Added new asset XCM location.
AssetLinkAdded(T::AssetId, MultiLocation),
}

#[pallet::pallet]
pub struct Pallet<T>(PhantomData<T>);

/// Relay network identifier.
#[pallet::storage]
#[pallet::getter(fn relay_network)]
pub(super) type RelayNetwork<T> = StorageValue<_, NetworkId>;

/// AssetId to location mapping.
#[pallet::storage]
#[pallet::getter(fn location_of)]
pub(super) type LocationOf<T: Config> =
StorageMap<_, Blake2_128Concat, T::AssetId, MultiLocation>;

/// Location to AssetId mapping.
#[pallet::storage]
#[pallet::getter(fn assetid_of)]
pub(super) type AssetIdOf<T: Config> =
StorageMap<_, Blake2_128Concat, MultiLocation, T::AssetId>;

#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::call_index(0)]
#[pallet::weight(10_000)]
pub fn set_relay_network(origin: OriginFor<T>, network_id: NetworkId) -> DispatchResult {
ensure_root(origin)?;

<RelayNetwork<T>>::put(network_id);
Self::deposit_event(Event::<T>::RelayNetworkChanged(network_id));

Ok(())
}

#[pallet::call_index(1)]
#[pallet::weight(10_000)]
pub fn set_asset_link(
origin: OriginFor<T>,
asset_id: T::AssetId,
location: MultiLocation,
) -> DispatchResult {
ensure_root(origin)?;

<LocationOf<T>>::insert(asset_id, location);
<AssetIdOf<T>>::insert(location, asset_id);
Self::deposit_event(Event::<T>::AssetLinkAdded(asset_id, location));

Ok(())
}
}

impl<T: Config> MaybeEquivalence<MultiLocation, T::AssetId> for Pallet<T> {
fn convert(id: &MultiLocation) -> Option<T::AssetId> {
<AssetIdOf<T>>::get(id)
}
fn convert_back(what: &T::AssetId) -> Option<MultiLocation> {
<LocationOf<T>>::get(what)
}
}
}
6 changes: 4 additions & 2 deletions runtime/main/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ build = "build.rs"
parity-scale-codec = { workspace = true }
smallvec = { workspace = true }
scale-info = { workspace = true }
lazy_static = { workspace = true }
hex-literal = { workspace = true, optional = true }

# primitives
Expand Down Expand Up @@ -49,6 +48,7 @@ pallet-vesting = { workspace = true }
pallet-timestamp = { workspace = true }
pallet-transaction-payment = { workspace = true }
pallet-transaction-payment-rpc-runtime-api = { workspace = true }
pallet-sudo = { workspace = true }

# robonomics dependencies
pallet-robonomics-datalog = { path = "../../frame/datalog", default-features = false }
Expand All @@ -73,6 +73,7 @@ xcm = { workspace = true }
xcm-builder = { workspace = true }
xcm-executor = { workspace = true }
pallet-xcm = { path = "../../vendor/pallet-xcm", default-features = false }
pallet-xcm-info = { path = "../../frame/xcm-info", default-features = false }
polkadot-parachain = { workspace = true }
polkadot-primitives = { workspace = true }

Expand All @@ -82,7 +83,6 @@ substrate-wasm-builder = { workspace = true }
[features]
default = ["std"]
with-tracing = ["frame-executive/with-tracing"]
polkadot = []
std = [
"parity-scale-codec/std",
"robonomics-primitives/std",
Expand Down Expand Up @@ -122,6 +122,7 @@ std = [
"pallet-robonomics-liability/std",
"pallet-robonomics-lighthouse/std",
"pallet-robonomics-rws/std",
"pallet-sudo/std",
"cumulus-pallet-parachain-system/std",
"cumulus-primitives-core/std",
"cumulus-primitives-utility/std",
Expand All @@ -133,6 +134,7 @@ std = [
"xcm-builder/std",
"xcm-executor/std",
"pallet-xcm/std",
"pallet-xcm-info/std",
"polkadot-parachain/std",
"polkadot-primitives/std",
"parachain-info/std",
Expand Down
Loading

0 comments on commit 11ec1ec

Please sign in to comment.