Skip to content

Implemeted lightweight loan-status view#35

Open
dubemoyibe-star wants to merge 2 commits into
LabsCrypt:mainfrom
dubemoyibe-star:feat/lightweight-loan-status-view
Open

Implemeted lightweight loan-status view#35
dubemoyibe-star wants to merge 2 commits into
LabsCrypt:mainfrom
dubemoyibe-star:feat/lightweight-loan-status-view

Conversation

@dubemoyibe-star

@dubemoyibe-star dubemoyibe-star commented Jun 19, 2026

Copy link
Copy Markdown

Summary

Add lightweight loan status view methods to reduce the need for full loan lookups and avoid triggering accrual logic during read-only operations.

Changes

  • Added get_loan_status(loan_id) to return the stored LoanStatus without running accrual.
  • Added an optional borrower loan accessor with status filtering and pagination support.
  • Added tests covering the new view methods.
  • Updated the contract documentation to include the new view APIs.

Why

The contract currently exposes:

  • get_loan
  • get_borrower_loans
  • get_total_loans

However, there is no lightweight way to:

  • Retrieve a loan's status without invoking accrual logic.
  • Query borrower loans by status.
  • Efficiently support frontend and indexing use cases.

As a result, consumers must call get_loan for every loan ID, which can be expensive and may introduce side effects through accrual calculations.

The new view methods provide a cheaper and safer way to inspect loan state.

Acceptance Criteria

  • Added get_loan_status(loan_id) returning the stored LoanStatus.
  • Added borrower loan retrieval with optional status filtering and pagination.
  • Added unit tests covering the new view methods.
  • Documented the new views in the contract README.

Files Changed

  • loan_manager/src/lib.rs
  • Contract README
  • Associated test files

Out of Scope

  • Global loan enumeration across all borrowers.
  • Indexer infrastructure or off-chain indexing support.

Closes #19

@ogazboiz ogazboiz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the view itself is good: get_loan_status is properly read-only (reads the loan, bumps ttl only, no accrual or set), returns the right status, and handles missing loans without panicking (LoanNotFound, and get_borrower_loans_by_status skips absent ids). the status coverage in the tests is thorough.

two blockers though:

  1. it clobbers #32, which just merged. your branch was built against an older main and put get_loan_status in the exact spot where #32 added pub fn quote_total_debt. github auto-merges this without a conflict marker, but the merged result silently deletes quote_total_debt (there's only a dangling doc-comment referencing it left at lib.rs:1150). that reverts #32. please rebase on current main (git fetch origin && git rebase origin/main && git push --force-with-lease) and add get_loan_status as a new function alongside quote_total_debt, fixing the now-dangling doc reference.

  2. ci is red on cargo fmt: loan_manager/src/test.rs:1701 (a let binding written with no indentation) and loan_manager/src/lib.rs:2070 (the get_borrower_loans_by_status signature wants splitting across lines). run cargo fmt and push.

once it's rebased so quote_total_debt survives and fmt is green, i'll re-review.

if you want to keep contributing, join us on Telegram: https://t.me/+DOylgFv1jyJlNzM0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Contracts] No lightweight loan-status view; get_loan triggers accrual and per-id calls are required

2 participants