feat(keys): add freeze status indexing and freeze/unfreeze admin endpoints (#964) - #995
Open
Cmitchelle7 wants to merge 3 commits into
Open
Cmitchelle7 wants to merge 3 commits into
Cmitchelle7 wants to merge 3 commits into
Conversation
|
@Cmitchelle7 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Prisma 6 rejects a BOM at the start of a schema file with P1012
('This line is invalid. It does not start with any known Prisma schema
keyword'). The BOM was introduced by PowerShell's Set-Content -Encoding UTF8
on Windows PowerShell 5.x, which writes UTF-8 with BOM. Re-encoded all new
files as UTF-8 without BOM.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements issue #964.
Adds freeze state tracking for keys, indexes freeze-related contract events, and exposes three endpoints under
/api/v1/keys/:keyIdfor reading freeze status and for admin-initiated freeze/unfreeze. Cache is invalidated on every state change.Closes #964
Scope
Endpoints
GET/api/v1/keys/:keyId/freezefrozenAt,frozenBy, andproposalId(if an unfreeze proposal is pending)POST/api/v1/keys/:keyId/freezex-admin-idheaderFREEZEevent, emits an audit event, invalidates cache. Returns 201.POST/api/v1/keys/:keyId/unfreezex-admin-idheaderPROPOSAL_CREATEDevent, emits an audit event, invalidates cache. Returns 202.Data model
Two new Prisma models in
prisma/schema/freeze.prisma:KeyFreeze— one row per key. HoldsisFrozen,reason,frozenAt,frozenBy,unfrozenAt,proposalId. Indexed onisFrozen.FreezeEvent— append-only event log from the contract stream (and admin actions). Fields:keyId,eventType,ledger,txHash,eventIndex,payload.@@unique([txHash, eventIndex])prevents duplicate ingestion;@@index([keyId, ledger])and@@index([ledger])support ordered scans.keyIdin both models corresponds toKeyOwnership.creatorId— the "key" identifier already used throughout the repo.Files added
prisma/schema/freeze.prismasrc/modules/freeze/freeze.schemas.ts— Zod schemas for:keyId, freeze body, unfreeze bodysrc/modules/freeze/freeze.service.ts—getFreezeStatus,emergencyFreeze,initiateUnfreeze,indexFreezeEventsrc/modules/freeze/freeze.controllers.ts— threeAsyncControllerhandlerssrc/modules/freeze/freeze.routes.ts— mounts routes withadminGuardon mutating endpointssrc/utils/freeze-cache.utils.ts— in-memory cache with TTL andinvalidateFreezeCacheFiles modified
src/modules/index.ts— mountsfreezeRouterat/keysAcceptance criteria
getFreezeStatusreads fromKeyFreeze, returnsnullfields when no row existsadminGuardmiddleware on the POST routeinitiateUnfreezegenerates aproposalIdand writes aPROPOSAL_CREATEDevent@@unique([txHash, eventIndex])+ sequential processing viaprocessIndexerChainEventsinvalidateFreezeCache(keyId)called in bothemergencyFreezeandinitiateUnfreezeDesign notes
Mapwith 30s TTL and explicit invalidation, matching the pattern ofcreators.cache.ts. No new dependency.emitAuditEvent, matching the pattern used inadmin.controllers.ts.emergencyFreezeusesupsert, so repeat calls on an already-frozen key are safe.FreezeEventuniqueness on(txHash, eventIndex)prevents duplicate event ingestion.indexFreezeEventis exported for the indexer worker to call from the contract event stream; it writes the event row, upserts the current state, and invalidates the cache in one call.Verification
Local verification was not possible in this environment because
node_moduleswas not present andcorepack enableis blocked byC:\Program Filespermissions. CI will runpnpm install,pnpm generate,pnpm lint,pnpm build, and tests on the PR.Follow-ups (out of scope)