mirror of
https://github.com/GMWalletApp/epusdt.git
synced 2026-07-07 10:16:15 +00:00
feat: add Solana payment scanning with USDT/USDC support and wallet management API
- Rewrite Solana scanner: stateless scan with processed-signature cache, query wallet + USDT ATA + USDC ATA addresses to cover all SPL transfers - Add network field to transaction_lock (4-tuple unique index) and order flow - Add wallet management endpoints (add/list/get/status/delete) with token auth - Add network info to Telegram payment notification - Add USDC hint to test script GMPay prompt - Add API docs and Solana scanning docs
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
package comm
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/assimon/luuu/model/data"
|
||||
"github.com/assimon/luuu/model/mdb"
|
||||
"github.com/assimon/luuu/util/constant"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
type addWalletRequest struct {
|
||||
Network string `json:"network" validate:"required"`
|
||||
Address string `json:"address" validate:"required"`
|
||||
}
|
||||
|
||||
type changeStatusRequest struct {
|
||||
Status int `json:"status" validate:"required|in:1,2"`
|
||||
}
|
||||
|
||||
// AddWallet 添加钱包地址
|
||||
func (c *BaseCommController) AddWallet(ctx echo.Context) error {
|
||||
req := new(addWalletRequest)
|
||||
if err := ctx.Bind(req); err != nil {
|
||||
return c.FailJson(ctx, constant.ParamsMarshalErr)
|
||||
}
|
||||
if err := c.ValidateStruct(ctx, req); err != nil {
|
||||
return c.FailJson(ctx, err)
|
||||
}
|
||||
wallet, err := data.AddWalletAddressWithNetwork(req.Network, req.Address)
|
||||
if err != nil {
|
||||
return c.FailJson(ctx, err)
|
||||
}
|
||||
return c.SucJson(ctx, wallet)
|
||||
}
|
||||
|
||||
// ListWallets 获取钱包列表
|
||||
func (c *BaseCommController) ListWallets(ctx echo.Context) error {
|
||||
network := ctx.QueryParam("network")
|
||||
var wallets []mdb.WalletAddress
|
||||
var err error
|
||||
if network != "" {
|
||||
wallets, err = data.GetAllWalletAddressByNetwork(network)
|
||||
} else {
|
||||
wallets, err = data.GetAllWalletAddress()
|
||||
}
|
||||
if err != nil {
|
||||
return c.FailJson(ctx, err)
|
||||
}
|
||||
return c.SucJson(ctx, wallets)
|
||||
}
|
||||
|
||||
// GetWallet 获取单个钱包
|
||||
func (c *BaseCommController) GetWallet(ctx echo.Context) error {
|
||||
id, err := strconv.ParseUint(ctx.Param("id"), 10, 64)
|
||||
if err != nil {
|
||||
return c.FailJson(ctx, constant.ParamsMarshalErr)
|
||||
}
|
||||
wallet, err := data.GetWalletAddressById(id)
|
||||
if err != nil {
|
||||
return c.FailJson(ctx, err)
|
||||
}
|
||||
if wallet.ID <= 0 {
|
||||
return c.FailJson(ctx, constant.NotAvailableWalletAddress)
|
||||
}
|
||||
return c.SucJson(ctx, wallet)
|
||||
}
|
||||
|
||||
// ChangeWalletStatus 启用/禁用钱包
|
||||
func (c *BaseCommController) ChangeWalletStatus(ctx echo.Context) error {
|
||||
id, err := strconv.ParseUint(ctx.Param("id"), 10, 64)
|
||||
if err != nil {
|
||||
return c.FailJson(ctx, constant.ParamsMarshalErr)
|
||||
}
|
||||
req := new(changeStatusRequest)
|
||||
if err := ctx.Bind(req); err != nil {
|
||||
return c.FailJson(ctx, constant.ParamsMarshalErr)
|
||||
}
|
||||
if err := c.ValidateStruct(ctx, req); err != nil {
|
||||
return c.FailJson(ctx, err)
|
||||
}
|
||||
if err := data.ChangeWalletAddressStatus(id, req.Status); err != nil {
|
||||
return c.FailJson(ctx, err)
|
||||
}
|
||||
return c.SucJson(ctx, nil)
|
||||
}
|
||||
|
||||
// DeleteWallet 删除钱包
|
||||
func (c *BaseCommController) DeleteWallet(ctx echo.Context) error {
|
||||
id, err := strconv.ParseUint(ctx.Param("id"), 10, 64)
|
||||
if err != nil {
|
||||
return c.FailJson(ctx, constant.ParamsMarshalErr)
|
||||
}
|
||||
if err := data.DeleteWalletAddressById(id); err != nil {
|
||||
return c.FailJson(ctx, err)
|
||||
}
|
||||
return c.SucJson(ctx, nil)
|
||||
}
|
||||
Reference in New Issue
Block a user