feat(stellar): implement trustline validation with Redis cache (close…#155
Open
TheWeirdDee wants to merge 1 commit into
Open
feat(stellar): implement trustline validation with Redis cache (close…#155TheWeirdDee wants to merge 1 commit into
TheWeirdDee wants to merge 1 commit into
Conversation
…Pidoko257#36) Before submitting a non-native Stellar asset payment, the payment service now validates that the recipient account holds a trustline for the asset. Validation results are cached in Redis for 60 seconds to avoid redundant Horizon round-trips on hot payment paths. Changes: - Add ERR_MISSING_TRUSTLINE error code mapped to HTTP 400 - Add `meta` field to AppError/errorHandler: always included in API responses (not stripped in production) so the changeTrustXdr is visible to clients - Add MissingTrustlineError class (extends BusinessLogicError) carrying assetCode, assetIssuer, recipientAddress, and changeTrustXdr - Add validateRecipientTrustline() in src/stellar/trustlineValidation.ts: - Skips check for native XLM - Resolves muxed (M-address) to base address before lookup - Redis cache key: trustline:validation:{address}:{code}:{issuer}, TTL 60 s - On cache miss: loads account from Horizon, checks balances - On missing trustline: builds unsigned ChangeTrust XDR for recipient to sign - Unfunded (404) accounts: fall back to dummy-sequence XDR template - Replace ad-hoc trustline checks in stellarService.sendPayment() and payments.executePathPayment() with validateRecipientTrustline() - Add localized ERR_MISSING_TRUSTLINE messages for en, fr, es, pt, sw - Add 21 tests covering cache hit/miss, 404, Horizon errors, XDR correctness, error class shape, cache TTL and key format (35/35 tests passing) - Fix pre-existing payments.test.ts issues: mock accounts were missing the Account interface methods (sequenceNumber, accountId) required by stellar-base 11, and the strictReceivePaths assertion had the wrong signature
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.
…s #36)
Before submitting a non-native Stellar asset payment, the payment service now validates that the recipient account holds a trustline for the asset. Validation results are cached in Redis for 60 seconds to avoid redundant Horizon round-trips on hot payment paths.
Changes:
metafield to AppError/errorHandler: always included in API responses (not stripped in production) so the changeTrustXdr is visible to clientsDescription
Brief description of changes.
Related Issue
Fixes #(issue number)
Type of Change
Changes Made
Testing
How did you test these changes?
Checklist
Screenshots (if applicable)
Additional Notes