Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Remove the Copy bound on AssetId #14158

Merged
merged 12 commits into from
May 23, 2023
8 changes: 4 additions & 4 deletions frame/asset-rate/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ mod benchmarks {
fn create() -> Result<(), BenchmarkError> {
let asset_id: T::AssetId = ASSET_ID.into();
#[extrinsic_call]
_(RawOrigin::Root, asset_id, default_conversion_rate());
_(RawOrigin::Root, asset_id.clone(), default_conversion_rate());

assert_eq!(
pallet_asset_rate::ConversionRateToNative::<T>::get(asset_id),
Expand All @@ -52,12 +52,12 @@ mod benchmarks {
let asset_id: T::AssetId = ASSET_ID.into();
assert_ok!(AssetRate::<T>::create(
RawOrigin::Root.into(),
asset_id,
asset_id.clone(),
default_conversion_rate()
));

#[extrinsic_call]
_(RawOrigin::Root, asset_id, FixedU128::from_u32(2));
_(RawOrigin::Root, asset_id.clone(), FixedU128::from_u32(2));

assert_eq!(
pallet_asset_rate::ConversionRateToNative::<T>::get(asset_id),
Expand All @@ -76,7 +76,7 @@ mod benchmarks {
));

#[extrinsic_call]
_(RawOrigin::Root, asset_id);
_(RawOrigin::Root, asset_id.clone());

assert!(pallet_asset_rate::ConversionRateToNative::<T>::get(asset_id).is_none());
Ok(())
Expand Down
10 changes: 5 additions & 5 deletions frame/asset-rate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ pub mod pallet {
T::CreateOrigin::ensure_origin(origin)?;

ensure!(
!ConversionRateToNative::<T>::contains_key(asset_id),
!ConversionRateToNative::<T>::contains_key(asset_id.clone()),
Error::<T>::AlreadyExists
);
ConversionRateToNative::<T>::set(asset_id, Some(rate));
ConversionRateToNative::<T>::set(asset_id.clone(), Some(rate));

Self::deposit_event(Event::AssetRateCreated { asset_id, rate });
Ok(())
Expand All @@ -184,7 +184,7 @@ pub mod pallet {
T::UpdateOrigin::ensure_origin(origin)?;

let mut old = FixedU128::zero();
ConversionRateToNative::<T>::mutate(asset_id, |maybe_rate| {
ConversionRateToNative::<T>::mutate(asset_id.clone(), |maybe_rate| {
if let Some(r) = maybe_rate {
old = *r;
*r = rate;
Expand All @@ -209,10 +209,10 @@ pub mod pallet {
T::RemoveOrigin::ensure_origin(origin)?;

ensure!(
ConversionRateToNative::<T>::contains_key(asset_id),
ConversionRateToNative::<T>::contains_key(asset_id.clone()),
Error::<T>::UnknownAssetId
);
ConversionRateToNative::<T>::remove(asset_id);
ConversionRateToNative::<T>::remove(asset_id.clone());

Self::deposit_event(Event::AssetRateRemoved { asset_id });
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion frame/assets/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ benchmarks_instance_pallet! {
let caller = T::CreateOrigin::ensure_origin(origin, &asset_id.into()).unwrap();
let caller_lookup = T::Lookup::unlookup(caller.clone());
T::Currency::make_free_balance_be(&caller, DepositBalanceOf::<T, I>::max_value());
}: _(SystemOrigin::Signed(caller.clone()), asset_id, caller_lookup, 1u32.into())
}: _(SystemOrigin::Signed(caller.clone()), asset_id.clone(), caller_lookup, 1u32.into())
verify {
assert_last_event::<T, I>(Event::Created { asset_id: asset_id.into(), creator: caller.clone(), owner: caller }.into());
}
Expand Down
6 changes: 3 additions & 3 deletions frame/assets/src/extra_mutator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl<T: Config<I>, I: 'static> ExtraMutator<T, I> {
id: T::AssetId,
who: impl sp_std::borrow::Borrow<T::AccountId>,
) -> Option<ExtraMutator<T, I>> {
if let Some(a) = Account::<T, I>::get(id, who.borrow()) {
if let Some(a) = Account::<T, I>::get(&id, who.borrow()) {
Some(ExtraMutator::<T, I> {
id,
who: who.borrow().clone(),
Expand All @@ -77,7 +77,7 @@ impl<T: Config<I>, I: 'static> ExtraMutator<T, I> {
/// Commit any changes to storage.
pub fn commit(&mut self) -> Result<(), ()> {
if let Some(extra) = self.pending.take() {
Account::<T, I>::try_mutate(self.id, self.who.borrow(), |maybe_account| {
Account::<T, I>::try_mutate(&self.id, &self.who, |maybe_account| {
maybe_account.as_mut().ok_or(()).map(|account| account.extra = extra)
})
} else {
Expand All @@ -88,7 +88,7 @@ impl<T: Config<I>, I: 'static> ExtraMutator<T, I> {
/// Revert any changes, even those already committed by `self` and drop self.
pub fn revert(mut self) -> Result<(), ()> {
self.pending = None;
Account::<T, I>::try_mutate(self.id, self.who.borrow(), |maybe_account| {
Account::<T, I>::try_mutate(&self.id, &self.who, |maybe_account| {
maybe_account
.as_mut()
.ok_or(())
Expand Down
Loading