likenft-indexer: record token acquisition time and expose token_updat… - #315
Merged
Conversation
…ed_at
- Set nfts.updated_at to the transfer event's block time in UpdateOwner
so it means "when the current owner acquired the token"
- Add optional token_updated_at (max across the account's owned copies)
to /account/{address}/token-booknfts rows
- Return the token's real updated_at (was minted_at) in /account/tokens
- Add backfill-nft-updated-at CLI to stamp existing rows from stored
Transfer/TransferWithMemo events
There was a problem hiding this comment.
Pull request overview
Updates the indexer’s semantics for nfts.updated_at to represent “when the current owner acquired the token”, exposes that timestamp through the OpenAPI responses, and provides a CLI backfill to stamp historical rows based on stored transfer events.
Changes:
- Set
nfts.updated_atfrom the transfer event block timestamp during ownership updates, and return this realupdated_atin/account/tokens. - Add
token_updated_at(latest acquisition time across an account’s owned copies for a class) to/account/{address}/token-booknftsresponses and OpenAPI schema/types. - Add
backfill-nft-updated-atCLI + repository backfill logic with accompanying database tests.
Reviewed changes
Copilot reviewed 12 out of 14 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| likenft-indexer/openapi/schema.yaml | Adds token_updated_at to the BookNFT schema as an optional date-time field. |
| likenft-indexer/openapi/api/oas_schemas_gen.go | Regenerates OpenAPI Go schema types to include TokenUpdatedAt and OptDateTime. |
| likenft-indexer/openapi/api/oas_json_gen.go | Regenerates JSON encode/decode to support token_updated_at and OptDateTime. |
| likenft-indexer/internal/logic/evmeventprocessor/transfer.go | Passes event timestamp into NFT ownership update to stamp acquisition time. |
| likenft-indexer/internal/logic/evmeventprocessor/transfer_with_memo.go | Same as above for TransferWithMemo. |
| likenft-indexer/internal/database/nftclass.go | Computes TokenUpdatedAt as max nfts.updated_at across owned copies per class. |
| likenft-indexer/internal/database/nft.go | Extends UpdateOwner to set updated_at; adds backfill method from transfer events. |
| likenft-indexer/internal/database/nft_test.go | Adds tests for updated-at stamping, token_updated_at aggregation, and backfill behavior. |
| likenft-indexer/internal/api/openapi/token_book_nfts_by_account.go | Uses updated model mapping to include token_updated_at in response rows. |
| likenft-indexer/internal/api/openapi/model/opt_date_time.go | Adds helper to map *time.Time into generated api.OptDateTime. |
| likenft-indexer/internal/api/openapi/model/nftclass.go | Extends BookNFT mapping to include TokenUpdatedAt. |
| likenft-indexer/internal/api/openapi/model/nft.go | Fixes /account/tokens to return e.UpdatedAt (not MintedAt). |
| likenft-indexer/cmd/cli/cmd/root.go | Registers the new backfill CLI command. |
| likenft-indexer/cmd/cli/cmd/backfill_nft_updated_at.go | Adds backfill-nft-updated-at CLI implementation. |
Files not reviewed (2)
- likenft-indexer/openapi/api/oas_json_gen.go: Generated file
- likenft-indexer/openapi/api/oas_schemas_gen.go: Generated file
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+287
to
+293
| // Update by primary key: matching on contract_address would compile | ||
| // EqualFold to ILIKE, which cannot use the btree index and would turn | ||
| // every update into a full table scan. | ||
| nfts, err := r.dbService.Client().NFT.Query(). | ||
| Select(nft.FieldID, nft.FieldContractAddress, nft.FieldTokenID, nft.FieldUpdatedAt). | ||
| All(ctx) | ||
| if err != nil { |
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.
…ed_at