Skip to content

fix: wallet balance cache, Stellar secret validation, destination check, WalletsService cleanup#883

Merged
portableDD merged 2 commits into
Nexacore-Org:mainfrom
prismn:prismn-feature-bundle
Jun 28, 2026
Merged

fix: wallet balance cache, Stellar secret validation, destination check, WalletsService cleanup#883
portableDD merged 2 commits into
Nexacore-Org:mainfrom
prismn:prismn-feature-bundle

Conversation

@prismn

@prismn prismn commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Changes

#869 — Wallet balance cache migration

  • Replaced in-memory Map with Redis-backed cache via global CacheModule
  • Cache key: wallet-balances:${userId} with configurable TTL (WALLET_BALANCE_CACHE_TTL_SECONDS, default 30s)
  • Cache invalidated on successful deposit/withdrawal via UsersService.invalidateWalletBalanceCache()

#868 — Secure Stellar secret key handling

  • Removed (this as any).configService?.get() pattern — properly typed ConfigService injection
  • Added onModuleInit() that validates STELLAR_HOT_WALLET_SECRET at startup (fail-fast)
  • Added getStellarSecretKey() with proper error handling
  • Made STELLAR_HOT_WALLET_SECRET a required field in Zod env validation schema

#867 — Eliminate JSONB balance bypass

  • Fixed duplicate variable declarations and duplicate method signature in WalletsService (compile errors)
  • All balance operations already go through WalletsService — no remaining user.balances JSONB access
  • WalletsService.adjustBalance already uses pessimistic_write row-level locking

#789 — Destination account validation

  • Added StellarService.accountExists(address) — queries Horizon /accounts/{address}
  • Result cached in Redis for 60 seconds per address
  • createWithdrawal checks destination before proceeding; returns 400 with clear message if unfunded
  • Added destinationAddress field to WithdrawalDto

Files Changed

  • src/config/env.validation.ts — required STELLAR_HOT_WALLET_SECRET, added WALLET_BALANCE_CACHE_TTL_SECONDS
  • src/users/users.service.ts — Redis-backed wallet balance cache with invalidation
  • src/wallet/wallets.service.ts — fixed duplicate declarations (compile errors)
  • src/stellar/stellar.service.ts — added accountExists() with Redis caching
  • src/transactions/transactions.service.ts — ConfigService injection, getStellarSecretKey, destination check, cache invalidation
  • src/transactions/transactions.module.ts — imported StellarModule

Closes #869
Closes #868
Closes #867
Closes #789

…count check, WalletsService fixes

- Nexacore-Org#869: Replace in-memory wallet balance cache with Redis-backed cache via CacheModule
- Nexacore-Org#868: Inject ConfigService properly, add getStellarSecretKey with startup validation
- Nexacore-Org#867: Fix WalletsService duplicate declarations, ensure all balance ops use WalletsService
- Nexacore-Org#789: Add StellarService.accountExists() with 60s Redis cache, check destination before withdrawal
- Add WALLET_BALANCE_CACHE_TTL_SECONDS env var for cache TTL configuration
- Make STELLAR_HOT_WALLET_SECRET required in Zod env schema (fail-fast startup)
@drips-wave

drips-wave Bot commented Jun 27, 2026

Copy link
Copy Markdown

@prismn 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! 🚀

Learn more about application limits

@portableDD

Copy link
Copy Markdown
Contributor

@prismn please resolve conflicts

@prismn

prismn commented Jun 28, 2026

Copy link
Copy Markdown
Contributor Author

@portableDD it has been fixed, tanks

@portableDD portableDD merged commit 20b8526 into Nexacore-Org:main Jun 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment