Skip to content

feat(stellar): implement trustline validation with Redis cache (close…#155

Open
TheWeirdDee wants to merge 1 commit into
Pidoko257:mainfrom
TheWeirdDee:feat/stellar-trustline-validation
Open

feat(stellar): implement trustline validation with Redis cache (close…#155
TheWeirdDee wants to merge 1 commit into
Pidoko257:mainfrom
TheWeirdDee:feat/stellar-trustline-validation

Conversation

@TheWeirdDee

Copy link
Copy Markdown

…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:

  • 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

Description

Brief description of changes.

Related Issue

Fixes #(issue number)

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Code refactoring
  • Performance improvement

Changes Made

Testing

How did you test these changes?

Checklist

  • Code follows project style
  • Self-reviewed my code
  • Commented complex code
  • Updated documentation
  • No new warnings
  • Added tests (if applicable)

Screenshots (if applicable)

Additional Notes

…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
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.

1 participant