Skip to content

Commit

Permalink
upgrade to v0.9.16
Browse files Browse the repository at this point in the history
  • Loading branch information
hussein-aitlahcen committed Feb 3, 2022
1 parent 167a271 commit adc2b1a
Show file tree
Hide file tree
Showing 50 changed files with 3,543 additions and 6,413 deletions.
9,373 changes: 3,194 additions & 6,179 deletions Cargo.lock

Large diffs are not rendered by default.

27 changes: 17 additions & 10 deletions frame/assets-registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub mod pallet {
+ PartialEq
+ Copy
+ MaybeSerializeDeserialize
+ MaxEncodedLen
+ From<u128>
+ Into<u128>
+ Debug
Expand All @@ -56,6 +57,7 @@ pub mod pallet {
type ForeignAssetId: FullCodec
+ Eq
+ PartialEq
+ MaxEncodedLen
// we wrap non serde type, so until written custom serde, cannot handle that
// + MaybeSerializeDeserialize
+ Debug
Expand Down Expand Up @@ -290,7 +292,7 @@ pub mod pallet {
let local_admin = <LocalAdmin<T>>::get();
let foreign_admin = <ForeignAdmin<T>>::get();
match current_candidate_status {
None =>
None => {
if Some(who) == local_admin {
<AssetsMappingCandidates<T>>::insert(
(local_asset_id, foreign_asset_id),
Expand All @@ -301,17 +303,20 @@ pub mod pallet {
(local_asset_id, foreign_asset_id),
CandidateStatus::ForeignAdminApproved,
);
},
Some(CandidateStatus::LocalAdminApproved) =>
}
},
Some(CandidateStatus::LocalAdminApproved) => {
if Some(who) == foreign_admin {
Self::set_location(local_asset_id, foreign_asset_id.clone())?;
<AssetsMappingCandidates<T>>::remove((local_asset_id, foreign_asset_id));
},
Some(CandidateStatus::ForeignAdminApproved) =>
}
},
Some(CandidateStatus::ForeignAdminApproved) => {
if Some(who) == local_admin {
Self::set_location(local_asset_id, foreign_asset_id.clone())?;
<AssetsMappingCandidates<T>>::remove((local_asset_id, foreign_asset_id));
},
}
},
};
Ok(().into())
}
Expand All @@ -322,8 +327,9 @@ pub mod pallet {
type Success = T::AccountId;
fn try_origin(o: T::Origin) -> Result<Self::Success, T::Origin> {
o.into().and_then(|o| match (o, LocalAdmin::<T>::try_get()) {
(frame_system::RawOrigin::Signed(ref who), Ok(ref f)) if who == f =>
Ok(who.clone()),
(frame_system::RawOrigin::Signed(ref who), Ok(ref f)) if who == f => {
Ok(who.clone())
},
(r, _) => Err(T::Origin::from(r)),
})
}
Expand All @@ -340,8 +346,9 @@ pub mod pallet {
type Success = T::AccountId;
fn try_origin(o: T::Origin) -> Result<Self::Success, T::Origin> {
o.into().and_then(|o| match (o, ForeignAdmin::<T>::try_get()) {
(frame_system::RawOrigin::Signed(ref who), Ok(ref f)) if who == f =>
Ok(who.clone()),
(frame_system::RawOrigin::Signed(ref who), Ok(ref f)) if who == f => {
Ok(who.clone())
},
(r, _) => Err(T::Origin::from(r)),
})
}
Expand Down
4 changes: 2 additions & 2 deletions frame/assets/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ sp-std = { default-features = false, git = "https://github.com/paritytech/substr

composable-traits = { path = "../composable-traits", default-features = false }

orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "63b32194e7b9aff6a6350d2d4434525de4eec7c1", default-features = false }
orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "2b1c9fb367ccb8e13601b2da43d1c5d9737b93c6", default-features = false }
num-traits = { version = "0.2.14", default-features = false }
scale-info = { version = "1.0", default-features = false, features = ["derive"] }

Expand All @@ -34,7 +34,7 @@ version = "2.0.0"

[dev-dependencies]
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.16" }
orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "63b32194e7b9aff6a6350d2d4434525de4eec7c1" }
orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "2b1c9fb367ccb8e13601b2da43d1c5d9737b93c6", default-features = false }
governance-registry = { package = "pallet-governance-registry", path = "../governance-registry", default-features = false }

[package.metadata.cargo-udeps.ignore]
Expand Down
4 changes: 2 additions & 2 deletions frame/bonded-finance/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ sp-std = { default-features = false, git = "https://github.com/paritytech/subst
scale-info = { version = "1.0", default-features = false, features = ["derive"] }

composable-traits = { path = "../../frame/composable-traits", default-features = false }
orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "63b32194e7b9aff6a6350d2d4434525de4eec7c1", default-features = false }
orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "2b1c9fb367ccb8e13601b2da43d1c5d9737b93c6", default-features = false }

[dev-dependencies]
composable-traits = { path = "../../frame/composable-traits" }
proptest = "1.0"
proptest-derive = "0.3"
serde = { version = "1.0.130" }
orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "63b32194e7b9aff6a6350d2d4434525de4eec7c1" }
orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "2b1c9fb367ccb8e13601b2da43d1c5d9737b93c6", default-features = false }
pallet-vesting = { path = "../../frame/vesting" }
composable-tests-helpers = { path = "../composable-tests-helpers", default-features = false }

Expand Down
21 changes: 15 additions & 6 deletions frame/bonded-finance/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,15 @@ pub mod pallet {
>;

/// The ID of a bond offer.
type BondOfferId: Copy + Clone + Eq + Debug + Zero + WrappingNext + FullCodec + TypeInfo;
type BondOfferId: Copy
+ Clone
+ Eq
+ Debug
+ Zero
+ WrappingNext
+ FullCodec
+ MaxEncodedLen
+ TypeInfo;

/// The dependency managing conversion of balance to u128 required for reward computation.
type Convert: Convert<BalanceOf<Self>, u128> + Convert<u128, BalanceOf<Self>>;
Expand Down Expand Up @@ -245,10 +253,11 @@ pub mod pallet {
// Continue on admin origin
(_, Ok(_)) => {},
// Only issuer is allowed
(Ok(account), _) =>
(Ok(account), _) => {
if issuer != account {
return Err(DispatchError::BadOrigin)
},
return Err(DispatchError::BadOrigin);
}
},
_ => return Err(DispatchError::BadOrigin),
};
let offer_account = Self::account_id(offer_id);
Expand Down Expand Up @@ -318,8 +327,8 @@ pub mod pallet {
Error::<T>::OfferCompleted
);
ensure!(
nb_of_bonds > BalanceOf::<T>::zero() &&
nb_of_bonds <= offer.nb_of_bonds,
nb_of_bonds > BalanceOf::<T>::zero()
&& nb_of_bonds <= offer.nb_of_bonds,
Error::<T>::InvalidNumberOfBonds
);
// can't overflow, subsumed by `offer.valid()` in
Expand Down
55 changes: 35 additions & 20 deletions frame/call-filter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ pub mod pallet {

use super::*;

type CallFilterEntryOf<T> = CallFilterEntry<<T as Config>::MaxStringSize>;

#[pallet::config]
pub trait Config: system::Config {
/// Overarching event type
Expand All @@ -44,8 +46,18 @@ pub mod pallet {
/// The origin which may set filter.
type UpdateOrigin: EnsureOrigin<Self::Origin>;

#[pallet::constant]
type MaxStringSize: Get<u32>
+ TypeInfo
+ core::fmt::Debug
+ MaxEncodedLen
+ Copy
+ Clone
+ PartialEq
+ Eq;

/// A hook that is able to block us from disabling/enabling an extrinsic.
type Hook: CallFilterHook;
type Hook: CallFilterHook<Self::MaxStringSize>;

/// Weight information for the extrinsics in this module.
type WeightInfo: WeightInfo;
Expand All @@ -63,17 +75,15 @@ pub mod pallet {
#[pallet::generate_deposit(fn deposit_event)]
pub enum Event<T: Config> {
/// Paused transaction
Disabled { entry: CallFilterEntry },
Disabled { entry: CallFilterEntryOf<T> },
/// Unpaused transaction
Enabled { entry: CallFilterEntry },
Enabled { entry: CallFilterEntryOf<T> },
}

/// The list of disabled extrinsics.
///
/// CallFilterEntry -> ()
#[pallet::storage]
#[pallet::getter(fn disabled_calls)]
pub type DisabledCalls<T: Config> = StorageMap<_, Twox64Concat, CallFilterEntry, ()>;
pub type DisabledCalls<T: Config> = StorageMap<_, Twox64Concat, CallFilterEntryOf<T>, ()>;

#[pallet::pallet]
pub struct Pallet<T>(_);
Expand All @@ -88,12 +98,12 @@ pub mod pallet {
/// Possibly emits a `Disabled` event.
#[pallet::weight(T::WeightInfo::disable())]
#[transactional]
pub fn disable(origin: OriginFor<T>, entry: CallFilterEntry) -> DispatchResult {
pub fn disable(origin: OriginFor<T>, entry: CallFilterEntryOf<T>) -> DispatchResult {
T::UpdateOrigin::ensure_origin(origin)?;
ensure!(entry.valid(), Error::<T>::InvalidString);
// We are not allowed to disable this pallet.
ensure!(
entry.pallet_name != <Self as PalletInfoAccess>::name().as_bytes(),
&entry.pallet_name.to_vec() != <Self as PalletInfoAccess>::name().as_bytes(),
Error::<T>::CannotDisable
);
Self::do_disable(&entry)?;
Expand All @@ -108,7 +118,7 @@ pub mod pallet {
/// Possibly emits an `Enabled` event.
#[pallet::weight(T::WeightInfo::enable())]
#[transactional]
pub fn enable(origin: OriginFor<T>, entry: CallFilterEntry) -> DispatchResult {
pub fn enable(origin: OriginFor<T>, entry: CallFilterEntryOf<T>) -> DispatchResult {
T::UpdateOrigin::ensure_origin(origin)?;
ensure!(entry.valid(), Error::<T>::InvalidString);
Self::do_enable(&entry)?;
Expand All @@ -117,11 +127,11 @@ pub mod pallet {
}

impl<T: Config> Pallet<T> {
pub(crate) fn disabled(entry: &CallFilterEntry) -> bool {
pub(crate) fn disabled(entry: &CallFilterEntryOf<T>) -> bool {
DisabledCalls::<T>::contains_key(entry)
}

pub(crate) fn do_enable(entry: &CallFilterEntry) -> DispatchResult {
pub(crate) fn do_enable(entry: &CallFilterEntryOf<T>) -> DispatchResult {
if Self::disabled(entry) {
T::Hook::enable_hook(entry)?;
DisabledCalls::<T>::remove(entry);
Expand All @@ -130,7 +140,7 @@ pub mod pallet {
Ok(())
}

pub(crate) fn do_disable(entry: &CallFilterEntry) -> DispatchResult {
pub(crate) fn do_disable(entry: &CallFilterEntryOf<T>) -> DispatchResult {
if !Self::disabled(entry) {
T::Hook::disable_hook(entry)?;
DisabledCalls::<T>::insert(entry, ());
Expand All @@ -140,15 +150,15 @@ pub mod pallet {
}
}

impl<T: Config> CallFilter for Pallet<T> {
fn disabled(entry: &CallFilterEntry) -> bool {
impl<T: Config> CallFilter<T::MaxStringSize> for Pallet<T> {
fn disabled(entry: &CallFilterEntryOf<T>) -> bool {
Self::disabled(entry)
}
fn enable(entry: &CallFilterEntry) -> DispatchResult {
fn enable(entry: &CallFilterEntryOf<T>) -> DispatchResult {
Self::do_enable(entry)
}

fn disable(entry: &CallFilterEntry) -> DispatchResult {
fn disable(entry: &CallFilterEntryOf<T>) -> DispatchResult {
Self::do_disable(entry)
}
}
Expand All @@ -159,10 +169,15 @@ pub mod pallet {
{
fn contains(call: &T::Call) -> bool {
let CallMetadata { function_name, pallet_name } = call.get_call_metadata();
DisabledCalls::<T>::contains_key(CallFilterEntry {
pallet_name: pallet_name.as_bytes().to_vec(),
function_name: function_name.as_bytes().to_vec(),
})
match (
BoundedVec::try_from(pallet_name.as_bytes().to_vec()),
BoundedVec::try_from(function_name.as_bytes().to_vec()),
) {
(Ok(pallet_name), Ok(function_name)) => {
DisabledCalls::<T>::contains_key(CallFilterEntry { pallet_name, function_name })
},
_ => false,
}
}
}
}
10 changes: 10 additions & 0 deletions frame/call-filter/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ impl system::Config for Runtime {
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
type MaxConsumers = ConstU32<16>;
}

parameter_types! {
Expand All @@ -65,11 +66,20 @@ ord_parameter_types! {
pub const One: AccountId = 1;
}

#[derive(PartialEq, Eq, Copy, Clone, Encode, Decode, MaxEncodedLen, TypeInfo, core::fmt::Debug)]
pub struct MaxStringSize;
impl Get<u32> for MaxStringSize {
fn get() -> u32 {
100
}
}

impl Config for Runtime {
type Event = Event;
type UpdateOrigin = EnsureSignedBy<One, AccountId>;
type Hook = ();
type WeightInfo = ();
type MaxStringSize = MaxStringSize;
}

type UncheckedExtrinsic = system::mocking::MockUncheckedExtrinsic<Runtime>;
Expand Down
26 changes: 14 additions & 12 deletions frame/call-filter/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ fn pause_transaction_work() {
System::set_block_number(1);

let balances_transfer = CallFilterEntry {
pallet_name: b"Balances".to_vec(),
function_name: b"transfer".to_vec(),
pallet_name: b"Balances".to_vec().try_into().unwrap(),
function_name: b"transfer".to_vec().try_into().unwrap(),
};
assert_noop!(Filter::disable(Origin::signed(5), balances_transfer.clone()), BadOrigin);

Expand All @@ -25,11 +25,13 @@ fn pause_transaction_work() {
}));
assert_eq!(Filter::disabled_calls(&balances_transfer), Some(()));

let filter_pause =
CallFilterEntry { pallet_name: b"Filter".to_vec(), function_name: b"disable".to_vec() };
let filter_pause = CallFilterEntry {
pallet_name: b"Filter".to_vec().try_into().unwrap(),
function_name: b"disable".to_vec().try_into().unwrap(),
};
let filter_pause_2 = CallFilterEntry {
pallet_name: b"Filter".to_vec(),
function_name: b"another_call".to_vec(),
pallet_name: b"Filter".to_vec().try_into().unwrap(),
function_name: b"another_call".to_vec().try_into().unwrap(),
};

assert_noop!(
Expand All @@ -42,8 +44,8 @@ fn pause_transaction_work() {
);

let other = CallFilterEntry {
pallet_name: b"OtherPallet".to_vec(),
function_name: b"disable".to_vec(),
pallet_name: b"OtherPallet".to_vec().try_into().unwrap(),
function_name: b"disable".to_vec().try_into().unwrap(),
};
assert_ok!(Filter::disable(Origin::signed(1), other));
});
Expand All @@ -55,8 +57,8 @@ fn enable_work() {
System::set_block_number(1);

let balances_transfer = CallFilterEntry {
pallet_name: b"Balances".to_vec(),
function_name: b"transfer".to_vec(),
pallet_name: b"Balances".to_vec().try_into().unwrap(),
function_name: b"transfer".to_vec().try_into().unwrap(),
};

assert_ok!(Filter::disable(Origin::signed(1), balances_transfer.clone()));
Expand All @@ -76,8 +78,8 @@ fn enable_work() {
fn paused_transaction_filter_work() {
ExtBuilder::default().build().execute_with(|| {
let balances_transfer = CallFilterEntry {
pallet_name: b"Balances".to_vec(),
function_name: b"transfer".to_vec(),
pallet_name: b"Balances".to_vec().try_into().unwrap(),
function_name: b"transfer".to_vec().try_into().unwrap(),
};

assert!(!Filter::contains(BALANCE_TRANSFER));
Expand Down
Loading

0 comments on commit adc2b1a

Please sign in to comment.