Skip to content

Fix Issue #75: Add assets field to v0 API InputInfo model#273

Open
algsoch wants to merge 1 commit intoergoplatform:masterfrom
algsoch:fix/issue-75-add-assets-input-v0-algsoch
Open

Fix Issue #75: Add assets field to v0 API InputInfo model#273
algsoch wants to merge 1 commit intoergoplatform:masterfrom
algsoch:fix/issue-75-add-assets-input-v0-algsoch

Conversation

@algsoch
Copy link

@algsoch algsoch commented Dec 13, 2025

PR Description: Fix Issue #75 - Add Assets to v0 API InputInfo Model

Summary

This PR adds the missing assets field to the API v0 InputInfo model, 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 InputInfo model was missing the assets field, making it impossible for API v0 clients to determine which tokens/assets were in input boxes. This was inconsistent with:

  • The v1 API InputInfo (which has assets)
  • The v0 API 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 v0 InputInfo model, following the exact same pattern used in:

  • v0 OutputInfo.batch() - for consistency within v0 API
  • v1 InputInfo - for consistency across API versions

Changes Made

1. InputInfo.scala (v0 model)

  • ✅ Added assets: List[AssetInstanceInfo] field
  • ✅ Updated OpenAPI schema with field description
  • ✅ Modified apply() method to accept and map assets
  • ✅ Modified batch() method to group assets by boxId and assign to inputs

2. TransactionSummary.scala (v0 model)

  • ✅ Updated InputInfo.batch() call to pass assets parameter
  • ✅ Mirrors existing OutputInfo.batch() call pattern

3. TransactionInfo.scala (v0 model)

  • ✅ Updated input mapping to lookup and assign assets by boxId
  • ✅ Follows same pattern as existing output mapping

Technical Details

Pattern Used: Asset grouping by boxId for efficient lookup

val groupedAssets = assets.groupBy(_.boxId)
inputs.map(in => InputInfo(in, groupedAssets.get(in.input.boxId).toList.flatten))

Data Flow:

ExtendedAsset (DB) → Group by boxId → AssetInstanceInfo (API) → InputInfo.assets

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:

  • Receive the new assets field if they update their models
  • Continue to work if they ignore unknown fields
  • Not experience any breaking changes

Testing

Compilation

⚠️ Cannot verify compilation due to pre-existing dependency issue (ergo-wallet SNAPSHOT artifact not available)

However: Code follows established patterns that already compile successfully in OutputInfo and v1 InputInfo.

Manual Testing Required

After deployment:

  1. Query /api/v0/transactions/{txId} for transaction with asset-bearing inputs
  2. Verify assets array is populated in input objects
  3. Verify assets are sorted by index
  4. Compare with v1 API response for consistency
  5. Test with inputs having no assets (should return empty array)

Database Impact

No database changes required - All necessary data already exists in the database via ExtendedInput and ExtendedAsset models.

Benefits

  • API Completeness - v0 API now provides complete transaction information
  • Consistency - Both v0 and v1 APIs expose input assets
  • Developer Experience - Eliminates need for additional API calls
  • Backward Compatible - No breaking changes for existing clients
  • Pattern Alignment - Follows established OutputInfo pattern
    Closes Add assets to API Input model #75

- 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
Copilot AI review requested due to automatic review settings December 13, 2025 20:18
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 v0 InputInfo model with OpenAPI documentation
  • Updated InputInfo.apply() and InputInfo.batch() methods to accept and map assets using the groupBy pattern
  • Modified TransactionSummary and TransactionInfo to pass assets to InputInfo.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.

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.

Add assets to API Input model

1 participant