NAC_Blockchain/services/nac-api-server
NAC Admin 74d88fc80f Issue #78 #79: protocol/ 和 rwa/ 目录分组重组
Issue #78: 将协议层模块迁移到 protocol/ 目录
- nac-udm, nac-cbpp, nac-cbpp-l0/l1, nac-csnp, nac-csnp-l0/l1/service
- nac-nvm, nac-nvm-service, nac-constitution-*, nac-lens
- 修复 nac-csnp-l0 缺少 sha3 依赖
- 修复 nac-constitution-clauses review_committee 字段名
- 所有 15 个 Rust 协议模块编译通过

Issue #79: 将 RWA 模块迁移到 rwa/ 目录
- nac-rwa-legal-model, nac-rwa-jurisdiction-adapters, nac-rwa-contract-templates
- nac-rwa-bilateral-rules, nac-rwa-sharia-compliance, nac-jurisdiction-rules/compat/version
- nac-lens-jurisdiction-router, nac-rwa-exchange, nac-asset-onboarding, nac-multi-jurisdiction
- 更新所有 Cargo.toml 路径引用
- nac-onboarding-system 归档(历史遗留编译问题)
- nac-api-server 路径更新并重新部署

目录结构: protocol/ rwa/ services/ ops/ sdk/ _archive/
2026-03-07 18:12:43 +08:00
..
src refactor: 目录重组 - 明确中心化运维与去中心化业务边界 2026-03-07 17:46:08 +08:00
tests refactor: 目录重组 - 明确中心化运维与去中心化业务边界 2026-03-07 17:46:08 +08:00
.gitignore refactor: 目录重组 - 明确中心化运维与去中心化业务边界 2026-03-07 17:46:08 +08:00
Cargo.lock refactor: 目录重组 - 明确中心化运维与去中心化业务边界 2026-03-07 17:46:08 +08:00
Cargo.toml Issue #78 #79: protocol/ 和 rwa/ 目录分组重组 2026-03-07 18:12:43 +08:00
README.md refactor: 目录重组 - 明确中心化运维与去中心化业务边界 2026-03-07 17:46:08 +08:00
config.toml.example refactor: 目录重组 - 明确中心化运维与去中心化业务边界 2026-03-07 17:46:08 +08:00
issue_007_nac_lens_upgrade.md refactor: 目录重组 - 明确中心化运维与去中心化业务边界 2026-03-07 17:46:08 +08:00

README.md

NAC API服务器

NAC公链统一API服务器为钱包应用和RWA资产交易所提供后端API支持。

功能特性

核心功能

  • 钱包API - 余额查询、转账、交易历史
  • 交易所API - 资产列表、订单管理、市场数据、订单簿
  • 区块链集成 - 通过RPC连接真实NAC区块链节点
  • 安全机制 - JWT认证、速率限制、输入验证
  • 错误处理 - 统一错误格式、详细日志
  • 配置管理 - TOML配置文件支持

技术栈

  • Web框架: Axum 0.7
  • 异步运行时: Tokio
  • 序列化: Serde
  • HTTP客户端: Reqwest
  • 认证: JWT (jsonwebtoken)
  • 验证: Validator
  • 日志: Tracing

快速开始

1. 配置

复制配置文件示例:

cp config.toml.example config.toml

编辑config.toml修改区块链RPC地址和JWT密钥。

2. 编译

cargo build --release

3. 运行

cargo run --release

服务器将在http://0.0.0.0:8080启动。

4. 测试

# 运行所有测试
cargo test

# 健康检查
curl http://localhost:8080/health

API文档

钱包API

  • GET /api/wallet/balance/:address - 查询余额
  • POST /api/wallet/transfer - 发起转账
  • GET /api/wallet/transactions/:address - 查询交易历史
  • GET /api/wallet/transaction/:hash - 查询交易详情

交易所API

  • GET /api/exchange/assets - 获取资产列表
  • POST /api/exchange/orders - 创建订单
  • GET /api/exchange/orders/:order_id - 查询订单详情
  • GET /api/exchange/market/:asset - 获取市场数据
  • GET /api/exchange/orderbook/:asset - 获取订单簿
  • GET /api/exchange/trades - 获取最近交易

详细API文档请参考代码注释。

项目结构

nac-api-server/
├── src/
│   ├── main.rs              # 主入口
│   ├── blockchain/          # 区块链客户端
│   ├── auth/                # 认证模块
│   ├── middleware/          # 中间件
│   ├── error/               # 错误处理
│   ├── config/              # 配置管理
│   ├── models/              # 数据模型
│   ├── wallet.rs            # 钱包API
│   └── exchange.rs          # 交易所API
├── tests/                   # 集成测试
├── Cargo.toml               # 依赖配置
├── config.toml.example      # 配置示例
└── README.md                # 本文档

测试统计

  • 总测试数: 20个
  • 测试通过率: 100%
  • 代码覆盖: 核心模块全覆盖

许可证

Copyright © 2026 NAC Team. All rights reserved.


版本: 1.0.0
最后更新: 2026-02-18