Skip to content

Commit

Permalink
MESH-2195: Check DID & Portfolio for settlements (#1724)
Browse files Browse the repository at this point in the history
* Check DID & Portfolio for settlements

* Fix linting

* Fix mocks

* Fix mocks again

---------

Co-authored-by: Robert Gabriel Jakabosky <[email protected]>
  • Loading branch information
adamdossa and Neopallium authored Sep 17, 2024
1 parent 6a479a8 commit 5414c35
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 1 deletion.
6 changes: 6 additions & 0 deletions pallets/common/src/traits/portfolio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ pub trait PortfolioSubTrait<AccountId> {
/// * `custodian` - DID of the custodian
fn ensure_portfolio_custody(portfolio: PortfolioId, custodian: IdentityId) -> DispatchResult;

/// Ensure that the `portfolio` exists.
///
/// # Arguments
/// * `portfolio` - Portfolio to check
fn ensure_portfolio_validity(portfolio: &PortfolioId) -> DispatchResult;

/// Locks some tokens of a portfolio
///
/// # Arguments
Expand Down
2 changes: 1 addition & 1 deletion pallets/identity/src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl<T: Config> Module<T> {
}

/// Returns `Err(DidDoesNotExist)` unless `id` has an associated record.
pub(crate) fn ensure_id_record_exists(id: IdentityId) -> DispatchResult {
pub fn ensure_id_record_exists(id: IdentityId) -> DispatchResult {
ensure!(Self::is_identity_exists(&id), Error::<T>::DidDoesNotExist);
Ok(())
}
Expand Down
5 changes: 5 additions & 0 deletions pallets/portfolio/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,11 @@ impl<T: Config> PortfolioSubTrait<T::AccountId> for Module<T> {
Ok(())
}

/// Ensure that the `portfolio` exists.
fn ensure_portfolio_validity(portfolio: &PortfolioId) -> DispatchResult {
Self::ensure_portfolio_validity(portfolio)
}

/// Ensures that the portfolio's custody is with the provided identity
fn ensure_portfolio_custody(portfolio: PortfolioId, custodian: IdentityId) -> DispatchResult {
Self::ensure_portfolio_custody(portfolio, custodian)
Expand Down
4 changes: 4 additions & 0 deletions pallets/runtime/tests/src/staking/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,10 @@ impl PortfolioSubTrait<AccountId> for Test {
unimplemented!()
}

fn ensure_portfolio_validity(_: &PortfolioId) -> DispatchResult {
unimplemented!()
}

fn lock_tokens(_: &PortfolioId, _: &AssetID, _: Balance) -> DispatchResult {
unimplemented!()
}
Expand Down
4 changes: 4 additions & 0 deletions pallets/settlement/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,10 @@ impl<T: Config> Module<T> {
Leg::OffChain { .. } => continue,
}
};
Identity::<T>::ensure_id_record_exists(sender.did)?;
Identity::<T>::ensure_id_record_exists(receiver.did)?;
T::Portfolio::ensure_portfolio_validity(sender)?;
T::Portfolio::ensure_portfolio_validity(receiver)?;

portfolios_pending_approval.insert(*sender);
if T::Portfolio::skip_portfolio_affirmation(receiver, asset_id) {
Expand Down

0 comments on commit 5414c35

Please sign in to comment.