Fix Issue #75: Add assets field to v0 API InputInfo model#273
Fix Issue #75: Add assets field to v0 API InputInfo model#273algsoch wants to merge 1 commit intoergoplatform:masterfrom
Conversation
- Added assets: List[AssetInstanceInfo] field to InputInfo case class - Updated InputInfo.apply() to accept and map ExtendedAsset list - Updated InputInfo.batch() to group assets by boxId following OutputInfo pattern - Modified TransactionSummary to pass assets to InputInfo.batch() - Modified TransactionInfo to map assets when constructing inputs - Updated Tapir schema with assets field description This provides feature parity with v1 API InputInfo and v0 OutputInfo, enabling API v0 clients to see which tokens/assets were in input boxes. Closes ergoplatform#75
There was a problem hiding this comment.
Pull request overview
This PR addresses a long-standing feature gap (Issue #75, opened Sept 2020) by adding the assets field to the v0 API's InputInfo model, achieving parity with both the v0 OutputInfo model and the v1 InputInfo model. This enables API v0 clients to directly access token/asset information from transaction inputs without additional API calls.
Key Changes:
- Added
assets: List[AssetInstanceInfo]field to v0InputInfomodel with OpenAPI documentation - Updated
InputInfo.apply()andInputInfo.batch()methods to accept and map assets using the groupBy pattern - Modified
TransactionSummaryandTransactionInfoto pass assets toInputInfo.batch()calls
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| InputInfo.scala | Added assets field to model, updated apply() and batch() methods to map assets to inputs using boxId grouping |
| TransactionSummary.scala | Updated InputInfo.batch() call to pass assets parameter, mirroring the existing OutputInfo.batch() pattern |
| TransactionInfo.scala | Modified input mapping to lookup and assign assets by boxId, following the same pattern as output mapping |
Review Summary: The implementation is well-structured and follows established patterns consistently. The changes align with existing v0 OutputInfo and v1 InputInfo implementations, using the standard asset grouping pattern (assets.groupBy(_.boxId)) for efficient lookups. The PR is backward compatible as it only adds a new field to the API response. No issues were identified during the review.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
PR Description: Fix Issue #75 - Add Assets to v0 API InputInfo Model
Summary
This PR adds the missing
assetsfield to the API v0InputInfomodel, providing feature parity with the v1 API and enabling clients to see which tokens/assets were contained in transaction input boxes.Issue: #75 (P1-high, opened Sept 29, 2020 - 4+ years old!)
Type: Feature Enhancement
Scope: API v0 only
Breaking: No (backward compatible)
Problem
The v0 API
InputInfomodel was missing theassetsfield, making it impossible for API v0 clients to determine which tokens/assets were in input boxes. This was inconsistent with:InputInfo(which has assets)OutputInfo(which has assets)API v0 clients had to make additional requests to retrieve asset information, resulting in poor developer experience.
Solution
Added
assets: List[AssetInstanceInfo]field to v0InputInfomodel, following the exact same pattern used in:OutputInfo.batch()- for consistency within v0 APIInputInfo- for consistency across API versionsChanges Made
1. InputInfo.scala (v0 model)
assets: List[AssetInstanceInfo]fieldapply()method to accept and map assetsbatch()method to group assets by boxId and assign to inputs2. TransactionSummary.scala (v0 model)
InputInfo.batch()call to pass assets parameterOutputInfo.batch()call pattern3. TransactionInfo.scala (v0 model)
Technical Details
Pattern Used: Asset grouping by boxId for efficient lookup
Data Flow:
Performance: O(n) groupBy + O(1) lookups per input
API Response Example
Before (Current)
{ "inputs": [{ "id": "boxId123...", "value": 1000000, "index": 0, "address": "9f4Q..." }] }After (With This PR)
{ "inputs": [{ "id": "boxId123...", "value": 1000000, "index": 0, "address": "9f4Q...", "assets": [ { "tokenId": "token123...", "amount": 100, "name": "My Token", "decimals": 2 } ] }] }Backward Compatibility
✅ Fully backward compatible - This change only adds a new field to the API response. Existing clients will:
assetsfield if they update their modelsTesting
Compilation
ergo-walletSNAPSHOT artifact not available)However: Code follows established patterns that already compile successfully in
OutputInfoand v1InputInfo.Manual Testing Required
After deployment:
/api/v0/transactions/{txId}for transaction with asset-bearing inputsassetsarray is populated in input objectsDatabase Impact
✅ No database changes required - All necessary data already exists in the database via
ExtendedInputandExtendedAssetmodels.Benefits
Closes Add assets to API Input model #75