Skip to content

Commit

Permalink
correct logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Szegoo committed Apr 7, 2024
1 parent a66aec6 commit e92ae47
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pallets/regions/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }

Expand Down Expand Up @@ -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",
Expand Down
7 changes: 2 additions & 5 deletions pallets/regions/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));

Expand Down Expand Up @@ -227,11 +229,6 @@ pub mod pallet {
.dispatch_request(DispatchRequest::Get(get), who.clone(), Zero::zero())
.map_err(|_| Error::<T>::IsmpDispatchError)?;

Regions::<T>::insert(
region_id,
Region { owner: who, record: None, record_status: RecordStatus::Pending },
);

// TODO: Emit event

Ok(())
Expand Down
19 changes: 18 additions & 1 deletion pallets/regions/src/nonfungible_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,24 @@ impl<T: Config> Mutate<T::AccountId> for Pallet<T> {
/// 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::<T>::insert(region_id, Region { owner: who.clone(), record: None, record_status });

Ok(())
}
Expand Down

0 comments on commit e92ae47

Please sign in to comment.