Description
Complete the Soroban blockchain indexer by filling in the placeholder methods in soroban.indexer.ts, integrating with the soroban-client SDK, and adding reliable event/transaction processing.
Background
soroban.indexer.ts currently contains stubbed implementations for key indexing behavior. The indexer is expected to:
- fetch and persist blockchain transactions
- stream and store smart contract events
- manage unprocessed events
- update transaction status reliably
Without these implementations, the platform cannot track Soroban blockchain activity or respond to contract events.
Scope
- Implement
indexBlock(blockNumber)
- Implement
indexContractEvents()
- Add
indexTransaction(txHash, type, metadata)
- Add
getUnprocessedEvents()
- Add
markEventProcessed(eventId)
- Integrate all of the above with
soroban-client
- Ensure transaction status is tracked correctly and contract events are streamed/processed
Goals
- Make
SorobanIndexer functional and production-ready
- Use real Soroban ledger and event APIs rather than placeholders
- Persist transactions and events into Prisma models
- Provide an event processing workflow for downstream consumers
- Track transaction confirmation status and handle retries/fresh indexing
Requirements
1. indexBlock(blockNumber)
- Fetch ledger/transaction data from Soroban for a given block/ledger sequence
- Use
Server methods from soroban-client to load the ledger and its transactions
- Parse each transaction and its effects
- Persist transaction records into
prisma.blockchainTransaction
- Handle blocks with multiple transactions, skipped or failed transactions
- Update transaction status using real on-chain confirmation state
- Avoid duplicate writes via upsert or duplicate key handling
2. indexContractEvents()
- Subscribe to or poll Soroban contract events using
soroban-client
- Filter events for
config.soroban.contractAddress and relevant event names
- Persist events into
prisma.contractEvent with metadata and a processed flag
- Support streaming or cursor-based polling so events are not missed
- Handle disconnects and reconnect/retry logic
3. indexTransaction(txHash, type, metadata)
- Create or update a transaction record for an arbitrary transaction hash
- Include:
txHash
- transaction
type
fromAddress
toAddress
amount
currency
contractAddress
functionName
parameters
status based on actual Soroban transaction result
blockNumber
timestamp
- Use status values like
PENDING, CONFIRMED, FAILED
- Track and update transaction status when confirmed on-chain
- Catch Prisma duplicate errors gracefully
4. getUnprocessedEvents()
- Return a batch of
contractEvent rows where processed = false
- Limit the result size for worker processing
- Use ordering to process oldest events first
- Support downstream event consumer loop in blockchain.worker.ts
5. markEventProcessed(eventId)
- Update a contract event row to
processed = true
- Optionally record processing metadata/timestamp
- Ensure this is idempotent and safe for retry
Integration requirements
- Use
soroban-client SDK APIs rather than placeholder comments
- Prefer real Soroban JSON-RPC endpoints from
config.soroban.networkUrl
- Keep indexer loop in sync with existing index.ts startup
- Ensure
indexLatestTransactions() and indexContractEvents() coordinate properly
- Add error handling and backoff for network or RPC failures
- Make event indexing resilient across restarts
Acceptance criteria
indexBlock() fetches and indexes transactions from actual Soroban ledgers
indexContractEvents() pulls or streams contract events and stores them
indexTransaction() persists real transaction metadata and status
getUnprocessedEvents() returns unprocessed contract events reliably
markEventProcessed() marks events as processed after handling
- Transaction records include correct on-chain status and ledger/block info
- The indexer can resume from the last processed ledger or event after restart
- Existing worker flows in blockchain.worker.ts can process events correctly
Notes
- If the current Prisma schema lacks the required fields, update it as needed
- Document any new config values or assumptions in index.ts
- Keep the implementation clean and use a service-oriented style
- Optionally add helper methods for event cursor persistence and transaction polling
Description
Complete the Soroban blockchain indexer by filling in the placeholder methods in soroban.indexer.ts, integrating with the
soroban-clientSDK, and adding reliable event/transaction processing.Background
soroban.indexer.ts currently contains stubbed implementations for key indexing behavior. The indexer is expected to:
Without these implementations, the platform cannot track Soroban blockchain activity or respond to contract events.
Scope
indexBlock(blockNumber)indexContractEvents()indexTransaction(txHash, type, metadata)getUnprocessedEvents()markEventProcessed(eventId)soroban-clientGoals
SorobanIndexerfunctional and production-readyRequirements
1.
indexBlock(blockNumber)Servermethods fromsoroban-clientto load the ledger and its transactionsprisma.blockchainTransaction2.
indexContractEvents()soroban-clientconfig.soroban.contractAddressand relevant event namesprisma.contractEventwith metadata and aprocessedflag3.
indexTransaction(txHash, type, metadata)txHashtypefromAddresstoAddressamountcurrencycontractAddressfunctionNameparametersstatusbased on actual Soroban transaction resultblockNumbertimestampPENDING,CONFIRMED,FAILED4.
getUnprocessedEvents()contractEventrows whereprocessed = false5.
markEventProcessed(eventId)processed = trueIntegration requirements
soroban-clientSDK APIs rather than placeholder commentsconfig.soroban.networkUrlindexLatestTransactions()andindexContractEvents()coordinate properlyAcceptance criteria
indexBlock()fetches and indexes transactions from actual Soroban ledgersindexContractEvents()pulls or streams contract events and stores themindexTransaction()persists real transaction metadata and statusgetUnprocessedEvents()returns unprocessed contract events reliablymarkEventProcessed()marks events as processed after handlingNotes