diff --git a/Cargo.lock b/Cargo.lock index 76e76c72..1ca25c18 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6722,6 +6722,7 @@ dependencies = [ "ismp", "ismp-parachain", "ismp-testsuite", + "log", "pallet-balances", "pallet-broker", "pallet-ismp", diff --git a/pallets/regions/Cargo.toml b/pallets/regions/Cargo.toml index 6199e5a0..d24c4032 100644 --- a/pallets/regions/Cargo.toml +++ b/pallets/regions/Cargo.toml @@ -12,6 +12,7 @@ edition = "2021" targets = ["x86_64-unknown-linux-gnu"] [dependencies] +log = { workspace = true } parity-scale-codec = { workspace = true, default-features = false, features = ["derive"] } scale-info = { workspace = true, default-features = false, features = ["derive"] } @@ -39,6 +40,7 @@ ismp-testsuite = { workspace = true } default = ["std"] runtime-benchmarks = ["frame-benchmarking/runtime-benchmarks"] std = [ + "log/std", "parity-scale-codec/std", "ismp/std", "ismp-parachain/std", diff --git a/pallets/regions/src/lib.rs b/pallets/regions/src/lib.rs index a8ed3a28..75368bc9 100644 --- a/pallets/regions/src/lib.rs +++ b/pallets/regions/src/lib.rs @@ -34,6 +34,8 @@ mod nonfungible_impls; mod types; use types::*; +const LOG_TARGET: &'static str = "runtime::regions"; + /// Constant Pallet ID pub const PALLET_ID: ModuleId = ModuleId::Pallet(PalletId(*b"ismp-reg")); @@ -227,11 +229,6 @@ pub mod pallet { .dispatch_request(DispatchRequest::Get(get), who.clone(), Zero::zero()) .map_err(|_| Error::::IsmpDispatchError)?; - Regions::::insert( - region_id, - Region { owner: who, record: None, record_status: RecordStatus::Pending }, - ); - // TODO: Emit event Ok(()) diff --git a/pallets/regions/src/nonfungible_impls.rs b/pallets/regions/src/nonfungible_impls.rs index 9ebe625d..deeed34a 100644 --- a/pallets/regions/src/nonfungible_impls.rs +++ b/pallets/regions/src/nonfungible_impls.rs @@ -39,7 +39,24 @@ impl Mutate for Pallet { /// Minting is used for depositing a region from the holding registar. fn mint_into(item: &Self::ItemId, who: &T::AccountId) -> DispatchResult { let region_id: RegionId = (*item).into(); - Self::do_request_region_record(region_id, who.clone())?; + + // We don't want the region to get trapped, so we will handle the error. + let record_status = match Self::do_request_region_record(region_id, who.clone()) { + Ok(_) => RecordStatus::Pending, + Err(_) => { + log::error!( + target: LOG_TARGET, + "Failed to request region record for region_id: {:?}", + region_id + ); + RecordStatus::Unavailable + }, + }; + + // Even if requesting the region record fails we still want to mint it to the owner. + // + // We will just have the region record not set. + Regions::::insert(region_id, Region { owner: who.clone(), record: None, record_status }); Ok(()) }