fix(blockchain+trading): 修复做市商区块链充值无法入账的三个 bug

1. OutboxPublisherService 未注册到 NestJS 模块,导致充值确认事件永远
   停留在 outbox_events 表 PENDING 状态,无法发布到 Kafka
2. trading-service 消费者监听的 Kafka topic 和 event type 与发布端不匹配
   (blockchain.market_maker.deposits → mining_blockchain.market_maker.deposits)
3. 消费者只更新 market_maker_config 余额,但 API 从 trading_accounts 读取
   余额,导致入账后前端仍显示 0

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-02-02 03:30:30 -08:00
parent 1f434f32fb
commit 758babfdf8
2 changed files with 18 additions and 4 deletions

View File

@ -3,6 +3,8 @@ import { InfrastructureModule } from '@/infrastructure/infrastructure.module';
import { DomainModule } from '@/domain/domain.module';
import { MpcTransferInitializerService } from './services/mpc-transfer-initializer.service';
import { MarketMakerDepositDetectionService } from './services/market-maker-deposit-detection.service';
import { OutboxPublisherService } from './services/outbox-publisher.service';
import { DepositAckConsumerService } from '@/infrastructure/kafka/deposit-ack-consumer.service';
@Module({
imports: [InfrastructureModule, DomainModule],
@ -11,7 +13,11 @@ import { MarketMakerDepositDetectionService } from './services/market-maker-depo
MpcTransferInitializerService,
// 做市商充值检测服务
MarketMakerDepositDetectionService,
// Outbox 事件发布服务(将确认的充值事件发布到 Kafka
OutboxPublisherService,
// 充值 ACK 消费者(接收 wallet-service 的确认回执)
DepositAckConsumerService,
],
exports: [],
exports: [OutboxPublisherService],
})
export class ApplicationModule {}

View File

@ -73,7 +73,7 @@ export class MarketMakerDepositConsumerService implements OnModuleInit, OnModule
return;
}
const topic = 'blockchain.market_maker.deposits';
const topic = 'mining_blockchain.market_maker.deposits';
try {
await this.consumer.connect();
@ -123,7 +123,7 @@ export class MarketMakerDepositConsumerService implements OnModuleInit, OnModule
const eventData = JSON.parse(message.value.toString());
// 检查事件类型
if (eventData.eventType !== 'blockchain.market_maker.deposit.confirmed') {
if (eventData.eventType !== 'mining_blockchain.market_maker.deposit.confirmed') {
return;
}
@ -210,7 +210,7 @@ export class MarketMakerDepositConsumerService implements OnModuleInit, OnModule
: marketMaker.cashBalance;
const newBalance = currentBalance.add(new Prisma.Decimal(payload.amountFormatted));
// 更新做市商余额
// 更新做市商配置余额
await tx.marketMakerConfig.update({
where: { id: marketMaker.id },
data: {
@ -218,6 +218,14 @@ export class MarketMakerDepositConsumerService implements OnModuleInit, OnModule
},
});
// 同步更新交易账户余额getConfig 从 trading_accounts 读取余额)
await tx.tradingAccount.update({
where: { accountSequence: marketMaker.accountSequence },
data: {
[assetField]: { increment: new Prisma.Decimal(payload.amountFormatted) },
},
});
// 3. 创建流水记录
const ledger = await tx.marketMakerLedger.create({
data: {