NAC_Blockchain/nac-api-server/README.md

114 lines
2.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 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. 配置
复制配置文件示例:
```bash
cp config.toml.example config.toml
```
编辑`config.toml`修改区块链RPC地址和JWT密钥。
### 2. 编译
```bash
cargo build --release
```
### 3. 运行
```bash
cargo run --release
```
服务器将在`http://0.0.0.0:8080`启动。
### 4. 测试
```bash
# 运行所有测试
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