diff --git a/backend/services/mining-blockchain-service/src/application/application.module.ts b/backend/services/mining-blockchain-service/src/application/application.module.ts index b0677eab..4ea6b85a 100644 --- a/backend/services/mining-blockchain-service/src/application/application.module.ts +++ b/backend/services/mining-blockchain-service/src/application/application.module.ts @@ -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 {} diff --git a/backend/services/trading-service/src/infrastructure/kafka/market-maker-deposit-consumer.service.ts b/backend/services/trading-service/src/infrastructure/kafka/market-maker-deposit-consumer.service.ts index 12971a31..9531571f 100644 --- a/backend/services/trading-service/src/infrastructure/kafka/market-maker-deposit-consumer.service.ts +++ b/backend/services/trading-service/src/infrastructure/kafka/market-maker-deposit-consumer.service.ts @@ -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: {