mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 22:11:02 +00:00
Adds Snowbridge to Rococo runtime (#2522)
# Description Adds Snowbridge to the Rococo bridge hub runtime. Includes config changes required in Rococo asset hub. --------- Co-authored-by: Alistair Singh <alistair.singh7@gmail.com> Co-authored-by: ron <yrong1997@gmail.com> Co-authored-by: Vincent Geddes <vincent.geddes@hey.com> Co-authored-by: claravanstaden <Cats 4 life!>
This commit is contained in:
@@ -58,6 +58,37 @@ impl<SelfParaId: Get<ParaId>> ContainsPair<MultiLocation, MultiLocation>
|
||||
}
|
||||
}
|
||||
|
||||
/// Checks if `a` is from the expected global consensus network. Checks that `MultiLocation-a`
|
||||
/// starts with `MultiLocation-b`, and that network is a foreign consensus system.
|
||||
pub struct FromNetwork<UniversalLocation, ExpectedNetworkId>(
|
||||
sp_std::marker::PhantomData<(UniversalLocation, ExpectedNetworkId)>,
|
||||
);
|
||||
impl<UniversalLocation: Get<InteriorMultiLocation>, ExpectedNetworkId: Get<NetworkId>>
|
||||
ContainsPair<MultiLocation, MultiLocation> for FromNetwork<UniversalLocation, ExpectedNetworkId>
|
||||
{
|
||||
fn contains(&a: &MultiLocation, b: &MultiLocation) -> bool {
|
||||
// `a` needs to be from `b` at least
|
||||
if !a.starts_with(b) {
|
||||
return false
|
||||
}
|
||||
|
||||
let universal_source = UniversalLocation::get();
|
||||
|
||||
// ensure that `a`` is remote and from the expected network
|
||||
match ensure_is_remote(universal_source, a) {
|
||||
Ok((network_id, _)) => network_id == ExpectedNetworkId::get(),
|
||||
Err(e) => {
|
||||
log::trace!(
|
||||
target: "xcm::contains",
|
||||
"FromNetwork origin: {:?} is not remote to the universal_source: {:?} {:?}",
|
||||
a, universal_source, e
|
||||
);
|
||||
false
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Adapter verifies if it is allowed to receive `MultiAsset` from `MultiLocation`.
|
||||
///
|
||||
/// Note: `MultiLocation` has to be from a different global consensus.
|
||||
@@ -95,3 +126,92 @@ impl<
|
||||
Reserves::contains(asset, origin)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use frame_support::parameter_types;
|
||||
|
||||
parameter_types! {
|
||||
pub UniversalLocation: InteriorMultiLocation = X2(GlobalConsensus(Rococo), Parachain(1000));
|
||||
pub ExpectedNetworkId: NetworkId = Wococo;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_network_contains_works() {
|
||||
// asset and origin from foreign consensus works
|
||||
let asset: MultiLocation = (
|
||||
Parent,
|
||||
Parent,
|
||||
GlobalConsensus(Wococo),
|
||||
Parachain(1000),
|
||||
PalletInstance(1),
|
||||
GeneralIndex(1),
|
||||
)
|
||||
.into();
|
||||
let origin: MultiLocation =
|
||||
(Parent, Parent, GlobalConsensus(Wococo), Parachain(1000)).into();
|
||||
assert!(FromNetwork::<UniversalLocation, ExpectedNetworkId>::contains(&asset, &origin));
|
||||
|
||||
// asset and origin from local consensus fails
|
||||
let asset: MultiLocation = (
|
||||
Parent,
|
||||
Parent,
|
||||
GlobalConsensus(Rococo),
|
||||
Parachain(1000),
|
||||
PalletInstance(1),
|
||||
GeneralIndex(1),
|
||||
)
|
||||
.into();
|
||||
let origin: MultiLocation =
|
||||
(Parent, Parent, GlobalConsensus(Rococo), Parachain(1000)).into();
|
||||
assert!(!FromNetwork::<UniversalLocation, ExpectedNetworkId>::contains(&asset, &origin));
|
||||
|
||||
// asset and origin from here fails
|
||||
let asset: MultiLocation = (PalletInstance(1), GeneralIndex(1)).into();
|
||||
let origin: MultiLocation = Here.into();
|
||||
assert!(!FromNetwork::<UniversalLocation, ExpectedNetworkId>::contains(&asset, &origin));
|
||||
|
||||
// asset from different consensus fails
|
||||
let asset: MultiLocation = (
|
||||
Parent,
|
||||
Parent,
|
||||
GlobalConsensus(Polkadot),
|
||||
Parachain(1000),
|
||||
PalletInstance(1),
|
||||
GeneralIndex(1),
|
||||
)
|
||||
.into();
|
||||
let origin: MultiLocation =
|
||||
(Parent, Parent, GlobalConsensus(Wococo), Parachain(1000)).into();
|
||||
assert!(!FromNetwork::<UniversalLocation, ExpectedNetworkId>::contains(&asset, &origin));
|
||||
|
||||
// origin from different consensus fails
|
||||
let asset: MultiLocation = (
|
||||
Parent,
|
||||
Parent,
|
||||
GlobalConsensus(Wococo),
|
||||
Parachain(1000),
|
||||
PalletInstance(1),
|
||||
GeneralIndex(1),
|
||||
)
|
||||
.into();
|
||||
let origin: MultiLocation =
|
||||
(Parent, Parent, GlobalConsensus(Polkadot), Parachain(1000)).into();
|
||||
assert!(!FromNetwork::<UniversalLocation, ExpectedNetworkId>::contains(&asset, &origin));
|
||||
|
||||
// asset and origin from unexpected consensus fails
|
||||
let asset: MultiLocation = (
|
||||
Parent,
|
||||
Parent,
|
||||
GlobalConsensus(Polkadot),
|
||||
Parachain(1000),
|
||||
PalletInstance(1),
|
||||
GeneralIndex(1),
|
||||
)
|
||||
.into();
|
||||
let origin: MultiLocation =
|
||||
(Parent, Parent, GlobalConsensus(Polkadot), Parachain(1000)).into();
|
||||
assert!(!FromNetwork::<UniversalLocation, ExpectedNetworkId>::contains(&asset, &origin));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user