Skip to content

feat: indexer-backed token provider#194

Open
dhyaniarun1993 wants to merge 4 commits intomainfrom
arun/feat/indexer-provider
Open

feat: indexer-backed token provider#194
dhyaniarun1993 wants to merge 4 commits intomainfrom
arun/feat/indexer-provider

Conversation

@dhyaniarun1993
Copy link
Copy Markdown
Member

Replaces per-request gRPC ACS scans with reads from the indexer's pre-materialized PostgreSQL tables.

Problem

The only Provider implementation was Canton, which calls GetActiveContracts on every balanceOf and totalSupply request. GetTotalSupply fetches the entire ACS for CIP56Holding and filters client-side; GetBalanceByFingerprint adds a second gRPC round-trip to resolve the fingerprint to a party via GetFingerprintMapping. The indexer already materialises this data into indexer_balances and indexer_tokens via its streaming processor.

Changes

pkg/indexer/client/ — new package: HTTP client for the indexer's admin API

  • Client interface mirrors indexer/service.Service (9 methods) so callers are agnostic to whether they talk to an in-process service or a remote indexer
  • HTTP struct implements all methods: token queries, balance queries, event/audit-trail queries
  • Pagination forwarded as ?page=&limit= query params; EventFilter.EventType forwarded as ?event_type=
  • 404 responses surfaced as apperrors.ResourceNotFoundError, consistent with the in-process service

pkg/token/provider/indexer.go — new Provider implementation backed by the indexer client

  • Thin adapter: resolves tokenSymbol → InstrumentAdmin from a configured instruments map, then delegates to the client
  • GetBalance maps ResourceNotFoundError (party holds zero) → "0" consistent with the Canton provider's no-holdings path

pkg/token/service.go / pkg/cantonsdk/token/client.go — eliminate double lookup

  • Provider.GetBalance now accepts partyID instead of fingerprint
  • service.getBalance passes usr.CantonPartyID directly — the user record was already loaded, no reason to discard the partyID
  • GetBalanceByPartyID exposed on the Canton Token interface; Canton provider delegates to it, eliminating the GetFingerprintMapping gRPC round-trip that was happening just to undo information already known

Closes #190

@dhyaniarun1993 dhyaniarun1993 self-assigned this Apr 8, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces an HTTP client for the indexer's admin API and a new Indexer token provider that utilizes this client to fetch balances and total supply from pre-materialized PostgreSQL tables. Additionally, it refactors the Provider and Token interfaces to use CantonPartyID instead of user fingerprints for balance queries, ensuring consistency across the service layer. Feedback was provided regarding the normalization of the base URL in the HTTP client to prevent malformed paths, the importance of handling potential decoding errors when processing non-2xx responses, and a recommendation to defensively copy the instruments map in the Indexer provider to prevent external mutations.

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.

feat(token): create IndexerProvider for balance and supply queries

2 participants