From 2c2b84c5451846d8be6b6cef57792d48ff9b0f4b Mon Sep 17 00:00:00 2001 From: Frederik Gartenmeister Date: Wed, 11 Sep 2024 10:22:21 +0200 Subject: [PATCH] safeguard --- pallets/token-mux/src/lib.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/pallets/token-mux/src/lib.rs b/pallets/token-mux/src/lib.rs index 15f33bdc63..20f6308286 100644 --- a/pallets/token-mux/src/lib.rs +++ b/pallets/token-mux/src/lib.rs @@ -282,18 +282,22 @@ pub mod pallet { } pub(crate) fn prepare_and( - currency_a: &T::CurrencyId, - currency_b: &T::CurrencyId, + currency_from: &T::CurrencyId, + currency_to: &T::CurrencyId, amount: T::Balance, and: FnOnce(T::Balance) -> DispatchResult, ) -> DispatchResult { - if currency_a.is_local_representation_of(¤cy_b) { - and(Self::adjust_amount(currency_a, currency_b, amount)?)?; + match ( + currency_a.is_local_representation_of(¤cy_b), + currency_b.is_local_representation_of(¤cy_a), + ) { + (true, false) => { + mint() + and(amount) + }, + (false, true) => and(Self::adjust_amount(currency_a, currency_b, amount)?)?, + (_, _) => Err(Error::::NoLocalRepresentation.into()), } - - if currency_b.is_local_representation_of(¤cy_a) {} - - Err(Error::::NoLocalRepresentation.into()) } } }