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:
parent
1f434f32fb
commit
758babfdf8
|
|
@ -3,6 +3,8 @@ import { InfrastructureModule } from '@/infrastructure/infrastructure.module';
|
||||||
import { DomainModule } from '@/domain/domain.module';
|
import { DomainModule } from '@/domain/domain.module';
|
||||||
import { MpcTransferInitializerService } from './services/mpc-transfer-initializer.service';
|
import { MpcTransferInitializerService } from './services/mpc-transfer-initializer.service';
|
||||||
import { MarketMakerDepositDetectionService } from './services/market-maker-deposit-detection.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({
|
@Module({
|
||||||
imports: [InfrastructureModule, DomainModule],
|
imports: [InfrastructureModule, DomainModule],
|
||||||
|
|
@ -11,7 +13,11 @@ import { MarketMakerDepositDetectionService } from './services/market-maker-depo
|
||||||
MpcTransferInitializerService,
|
MpcTransferInitializerService,
|
||||||
// 做市商充值检测服务
|
// 做市商充值检测服务
|
||||||
MarketMakerDepositDetectionService,
|
MarketMakerDepositDetectionService,
|
||||||
|
// Outbox 事件发布服务(将确认的充值事件发布到 Kafka)
|
||||||
|
OutboxPublisherService,
|
||||||
|
// 充值 ACK 消费者(接收 wallet-service 的确认回执)
|
||||||
|
DepositAckConsumerService,
|
||||||
],
|
],
|
||||||
exports: [],
|
exports: [OutboxPublisherService],
|
||||||
})
|
})
|
||||||
export class ApplicationModule {}
|
export class ApplicationModule {}
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ export class MarketMakerDepositConsumerService implements OnModuleInit, OnModule
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const topic = 'blockchain.market_maker.deposits';
|
const topic = 'mining_blockchain.market_maker.deposits';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await this.consumer.connect();
|
await this.consumer.connect();
|
||||||
|
|
@ -123,7 +123,7 @@ export class MarketMakerDepositConsumerService implements OnModuleInit, OnModule
|
||||||
const eventData = JSON.parse(message.value.toString());
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -210,7 +210,7 @@ export class MarketMakerDepositConsumerService implements OnModuleInit, OnModule
|
||||||
: marketMaker.cashBalance;
|
: marketMaker.cashBalance;
|
||||||
const newBalance = currentBalance.add(new Prisma.Decimal(payload.amountFormatted));
|
const newBalance = currentBalance.add(new Prisma.Decimal(payload.amountFormatted));
|
||||||
|
|
||||||
// 更新做市商余额
|
// 更新做市商配置余额
|
||||||
await tx.marketMakerConfig.update({
|
await tx.marketMakerConfig.update({
|
||||||
where: { id: marketMaker.id },
|
where: { id: marketMaker.id },
|
||||||
data: {
|
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. 创建流水记录
|
// 3. 创建流水记录
|
||||||
const ledger = await tx.marketMakerLedger.create({
|
const ledger = await tx.marketMakerLedger.create({
|
||||||
data: {
|
data: {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue