rwadurian/backend/services/wallet-service/src
hailin 0f3d03d832 fix(wallet-service): 修复提现失败时不写 UNFREEZE ledger 流水的 bug
问题描述:
withdrawal-status.handler.ts 的 executeWithdrawalFailed() 方法在处理
提现失败事件时,虽然正确地将冻结余额退回到可用余额(usdt_frozen → usdt_available),
但没有在 wallet_ledger_entries 表中写入 UNFREEZE 类型的流水记录,导致审计缺口。

对比 system-withdrawal-application.service.ts 中的同名方法 handleWithdrawalFailed(),
后者在退回余额时正确地写入了 UNFREEZE ledger entry。两者逻辑应保持一致。

影响范围:
所有通过 blockchain-service Kafka 事件触发的提现失败场景(包括链上提现和内部转账),
余额变动不会被记录到流水表中,无法审计追踪。

修复内容:
在 wallet_accounts 余额更新成功后,新增 tx.ledgerEntry.create() 调用,
写入 UNFREEZE 类型的流水记录,包含:
- amount: 实际退回金额(newAvailable - currentAvailable,兼容冻结不足的边缘情况)
- memo: "提现失败退款: {error}"
- payloadJson: toAddress, chainType, error 便于排查

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 09:13:40 -08:00
..
api fix(wallet): 统一使用 accountSequence 查询钱包,修复转账余额不足问题 2026-01-15 23:00:40 -08:00
application fix(wallet-service): 修复提现失败时不写 UNFREEZE ledger 流水的 bug 2026-02-02 09:13:40 -08:00
config feat(wallet-service): add Redis caching for wallet queries 2025-12-06 18:37:13 -08:00
domain fix(wallet-service): 修复提现订单查询使用 userId 的问题 2026-01-08 11:24:31 -08:00
infrastructure fix(wallet-service): 修复提现订单查询使用 userId 的问题 2026-01-08 11:24:31 -08:00
shared feat(wallet/mpc): 增强提现和充值流程可靠性 2025-12-15 19:47:20 -08:00
app.module.ts feat: 省市团队账户及待领取奖励逐笔追踪 2025-12-13 03:32:47 -08:00
main.ts feat(sync): implement Outbox Pattern for reward-service to wallet-service sync 2025-12-10 23:26:49 -08:00