feat: implement GET /account/:id/operations endpoint - #654
Open
rahimatonize wants to merge 1 commit into
Open
Conversation
|
@rahimatonize Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
- Add new operations endpoint with pagination support - Support type filtering (?type=payment, etc.) - Return normalized operations with type-specific fields - Include comprehensive test coverage - Handle all operation types (payment, create_account, change_trust, etc.) - Proper error handling for invalid types and non-existent accounts - ISO 8601 timestamp formatting Resolves stellarkit-lab-devtools#626
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.
Implements a new GET /account/:id/operations endpoint that provides developers with a clean, dedicated way to retrieve account operations. This endpoint offers normalized operation data with pagination and type filtering, making it ideal for building operation explorers and activity feeds.
✨ Features
Dedicated Operations Endpoint: Returns a paginated list of operations for any Stellar account
Type Filtering: Support for ?type= query parameter to filter by operation type (e.g., ?type=payment, ?type=change_trust)
Full Pagination: Supports limit and cursor parameters for efficient data retrieval
Normalized Response: Consistent structure with operationId, type, createdAt, transactionHash, and type-specific fields
Type-Specific Fields: Each operation includes relevant fields based on its type:
Payment: amount, asset, from, to
Create Account: startingBalance, funder, account
Change Trust: asset, limit, trustor
Manage Offers: amount, price, buyingAsset, sellingAsset, offerId
Path Payments: amount, sourceAmount, sourceAsset, asset, from, to
And more...
🔧 Technical Details
Endpoint: GET /account/:id/operations
Query Parameters:
limit (number, default: 20, max: 200) - Number of operations to return
cursor (string, optional) - Pagination cursor for fetching subsequent pages
type (string, optional) - Filter by operation type (e.g., payment, create_account, change_trust)
Response Format:
{
"success": true,
"data": {
"operations": [
{
"operationId": "15144509952245761",
"type": "payment",
"createdAt": "2026-07-10T01:21:00.000Z",
"transactionHash": "b9f5876159b7a4fe082c8c2234d953ce14744c17f4bd424f5d6cc0be1fababe5",
"amount": "24.1980163",
"asset": {
"code": "XLM",
"issuer": null,
"type": "native"
},
"from": "GAEOGWJQGL...",
"to": "GAAZI4TCR3..."
}
],
"total": 5,
"limit": 20,
"cursor": "15144509952245761"
}
}
Error Handling:
Returns 404 if the account does not exist
Returns 400 for invalid operation types with a list of valid types
Returns 400 for invalid pagination parameters
✅ Testing
✅ Comprehensive test suite with 60+ test cases
✅ Manual verification script confirms all functionality works
✅ Validates response structure and required fields
✅ Tests pagination with limit and cursor
✅ Tests type filtering for multiple operation types
✅ Validates error handling for invalid inputs
✅ Verifies ISO 8601 timestamp formatting
✅ All tests pass successfully
Test Results:
✅ Test 1 passed - Basic operations retrieval
✅ Test 2 passed - Type filtering (payment)
✅ Test 3 passed - Invalid operation type handling
✅ Test 4 passed - Account validation
✅ Test 5 passed - Pagination
✅✅✅ ALL TESTS PASSED ✅✅✅
📝 Changes Made
New Endpoint (
account.js
):
Added GET /account/:id/operations route handler
Implemented operation type filtering
Added normalization for all operation types
Proper asset normalization for native and issued assets
Test Coverage (
account.operations.test.js
):
60+ test cases covering all functionality
Tests for pagination, filtering, validation, and error handling
Manual Verification (test-operations-endpoint.js):
Quick verification script for manual testing
Demonstrates endpoint functionality
🔍 Code Quality
✅ Follows existing project patterns and conventions
✅ Proper error handling with meaningful error messages
✅ Consistent response format matching other endpoints
✅ No merge conflicts or syntax errors
✅ Validation reuses existing utilities
✅ ISO 8601 timestamp formatting
📖 Usage Examples
Get recent operations:
GET /account/GAAZI4TCR3TY5OJHCTJC2A4QSY6CJWJH5IAJTGKIN2ER7LBNVKOCCWN7/operations?limit=10
Filter by payment type:
GET /account/GAAZI4TCR3TY5OJHCTJC2A4QSY6CJWJH5IAJTGKIN2ER7LBNVKOCCWN7/operations?type=payment&limit=20
Paginate results:
GET /account/GAAZI4TCR3TY5OJHCTJC2A4QSY6CJWJH5IAJTGKIN2ER7LBNVKOCCWN7/operations?limit=50&cursor=15144509952245761
🎨 Benefits
Developer Experience: Clean, dedicated endpoint for operations (vs. filtering from full transaction history)
Performance: Pagination support prevents large data transfers
Flexibility: Type filtering allows targeted queries
Consistency: Follows existing API patterns and response formats
Completeness: Handles all Stellar operation types with appropriate fields
📋 Checklist
Implementation matches acceptance criteria
All tests pass
Code follows project conventions
Error handling is comprehensive
Response format is consistent
Documentation is clear
No breaking changes
Ready for review
Closes #626