From 2d57d1f2441f29431c65b54fac29b04c61325f7a Mon Sep 17 00:00:00 2001 From: cuteolaf Date: Thu, 8 Aug 2024 03:55:24 +0200 Subject: [PATCH] add new events for regions pallet --- pallets/regions/src/lib.rs | 24 ++++++++++++++++++++++++ pallets/regions/src/nonfungible_impls.rs | 12 +++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/pallets/regions/src/lib.rs b/pallets/regions/src/lib.rs index 3bf90da..c44200e 100644 --- a/pallets/regions/src/lib.rs +++ b/pallets/regions/src/lib.rs @@ -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] diff --git a/pallets/regions/src/nonfungible_impls.rs b/pallets/regions/src/nonfungible_impls.rs index 02d2fbf..eb5af40 100644 --- a/pallets/regions/src/nonfungible_impls.rs +++ b/pallets/regions/src/nonfungible_impls.rs @@ -70,6 +70,8 @@ impl Mutate for Pallet { Region { owner: who.clone(), locked: false, record: Record::Unavailable }, ); + Pallet::::deposit_event(Event::RegionMinted { region_id }); + log::info!( target: LOG_TARGET, "Minted region: {:?}", @@ -90,6 +92,8 @@ impl Mutate for Pallet { Regions::::remove(region_id); + Pallet::::deposit_event(Event::RegionBurnt { region_id }); + Ok(()) } } @@ -111,7 +115,10 @@ impl RegionInspect> for Pallet { impl LockableNonFungible for Pallet { fn lock(item: &Self::ItemId, maybe_check_owner: Option) -> DispatchResult { let region_id: RegionId = (*item).into(); - let mut region = Regions::::get(region_id).ok_or(Error::::UnknownRegion)?; + let mut region: Region< + ::AccountId, + <::Currency as Inspect<::AccountId>>::Balance, + > = Regions::::get(region_id).ok_or(Error::::UnknownRegion)?; if let Some(owner) = maybe_check_owner { ensure!(owner.clone() == region.owner, Error::::NotOwner); @@ -121,6 +128,7 @@ impl LockableNonFungible for Pallet { region.locked = true; Regions::::insert(region_id, region); + Pallet::::deposit_event(Event::RegionLocked { region_id }); Ok(()) } @@ -136,6 +144,8 @@ impl LockableNonFungible for Pallet { region.locked = false; Regions::::insert(region_id, region); + Pallet::::deposit_event(Event::RegionUnlocked { region_id }); + Ok(()) } }