Skip to content

Commit

Permalink
fix(fc-traits-gas-tank): return DispatchResult when calling `make_t…
Browse files Browse the repository at this point in the history
…ank` to catch on attribute setting errors
  • Loading branch information
pandres95 committed Dec 13, 2024
1 parent 8dae394 commit 4b43368
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
10 changes: 5 additions & 5 deletions traits/gas-tank/src/impl_nonfungibles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ where
F::typed_system_attribute(collection_id, Some(item_id), &ATTR_MEMBERSHIP_GAS)
}

fn put<F, I>(&self, collection_id: &F::CollectionId, item_id: &F::ItemId) -> Option<()>
fn put<F, I>(&self, collection_id: &F::CollectionId, item_id: &F::ItemId) -> DispatchResult
where
F: nonfungibles_v2::Inspect<T::AccountId> + nonfungibles_v2::Mutate<T::AccountId, I>,
{
F::set_typed_attribute(collection_id, item_id, &ATTR_MEMBERSHIP_GAS, self).ok()
F::set_typed_attribute(collection_id, item_id, &ATTR_MEMBERSHIP_GAS, self)
}
}

Expand Down Expand Up @@ -92,7 +92,7 @@ where
if block_number.checked_sub(&tank.since)? > period {
tank.since = block_number.checked_add(&period)?;
tank.used = Weight::zero();
tank.put::<F, ItemConfig>(&collection, &item)?;
tank.put::<F, ItemConfig>(&collection, &item).ok()?;
};

let remaining = capacity.checked_sub(&tank.used.checked_add(estimated)?)?;
Expand Down Expand Up @@ -127,7 +127,7 @@ where
tank.used = tank.used.checked_add(used)?;
}

tank.put::<F, ItemConfig>(&collection, &item)?;
tank.put::<F, ItemConfig>(&collection, &item).ok()?;

let max_weight = tank.capacity_per_period?;
Some(max_weight.saturating_sub(tank.used))
Expand Down Expand Up @@ -190,7 +190,7 @@ where
(collection_id, item_id): &Self::TankId,
capacity: Option<Self::Gas>,
periodicity: Option<Self::BlockNumber>,
) -> Option<()> {
) -> DispatchResult {
WeightTank::<T>::new(capacity, periodicity).put::<F, ItemConfig>(collection_id, item_id)
}
}
3 changes: 2 additions & 1 deletion traits/gas-tank/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use frame_support::Parameter;
use sp_runtime::traits::BlockNumber;
use sp_runtime::DispatchResult;

#[cfg(test)]
mod tests;
Expand Down Expand Up @@ -52,5 +53,5 @@ pub trait MakeTank {
id: &Self::TankId,
capacity: Option<Self::Gas>,
periodicity: Option<Self::BlockNumber>,
) -> Option<()>;
) -> DispatchResult;
}

0 comments on commit 4b43368

Please sign in to comment.