增加主动查询 api
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"math/big"
|
||||
"net/http"
|
||||
"os"
|
||||
"sync"
|
||||
@@ -79,6 +80,7 @@ func main() {
|
||||
http.HandleFunc("/remove-address", removeAddress)
|
||||
http.HandleFunc("/list-addresses", listAddresses)
|
||||
http.HandleFunc("/payments", getPayments)
|
||||
http.HandleFunc("/query", queryTransactions)
|
||||
http.HandleFunc("/ws", handleWebSocket)
|
||||
http.HandleFunc("/", serveIndex)
|
||||
|
||||
@@ -196,6 +198,59 @@ func getPayments(w http.ResponseWriter, r *http.Request) {
|
||||
})
|
||||
}
|
||||
|
||||
func queryTransactions(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
jsonResponse(w, false, "Method not allowed", nil)
|
||||
return
|
||||
}
|
||||
|
||||
var req struct {
|
||||
Address string `json:"address"`
|
||||
StartTime int64 `json:"startTime"` // 毫秒时间戳
|
||||
EndTime int64 `json:"endTime"` // 毫秒时间戳
|
||||
MinAmount string `json:"minAmount"` // 字符串格式的金额
|
||||
MinConfirmations int64 `json:"minConfirmations"` // 最小确认数
|
||||
Limit int `json:"limit"` // 查询数量
|
||||
}
|
||||
|
||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
||||
jsonResponse(w, false, "invalid request", nil)
|
||||
return
|
||||
}
|
||||
|
||||
if req.Address == "" {
|
||||
jsonResponse(w, false, "address is required", nil)
|
||||
return
|
||||
}
|
||||
|
||||
filter := usdtman.QueryFilter{
|
||||
Address: req.Address,
|
||||
StartTime: req.StartTime,
|
||||
EndTime: req.EndTime,
|
||||
MinConfirmations: req.MinConfirmations,
|
||||
Limit: req.Limit,
|
||||
}
|
||||
|
||||
// 解析最小金额
|
||||
if req.MinAmount != "" {
|
||||
minAmount := new(big.Int)
|
||||
if _, ok := minAmount.SetString(req.MinAmount, 10); ok {
|
||||
filter.MinAmount = minAmount
|
||||
}
|
||||
}
|
||||
|
||||
payments, err := uman.QueryTransactions(filter)
|
||||
if err != nil {
|
||||
jsonResponse(w, false, fmt.Sprintf("查询失败: %v", err), nil)
|
||||
return
|
||||
}
|
||||
|
||||
jsonResponse(w, true, "success", map[string]interface{}{
|
||||
"payments": payments,
|
||||
"count": len(payments),
|
||||
})
|
||||
}
|
||||
|
||||
func handleWebSocket(w http.ResponseWriter, r *http.Request) {
|
||||
conn, err := upgrader.Upgrade(w, r, nil)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user