Commit Graph

1664 Commits

Author SHA1 Message Date
hailin ec73541fe1 refactor(mining-blockchain): 移除 mpc-service 依赖,改为 HTTP 直调 mpc-system
将 mining-blockchain-service 的 MPC 签名通信从 Kafka 事件驱动(经由 mpc-service 中转)
改为 HTTP 直接调用 mpc-system 的 account-service (port 4000)。

## 核心变更

### mpc-signing.client.ts (重写)
- 移除 EventPublisherService、MpcEventConsumerService 依赖和 pendingRequests Map
- 移除 OnModuleInit 中的 Kafka 事件注册
- 新增 HttpService (@nestjs/axios) + JwtService (@nestjs/jwt) 依赖注入
- 签名流程改为:
  1. POST /api/v1/mpc/sign → 创建签名会话 (snake_case: username, message_hash)
  2. GET /api/v1/mpc/sessions/{session_id} → 轮询结果 (每 2s, 最多 5 分钟)
- JWT 认证: 使用 MPC_JWT_SECRET (HS256) 生成 Bearer token,匹配 mpc-system 格式
- 所有公共接口不变 (signMessage, signMessageAsXxxMarketMaker, isConfigured, getXxxAddress 等)

### 删除的文件
- mpc-event-consumer.service.ts: Kafka MPC 事件消费者 (SigningCompleted/SessionFailed/KeygenCompleted)
- mpc-keygen-completed.handler.ts: Keygen 地址派生处理器 (不再由此服务处理)

### 模块更新
- infrastructure.module.ts: 移除 MpcEventConsumerService,新增 JwtModule.register({})
- kafka/index.ts: 移除 mpc-event-consumer.service 导出
- event-handlers/index.ts: 移除 mpc-keygen-completed.handler 导出

### 部署配置
- docker-compose.2.0.yml: 新增 MPC_ACCOUNT_SERVICE_URL 和 MPC_JWT_SECRET 环境变量
- deploy-mining.sh: standalone 模式新增 export MPC_ACCOUNT_SERVICE_URL (默认 http://192.168.1.111:4000)

## 不受影响的部分
- Erc20TransferService / MpcTransferInitializerService 调用方式不变
- EventPublisherService (用于其他事件) 不变
- WithdrawalEventConsumerService 不变
- mpc-system 本身零修改

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 20:53:35 -08:00
hailin c657bf6e2b revert: 撤回 mpc-service HTTP 调用方案,改为直接调用 mpc-system
Revert "fix(deploy): export MPC_SERVICE_URL in standalone mode"
Revert "refactor(mining-blockchain): replace Kafka MPC signing with HTTP direct calls"

将改为直接调用 mpc-system (Go TSS 后端) 的 API,跳过 mpc-service 中间层。

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 20:33:39 -08:00
hailin 3102f3e7fb fix(deploy): export MPC_SERVICE_URL in standalone mode
In standalone mode, mpc-service runs on the 1.0 server (192.168.1.111),
not in the local Docker network. The default docker-compose value
http://mpc-service:3006 won't resolve. Export MPC_SERVICE_URL pointing
to the 1.0 server's IP so mining-blockchain-service can reach it.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 20:30:44 -08:00
hailin 1106a40ff1 refactor(mining-blockchain): replace Kafka MPC signing with HTTP direct calls
Remove Kafka event-driven MPC signing (publish/consume pattern) and replace
with HTTP POST + polling to mpc-service, matching identity-service approach.

- Rewrite mpc-signing.client.ts: POST /api/v1/mpc/sign + poll status
- Delete mpc-event-consumer.service.ts (no longer needed)
- Delete mpc-keygen-completed.handler.ts (keygen handled elsewhere)
- Add MPC_SERVICE_URL env var to docker-compose.2.0.yml

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 20:28:26 -08:00
hailin 0d47fadf59 feat(kafka): add EXTERNAL listener on port 9093 for LAN access
Add a third Kafka listener (EXTERNAL://0.0.0.0:9093) so that
2.0 standalone services on other servers (e.g. 192.168.1.10) can
connect to 1.0's Kafka at 192.168.1.111:9093.

Listeners now:
- PLAINTEXT (kafka:29092) - internal Docker network
- PLAINTEXT_HOST (localhost:9092) - host-local access
- EXTERNAL (192.168.1.111:9093) - LAN access for remote services

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 19:49:34 -08:00
hailin ee07b52af9 feat(mining-2.0): 支持 standalone 独立部署模式,2.0 服务可脱离 1.0 单独运行
## 背景
2.0 挖矿生态需要从 1.0 服务器(192.168.1.111)迁移到独立服务器(192.168.1.10),
实现物理隔离部署。2.0 拥有独立的 PostgreSQL/Redis,通过远程 Kafka 接收 1.0 CDC 数据。

## docker-compose.2.0.yml 变更

### 网络参数化
- 网络改为 external: true + name 参数化:
  `name: ${RWA_NETWORK_NAME:-services_rwa-network}`
- shared 模式复用 1.0 网络, standalone 模式使用独立 rwa-2-network

### 基础设施地址参数化 (所有 7 个 backend service)
- DATABASE_URL: @${POSTGRES_HOST:-postgres}:${POSTGRES_PORT:-5432}
- REDIS_HOST: ${REDIS_HOST:-redis}
- KAFKA_BROKERS: ${KAFKA_BROKERS:-kafka:29092}

### 新增 3 个 standalone profile 基础设施服务
- postgres-2: PostgreSQL 16, WAL logical, init-multiple-dbs.sh 自动建库
- redis-2: Redis 7, appendonly 持久化
- debezium-2: Debezium Connect 2.4, 连接远程 Kafka(192.168.1.111:9093)
  用于 2.0 内部 outbox 模式 (服务事件 → Kafka → mining-admin-service)

### 可选依赖
- 应用 service 添加 depends_on postgres-2/redis-2 with required: false
  (Docker Compose v2.20+, shared 模式下自动跳过)

## deploy-mining.sh 变更

### 部署模式切换
- DEPLOY_MODE 环境变量: shared(默认) / standalone
- load_env() 按模式设置基础设施地址和 COMPOSE_ARGS
- shared 模式不 export 变量,避免覆盖容器侧 Docker Compose 默认值

### Kafka 远程操作支持
- run_kafka_cmd() / run_kafka_cmd_stdin(): standalone 模式用临时容器执行 Kafka CLI
- 所有 Kafka 操作函数 (sync_reset, sync_status, cdc_resnapshot, full_reset) 已适配

### 基础设施生命周期管理
- infra_up / infra_down: 独立管理 standalone 基础设施
- services_up(): standalone 模式自动先启动基础设施
- services_down(): standalone 模式同时停止基础设施
- services_clean(): fallback 列表包含 standalone 容器名

### full_reset() standalone 适配
- standalone 模式跳过 1.0 source CDC 操作 (远程 Debezium 管理)
- standalone 使用 debezium_2_offsets offset topic
- 自动启动 debezium-2 后注册 outbox connectors

### 其他
- health_check(): standalone 模式检查本地 PG/Redis 容器 + 远程 Kafka
- show_help(): 新增 DEPLOY_MODE 说明和 infra-up/infra-down 命令
- print_header(): 显示当前 DEPLOY_MODE
- 所有 ~15 处 docker compose 调用统一使用 $COMPOSE_ARGS

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 19:32:03 -08:00
hailin f39fd52001 feat(c2c-bot): rename HOT_WALLET to C2C_BOT_WALLET and change dUSDT to 绿积分
- Rename env vars HOT_WALLET_ADDRESS/USERNAME to C2C_BOT_WALLET_ADDRESS/USERNAME
  in mining-blockchain-service to avoid conflict with existing hot wallet
- Update docker-compose.2.0.yml with new env var names
- Change all "dUSDT" labels to "绿积分" on C2C Bot admin page

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 08:40:45 -08:00
hailin be52ac979b fix(trading-service): add MINING_BLOCKCHAIN_SERVICE_URL to docker-compose
trading-service BlockchainClient defaults to http://localhost:3020 but
mining-blockchain-service runs on port 3026. Add the correct Docker
internal URL so the C2C Bot can reach the blockchain service.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 08:21:17 -08:00
hailin 8d7e5b17a1 fix(mining-admin-service): cast response.data to any for envelope unwrapping
TypeScript build fails because MiningServiceResponse type doesn't have
a 'data' property. The runtime response from mining-service wraps data
in a { success, data } envelope, so we need `as any` to access it.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 07:49:31 -08:00
hailin 7549b2b9a9 fix(mining-admin): 解包mining-service响应信封,取response.data.data
mining-service返回 { success, data: { ... } } 格式,
mining-admin-service需要取 .data.data 而非 .data,
否则前端读到的是信封对象而非实际数据,导致 TypeError。

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 07:44:17 -08:00
hailin 48720d1846 feat(blockchain): 1.0 blockchain-service 同步添加 RPC 端点自动故障转移
与 mining-blockchain-service (2.0) 保持一致的故障转移方案:
当 RPC 端点连续失败超过 3 分钟后自动轮转到下一个备选端点。

新增文件:
- rpc-provider-manager.service.ts: RPC 故障转移管理器(与 2.0 相同逻辑)

修改文件:
- blockchain.config.ts: 新增 rpcUrls 配置字段
- chain-config.service.ts: 新增 rpcUrls 属性和 parseRpcUrls 解析方法
- domain.module.ts: 注册并导出 RpcProviderManager
- index.ts: 导出 RpcProviderManager
- evm-provider.adapter.ts: 委托 RpcProviderManager 获取 provider,
  所有方法通过 executeWithFailover 包裹
- erc20-transfer.service.ts: 移除本地 providers Map,改用 RpcProviderManager,
  新增 isRpcConnectionError 区分 RPC 网络错误与合约执行错误
- docker-compose.yml: blockchain-service 添加 KAVA_RPC_URLS 默认 4 个端点

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 07:36:02 -08:00
hailin b9e9bb6e4e fix(mining-admin): 修正调用mining-service的URL路径,补全/api/v2/mining前缀
mining-service有全局前缀api/v2和控制器前缀mining/admin,
但mining-admin-service的HTTP调用缺少这两个前缀导致404,
错误被catch静默吞掉,前端显示空数据。

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 07:34:21 -08:00
hailin 3635369a8a feat(mining-blockchain): RPC端点自动故障转移,连续失败3分钟后切换备选节点
问题:Kava主网RPC (evm.kava.io) 偶发503,导致mining-blockchain-service
所有链上操作失败(转账、余额查询、区块扫描等)。

方案:新增RpcProviderManager单例服务,统一管理各链的JsonRpcProvider实例,
当某个RPC端点连续失败超过3分钟后自动轮转到下一个备选端点。

新增文件:
- rpc-provider-manager.service.ts: 核心故障转移管理器
  · 每条链维护 provider/urls/currentIndex/failureState
  · reportSuccess() 重置失败状态
  · reportFailure() 记录失败,>=3分钟触发 switchToNextUrl()
  · 轮转创建新 JsonRpcProvider,替换旧实例
  · 每30秒记录一次失败日志,避免日志刷屏

修改文件:
- blockchain.config.ts: 新增 rpcUrls 配置字段(KAVA_RPC_URLS/BSC_RPC_URLS)
- chain-config.service.ts: 解析逗号分隔的URL列表,回退到单个rpcUrl
- domain.module.ts: 注册并导出 RpcProviderManager
- index.ts: 导出 RpcProviderManager
- evm-provider.adapter.ts: 委托RpcProviderManager获取provider,
  所有公开方法通过executeWithFailover包裹,自动上报成功/失败
- erc20-transfer.service.ts: 移除本地providers Map,改用RpcProviderManager,
  新增isRpcConnectionError()区分RPC网络错误与合约执行错误
- docker-compose.2.0.yml: 添加KAVA_RPC_URLS默认4个端点
- .env.example: 添加KAVA_RPC_URLS配置说明

默认端点仍为 evm.kava.io,备选: evm.kava-rpc.com,
kava-evm-rpc.publicnode.com, rpc.ankr.com/kava_evm

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 07:06:31 -08:00
hailin ef663c0c08 fix(deploy): replace envsubst with eval heredoc for ${VAR:-default} support
GNU envsubst does not handle ${VAR:-default} bash syntax - it leaves
the entire expression unsubstituted. This caused CDC connector
registration to fail with "password authentication failed for user
${POSTGRES_USER:-rwa_user}".

Replace all envsubst calls with a substitute_env_vars() helper that
uses eval+heredoc, which natively supports bash default value syntax.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 06:22:01 -08:00
hailin ea3d256647 fix(deploy): 恢复connector JSON原样,仅在load_env中export变量修复envsubst
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 06:09:53 -08:00
hailin 5728953b41 fix(deploy): connector JSON改为硬编码凭据,与outbox connector保持一致
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 06:06:47 -08:00
hailin a4f3a8d3ab fix(deploy): 修复envsubst无法解析${VAR:-default}语法导致CDC connector注册失败
问题:
  commit 5b1f4c82 在 full-reset Step 9 中用 envsubst 替换 connector JSON 中的
  数据库凭据,但 envsubst(GNU gettext)不支持 bash 的 ${VAR:-default} 语法,
  导致 "${POSTGRES_USER:-rwa_user}" 被原样发送给 Debezium,认证失败。

修复:
  1. deploy-mining.sh load_env(): 默认值赋值改为 export,确保 envsubst 能访问
  2. connector JSON 文件: ${VAR:-default} 改为 ${VAR},默认值由脚本 export 提供

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 06:03:38 -08:00
hailin b9f803c5c8 fix(blockchain): 修复health check路径不匹配并配置C2C Bot热钱包
- app.config.ts: 添加apiPrefix读取API_PREFIX环境变量
- docker-compose: health check从api/v2改为api/v1(与trading-service一致)
- docker-compose: 配置HOT_WALLET默认值,解决"区块链服务不可用"和钱包地址不显示

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 05:46:58 -08:00
hailin c802519ec2 fix(c2c-bot): 调整purchaseOrder操作顺序,先扣余额再链上转账
问题:原流程先执行不可逆的链上dUSDT转账,再扣减卖家DB余额。
若转账成功但扣减失败(余额不足、DB异常),会导致:
- dUSDT已转出(链上不可回退)
- 订单仍为PENDING(可能被重复处理)
- 卖家余额未扣减

修复:
1. 将deductSellerBalance移至transferDusdt之前(可逆操作先行)
2. 链上转账失败时调用restoreSellerBalance回补余额
3. 新增restoreSellerBalance方法,失败时记录CRITICAL级别日志

修改后流程:扣余额(可逆) → 链上转账(不可逆) → 更新订单状态(DB)
任何步骤失败都不会导致资金损失。

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 05:02:19 -08:00
hailin 251e37f772 feat(c2c-bot): 添加C2C Bot管理页面,支持运行时开关和热钱包查看
- 新增C2C Bot管理页面(mining-admin-web):Bot开关、热钱包余额/地址/QR码、统计、订单历史
- 新增admin API端点(trading-service):status/enable/disable/orders
- 重构Bot调度器enabled为Redis驱动,支持运行时开关(多实例安全)
- C2cOrderRepository新增findBotPurchasedOrders和getBotStats查询方法
- 侧边栏添加C2C Bot导航入口

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 04:47:28 -08:00
hailin bf772967f5 feat(mining): 批量补发30%分配到运营和总部账户,并添加交易筛选器
- 批量补发时将剩余30%分配到运营(12%)和总部(18%)系统账户
- SystemMiningAccountRepository.mine()支持referenceId/referenceType参数
- BatchMiningExecution新增operationAmount/headquartersAmount字段(含DB迁移)
- 三层架构(mining-service→admin-service→admin-web)全链路支持referenceType筛选
- 系统账户交易记录页面增加"全部/批量补发"筛选按钮

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 04:25:20 -08:00
hailin 338321b3a2 fix(c2c): 用updateMany+status条件防止合并时的竞态条件
findFirst找到PENDING订单后,如果被takeOrder接走(状态变MATCHED),
updateMany因status!=PENDING返回count=0,自动回退到创建新订单。

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 03:29:27 -08:00
hailin 60d99add2c fix(c2c): 过期恢复时合并到已有PENDING订单,避免同maker产生重复挂单
原来每个过期的MATCHED子订单都创建独立PENDING,导致一个卖单被多人
部分接单后过期会产生多个重复挂单。现在恢复时先查找同maker/type/price
的PENDING订单,有则合并数量,无则创建新订单。

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 03:25:57 -08:00
hailin 49ba2fcb19 feat(c2c): 添加expireOrder事务流程的详细调试日志
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 03:09:50 -08:00
hailin 627c3c943c refactor(c2c): expireOrder使用Prisma事务确保原子性
将 expireOrder 中的 解冻/状态更新/恢复创建 包在 prisma.$transaction 中:
- 事务失败全部回滚,不会出现半完成的不一致状态
- SELL MATCHED/PAID 过期恢复:保持冻结 + 标记EXPIRED + 创建PENDING 原子执行
- BUY MATCHED/PAID 过期恢复:解冻taker + 标记EXPIRED + 创建PENDING 原子执行
- PENDING 过期:解冻 + 标记EXPIRED 原子执行
- 删除 restoreExpiredOrder 方法,逻辑合并到事务内
- 遵循现有模式(executeTransfer 等),在事务回调中直接使用 tx 操作

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 02:43:48 -08:00
hailin 33dda98e81 fix(c2c): 修复过期恢复的竞态条件,SELL订单保持冻结避免资金窗口
- SELL MATCHED/PAID 订单过期恢复时,不再先解冻再重新冻结
- 保持 maker 的冻结不变,直接转给新 PENDING 订单
- 消除了解冻→重新冻结之间的竞态窗口(余额可能被其他操作消耗)
- 恢复失败时补充解冻,防止 maker 资金被永久冻结
- BUY 订单恢复时不复制上一个 taker 的 sellerKavaAddress

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 02:11:47 -08:00
hailin 4e4a876341 fix(c2c): MATCHED/PAID订单过期后自动恢复为新PENDING订单
当部分成交的订单过期时,将过期数量恢复到市场:
- BUY单过期:直接为maker创建新PENDING BUY单
- SELL单过期:检查maker余额,重新冻结后创建新PENDING SELL单
- 恢复失败不影响过期流程(仅记录日志)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 01:37:00 -08:00
hailin b8f8831516 feat: PENDING订单自动过期、接单显示余额、积分股金额输入
1. C2C PENDING订单24小时自动过期并解冻冻结资产
   - 新增 DEFAULT_PENDING_TIMEOUT_HOURS 常量
   - findExpiredOrders 支持 PENDING 状态查询
   - expireOrder 处理 PENDING 卖单解冻

2. C2C接单对话框显示卖方可用余额
   - 确认出售时显示用户账户可用积分值(非订单数量)
   - 新增订单数量行,方便对比

3. 积分股兑换页面新增金额输入
   - 卖出时显示金额输入框(积分值),与数量双向联动
   - 输入数量自动计算金额,输入金额自动反算数量
   - 全部按钮同步更新两个字段

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-31 22:15:47 -08:00
hailin 6ccc192bc6 fix(c2c): 用户无交易账户时自动创建零余额账户
createOrder 和 takeOrder 中,如果用户没有交易账户,
自动创建零余额账户而非报错"交易账户不存在"。
买单不需要余额,不应因缺少账户而无法下单。

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-31 21:29:42 -08:00
hailin a1c3657390 fix(c2c): 修复付款水单图片无法显示的问题
1. 后端: proofs 图片端点添加 @Public() 装饰器,
   Image.network 无法携带 JWT token
2. 前端: paymentProofUrl 是相对路径,拼接 baseUrl
   构建完整 URL 供 Image.network 加载

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-31 21:16:53 -08:00
hailin 5b1f4c82e6 fix(deploy): full-reset 时重建 1.0 source CDC connectors 以确保完整数据同步
问题:
  执行 deploy-mining.sh full-reset 后,identity-postgres-connector 等 1.0 source
  CDC connectors 保留了旧的 Debezium offset 和 replication slot,导致 Debezium
  认为 initial snapshot 已完成而跳过重新快照。如果 connector 的 JSON 配置文件中
  新增了表(如 identity-connector.json 中的 wallet_addresses),这些表的存量数据
  永远不会被捕获到 Kafka topic,2.0 服务无法通过 CDC 同步到这些数据。

  具体表现:Kafka topic cdc.identity.public.wallet_addresses 始终为空(0条消息),
  2.0 auth-service 的 synced_wallet_addresses 表为空,用户 KAVA 地址未同步。

修复:
  在 full_reset() 的 Step 4 中,除了处理 outbox connectors,还新增了对 1.0 source
  CDC connectors (identity/referral/planting) 的处理:
  1. 删除 connector(释放 replication slot)
  2. 发送 tombstone 清除 debezium_offsets topic 中的偏移量
  3. 调用 pg_drop_replication_slot() 删除 PostgreSQL replication slot

  新增 Step 9:从 scripts/debezium/*.json 配置文件重新注册 source connectors,
  因为 offset 和 slot 都已清除,snapshot.mode=initial 会触发全新的 initial snapshot,
  确保所有配置表(包括新增的 wallet_addresses)的存量数据都被灌入 Kafka topic。

  总步骤数从 18 调整为 19。

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-31 20:26:06 -08:00
hailin f60e3751b8 fix(c2c): 修复水单上传权限、手机号、卖方ID、资产显示
- Dockerfile: 用 su-exec 模式解决 Docker volume 权限问题
- JWT guard: 从 token 提取 phone 字段
- 订单详情: 新增卖方ID显示
- C2C市场页: 修复资产概览两列重复显示 availableCash,
  改为左列显示可用积分股、右列显示可用积分值

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-31 09:19:38 -08:00
hailin e783661002 fix(c2c): 修复水单上传权限、手机号显示、卖方ID显示
- Dockerfile 预创建 /app/uploads/c2c-proofs 并设置正确权限
- JWT guard 从 token payload 提取 phone 字段(之前仅提取 accountSequence)
- 订单详情页订单信息组新增卖方ID显示

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-31 09:13:46 -08:00
hailin 25ea0bf64e fix(trading-service): 修复 Multer 类型缺失导致构建失败
使用内联类型替代 Express.Multer.File,避免 @types/multer 依赖

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-31 08:58:55 -08:00
hailin ce173451f5 feat(c2c): 订单详情增强、付款水单上传、买单逻辑修复及schema对齐
- 订单详情页显示完整手机号和收款账号信息
- 新增付款水单上传功能(前后端全链路)
- 修复时间显示为本地时区格式
- 移除买单发布时的积分值余额验证(买方通过外部绿积分支付)
- 前端买单发布页隐藏余额卡片和"全部"按钮
- 补齐 Prisma migration 与 schema 差异(payment_proof_url、
  bot_purchased索引、market_maker_deposits/withdraws表)
- docker-compose 新增 trading-uploads 卷用于水单持久化

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-31 08:54:05 -08:00
hailin 4df23b02b8 fix(trading-service): 添加做市商钱包环境变量,修复地址未配置问题
FUSDT/EUSDT_MARKET_MAKER_ADDRESS 和 USERNAME 只传给了
mining-blockchain-service,但 trading-service 初始化时也需要
读取这些变量写入数据库,导致前端显示"做市商钱包地址未配置"。

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-31 07:56:16 -08:00
hailin 8e63547a3e fix(transfer): 修复积分股划转到分配账户失败问题
后端:
- transfer.service.ts: Error → BadRequestException,业务错误返回HTTP 400而非500
- transfer.controller.ts: Error → UnauthorizedException,正确返回HTTP 401
- 错误信息改为中文:余额不足、账户不存在等提示更明确

前端:
- asset_display.dart: 新增 tradingAvailableShares 计算属性(总可用 - 挖矿可用)
- trading_page.dart: 划转弹窗显示可用余额(扣除冻结)而非总余额
- trading_page.dart: 划转失败时显示后端具体错误信息而非通用提示

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-31 06:24:35 -08:00
hailin 3cbb874503 fix(auth-service): 返回完整手机号,修复QR码扫码失败
- login/profile 接口返回 user.phone.value 替代 user.phone.masked
- 根因:QR码编码脱敏号 199****9327,正则要求纯数字匹配失败

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-31 06:00:47 -08:00
hailin 8c31dee000 fix(c2c): 修复买方待付款页面灰色无法操作问题
根因: c2c_order_model.dart 的 _parsePaymentMethod 不识别 GREEN_POINTS,
导致 paymentMethod=null → hasPaymentInfo=false → 收款信息卡片隐藏 → 页面不可操作

前端修复:
- C2cPaymentMethod 枚举增加 greenPoints,解析器支持 GREEN_POINTS
- 支持逗号分隔的多支付方式字符串(取第一个作为主要方式)
- 订单详情页增加绿积分图标和卖方 Kava 地址显示(买方可复制)

后端修复:
- takeOrder() 接买单时自动获取卖方 Kava 地址写入 sellerKavaAddress
- 买方在订单详情页可看到卖方 Kava 地址用于转绿积分

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-31 05:41:14 -08:00
hailin f167f1227c Revert "fix(trading-service): C2C卖单不再强制要求Kava钱包地址"
This reverts commit 9b8f720915.
2026-01-30 21:04:27 -08:00
hailin 9b8f720915 fix(trading-service): C2C卖单不再强制要求Kava钱包地址
executeTransfer不使用sellerKavaAddress,C2C交易是积分值划转+外部绿积分支付,
不涉及Kava链上操作。改为可选获取,失败不阻断订单创建。

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 21:03:59 -08:00
hailin 7180e2ac27 fix(contribution): 算力记录按层级升序排列 L1→L2→...→L15
用户期望 L1 在前 L15 在后,将 levelDepth/bonusTier 排序从 DESC 改为 ASC

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 20:14:31 -08:00
hailin 17f8a61bcf feat(contribution-service): 贡献值明细按 L/T 降序排序
- 同伴下贡献值 (TEAM_LEVEL): 按 levelDepth DESC 排序 (L3, L2, L1)
- 同伴上贡献值 (TEAM_BONUS): 按 bonusTier DESC 排序 (T3, T2, T1)
- 全部/本人: 按 levelDepth DESC, bonusTier DESC, createdAt DESC

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 14:20:03 -08:00
hailin a31fcaa9b8 fix(mining-admin): configValue → value,修复配置读取后 fallback 到默认值
Prisma 返回的字段是 value,controller 写成了 configValue,
导致 getP2pTransferFee / getTransferEnabled 永远返回默认值

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 14:18:13 -08:00
hailin 3507805005 fix(mining-admin): Docker uploads 目录权限修复,预创建 /app/uploads 并设置 nestjs 用户所有权
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 13:19:14 -08:00
hailin 6900905475 fix(mining-admin): APK下载URL指向localhost导致手机无法下载
问题:FileStorageService 默认 UPLOAD_BASE_URL 为 http://localhost:3020/downloads,
手机端无法访问服务器的 localhost。

修复:
- docker-compose.2.0.yml: 添加 UPLOAD_BASE_URL=https://rwaapi.szaiai.com/mining-admin/downloads
- 添加 mining-admin-uploads volume 持久化上传的 APK 文件
- 修正默认端口 3020→3023(mining-admin-service 实际端口)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 12:56:40 -08:00
hailin 94d4524ee3 fix(c2c): 积分股→积分值,C2C交易对象修正为积分值(cash)
C2C交易的产品是积分值,支付方式是绿积分(外部1.0系统),与积分股无关。

前端:
- c2c_publish_page: 余额卡、数量输入、提示文案、确认弹窗全部改为积分值
- c2c_market_page: 余额概览(availableShares→availableCash)、订单数量标签、接单弹窗
- c2c_order_detail_page: 订单详情、划转提示、确认收款弹窗

后端 c2c.service.ts:
- createOrder SELL: freezeShares→freezeCash
- takeOrder BUY(taker=卖方): freezeShares→freezeCash
- takeOrder SELL(taker=买方): 移除冻结(买方通过外部支付绿积分)
- cancelOrder SELL: unfreezeShares→unfreezeCash
- expireOrder: unfreezeShares→unfreezeCash,SELL不再解冻taker
- executeTransfer: 统一BUY/SELL为单向积分值划转,assetType改为CASH

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 12:41:23 -08:00
hailin 49bcb96c4c fix(trading): 补充 p2p_transfers 表遗漏的 fee 列
schema 中定义了 fee 字段但 0002 migration 遗漏,导致
prisma.p2pTransfer.create() 报错 "column fee does not exist"

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 12:24:50 -08:00
hailin f0c7cee94e fix(auth): lookupByPhone 支持查询未迁移的 1.0 用户
P2P 转账验证手机号时,lookupByPhone 只查 users 表(V2 注册用户),
导致未登录过 2.0 的 1.0 老用户(CDC 同步在 synced_legacy_users 表)
被报"不存在"。修改为先查 users 表,未找到再查 synced_legacy_users。

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 11:41:58 -08:00
hailin 187b82e9ac feat(c2c): 修复6项C2C交易问题 (#11-#16)
- #11: 价格固定1:1,最小交易数量为1
- #12: BUY买单不再冻结买方积分值(绿积分通过外部1.0系统支付)
- #13: 支持部分成交,taker可指定数量,剩余自动拆分为新PENDING订单
- #14: 发布页双向输入,积分股数量与积分值金额1:1联动
- #15: 接BUY单时弹出收款信息输入(收款方式、账号、姓名)
- #16: BUY单创建时验证积分值余额但不冻结

后端: cancelOrder/expireOrder/executeTransfer 均按BUY/SELL分别处理
前端: 发布页价格只读、市场页接单对话框增加数量和收款输入

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 11:36:57 -08:00