fix: EnsureOrigin try_successful_origin and snowbridge rename
- Fix pezpallet-welati EnsureOrigin implementations (3 fixes)
- Remove incorrect #[cfg(not(feature = "runtime-benchmarks"))] blocks
- Affects EnsureSerok, EnsureParlementer, EnsureDiwan
- Fix asset-hub-zagros governance origins macros (2 fixes)
- Remove non-benchmark try_successful_origin from decl_unit_ensures!
- Remove non-benchmark try_successful_origin from decl_ensure!
- Rename snowbridge -> pezsnowbridge for consistency
- Update WORKFLOW_PLAN.md with build status and package names
- Correct package names: pezkuwi-teyrchain-bin, pezstaging-node-cli
- Mark completed builds: pezkuwi, pezkuwi-teyrchain-bin,
pezstaging-node-cli, teyrchain-template-node
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
[package]
|
||||
name = "pezsnowbridge-runtime-common"
|
||||
description = "Snowbridge Runtime Common"
|
||||
version = "0.2.0"
|
||||
authors = ["Snowfork <contact@snowfork.com>"]
|
||||
edition.workspace = true
|
||||
repository.workspace = true
|
||||
license = "Apache-2.0"
|
||||
categories = ["cryptography::cryptocurrencies"]
|
||||
documentation = "https://docs.pezkuwichain.io/pezsnowbridge-runtime-common"
|
||||
homepage = { workspace = true }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
[package.metadata.pezkuwi-sdk]
|
||||
exclude-from-umbrella = true
|
||||
|
||||
[dependencies]
|
||||
codec = { workspace = true }
|
||||
pezframe-support = { workspace = true }
|
||||
pezframe-system = { workspace = true }
|
||||
pezpallet-xcm = { workspace = true }
|
||||
pezsp-arithmetic = { workspace = true }
|
||||
pezsp-std = { workspace = true }
|
||||
tracing = { workspace = true }
|
||||
xcm = { workspace = true }
|
||||
xcm-builder = { workspace = true }
|
||||
xcm-executor = { workspace = true }
|
||||
|
||||
[dev-dependencies]
|
||||
|
||||
[features]
|
||||
default = ["std"]
|
||||
std = [
|
||||
"codec/std",
|
||||
"pezframe-support/std",
|
||||
"pezframe-system/std",
|
||||
"pezpallet-xcm/std",
|
||||
"pezsp-arithmetic/std",
|
||||
"pezsp-std/std",
|
||||
"tracing/std",
|
||||
"xcm-builder/std",
|
||||
"xcm-executor/std",
|
||||
"xcm/std",
|
||||
]
|
||||
runtime-benchmarks = [
|
||||
"pezframe-support/runtime-benchmarks",
|
||||
"pezframe-system/runtime-benchmarks",
|
||||
"pezpallet-xcm/runtime-benchmarks",
|
||||
"xcm-builder/runtime-benchmarks",
|
||||
"xcm-executor/runtime-benchmarks",
|
||||
"xcm/runtime-benchmarks",
|
||||
]
|
||||
try-runtime = [
|
||||
"pezframe-support/try-runtime",
|
||||
"pezframe-system/try-runtime",
|
||||
"pezpallet-xcm/try-runtime",
|
||||
]
|
||||
@@ -0,0 +1,3 @@
|
||||
# Snowbridge Runtime Common
|
||||
|
||||
Common crate to contain runtime related structs and implementations for Snowbridge.
|
||||
@@ -0,0 +1,8 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-FileCopyrightText: 2023 Snowfork <hello@snowfork.com>
|
||||
//! # Runtime Common
|
||||
//!
|
||||
//! Common traits and types shared by runtimes.
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
pub mod v2;
|
||||
pub use v2::register_token::{ForeignAssetOwner, LocalAssetOwner};
|
||||
@@ -0,0 +1,3 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-FileCopyrightText: 2023 Snowfork <hello@snowfork.com>
|
||||
pub mod register_token;
|
||||
@@ -0,0 +1,101 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-FileCopyrightText: 2023 Snowfork <hello@snowfork.com>
|
||||
|
||||
use pezframe_support::{
|
||||
dispatch::RawOrigin,
|
||||
pezsp_runtime::traits::MaybeEquivalence,
|
||||
traits::{ContainsPair, EnsureOrigin, EnsureOriginWithArg, Everything, OriginTrait},
|
||||
};
|
||||
use pezframe_system::ensure_signed;
|
||||
use pezpallet_xcm::{EnsureXcm, Origin as XcmOrigin};
|
||||
use xcm::prelude::Location;
|
||||
|
||||
/// Origin check that verifies that an origin is the owner of a foreign asset.
|
||||
/// 1. Allows XCM origins
|
||||
/// 2. Checks that the asset exists
|
||||
/// 3. The origin must be the owner of the asset
|
||||
pub struct ForeignAssetOwner<IsForeign, AssetInspect, AccountId, LocationToAccountId, L = Location>(
|
||||
core::marker::PhantomData<(IsForeign, AssetInspect, AccountId, LocationToAccountId, L)>,
|
||||
);
|
||||
impl<
|
||||
IsForeign: ContainsPair<L, L>,
|
||||
AssetInspect: pezframe_support::traits::fungibles::roles::Inspect<AccountId>,
|
||||
AccountId: Eq + Clone,
|
||||
LocationToAccountId: xcm_executor::traits::ConvertLocation<AccountId>,
|
||||
RuntimeOrigin: From<XcmOrigin> + OriginTrait + Clone,
|
||||
L: From<Location> + Into<Location> + Clone,
|
||||
> EnsureOriginWithArg<RuntimeOrigin, L>
|
||||
for ForeignAssetOwner<IsForeign, AssetInspect, AccountId, LocationToAccountId, L>
|
||||
where
|
||||
for<'a> &'a RuntimeOrigin::PalletsOrigin: TryInto<&'a XcmOrigin>,
|
||||
<AssetInspect as pezframe_support::traits::fungibles::Inspect<AccountId>>::AssetId:
|
||||
From<Location>,
|
||||
{
|
||||
type Success = L;
|
||||
|
||||
fn try_origin(
|
||||
origin: RuntimeOrigin,
|
||||
asset_location: &L,
|
||||
) -> Result<Self::Success, RuntimeOrigin> {
|
||||
let origin_location = EnsureXcm::<Everything, L>::try_origin(origin.clone())?;
|
||||
if !IsForeign::contains(asset_location, &origin_location) {
|
||||
return Err(origin);
|
||||
}
|
||||
let asset_location: Location = asset_location.clone().into();
|
||||
let owner = AssetInspect::owner(asset_location.into());
|
||||
let location: Location = origin_location.clone().into();
|
||||
let from = LocationToAccountId::convert_location(&location);
|
||||
if from != owner {
|
||||
return Err(origin);
|
||||
}
|
||||
Ok(location.into())
|
||||
}
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
fn try_successful_origin(a: &L) -> Result<RuntimeOrigin, ()> {
|
||||
let latest_location: Location = (*a).clone().try_into().map_err(|_| ())?;
|
||||
Ok(pezpallet_xcm::Origin::Xcm(latest_location).into())
|
||||
}
|
||||
}
|
||||
|
||||
/// Origin check that verifies that an origin is the owner of a local trusted asset.
|
||||
/// 1. Allows signed origins
|
||||
/// 2. Checks that the asset exists
|
||||
/// 3. The origin must be the owner of the asset
|
||||
pub struct LocalAssetOwner<MatchAssetId, AssetInspect, AccountId, AssetId, L = Location>(
|
||||
core::marker::PhantomData<(MatchAssetId, AssetInspect, AccountId, AssetId, L)>,
|
||||
);
|
||||
impl<
|
||||
MatchAssetId: MaybeEquivalence<L, AssetId>,
|
||||
AssetInspect: pezframe_support::traits::fungibles::roles::Inspect<AccountId>,
|
||||
AccountId: Eq + Clone + Into<L>,
|
||||
AssetId: Eq + Clone,
|
||||
RuntimeOrigin: OriginTrait + Clone,
|
||||
L: From<Location> + Into<Location> + Clone,
|
||||
> EnsureOriginWithArg<RuntimeOrigin, L>
|
||||
for LocalAssetOwner<MatchAssetId, AssetInspect, AccountId, AssetId, L>
|
||||
where
|
||||
RuntimeOrigin: Into<Result<RawOrigin<AccountId>, RuntimeOrigin>> + From<RawOrigin<AccountId>>,
|
||||
<AssetInspect as pezframe_support::traits::fungibles::Inspect<AccountId>>::AssetId:
|
||||
From<AssetId>,
|
||||
{
|
||||
type Success = L;
|
||||
|
||||
fn try_origin(
|
||||
origin: RuntimeOrigin,
|
||||
asset_location: &L,
|
||||
) -> Result<Self::Success, RuntimeOrigin> {
|
||||
let who = ensure_signed(origin.clone()).map_err(|_| origin.clone())?;
|
||||
let asset_id = MatchAssetId::convert(asset_location).ok_or(origin.clone())?;
|
||||
let owner = AssetInspect::owner(asset_id.into()).ok_or(origin.clone())?;
|
||||
if who != owner {
|
||||
return Err(origin);
|
||||
}
|
||||
Ok(who.into())
|
||||
}
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
fn try_successful_origin(_: &L) -> Result<RuntimeOrigin, ()> {
|
||||
Ok(RawOrigin::Root.into())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user