-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
332 additions
and
330 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use codec::{Decode, Encode, MaxEncodedLen}; | ||
use frame_support::RuntimeDebugNoBound; | ||
use scale_info::TypeInfo; | ||
use sp_runtime::{ArithmeticError, DispatchError}; | ||
|
||
use crate::{ | ||
entities::pricing::external::ExternalAmount, | ||
pallet::{Config, Error}, | ||
types::RepaidAmount, | ||
}; | ||
|
||
#[derive(Encode, Decode, Clone, PartialEq, Eq, TypeInfo, RuntimeDebugNoBound, MaxEncodedLen)] | ||
#[scale_info(skip_type_params(T))] | ||
pub enum PrincipalInput<T: Config> { | ||
Internal(T::Balance), | ||
External(ExternalAmount<T>), | ||
} | ||
|
||
impl<T: Config> PrincipalInput<T> { | ||
pub fn balance(&self) -> Result<T::Balance, ArithmeticError> { | ||
match self { | ||
Self::Internal(amount) => Ok(*amount), | ||
Self::External(external) => external.balance(), | ||
} | ||
} | ||
|
||
pub fn internal(&self) -> Result<T::Balance, DispatchError> { | ||
match self { | ||
Self::Internal(amount) => Ok(*amount), | ||
Self::External(_) => Err(Error::<T>::MismatchedPricingMethod.into()), | ||
} | ||
} | ||
|
||
pub fn external(&self) -> Result<ExternalAmount<T>, DispatchError> { | ||
match self { | ||
Self::Internal(_) => Err(Error::<T>::MismatchedPricingMethod.into()), | ||
Self::External(principal) => Ok(principal.clone()), | ||
} | ||
} | ||
} | ||
|
||
#[derive(Encode, Decode, Clone, PartialEq, Eq, TypeInfo, RuntimeDebugNoBound, MaxEncodedLen)] | ||
#[scale_info(skip_type_params(T))] | ||
pub struct RepaidInput<T: Config> { | ||
pub principal: PrincipalInput<T>, | ||
pub interest: T::Balance, | ||
pub unscheduled: T::Balance, | ||
} | ||
|
||
impl<T: Config> RepaidInput<T> { | ||
pub fn repaid_amount(&self) -> Result<RepaidAmount<T::Balance>, ArithmeticError> { | ||
Ok(RepaidAmount { | ||
principal: self.principal.balance()?, | ||
interest: self.interest, | ||
unscheduled: self.unscheduled, | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.