feat(mining-wallet): publish outbox events for system/pool accounts
Add WalletSystemAccountCreated and WalletPoolAccountCreated events: - seed.ts: publish events when creating HQ/OP/FEE and pool accounts - contribution-wallet.service.ts: publish events when auto-creating province/city system accounts This enables mining-admin-service to sync system accounts via CDC. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
0bbb52284c
commit
eff71a6b22
|
|
@ -19,7 +19,7 @@ async function main() {
|
|||
});
|
||||
|
||||
if (!existing) {
|
||||
await prisma.systemAccount.create({
|
||||
const created = await prisma.systemAccount.create({
|
||||
data: {
|
||||
accountType: account.accountType as any,
|
||||
name: account.name,
|
||||
|
|
@ -27,6 +27,35 @@ async function main() {
|
|||
isActive: true,
|
||||
},
|
||||
});
|
||||
|
||||
// 发布系统账户创建事件到 Outbox
|
||||
await prisma.outboxEvent.create({
|
||||
data: {
|
||||
aggregateType: 'SystemAccount',
|
||||
aggregateId: created.id,
|
||||
eventType: 'WalletSystemAccountCreated',
|
||||
topic: 'mining-wallet.system-account.created',
|
||||
key: created.code,
|
||||
payload: {
|
||||
id: created.id,
|
||||
accountType: created.accountType,
|
||||
name: created.name,
|
||||
code: created.code,
|
||||
provinceId: null,
|
||||
cityId: null,
|
||||
shareBalance: 0,
|
||||
usdtBalance: 0,
|
||||
greenPointBalance: 0,
|
||||
frozenShare: 0,
|
||||
frozenUsdt: 0,
|
||||
totalInflow: 0,
|
||||
totalOutflow: 0,
|
||||
blockchainAddress: null,
|
||||
isActive: created.isActive,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
console.log(`Created system account: ${account.code}`);
|
||||
} else {
|
||||
console.log(`System account already exists: ${account.code}`);
|
||||
|
|
@ -62,7 +91,7 @@ async function main() {
|
|||
});
|
||||
|
||||
if (!existing) {
|
||||
await prisma.poolAccount.create({
|
||||
const created = await prisma.poolAccount.create({
|
||||
data: {
|
||||
poolType: pool.poolType as any,
|
||||
name: pool.name,
|
||||
|
|
@ -73,6 +102,29 @@ async function main() {
|
|||
isActive: true,
|
||||
},
|
||||
});
|
||||
|
||||
// 发布池账户创建事件到 Outbox
|
||||
await prisma.outboxEvent.create({
|
||||
data: {
|
||||
aggregateType: 'PoolAccount',
|
||||
aggregateId: created.id,
|
||||
eventType: 'WalletPoolAccountCreated',
|
||||
topic: 'mining-wallet.pool-account.created',
|
||||
key: created.poolType,
|
||||
payload: {
|
||||
id: created.id,
|
||||
poolType: created.poolType,
|
||||
name: created.name,
|
||||
balance: created.balance.toString(),
|
||||
totalInflow: 0,
|
||||
totalOutflow: 0,
|
||||
targetBurn: created.targetBurn?.toString() || null,
|
||||
remainingBurn: created.remainingBurn?.toString() || null,
|
||||
isActive: created.isActive,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
console.log(`Created pool account: ${pool.poolType}`);
|
||||
} else {
|
||||
console.log(`Pool account already exists: ${pool.poolType}`);
|
||||
|
|
|
|||
|
|
@ -331,6 +331,35 @@ export class ContributionWalletService {
|
|||
},
|
||||
});
|
||||
this.logger.log(`Auto-created province system account: ${account.code}`);
|
||||
|
||||
// 发布系统账户创建事件到 Outbox
|
||||
await tx.outboxEvent.create({
|
||||
data: {
|
||||
aggregateType: 'SystemAccount',
|
||||
aggregateId: account.id,
|
||||
eventType: 'WalletSystemAccountCreated',
|
||||
topic: 'mining-wallet.system-account.created',
|
||||
key: account.code,
|
||||
payload: {
|
||||
id: account.id,
|
||||
accountType: account.accountType,
|
||||
name: account.name,
|
||||
code: account.code,
|
||||
provinceId: account.provinceId,
|
||||
cityId: null,
|
||||
shareBalance: 0,
|
||||
usdtBalance: 0,
|
||||
greenPointBalance: 0,
|
||||
frozenShare: 0,
|
||||
frozenUsdt: 0,
|
||||
totalInflow: 0,
|
||||
totalOutflow: 0,
|
||||
blockchainAddress: null,
|
||||
isActive: account.isActive,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return account;
|
||||
}
|
||||
|
||||
|
|
@ -387,6 +416,35 @@ export class ContributionWalletService {
|
|||
},
|
||||
});
|
||||
this.logger.log(`Auto-created city system account: ${account.code}`);
|
||||
|
||||
// 发布系统账户创建事件到 Outbox
|
||||
await tx.outboxEvent.create({
|
||||
data: {
|
||||
aggregateType: 'SystemAccount',
|
||||
aggregateId: account.id,
|
||||
eventType: 'WalletSystemAccountCreated',
|
||||
topic: 'mining-wallet.system-account.created',
|
||||
key: account.code,
|
||||
payload: {
|
||||
id: account.id,
|
||||
accountType: account.accountType,
|
||||
name: account.name,
|
||||
code: account.code,
|
||||
provinceId: account.provinceId,
|
||||
cityId: account.cityId,
|
||||
shareBalance: 0,
|
||||
usdtBalance: 0,
|
||||
greenPointBalance: 0,
|
||||
frozenShare: 0,
|
||||
frozenUsdt: 0,
|
||||
totalInflow: 0,
|
||||
totalOutflow: 0,
|
||||
blockchainAddress: null,
|
||||
isActive: account.isActive,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return account;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue