rwadurian/backend/services/wallet-service
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
..
docs refactor(mpc-system): migrate to party-driven architecture with PartyID-based routing 2025-12-05 08:11:28 -08:00
prisma fix(cdc): 添加 Debezium heartbeat 机制防止 WAL 堆积 2026-01-19 17:42:41 -08:00
scripts feat(admin-web): 仪表板改用 planting-service 源数据 2026-01-06 10:47:44 -08:00
src fix(wallet-service): 修复提现失败时不写 UNFREEZE ledger 流水的 bug 2026-02-02 09:13:40 -08:00
test refactor(mpc-system): migrate to party-driven architecture with PartyID-based routing 2025-12-05 08:11:28 -08:00
.env.example refactor(mpc-system): migrate to party-driven architecture with PartyID-based routing 2025-12-05 08:11:28 -08:00
.gitignore refactor(mpc-system): migrate to party-driven architecture with PartyID-based routing 2025-12-05 08:11:28 -08:00
Dockerfile perf(docker): 优化Dockerfile构建,避免最后chown整个目录 2025-12-21 19:31:58 -08:00
deploy.sh fix: convert deploy.sh CRLF to LF and add executable permission 2025-12-07 07:01:13 -08:00
nest-cli.json refactor(mpc-system): migrate to party-driven architecture with PartyID-based routing 2025-12-05 08:11:28 -08:00
package.json fix(backend): 修复构建错误并添加 TOTP 数据库迁移 2025-12-15 05:29:29 -08:00
tsconfig.build.json refactor(mpc-system): migrate to party-driven architecture with PartyID-based routing 2025-12-05 08:11:28 -08:00
tsconfig.json refactor(mpc-system): migrate to party-driven architecture with PartyID-based routing 2025-12-05 08:11:28 -08:00