Skip to content

Commit 11ec1ec

Browse files
committed
United Polkadot&Kusama parachain runtime
* Remove SUDO from polkadot parachain runtime * Added XcmInfo pallet for fine tune XCM settings
1 parent 492b059 commit 11ec1ec

File tree

8 files changed

+181
-402
lines changed

8 files changed

+181
-402
lines changed

Diff for: Cargo.lock

+23-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Cargo.toml

+2-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ homepage.workspace = true
1212
repository.workspace = true
1313

1414
[workspace.package]
15-
version = "3.1.0"
15+
version = "3.2.0"
1616
edition = "2021"
1717
authors = ["Airalab <[email protected]>"]
1818
license = "Apache-2.0"
@@ -51,6 +51,7 @@ members = [
5151
"frame/liability",
5252
"frame/lighthouse",
5353
"frame/digital-twin",
54+
"frame/xcm-info",
5455
"primitives",
5556
"runtime/dev",
5657
"runtime/main",
@@ -70,9 +71,6 @@ scale-info = { version = "2.5.0", default-features = false, features = [
7071
"derive",
7172
] }
7273
smallvec = { version = "1.11", default-features = false }
73-
lazy_static = { version = "1.4", default-features = false, features = [
74-
"spin_no_std",
75-
] }
7674
log = { version = "0.4.19", default-features = false }
7775

7876
# (native)

Diff for: frame/xcm-info/Cargo.toml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
[package]
2+
name = "pallet-xcm-info"
3+
description = "XCM setup & information pallet"
4+
version = "0.1.0"
5+
authors.workspace = true
6+
edition.workspace = true
7+
homepage.workspace = true
8+
repository.workspace = true
9+
10+
[dependencies]
11+
frame-support = { workspace = true }
12+
frame-system = { workspace = true }
13+
parity-scale-codec = { workspace = true }
14+
scale-info = { workspace = true }
15+
sp-runtime = { workspace = true }
16+
sp-std = { workspace = true }
17+
xcm = { workspace = true }
18+
19+
[features]
20+
default = ["std"]
21+
std = [
22+
"frame-support/std",
23+
"frame-system/std",
24+
"parity-scale-codec/std",
25+
"scale-info/std",
26+
"sp-runtime/std",
27+
"sp-std/std",
28+
"xcm/std",
29+
]

Diff for: frame/xcm-info/src/lib.rs

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
///////////////////////////////////////////////////////////////////////////////
2+
//
3+
// Copyright 2018-2024 Robonomics Network <[email protected]>
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
//
17+
///////////////////////////////////////////////////////////////////////////////
18+
//! On-chain XCM setup & information.
19+
#![cfg_attr(not(feature = "std"), no_std)]
20+
21+
pub use pallet::*;
22+
23+
#[frame_support::pallet]
24+
pub mod pallet {
25+
use super::*;
26+
use frame_support::pallet_prelude::*;
27+
use frame_system::{ensure_root, pallet_prelude::*};
28+
use sp_runtime::traits::MaybeEquivalence;
29+
use xcm::latest::prelude::*;
30+
31+
#[pallet::config]
32+
pub trait Config: frame_system::Config {
33+
/// AssetId type for asset<>location linkage setup.
34+
type AssetId: Parameter + Copy + Default + MaxEncodedLen;
35+
/// The overarching event type.
36+
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
37+
}
38+
39+
#[pallet::error]
40+
pub enum Error<T> {}
41+
42+
#[pallet::event]
43+
#[pallet::generate_deposit(pub(super) fn deposit_event)]
44+
pub enum Event<T: Config> {
45+
/// Updated Relay XCM identifier.
46+
RelayNetworkChanged(NetworkId),
47+
/// Added new asset XCM location.
48+
AssetLinkAdded(T::AssetId, MultiLocation),
49+
}
50+
51+
#[pallet::pallet]
52+
pub struct Pallet<T>(PhantomData<T>);
53+
54+
/// Relay network identifier.
55+
#[pallet::storage]
56+
#[pallet::getter(fn relay_network)]
57+
pub(super) type RelayNetwork<T> = StorageValue<_, NetworkId>;
58+
59+
/// AssetId to location mapping.
60+
#[pallet::storage]
61+
#[pallet::getter(fn location_of)]
62+
pub(super) type LocationOf<T: Config> =
63+
StorageMap<_, Blake2_128Concat, T::AssetId, MultiLocation>;
64+
65+
/// Location to AssetId mapping.
66+
#[pallet::storage]
67+
#[pallet::getter(fn assetid_of)]
68+
pub(super) type AssetIdOf<T: Config> =
69+
StorageMap<_, Blake2_128Concat, MultiLocation, T::AssetId>;
70+
71+
#[pallet::call]
72+
impl<T: Config> Pallet<T> {
73+
#[pallet::call_index(0)]
74+
#[pallet::weight(10_000)]
75+
pub fn set_relay_network(origin: OriginFor<T>, network_id: NetworkId) -> DispatchResult {
76+
ensure_root(origin)?;
77+
78+
<RelayNetwork<T>>::put(network_id);
79+
Self::deposit_event(Event::<T>::RelayNetworkChanged(network_id));
80+
81+
Ok(())
82+
}
83+
84+
#[pallet::call_index(1)]
85+
#[pallet::weight(10_000)]
86+
pub fn set_asset_link(
87+
origin: OriginFor<T>,
88+
asset_id: T::AssetId,
89+
location: MultiLocation,
90+
) -> DispatchResult {
91+
ensure_root(origin)?;
92+
93+
<LocationOf<T>>::insert(asset_id, location);
94+
<AssetIdOf<T>>::insert(location, asset_id);
95+
Self::deposit_event(Event::<T>::AssetLinkAdded(asset_id, location));
96+
97+
Ok(())
98+
}
99+
}
100+
101+
impl<T: Config> MaybeEquivalence<MultiLocation, T::AssetId> for Pallet<T> {
102+
fn convert(id: &MultiLocation) -> Option<T::AssetId> {
103+
<AssetIdOf<T>>::get(id)
104+
}
105+
fn convert_back(what: &T::AssetId) -> Option<MultiLocation> {
106+
<LocationOf<T>>::get(what)
107+
}
108+
}
109+
}

Diff for: runtime/main/Cargo.toml

+4-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ build = "build.rs"
1010
parity-scale-codec = { workspace = true }
1111
smallvec = { workspace = true }
1212
scale-info = { workspace = true }
13-
lazy_static = { workspace = true }
1413
hex-literal = { workspace = true, optional = true }
1514

1615
# primitives
@@ -49,6 +48,7 @@ pallet-vesting = { workspace = true }
4948
pallet-timestamp = { workspace = true }
5049
pallet-transaction-payment = { workspace = true }
5150
pallet-transaction-payment-rpc-runtime-api = { workspace = true }
51+
pallet-sudo = { workspace = true }
5252

5353
# robonomics dependencies
5454
pallet-robonomics-datalog = { path = "../../frame/datalog", default-features = false }
@@ -73,6 +73,7 @@ xcm = { workspace = true }
7373
xcm-builder = { workspace = true }
7474
xcm-executor = { workspace = true }
7575
pallet-xcm = { path = "../../vendor/pallet-xcm", default-features = false }
76+
pallet-xcm-info = { path = "../../frame/xcm-info", default-features = false }
7677
polkadot-parachain = { workspace = true }
7778
polkadot-primitives = { workspace = true }
7879

@@ -82,7 +83,6 @@ substrate-wasm-builder = { workspace = true }
8283
[features]
8384
default = ["std"]
8485
with-tracing = ["frame-executive/with-tracing"]
85-
polkadot = []
8686
std = [
8787
"parity-scale-codec/std",
8888
"robonomics-primitives/std",
@@ -122,6 +122,7 @@ std = [
122122
"pallet-robonomics-liability/std",
123123
"pallet-robonomics-lighthouse/std",
124124
"pallet-robonomics-rws/std",
125+
"pallet-sudo/std",
125126
"cumulus-pallet-parachain-system/std",
126127
"cumulus-primitives-core/std",
127128
"cumulus-primitives-utility/std",
@@ -133,6 +134,7 @@ std = [
133134
"xcm-builder/std",
134135
"xcm-executor/std",
135136
"pallet-xcm/std",
137+
"pallet-xcm-info/std",
136138
"polkadot-parachain/std",
137139
"polkadot-primitives/std",
138140
"parachain-info/std",

0 commit comments

Comments
 (0)