Skip to content

Commit

Permalink
rename api name
Browse files Browse the repository at this point in the history
  • Loading branch information
lemunozm committed May 8, 2024
1 parent a60d0fd commit a864ad4
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pallets/loans/src/entities/loans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ impl<T: Config> ActiveLoan<T> {
.ensure_sub(self.total_repaid.principal)?)
}

pub fn cashflow(&self) -> Result<Vec<CashflowPayment<T::Balance>>, DispatchError> {
pub fn expected_cashflows(&self) -> Result<Vec<CashflowPayment<T::Balance>>, DispatchError> {
self.schedule.generate_cashflows(
self.repayments_on_schedule_until,
self.principal()?,
Expand Down
4 changes: 2 additions & 2 deletions pallets/loans/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1215,14 +1215,14 @@ pub mod pallet {
.transpose()
}

pub fn cashflow(
pub fn expected_cashflows(

Check warning on line 1218 in pallets/loans/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

pallets/loans/src/lib.rs#L1218

Added line #L1218 was not covered by tests
pool_id: T::PoolId,
loan_id: T::LoanId,
) -> Result<Vec<CashflowPayment<T::Balance>>, DispatchError> {
ActiveLoans::<T>::get(pool_id)

Check warning on line 1222 in pallets/loans/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

pallets/loans/src/lib.rs#L1222

Added line #L1222 was not covered by tests
.into_iter()
.find(|(id, _)| *id == loan_id)
.map(|(_, loan)| loan.cashflow())
.map(|(_, loan)| loan.expected_cashflows())
.ok_or(Error::<T>::LoanNotActiveOrNotFound)?

Check warning on line 1226 in pallets/loans/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

pallets/loans/src/lib.rs#L1224-L1226

Added lines #L1224 - L1226 were not covered by tests
}
}
Expand Down
8 changes: 4 additions & 4 deletions pallets/loans/src/tests/borrow_loan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ mod cashflow {
let interest = Rate::from_float(interest_rate_per_month).saturating_mul_int(principal);

assert_eq!(
loan.cashflow()
loan.expected_cashflows()
.unwrap()
.into_iter()
.map(|payment| (payment.when, payment.principal, payment.interest))
Expand Down Expand Up @@ -691,7 +691,7 @@ mod cashflow {
PrincipalInput::Internal(COLLATERAL_VALUE / 2)
));

let cashflow = util::get_loan(loan_id).cashflow().unwrap();
let cashflow = util::get_loan(loan_id).expected_cashflows().unwrap();

let time_until_next_month = Duration::from_secs(cashflow[0].when) - now();
advance_time(time_until_next_month);
Expand Down Expand Up @@ -719,7 +719,7 @@ mod cashflow {
PrincipalInput::Internal(COLLATERAL_VALUE / 2)
));

let cashflow = util::get_loan(loan_id).cashflow().unwrap();
let cashflow = util::get_loan(loan_id).expected_cashflows().unwrap();

let time_until_next_month = Duration::from_secs(cashflow[0].when) - now();
advance_time(time_until_next_month);
Expand Down Expand Up @@ -753,7 +753,7 @@ mod cashflow {
PrincipalInput::Internal(COLLATERAL_VALUE / 2)
));

let cashflow = util::get_loan(loan_id).cashflow().unwrap();
let cashflow = util::get_loan(loan_id).expected_cashflows().unwrap();

let time_until_next_month = Duration::from_secs(cashflow[0].when) - now();
advance_time(time_until_next_month);
Expand Down
5 changes: 2 additions & 3 deletions runtime/altair/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2352,12 +2352,11 @@ impl_runtime_apis! {
Ok(runtime_common::update_nav_with_input(pool_id, input_prices)?.nav_aum)
}

fn cashflow(pool_id: PoolId, loan_id: LoanId) -> Result<Vec<CashflowPayment<Balance>>, DispatchError> {
Loans::cashflow(pool_id, loan_id)
fn expected_cashflows(pool_id: PoolId, loan_id: LoanId) -> Result<Vec<CashflowPayment<Balance>>, DispatchError> {
Loans::expected_cashflows(pool_id, loan_id)

Check warning on line 2356 in runtime/altair/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

runtime/altair/src/lib.rs#L2355-L2356

Added lines #L2355 - L2356 were not covered by tests
}
}


// Investment Runtime APIs
impl runtime_common::apis::InvestmentsApi<Block, AccountId, TrancheCurrency, InvestmentPortfolio<Balance, CurrencyId>> for Runtime {
fn investment_portfolio(account_id: AccountId) -> Vec<(TrancheCurrency, InvestmentPortfolio<Balance, CurrencyId>)> {
Expand Down
4 changes: 2 additions & 2 deletions runtime/centrifuge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2400,8 +2400,8 @@ impl_runtime_apis! {
Ok(runtime_common::update_nav_with_input(pool_id, input_prices)?.nav_aum)
}

fn cashflow(pool_id: PoolId, loan_id: LoanId) -> Result<Vec<CashflowPayment<Balance>>, DispatchError> {
Loans::cashflow(pool_id, loan_id)
fn expected_cashflows(pool_id: PoolId, loan_id: LoanId) -> Result<Vec<CashflowPayment<Balance>>, DispatchError> {
Loans::expected_cashflows(pool_id, loan_id)

Check warning on line 2404 in runtime/centrifuge/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

runtime/centrifuge/src/lib.rs#L2403-L2404

Added lines #L2403 - L2404 were not covered by tests
}
}

Expand Down
2 changes: 1 addition & 1 deletion runtime/common/src/apis/loans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ decl_runtime_apis! {
fn portfolio(pool_id: PoolId) -> Vec<(LoanId, Loan)>;
fn portfolio_loan(pool_id: PoolId, loan_id: LoanId) -> Option<Loan>;
fn portfolio_valuation(pool_id: PoolId, input_prices: PriceCollectionInput) -> Result<Balance, DispatchError>;
fn cashflow(pool_id: PoolId, loan_id: LoanId) -> Result<Vec<CashflowPayment<Balance>>, DispatchError>;
fn expected_cashflows(pool_id: PoolId, loan_id: LoanId) -> Result<Vec<CashflowPayment<Balance>>, DispatchError>;
}
}
4 changes: 2 additions & 2 deletions runtime/development/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2439,8 +2439,8 @@ impl_runtime_apis! {
Ok(runtime_common::update_nav_with_input(pool_id, input_prices)?.nav_aum)
}

fn cashflow(pool_id: PoolId, loan_id: LoanId) -> Result<Vec<CashflowPayment<Balance>>, DispatchError> {
Loans::cashflow(pool_id, loan_id)
fn expected_cashflows(pool_id: PoolId, loan_id: LoanId) -> Result<Vec<CashflowPayment<Balance>>, DispatchError> {
Loans::expected_cashflows(pool_id, loan_id)

Check warning on line 2443 in runtime/development/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

runtime/development/src/lib.rs#L2442-L2443

Added lines #L2442 - L2443 were not covered by tests
}
}

Expand Down

0 comments on commit a864ad4

Please sign in to comment.