Skip to content

feat(backend): serve account delegation history - #4320

Open
kusssal wants to merge 4 commits into
developfrom
feat/1658-account-delegation-history
Open

kusssal wants to merge 4 commits into
developfrom
feat/1658-account-delegation-history

Conversation

@kusssal

@kusssal kusssal commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

List of changes

  • Add GET /account/{stakeKey}/delegation-history: the account's governance delegations, newest first, as { elements, page, pageSize, total }, read through the provider's listDelegationHistory
  • Serve account.delegationHistory where the provider has that method (db-sync); Koios, Blockfrost and the fixture keep it unavailable (noSource) and the route answers 501
  • Clear the history's cache on a new block with the rest of a wallet's state
  • Record it as D178 in docs/api/decisions.md and in the rest-api-v1.md route maps

The redesigned DRep dashboard (#4316) already reads this route once the feature is served.

Checklist

  • related issue
  • My changes generate no new warnings
  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the changelog
  • I have added tests that prove my fix is effective or that my feature works

@mesudip mesudip 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 route itself looks right: literal path before :stakeKey, page validation, the cache in the wallet-state namespaces (cleared per block), 501 through withMethod, the feature following the provider's method, NO_ROUTE and the capability specs updated, and the rest-api-v1 maps. npm run verify in govtool-backend passes (23 suites, 476 tests). One claim needs fixing before merge, because it lands in the append-only decision log and the redesigned dashboard (#4316) already relies on it.

Must fix

  1. "Newest first, so the first row is the current one" is not true.

    • Where: D178 in docs/api/decisions.md:5949, the doc comment on getDelegationHistory (src/account/account.service.ts:89), and the test name at test/account-delegation-history.spec.ts:95.
    • The history is every delegation_vote certificate (HISTORY_SQL, govtool-provider-dbsync/src/accounts.ts:210). A delegation stops standing when the account deregisters its stake key, or when the DRep retires (cleared by the ledger from protocol 10). The provider's own current-delegation query checks both: account_deregistered and drep_retired in DELEGATION_SQL, accounts.ts:103-126.
    • Effect: #4316's My Delegations table (GovernanceTab.tsx:592-594) marks row 0 "Current" and shows the account's present voting power next to it, even when that delegation is gone.
    • Fix: word it as "newest first; the newest row is the latest delegation certificate, which may no longer stand (the current delegation is /ada-holder/get-current-delegation)". Decisions are append-only, so this has to be right when it merges.
  2. Decision number. #4318 also adds a D178 ("Page tags come from the backend through nginx includes"), and #4322's D179 refers to this PR's D178. Whichever of these merges second needs to renumber.

Should fix (or follow up)

  1. Page numbering.

    • This route is 1-based and reads page=0 as page 1 (src/account/account.controller.ts:19-20). It answers with the same { elements, page, pageSize, total } envelope as /drep/list and /proposal/list, which are 0-based (drep.controller.ts:79, proposal.controller.ts:40).
    • A caller paging it like those lists gets the first page twice, with no error.
    • Either reject page=0 with a 400 or state the base in rest-api-v1.md. pageSize=0 is also silently read as 1.
  2. Docs. govtool/AGENTS.md's list of what govtool-backend serves beyond the legacy routes doesn't name the new route. Neither does tests/AGENTS.md's list of newer routes that have no pytest cases.

@kusssal
kusssal force-pushed the feat/1658-account-delegation-history branch from 8e3593b to 200fcee Compare December 3, 2026 08:09
@kusssal

kusssal commented Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

Thanks. I rebased the branch on develop (it conflicted after #4317, #4318 and #4319) and force-pushed; the fixes are three commits on top of e960773:

  1. "The first row is the current one": fixed in 890930b. D178, the doc comment on getDelegationHistory, the test name and the CHANGELOG now say the rows are delegation certificates, newest first, and that the newest may no longer stand once the stake key is deregistered or the DRep retires; the current delegation stays GET /ada-holder/get-current-delegation/{stakeKey}. The My Delegations table in Feat/frontend redesign #4316, which labels row 0 "Current", needs the matching change; that belongs in Feat/frontend redesign #4316, not here.
  2. Decision number: feat: page tags, link previews and sitemap for SEO #4318 merged as D180, so this stays D178. The rebase put D178 before D180 in the log and kept both CHANGELOG lines.
  3. Page numbering: fixed in 4fcd2ac. page=0 and pageSize=0 now answer 400 ("page must be at least 1") instead of being read as 1. D178 and rest-api-v1.md say the route counts pages from 1, unlike /drep/list and /proposal/list. The redesigned dashboard asks for page=1, so it is unaffected.
  4. Docs: 200fcee adds the route to govtool/AGENTS.md's list of what govtool-backend serves and to tests/AGENTS.md's newer routes without pytest cases.

npm run verify in govtool-backend on 200fcee: 31 suites, 651 tests.

This branch has not been deployed

No deployments
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