Commit Graph

2 Commits

Author SHA1 Message Date
hailin be3555f338 fix(chain-indexer): 替换Mock为真实区块链RPC索引 — 接入Genex Chain EVM节点
## 背景
chain-indexer(:3009)此前使用Mock模式,每10秒生成假区块数据(hash为纯数字填充,
txCount固定为0),未连接任何真实区块链节点。这是整个区块链架构中唯一的功能缺口
(8大核心服务中TX Indexer完成度仅85%)。

## 改动内容

### 新增文件
- internal/domain/repository/chain_client.go
  DDD领域接口ChainClient,定义GetLatestBlockNumber/GetBlockByNumber/Close三个方法,
  遵循依赖倒置原则,应用层不依赖具体RPC实现

- internal/infrastructure/rpc/eth_client.go
  EthChainClient实现,基于go-ethereum/ethclient:
  · ethclient.Dial()连接EVM JSON-RPC节点
  · BlockByNumber()获取完整区块(hash/timestamp/txCount)
  · types.LatestSignerForChainID()恢复交易发送方地址
  · TransactionReceipt()获取交易执行状态(confirmed/failed)

### 修改文件
- go.mod: 新增github.com/ethereum/go-ethereum v1.14.8依赖

- internal/application/service/indexer_service.go
  · 注入ChainClient依赖,移除所有Mock逻辑
  · 轮询间隔10s→2s(匹配链~1s出块时间)
  · 批量追赶:每周期最多索引50个区块,快速消化落后高度
  · 新增GetChainHeight()/IsSynced()方法供API层使用
  · 区块+交易分别持久化,每条交易独立发布Kafka事件

- cmd/server/main.go
  · 新增RPC_URL环境变量(默认http://localhost:8545)
  · 初始化EthChainClient并注入IndexerService
  · /api/v1/chain/status返回真实chainHeight和syncing状态

- internal/interface/http/handler/admin_chain_handler.go
  · GetContracts: 合约列表更新为真实11个已部署合约(与genex-contracts对齐)
  · GetGasMonitor: Gas数据全部归零(Genex Chain min_gas_price=0平台补贴)
  · GetChainStats: 使用真实chainHeight计算indexerLag/tps/indexerStatus
  · chainId修正88888→8888,consensusType修正PoA→CometBFT

## 环境变量
RPC_URL=http://localhost:8545  (Docker内使用 http://genex-node-1:8545)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-16 18:04:18 -08:00
hailin acaec56849 feat: 全12服务DDD重构 + 公告定向推送系统 (移植自rwadurian)
## 一、DDD + Clean Architecture 重构 (全12服务)

对全部12个微服务(9 NestJS + 3 Go)实施严格的DDD分层:

### NestJS 服务 (9个):
- auth-service: JWT策略已在domain层
- user-service: 新增 5 个 repository interface + implementation,
  5 个 value objects (Email/Phone/KycLevel/Money), 3 组 domain events
- issuer-service: 新增 5 个 repository interface + implementation,
  3 个 value objects, 2 组 domain events, external AI client port
- clearing-service: 新增 5 个 repository interface + implementation,
  2 个 value objects, domain events
- compliance-service: 新增 7 个 repository interface + implementation,
  2 个 value objects, domain events, audit logger service
- ai-service: 新增 conversation repository + TypeORM entity,
  AI agent client port 移至 domain/ports/
- notification-service: 新增 notification repository interface +
  implementation, channel providers, value objects
- telemetry-service: 新增 3 个 repository interface + implementation
- admin-service: 新增 app-version repository interface + implementation

### Go 服务 (3个):
- trading-service: 重构为 domain/application/infrastructure 分层,
  新增 repository interface + postgres 实现, matching engine 移入
  application/service, 新增 value objects (Price/Quantity/OrderSide/OrderType),
  Kafka event publisher
- translate-service: 新增 repository interface + postgres 实现,
  value objects (Address/ChainType)
- chain-indexer: 新增 repository interface + postgres 实现,
  value objects (BlockHeight/TxHash), Kafka event publisher

### 关键模式:
- NestJS: Symbol token DI (provide: Symbol → useClass: Impl)
- Go: compile-time interface check (var _ Interface = (*Impl)(nil))
- TypeORM entity 保留 domain methods (pragmatic DDD)
- Repository interface 在 domain/, 实现在 infrastructure/persistence/

## 二、公告定向推送系统 (ported from rwadurian)

在 notification-service 中新增 Announcement 公告体系,
支持管理端向全体/标签/指定用户推送消息:

### 数据库:
- 038_create_announcements.sql: 5张新表
  - announcements (公告主表)
  - announcement_tag_targets (标签定向)
  - announcement_user_targets (用户定向)
  - announcement_reads (已读记录)
  - user_tags (用户标签)

### 三种定向模式:
- ALL: 推送给全体用户
- BY_TAG: 按标签筛选用户 (用户标签与公告标签有交集)
- SPECIFIC: 指定用户ID列表

### 新增文件 (15个):
- 5 个 TypeORM entity (Announcement + Read + TagTarget + UserTarget + UserTag)
- 2 个 repository interface (IAnnouncementRepository 11方法, IUserTagRepository 6方法)
- 2 个 repository 实现 (TypeORM QueryBuilder, targeting filter SQL)
- 2 个 application service (AnnouncementService, UserTagService)
- 2 个 DTO 文件 (announcement.dto.ts, user-tag.dto.ts)
- 1 个 controller 文件 (含3个controller: AdminAnnouncement/AdminUserTag/UserAnnouncement)
- 1 个 migration SQL

### API 端点:
管理端:
  POST   /admin/announcements       创建公告(含定向配置)
  GET    /admin/announcements       公告列表
  GET    /admin/announcements/:id   公告详情
  PUT    /admin/announcements/:id   更新公告
  DELETE /admin/announcements/:id   删除公告
  GET    /admin/user-tags           所有标签(含用户数)
  POST   /admin/user-tags/:userId   添加用户标签
  DELETE /admin/user-tags/:userId   移除用户标签
  PUT    /admin/user-tags/:userId/sync  同步用户标签

用户端:
  GET    /announcements             用户公告(按定向过滤+已读状态)
  GET    /announcements/unread-count  未读数
  PUT    /announcements/:id/read    标记已读
  PUT    /announcements/read-all    全部已读

### 设计决策:
- Announcement 与现有 Notification 并存 (双轨):
  Notification = 事件驱动1:1通知, Announcement = 管理端广播/定向
- rwadurian accountSequences → gcx userIds (UUID)
- rwadurian Prisma → gcx TypeORM

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-12 21:11:24 -08:00