feat(identity-service): 添加手动钱包重试 API
功能: - 新增 POST /user/wallet/retry 接口 - 用户可主动触发钱包生成重试 - 自动检查钱包是否已完成,避免重复生成 - 幂等操作:重新发布 UserAccountCreatedEvent 实现: - UserAccountController: 添加 wallet/retry 端点 - UserApplicationService: 实现 retryWalletGeneration 方法 - 重用现有的 createWalletGenerationEvent 方法 - 更新 Redis 状态为 pending 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
959fe93092
commit
ceee3167cb
|
|
@ -212,6 +212,15 @@ export class UserAccountController {
|
|||
);
|
||||
}
|
||||
|
||||
@Post('wallet/retry')
|
||||
@ApiBearerAuth()
|
||||
@ApiOperation({ summary: '手动重试钱包生成', description: '当钱包生成失败或超时时,用户可手动触发重试' })
|
||||
@ApiResponse({ status: 200, description: '重试请求已提交' })
|
||||
async retryWalletGeneration(@CurrentUser() user: CurrentUserData) {
|
||||
await this.userService.retryWalletGeneration(user.userId);
|
||||
return { message: '钱包生成重试已触发,请稍后查询钱包状态' };
|
||||
}
|
||||
|
||||
@Put('mnemonic/backup')
|
||||
@ApiBearerAuth()
|
||||
@ApiOperation({ summary: '标记助记词已备份' })
|
||||
|
|
|
|||
|
|
@ -807,6 +807,59 @@ export class UserApplicationService {
|
|||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 手动重试钱包生成
|
||||
*
|
||||
* 用户可以通过此方法手动触发钱包生成重试
|
||||
* 幂等操作:重新发布 UserAccountCreatedEvent
|
||||
*/
|
||||
async retryWalletGeneration(userId: string): Promise<void> {
|
||||
this.logger.log(`[WALLET-RETRY] Manual retry requested for user: ${userId}`);
|
||||
|
||||
try {
|
||||
// 1. 获取用户账号信息
|
||||
const userIdObj = UserId.create(BigInt(userId));
|
||||
const account = await this.userRepository.findById(userIdObj);
|
||||
|
||||
if (!account) {
|
||||
throw new ApplicationError('用户不存在');
|
||||
}
|
||||
|
||||
// 2. 检查钱包是否已经生成完成
|
||||
const wallets = account.getAllWalletAddresses();
|
||||
const kavaWallet = wallets.find(w => w.chainType === ChainType.KAVA);
|
||||
const dstWallet = wallets.find(w => w.chainType === ChainType.DST);
|
||||
const bscWallet = wallets.find(w => w.chainType === ChainType.BSC);
|
||||
|
||||
if (kavaWallet && dstWallet && bscWallet) {
|
||||
this.logger.log(`[WALLET-RETRY] Wallet already complete for user: ${userId}`);
|
||||
return; // 钱包已完成,无需重试
|
||||
}
|
||||
|
||||
// 3. 重新触发钱包生成流程
|
||||
const event = account.createWalletGenerationEvent();
|
||||
await this.eventPublisher.publish(event);
|
||||
|
||||
this.logger.log(`[WALLET-RETRY] Wallet generation retry triggered for user: ${userId}`);
|
||||
|
||||
// 4. 更新 Redis 状态为 pending(等待重新生成)
|
||||
const statusData = {
|
||||
status: 'pending',
|
||||
userId,
|
||||
updatedAt: new Date().toISOString(),
|
||||
};
|
||||
|
||||
await this.redisService.set(
|
||||
`keygen:status:${userId}`,
|
||||
JSON.stringify(statusData),
|
||||
60 * 60 * 24, // 24 小时
|
||||
);
|
||||
} catch (error) {
|
||||
this.logger.error(`[WALLET-RETRY] Failed to retry wallet generation for user ${userId}`, error);
|
||||
throw new ApplicationError('钱包生成重试失败,请稍后再试');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户的恢复助记词
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue