Files
usdtman/README.md
2026-02-03 00:10:43 +08:00

76 lines
1.9 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.
# USDTMan
TRON USDT TRC20 收款监听服务 - 基于交易记录扫描 + 区块确认数验证
## 功能
- 实时监听多个 TRON 地址的 USDT 收款
- 区块确认数验证默认6个确认
- WebSocket 实时推送收款通知
- HTTP API 管理监听地址
## API 使用方式
```go
// 创建监听器(配置对象方式)
uman := usdtman.NewUSDTMan(usdtman.Config{
Addresses: []string{"地址1", "地址2"},
APIKey: "YOUR_API_KEY",
QueryInterval: 5 * time.Second, // 查询间隔(可选,默认 5 秒)
MinConfirmations: 6, // 最小确认数(可选,默认 6
MaxHistoryTxns: 20, // 查询历史交易数(可选,默认 20
ProxyURL: "http://127.0.0.1:7890", // HTTP/SOCKS5 代理(可选)
})
// 或者使用自定义 Transport
uman := usdtman.NewUSDTMan(usdtman.Config{
Addresses: []string{"地址1"},
APIKey: "YOUR_API_KEY",
Transport: &http.Transport{
Proxy: http.ProxyURL(proxyURL),
// 其他自定义配置...
},
})
// 设置收款回调
uman.OnPaymentComplete(func(payment *usdtman.USDTPayment) {
fmt.Printf("收到 %.6f USDT确认数: %d\n", payment.Amount, payment.Confirmations)
})
// 启动监听
uman.Start()
// 停止监听
uman.Stop()
// 动态添加/移除地址
uman.AddAddress("新地址")
uman.RemoveAddress("旧地址")
```
## 运行
```bash
cd cmd/server
go run main.go
```
访问 http://localhost:8084
## 接口
- `POST /start` - 启动监听
- `POST /stop` - 停止监听
- `POST /add-address` - 添加监听地址
- `POST /remove-address` - 移除地址
- `GET /list-addresses` - 列出所有地址
- `GET /payments` - 获取收款历史
- `WS /ws` - WebSocket 连接
## 确认机制
- 扫描地址的最近交易记录
- 计算区块确认数(当前区块 - 交易区块)
- 仅在确认数 >= 6 时触发回调
- 自动去重,避免重复处理