Skip to content

Commit

Permalink
Avoid erroring out when collection is outdated
Browse files Browse the repository at this point in the history
  • Loading branch information
lemunozm committed Feb 23, 2024
1 parent 39d2e3f commit e52e958
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions libs/mocks/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ pub mod pallet {
}
}

impl<DataId, Data> Default for MockDataCollection<DataId, Data> {
fn default() -> Self {
Self(Box::new(|_| {
Err(DispatchError::Other("MockDataCollection: Data not found"))
}))
}
}

impl<DataId, Data> DataCollection<DataId> for MockDataCollection<DataId, Data> {
type Data = Data;

Expand Down
2 changes: 1 addition & 1 deletion libs/traits/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub trait DataRegistry<DataId, CollectionId> {
}

/// Abstration to represent a collection of data in memory
pub trait DataCollection<DataId> {
pub trait DataCollection<DataId>: Default {
/// Represents a data
type Data;

Expand Down
2 changes: 1 addition & 1 deletion pallets/loans/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,7 @@ pub mod pallet {
pool_id: T::PoolId,
) -> Result<(T::Balance, u32), DispatchError> {
let rates = T::InterestAccrual::rates();
let prices = T::PriceRegistry::collection(&pool_id)?;
let prices = T::PriceRegistry::collection(&pool_id).unwrap_or_default();
let loans = ActiveLoans::<T>::get(pool_id);
let values = loans
.iter()
Expand Down

0 comments on commit e52e958

Please sign in to comment.