Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Register origin #174

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions bridges/snowbridge/pallets/system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pub mod weights;
pub use weights::*;

use frame_support::{
dispatch::RawOrigin,
pallet_prelude::*,
traits::{
fungible::{Inspect, Mutate},
Expand All @@ -83,7 +84,6 @@ use sp_std::prelude::*;
use xcm::prelude::*;
use xcm_executor::traits::ConvertLocation;

#[cfg(feature = "runtime-benchmarks")]
use frame_support::traits::OriginTrait;

pub use pallet::*;
Expand Down Expand Up @@ -182,6 +182,8 @@ pub mod pallet {

#[cfg(feature = "runtime-benchmarks")]
type Helper: BenchmarkHelper<Self::RuntimeOrigin>;

type RegisterTokenOrigin: EnsureOrigin<Self::RuntimeOrigin>;
}

#[pallet::event]
Expand Down Expand Up @@ -623,18 +625,23 @@ pub mod pallet {
location: Box<VersionedLocation>,
metadata: AssetMetadata,
) -> DispatchResultWithPostInfo {
ensure_root(origin)?;
T::RegisterTokenOrigin::ensure_origin_or_root(origin.clone())?;

let pays_fee = match origin.as_system_ref() {
Some(&RawOrigin::Root) => Ok((PaysFee::<T>::No, Pays::No)),
Some(&RawOrigin::Signed(ref who)) =>
Ok((PaysFee::<T>::Yes(who.clone()), Pays::Yes)),
_ => Err(BadOrigin),
}?;

let location: Location =
(*location).try_into().map_err(|_| Error::<T>::UnsupportedLocationVersion)?;

let pays_fee = PaysFee::<T>::No;

Self::do_register_token(&location, metadata, pays_fee)?;
Self::do_register_token(&location, metadata, pays_fee.0)?;

Ok(PostDispatchInfo {
actual_weight: Some(T::WeightInfo::register_token()),
pays_fee: Pays::No,
pays_fee: pays_fee.1,
})
}
}
Expand Down
2 changes: 2 additions & 0 deletions bridges/snowbridge/pallets/system/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use frame_support::{
weights::IdentityFee,
PalletId,
};
use frame_system::EnsureRoot;
use sp_core::H256;
use xcm_executor::traits::ConvertLocation;

Expand Down Expand Up @@ -212,6 +213,7 @@ impl crate::Config for Test {
type EthereumNetwork = EthereumNetwork;
#[cfg(feature = "runtime-benchmarks")]
type Helper = ();
type RegisterTokenOrigin = EnsureRoot<AccountId>;
}

// Build genesis storage according to the mock runtime.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use crate::xcm_config::RelayNetwork;
#[cfg(feature = "runtime-benchmarks")]
use benchmark_helpers::DoNothingRouter;
use frame_support::{parameter_types, weights::ConstantMultiplier};
use frame_system::EnsureRoot;
use pallet_xcm::EnsureXcm;
use sp_runtime::{
traits::{ConstU32, ConstU8, Keccak256},
Expand Down Expand Up @@ -190,6 +191,7 @@ impl snowbridge_pallet_system::Config for Runtime {
type InboundDeliveryCost = EthereumInboundQueue;
type UniversalLocation = UniversalLocation;
type EthereumNetwork = EthereumNetwork;
type RegisterTokenOrigin = EnsureRoot<Self::AccountId>;
}

#[cfg(feature = "runtime-benchmarks")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use crate::xcm_config::RelayNetwork;
#[cfg(feature = "runtime-benchmarks")]
use benchmark_helpers::DoNothingRouter;
use frame_support::{parameter_types, weights::ConstantMultiplier};
use frame_system::EnsureRoot;
use pallet_xcm::EnsureXcm;
use sp_runtime::{
traits::{ConstU32, ConstU8, Keccak256},
Expand Down Expand Up @@ -190,6 +191,7 @@ impl snowbridge_pallet_system::Config for Runtime {
type InboundDeliveryCost = EthereumInboundQueue;
type UniversalLocation = UniversalLocation;
type EthereumNetwork = EthereumNetwork;
type RegisterTokenOrigin = EnsureRoot<Self::AccountId>;
}

#[cfg(feature = "runtime-benchmarks")]
Expand Down
Loading