Skip to content

Show last-day and lifetime totals in the ledger view, and track deposits - #68

Merged
Drefvelin merged 1 commit into
mainfrom
feat/ledger-history
Sep 27, 2026
Merged

Drefvelin merged 1 commit into
mainfrom
feat/ledger-history

Conversation

@Drefvelin

@Drefvelin Drefvelin commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

What

The faction ledger view icons (Citizens, Guild Taxes, Vassals, Tributes, Tariffs) now show three sections, each with a total and the top 5 payers:

  • Today: what is due at the next new day (what the icon showed before)
  • Last day: what was actually settled at the last new day
  • Lifetime: running total of every settled day

A new Deposits icon (chest, slot 15) tracks members' /f deposit and /g deposit amounts the same way. Deposits are recorded only. They are not income, and settlement never reads them.

How

  • LedgerHistory (per guild ledger) holds last-day and lifetime maps per source, keyed by payer name, plus today's deposits.
  • Ledger.collectHistoryDay runs once in settleIncome before Phase 1 clears citizen taxes. It walks payers the same way applySettlementFor does (skipping bankrupt or bankless payers and receivers with no bank), so the snapshot matches what moves.
  • After Phase 3, each guild's history closes the day, moving the snapshot and today's deposits into last day and lifetime.
  • History is saved in the guild JSON (ledger last day, ledger lifetime, deposits today). Old files load with empty history.
  • Tributes "Today" now uses getInternalTaxableIncome, the base settlement charges tribute on, instead of the gross base, so Today and Last day agree.

Tests

LedgerHistoryTest covers day rollover, lifetime accumulation, deposits, JSON round trip, old JSON, and the settlement snapshot (citizens, tariffs, bankrupt payer). Full suite passes locally (2298 tests).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Guild ledgers now show income totals for today, the previous day, and over the guild’s lifetime, with contributors ranked by amount.
    • Guild and faction deposits are tracked in the guild ledger and included in today’s deposit totals.
    • Ledger history is saved and restored, so daily and lifetime records remain available after a restart.
    • Ledger sections now display an empty-state message when they have no entries.

Each ledger view icon (Citizens, Guild Taxes, Vassals, Tributes, Tariffs)
now lists today's payers, what they paid on the last day, and what they
have paid in total. A new Deposits icon does the same for members'
/f deposit and /g deposit amounts.

- Snapshot each capital's per-payer receipts from the payer side just
  before settlement, mirroring what applySettlementFor moves
- Roll the snapshot into last-day and lifetime totals after settlement
- Deposits are tracked only; settlement never reads the history
- Save the history with the guild so a restart keeps it
- Tributes "Today" uses the same internal income base as settlement

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: dd4dfccc-0075-4195-b80c-fc31f92b55a8

📥 Commits

Reviewing files that changed from the base of the PR and between d4d1bea and 9ea6a2e.

📒 Files selected for processing (10)
  • src/main/java/net/tfminecraft/simplefactions/database/Database.java
  • src/main/java/net/tfminecraft/simplefactions/database/GuildData.java
  • src/main/java/net/tfminecraft/simplefactions/guild/Guild.java
  • src/main/java/net/tfminecraft/simplefactions/guild/income/Ledger.java
  • src/main/java/net/tfminecraft/simplefactions/guild/income/LedgerHistory.java
  • src/main/java/net/tfminecraft/simplefactions/managers/CommandManager.java
  • src/main/java/net/tfminecraft/simplefactions/managers/FactionManager.java
  • src/main/java/net/tfminecraft/simplefactions/managers/inventory/GuildCreator.java
  • src/main/java/net/tfminecraft/simplefactions/managers/inventory/GuildView.java
  • src/test/java/net/tfminecraft/simplefactions/guild/income/LedgerHistoryTest.java

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The change adds guild ledger history for daily and lifetime amounts, tracks current-day deposits, saves and restores this data, and displays the totals and contributors in guild ledger inventories.

Changes

Guild Ledger History

Layer / File(s) Summary
History model and collection
src/main/java/net/tfminecraft/simplefactions/guild/income/LedgerHistory.java, src/main/java/net/tfminecraft/simplefactions/guild/income/Ledger.java, src/test/java/net/tfminecraft/simplefactions/guild/income/LedgerHistoryTest.java
LedgerHistory stores daily and lifetime amounts by source and contributor, and tracks current-day deposits. Ledger.collectHistoryDay() gathers eligible amounts for receiving guilds. Tests cover history updates, persistence, and collection behavior.
Daily recording and persistence
src/main/java/net/tfminecraft/simplefactions/database/*, src/main/java/net/tfminecraft/simplefactions/guild/Guild.java, src/main/java/net/tfminecraft/simplefactions/managers/CommandManager.java, src/main/java/net/tfminecraft/simplefactions/managers/FactionManager.java
Guild data saves and restores ledger history. Deposit commands record deposits, and daily settlement collects history before transfers and closes it after deposits and liquidations.
Ledger history display
src/main/java/net/tfminecraft/simplefactions/managers/inventory/GuildCreator.java, src/main/java/net/tfminecraft/simplefactions/managers/inventory/GuildView.java
Ledger items display today, last-day, and lifetime totals with descending contributors. Base guild ledger inventories include a deposits item.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant FactionManager
  participant Ledger
  participant LedgerHistory
  FactionManager->>Ledger: collectHistoryDay(getAllGuilds())
  Ledger-->>FactionManager: per-guild history snapshots
  FactionManager->>LedgerHistory: closeDay(snapshot) for each guild ledger
Loading

Suggested reviewers: ryanbarlow97

Merge Risk: ⚪ Minimal · up to 9ea6a

No actionable issue remains from the reviewed ledger history, deposit, or display changes. The PR is mergeable after normal checks.

Security Architecture Review

Security architecture risk: 🟡 Moderate · up to 9ea6a

Players can see newly recorded deposit amounts and historical payer totals for factions they do not belong to. The history can also become inaccurate if a daily settlement step fails. The reviewed changes do not show a new way to move bank funds without authorization.

Retained concerns

  • Medium · security · observed: The public faction-list-to-ledger path now reveals members' deposit identities and amounts and persistent payer histories without a viewer-membership check.
  • Medium · reliability · inferred: A failed or partial daily settlement can still be recorded as settled in last-day and lifetime history.
Security review details

Security Blast Radius

  • inferred — Any player able to use the public faction-list navigation can inspect the newly displayed history of a listed faction's main guild; the exposure is read-only and limited to the displayed totals and top contributors.

Security Findings and Attack Paths

  • observed — The public list opens a faction view whose ledger click reaches the main-guild ledger without a membership check; the new deposits item then displays player names and amounts. The same route existed before, but the deposit and historical data did not.

Trust Boundaries and Controls

  • observed — Guild and faction deposit commands retain member, bank-location, positive-amount, and sufficient-funds checks before moving funds and recording history; no new unauthenticated bank-write path was established.

Resilience and Maintainability Implications

  • inferred — If a settlement step fails after history capture, exception handling permits later history closure. The resulting displayed financial history need not attest to funds that actually moved; a concrete runtime failure was not demonstrated.

Hardening Proposals

  • proposed — Enforce an explicit viewer policy before displaying member deposits or persistent payer history, and derive settled history from confirmed movements or retain a recoverable settlement outcome before closing the day.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 42 functions across 10 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the primary changes: displaying last-day and lifetime ledger totals and tracking deposits. It is concise, specific, and aligned with the pull request objectives.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

A rabbit counts the guild’s deposits,
Then files each sum by name and source.
The daily page turns; totals remain,
The ledger shows who filled its banks.
“Hop,” says the rabbit, “history’s saved!”

Comment @coderabbitai help to get the list of available commands.

@Drefvelin
Drefvelin merged commit 5928237 into main Sep 27, 2026
2 checks passed
@Drefvelin
Drefvelin deleted the feat/ledger-history branch September 27, 2026 22:46
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.

2 participants