Skip to content

Commit

Permalink
add new events for regions pallet
Browse files Browse the repository at this point in the history
  • Loading branch information
cuteolaf committed Aug 8, 2024
1 parent 5890fcd commit 2d57d1f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
24 changes: 24 additions & 0 deletions pallets/regions/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,30 @@ pub mod pallet {
/// The ismp get request commitment.
request_commitment: H256,
},

/// A region was minted via a cross chain transfer.
RegionMinted {
/// minted region id
region_id: RegionId,
},

/// A region was burnt.
RegionBurnt {
/// burnt region id
region_id: RegionId,
},

/// A region was locked.
RegionLocked {
/// locked region id
region_id: RegionId,
},

/// A region was unlocked.
RegionUnlocked {
/// unlocked region id
region_id: RegionId,
},
}

#[pallet::error]
Expand Down
12 changes: 11 additions & 1 deletion pallets/regions/src/nonfungible_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ impl<T: Config> Mutate<T::AccountId> for Pallet<T> {
Region { owner: who.clone(), locked: false, record: Record::Unavailable },
);

Pallet::<T>::deposit_event(Event::RegionMinted { region_id });

log::info!(
target: LOG_TARGET,
"Minted region: {:?}",
Expand All @@ -90,6 +92,8 @@ impl<T: Config> Mutate<T::AccountId> for Pallet<T> {

Regions::<T>::remove(region_id);

Pallet::<T>::deposit_event(Event::RegionBurnt { region_id });

Ok(())
}
}
Expand All @@ -111,7 +115,10 @@ impl<T: Config> RegionInspect<T::AccountId, BalanceOf<T>> for Pallet<T> {
impl<T: Config> LockableNonFungible<T::AccountId> for Pallet<T> {
fn lock(item: &Self::ItemId, maybe_check_owner: Option<T::AccountId>) -> DispatchResult {
let region_id: RegionId = (*item).into();
let mut region = Regions::<T>::get(region_id).ok_or(Error::<T>::UnknownRegion)?;
let mut region: Region<
<T as Config>::AccountId,
<<T as Config>::Currency as Inspect<<T as Config>::AccountId>>::Balance,
> = Regions::<T>::get(region_id).ok_or(Error::<T>::UnknownRegion)?;

if let Some(owner) = maybe_check_owner {
ensure!(owner.clone() == region.owner, Error::<T>::NotOwner);
Expand All @@ -121,6 +128,7 @@ impl<T: Config> LockableNonFungible<T::AccountId> for Pallet<T> {
region.locked = true;
Regions::<T>::insert(region_id, region);

Pallet::<T>::deposit_event(Event::RegionLocked { region_id });
Ok(())
}

Expand All @@ -136,6 +144,8 @@ impl<T: Config> LockableNonFungible<T::AccountId> for Pallet<T> {
region.locked = false;
Regions::<T>::insert(region_id, region);

Pallet::<T>::deposit_event(Event::RegionUnlocked { region_id });

Ok(())
}
}

0 comments on commit 2d57d1f

Please sign in to comment.