Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6a2f3b6d6e | ||
|
|
e906090ba6 | ||
|
|
077070b2cb |
+7
-2
@@ -1,9 +1,14 @@
|
||||
# 监听地址,格式为 ip:port,例如 :8080
|
||||
LISTEN=127.0.0.1:8080
|
||||
|
||||
# 日志文件保存路径
|
||||
LOG=/var/log/bepusdt/
|
||||
|
||||
# SQLite 数据库文件路径(如果使用 MySQL,此项可忽略)
|
||||
SQLITE=/var/lib/bepusdt/sqlite.db
|
||||
# MySQL 数据库连接字符串(留空则使用 SQLite)
|
||||
# 格式:user:password@tcp(host:port)/database?charset=utf8mb4&parseTime=True&loc=Local
|
||||
|
||||
# MySQL 数据库
|
||||
# MYSQL_DSN=user:password@tcp(127.0.0.1:3306)/bepusdt?charset=utf8mb4&parseTime=True&loc=Local&timeout=3s&readTimeout=10s&writeTimeout=10s
|
||||
|
||||
# PostgreSQL 数据库
|
||||
# POSTGRESQL_DSN=postgres://user:password@localhost:5432/bepusdt?sslmode=disable&connect_timeout=3
|
||||
@@ -16,6 +16,13 @@ var MySQLDSNFlag = &cli.StringFlag{
|
||||
Sources: cli.EnvVars("MYSQL_DSN"),
|
||||
}
|
||||
|
||||
var PostgresDSNFlag = &cli.StringFlag{
|
||||
Name: "postgres",
|
||||
Value: "",
|
||||
Usage: "PostgreSQL 数据库连接字符串 (DSN),例如: postgres://user:password@localhost:5432/bepusdt?sslmode=disable&connect_timeout=3",
|
||||
Sources: cli.EnvVars("POSTGRESQL_DSN"),
|
||||
}
|
||||
|
||||
var LogFlag = &cli.StringFlag{
|
||||
Name: "log",
|
||||
Value: "/var/log/bepusdt/",
|
||||
|
||||
+4
-3
@@ -15,11 +15,12 @@ import (
|
||||
var Reset = &cli.Command{
|
||||
Name: "reset",
|
||||
Usage: "忘记密码时,此命令可重置账号密码登录入口",
|
||||
Flags: []cli.Flag{SQLiteFlag, MySQLDSNFlag},
|
||||
Flags: []cli.Flag{SQLiteFlag, MySQLDSNFlag, PostgresDSNFlag},
|
||||
Before: func(ctx context.Context, c *cli.Command) (context.Context, error) {
|
||||
dsn := c.String("mysql")
|
||||
mysql := c.String("mysql")
|
||||
postgres := c.String("postgres")
|
||||
sqlite := c.String("sqlite")
|
||||
if err := model.Init(sqlite, dsn); err != nil {
|
||||
if err := model.Init(sqlite, mysql, postgres); err != nil {
|
||||
return ctx, fmt.Errorf("数据库初始化失败 %w", err)
|
||||
}
|
||||
|
||||
|
||||
+4
-3
@@ -27,11 +27,12 @@ import (
|
||||
var Start = &cli.Command{
|
||||
Name: "start",
|
||||
Usage: "启动收款网关",
|
||||
Flags: []cli.Flag{SQLiteFlag, MySQLDSNFlag, LogFlag, ListenFlag},
|
||||
Flags: []cli.Flag{SQLiteFlag, MySQLDSNFlag, PostgresDSNFlag, LogFlag, ListenFlag},
|
||||
Before: func(ctx context.Context, c *cli.Command) (context.Context, error) {
|
||||
dsn := c.String("mysql")
|
||||
mysql := c.String("mysql")
|
||||
postgres := c.String("postgres")
|
||||
sqlite := c.String("sqlite")
|
||||
if err := model.Init(sqlite, dsn); err != nil {
|
||||
if err := model.Init(sqlite, mysql, postgres); err != nil {
|
||||
return ctx, fmt.Errorf("数据库初始化失败 %w", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ type methodsReq struct {
|
||||
Currency string `json:"currency"`
|
||||
}
|
||||
|
||||
type methodItem struct {
|
||||
type PaymentItem struct {
|
||||
Amount string `json:"amount"`
|
||||
ActualAmount string `json:"actual_amount"`
|
||||
Fiat string `json:"fiat"`
|
||||
@@ -186,6 +186,7 @@ func (Epusdt) CreateOrder(ctx *gin.Context) {
|
||||
"amount": order.Money,
|
||||
"expiration_time": uint64(order.ExpiredAt.Sub(time.Now()).Seconds()),
|
||||
"payment_url": model.CheckoutCashier(host, order.TradeId),
|
||||
"network": GetPaymentItem("", order),
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -393,6 +394,7 @@ func (Epusdt) CheckoutCashier(ctx *gin.Context) {
|
||||
"name": order.Name,
|
||||
"money": order.Money,
|
||||
"fiat": order.Fiat,
|
||||
"network": GetPaymentItem("", order),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -441,10 +443,15 @@ func (Epusdt) GetPaymentMethods(ctx *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// 强制使用订单的法币类型
|
||||
ctx.JSON(200, respSuccJson(gin.H{
|
||||
"methods": GetPaymentItem(model.Crypto(req.Currency), order),
|
||||
}))
|
||||
}
|
||||
|
||||
func GetPaymentItem(crypto model.Crypto, order model.Order) []PaymentItem {
|
||||
fiat := order.Fiat
|
||||
|
||||
var methods []methodItem
|
||||
var methods = make([]PaymentItem, 0)
|
||||
allTrades := model.GetAllTradeConfig()
|
||||
|
||||
// 解析限定币种
|
||||
@@ -463,7 +470,7 @@ func (Epusdt) GetPaymentMethods(ctx *gin.Context) {
|
||||
|
||||
for tradeTypeStr, conf := range allTrades {
|
||||
// 如果指定了货币,则进行过滤
|
||||
if req.Currency != "" && string(conf.Crypto) != req.Currency {
|
||||
if crypto != "" && conf.Crypto != crypto {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -478,10 +485,7 @@ func (Epusdt) GetPaymentMethods(ctx *gin.Context) {
|
||||
}
|
||||
|
||||
// 检查是否有可用钱包
|
||||
var count int
|
||||
tradeType := model.TradeType(tradeTypeStr)
|
||||
count = len(model.GetAvailableAddress(tradeType))
|
||||
|
||||
count := len(model.GetAvailableAddress(model.TradeType(tradeTypeStr)))
|
||||
if count == 0 {
|
||||
continue
|
||||
}
|
||||
@@ -506,16 +510,15 @@ func (Epusdt) GetPaymentMethods(ctx *gin.Context) {
|
||||
if actualAmount.LessThan(atom) {
|
||||
actualAmount = atom
|
||||
}
|
||||
actualAmountStr := actualAmount.String()
|
||||
|
||||
methods = append(methods, methodItem{
|
||||
methods = append(methods, PaymentItem{
|
||||
Amount: order.Money,
|
||||
ActualAmount: actualAmountStr,
|
||||
ActualAmount: actualAmount.String(),
|
||||
Fiat: string(fiat),
|
||||
ExchangeRate: rate.String(),
|
||||
Currency: string(conf.Crypto),
|
||||
Network: string(conf.Network),
|
||||
TokenNetName: string(conf.NetworkName),
|
||||
TokenNetName: conf.NetworkName,
|
||||
TokenCustomName: "", // 暂为空
|
||||
IsPopular: false, // 暂为 false
|
||||
})
|
||||
@@ -529,9 +532,7 @@ func (Epusdt) GetPaymentMethods(ctx *gin.Context) {
|
||||
return methods[i].Network < methods[j].Network
|
||||
})
|
||||
|
||||
ctx.JSON(200, respSuccJson(gin.H{
|
||||
"methods": methods,
|
||||
}))
|
||||
return methods
|
||||
}
|
||||
|
||||
func respFailJson(message string) gin.H {
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ func (c Conf) TableName() string {
|
||||
|
||||
func SetK(k ConfKey, v string) {
|
||||
if err = Db.Transaction(func(db *gorm.DB) error {
|
||||
if err2 := db.Where("`k` = ?", k).Delete(&Conf{}).Error; err2 != nil {
|
||||
if err2 := db.Where("k = ?", k).Delete(&Conf{}).Error; err2 != nil {
|
||||
|
||||
return err2
|
||||
}
|
||||
|
||||
+48
-6
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"github.com/glebarez/sqlite"
|
||||
"gorm.io/driver/mysql"
|
||||
"gorm.io/driver/postgres"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@@ -19,14 +20,16 @@ type Id struct {
|
||||
}
|
||||
|
||||
type AutoTimeAt struct {
|
||||
CreatedAt *Datetime `gorm:"column:created_at;type:Datetime;not null;comment:记录创建时间;index" json:"created_at"`
|
||||
UpdatedAt *Datetime `gorm:"column:updated_at;type:Datetime;not null;comment:最后更新时间" json:"updated_at"`
|
||||
CreatedAt *Datetime `gorm:"column:created_at;not null;comment:记录创建时间;index" json:"created_at"`
|
||||
UpdatedAt *Datetime `gorm:"column:updated_at;not null;comment:最后更新时间" json:"updated_at"`
|
||||
}
|
||||
|
||||
func Init(path, dsn string) error {
|
||||
if dsn != "" {
|
||||
|
||||
return initMySQL(dsn)
|
||||
func Init(path, mysql, postgres string) error {
|
||||
if postgres != "" {
|
||||
return initPostgres(postgres)
|
||||
}
|
||||
if mysql != "" {
|
||||
return initMySQL(mysql)
|
||||
}
|
||||
|
||||
return initSqlite(path)
|
||||
@@ -120,6 +123,45 @@ func initMySQL(dsn string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func initPostgres(dsn string) error {
|
||||
// 首次启动可能出现 SLOW SQL 告警,这是由于连接池首次连接预热引起的,后续连接将正常
|
||||
|
||||
var err error
|
||||
Db, err = gorm.Open(postgres.New(postgres.Config{DSN: dsn, PreferSimpleProtocol: true}), &gorm.Config{})
|
||||
if err != nil {
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
{
|
||||
sqlDB, err := Db.DB()
|
||||
if err != nil {
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
sqlDB.SetMaxIdleConns(10)
|
||||
sqlDB.SetMaxOpenConns(100)
|
||||
sqlDB.SetConnMaxLifetime(30 * time.Minute)
|
||||
sqlDB.SetConnMaxIdleTime(10 * time.Minute)
|
||||
}
|
||||
|
||||
if err = AutoMigrate(); err != nil {
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
var count int64
|
||||
Db.Model(&Conf{}).Count(&count)
|
||||
if count == 0 {
|
||||
ConfInit()
|
||||
}
|
||||
|
||||
RefreshC()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func AutoMigrate() error {
|
||||
return Db.AutoMigrate(&Wallet{}, &Order{}, &NotifyRecord{}, &Conf{}, &Rate{})
|
||||
}
|
||||
|
||||
+8
-8
@@ -67,17 +67,17 @@ type Order struct {
|
||||
Money string `gorm:"column:money;type:varchar(32);not null;default:0.00;comment:交易金额" json:"money"`
|
||||
Address string `gorm:"column:address;type:varchar(128);index;not null;comment:收款地址" json:"address"`
|
||||
FromAddress string `gorm:"column:from_address;type:varchar(128);not null;default:'';comment:支付地址" json:"from_address"`
|
||||
Status int `gorm:"column:status;type:tinyint(1);not null;default:1;index;comment:交易状态" json:"status"`
|
||||
Status int `gorm:"column:status;not null;default:1;index;comment:交易状态" json:"status"`
|
||||
Name string `gorm:"column:name;type:varchar(64);not null;default:'';comment:商品名称" json:"name"`
|
||||
ApiType string `gorm:"column:api_type;type:varchar(20);not null;default:'epusdt';comment:API类型" json:"api_type"`
|
||||
ReturnUrl string `gorm:"column:return_url;type:varchar(255);not null;default:'';comment:同步地址" json:"return_url"`
|
||||
NotifyUrl string `gorm:"column:notify_url;type:varchar(255);not null;default:'';comment:异步地址" json:"notify_url"`
|
||||
NotifyNum int `gorm:"column:notify_num;type:int(11);not null;default:0;comment:回调次数" json:"notify_num"`
|
||||
NotifyState int `gorm:"column:notify_state;type:tinyint(1);not null;default:0;comment:回调状态 1:成功 0:失败" json:"notify_state"`
|
||||
NotifyNum int `gorm:"column:notify_num;not null;default:0;comment:回调次数" json:"notify_num"`
|
||||
NotifyState int `gorm:"column:notify_state;not null;default:0;comment:回调状态 1:成功 0:失败" json:"notify_state"`
|
||||
RefHash string `gorm:"column:ref_hash;type:varchar(128);not null;default:'';index;comment:交易哈希" json:"ref_hash"`
|
||||
RefBlockNum int64 `gorm:"column:ref_block_num;type:varchar(64);not null;default:0;comment:区块索引" json:"ref_block_num"`
|
||||
ExpiredAt time.Time `gorm:"column:expired_at;type:datetime;not null;comment:失效时间" json:"expired_at"`
|
||||
ConfirmedAt *time.Time `gorm:"column:confirmed_at;type:datetime;not null;comment:交易确认时间" json:"confirmed_at"`
|
||||
RefBlockNum int `gorm:"column:ref_block_num;not null;default:0;comment:区块索引" json:"ref_block_num"`
|
||||
ExpiredAt time.Time `gorm:"column:expired_at;not null;comment:失效时间" json:"expired_at"`
|
||||
ConfirmedAt *time.Time `gorm:"column:confirmed_at;not null;comment:交易确认时间" json:"confirmed_at"`
|
||||
AutoTimeAt
|
||||
}
|
||||
|
||||
@@ -105,11 +105,11 @@ func (o *Order) SetFailed() {
|
||||
Db.Save(o)
|
||||
}
|
||||
|
||||
func (o *Order) MarkConfirming(blockNum int64, from, hash string, at time.Time) {
|
||||
func (o *Order) MarkConfirming(blockNum int, from, hash string, at time.Time) {
|
||||
o.FromAddress = from
|
||||
o.ConfirmedAt = &at
|
||||
o.RefHash = hash
|
||||
o.RefBlockNum = blockNum
|
||||
o.RefBlockNum = int(blockNum)
|
||||
o.Status = OrderStatusConfirming
|
||||
|
||||
Db.Save(o)
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ type TronTransfer struct {
|
||||
RecvAddress string
|
||||
Timestamp time.Time
|
||||
TradeType TradeType
|
||||
BlockNum int64
|
||||
BlockNum int
|
||||
}
|
||||
|
||||
type TronResource struct {
|
||||
|
||||
+2
-2
@@ -14,11 +14,11 @@ const (
|
||||
type Wallet struct {
|
||||
Id
|
||||
Name string `gorm:"column:name;type:varchar(32);not null;default:-';comment:名称" json:"name"`
|
||||
Status uint8 `gorm:"column:status;type:tinyint(1);not null;default:1;comment:地址状态" json:"status"`
|
||||
Status uint8 `gorm:"column:status;not null;default:1;comment:地址状态" json:"status"`
|
||||
Address string `gorm:"column:address;type:varchar(128);not null;index;comment:钱包地址" json:"address"`
|
||||
MatchAddr string `gorm:"column:match_addr;type:varchar(128);not null;uniqueIndex:idx_address;comment:匹配地址" json:"match_addr"`
|
||||
TradeType string `gorm:"column:trade_type;type:varchar(20);not null;uniqueIndex:idx_address;comment:交易类型" json:"trade_type"`
|
||||
OtherNotify uint8 `gorm:"column:other_notify;type:tinyint(1);not null;default:0;comment:其它通知" json:"other_notify"`
|
||||
OtherNotify uint8 `gorm:"column:other_notify;not null;default:0;comment:其它通知" json:"other_notify"`
|
||||
Remark string `gorm:"column:remark;type:varchar(255);not null;default:'';comment:备注" json:"remark"`
|
||||
AutoTimeAt
|
||||
}
|
||||
|
||||
+9
-9
@@ -22,17 +22,17 @@ import (
|
||||
)
|
||||
|
||||
type aptos struct {
|
||||
versionChunkSize int64
|
||||
versionConfirmedOffset int64
|
||||
lastVersion int64
|
||||
versionChunkSize int
|
||||
versionConfirmedOffset int
|
||||
lastVersion int
|
||||
versionQueue *chanx.UnboundedChan[version]
|
||||
client *http.Client
|
||||
earliestBlockTs atomic.Int64
|
||||
}
|
||||
|
||||
type version struct {
|
||||
Start int64
|
||||
Limit int64
|
||||
Start int
|
||||
Limit int
|
||||
}
|
||||
|
||||
var apt aptos
|
||||
@@ -96,7 +96,7 @@ func (a *aptos) syncVersionForward(ctx context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
now := gjson.GetBytes(body, "ledger_version").Int()
|
||||
now := int(gjson.GetBytes(body, "ledger_version").Int())
|
||||
if now <= 0 {
|
||||
log.Task.Warn("syncVersionForward Error: invalid ledger_version:", now)
|
||||
|
||||
@@ -116,7 +116,7 @@ func (a *aptos) syncVersionForward(ctx context.Context) {
|
||||
a.versionQueue.In <- version{Start: a.lastVersion, Limit: sub}
|
||||
} else {
|
||||
chunks := (sub + a.versionChunkSize - 1) / a.versionChunkSize
|
||||
for i := int64(0); i < chunks; i++ {
|
||||
for i := 0; i < chunks; i++ {
|
||||
limit := a.versionChunkSize
|
||||
start := a.lastVersion + a.versionChunkSize*i
|
||||
if i == chunks-1 {
|
||||
@@ -133,7 +133,7 @@ func (a *aptos) syncVersionForward(ctx context.Context) {
|
||||
a.lastVersion = now
|
||||
}
|
||||
|
||||
func (a *aptos) syncVersionBackward(ctx context.Context, now int64) {
|
||||
func (a *aptos) syncVersionBackward(ctx context.Context, now int) {
|
||||
var o model.Order
|
||||
trade := model.GetNetworkTrades(conf.Aptos)
|
||||
model.Db.Model(&model.Order{}).Where("status = ? and trade_type in (?)",
|
||||
@@ -247,7 +247,7 @@ func (a *aptos) versionParse(n any) {
|
||||
timestamp := time.Unix(tsNano/1e9, tsNano%1e9)
|
||||
a.recordEarliestBlockTs(timestamp.Unix())
|
||||
|
||||
ver := trans.Get("version").Int()
|
||||
ver := int(trans.Get("version").Int())
|
||||
hash := trans.Get("hash").String()
|
||||
addrOwner := make(map[string]string) // [address] => owner address
|
||||
addrType := make(map[string]model.TradeType) // [address] => tradeType
|
||||
|
||||
+5
-13
@@ -8,7 +8,6 @@ import (
|
||||
"io"
|
||||
"math/big"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -33,7 +32,7 @@ var chainBlockNum sync.Map
|
||||
|
||||
type block struct {
|
||||
RollDelayOffset int64 // 延迟偏移量,某些RPC节点如果不延迟,会报错 block is out of range,目前发现 https://rpc.xlayer.tech/ 存在此问题
|
||||
ConfirmedOffset int64 // 确认偏移量,开启交易确认后,区块高度需要减去此值认为交易已确认
|
||||
ConfirmedOffset int // 确认偏移量,开启交易确认后,区块高度需要减去此值认为交易已确认
|
||||
}
|
||||
|
||||
type evmNative struct {
|
||||
@@ -256,7 +255,7 @@ func (e *evm) getBlockByNumber(a any) {
|
||||
var array = itm.Get("result.transactions").Array()
|
||||
if e.Native.Parse && len(array) != 0 {
|
||||
|
||||
nativeTransfers = append(nativeTransfers, e.parseNativeTransfer(array, utils.HexStr2Int(blockNumHex).Int64(), blockTime)...)
|
||||
nativeTransfers = append(nativeTransfers, e.parseNativeTransfer(array, int(utils.HexStr2Int(blockNumHex).Int64()), blockTime)...)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -279,7 +278,7 @@ func (e *evm) getBlockByNumber(a any) {
|
||||
log.Task.Info(fmt.Sprintf("区块扫描完成(%s): %d → %d 成功率:%s", e.Network, b.From, b.To, conf.GetSuccessRate(e.Network)))
|
||||
}
|
||||
|
||||
func (e *evm) parseNativeTransfer(array []gjson.Result, num int64, timestamp time.Time) []transfer {
|
||||
func (e *evm) parseNativeTransfer(array []gjson.Result, num int, timestamp time.Time) []transfer {
|
||||
nativeTransfers := make([]transfer, 0)
|
||||
for _, tx := range array {
|
||||
if tx.Get("input").String() != "0x" {
|
||||
@@ -372,20 +371,13 @@ func (e *evm) parseEventTransfer(b evmBlock, timestamp map[string]time.Time) ([]
|
||||
continue
|
||||
}
|
||||
|
||||
blockNum, err := strconv.ParseInt(itm.Get("blockNumber").String(), 0, 64)
|
||||
if err != nil {
|
||||
log.Task.Warn("evmBlockParse Error parsing block number:", err)
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
transfers = append(transfers, transfer{
|
||||
Network: e.Network,
|
||||
FromAddress: from,
|
||||
RecvAddress: recv,
|
||||
Amount: decimal.NewFromBigInt(amount, model.GetContractDecimal(to)),
|
||||
TxHash: itm.Get("transactionHash").String(),
|
||||
BlockNum: blockNum,
|
||||
BlockNum: cast.ToInt(itm.Get("blockNumber").String()),
|
||||
Timestamp: timestamp[itm.Get("blockNumber").String()],
|
||||
TradeType: tradeType,
|
||||
})
|
||||
@@ -404,7 +396,7 @@ func (e *evm) tradeConfirmHandle(ctx context.Context) {
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if last.(int64)-o.RefBlockNum < e.Block.ConfirmedOffset {
|
||||
if last.(int)-o.RefBlockNum < e.Block.ConfirmedOffset {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
+10
-10
@@ -28,9 +28,9 @@ import (
|
||||
// - https://github.com/solana-program/token/blob/6d18ff73b1dd30703a30b1ca941cb0f1d18c2b2a/program/src/instruction.rs
|
||||
|
||||
type solana struct {
|
||||
slotConfirmedOffset int64
|
||||
lastSlotNum int64
|
||||
slotQueue *chanx.UnboundedChan[int64]
|
||||
slotConfirmedOffset int
|
||||
lastSlotNum int
|
||||
slotQueue *chanx.UnboundedChan[int]
|
||||
client *http.Client
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ func newSolana() solana {
|
||||
return solana{
|
||||
slotConfirmedOffset: 60,
|
||||
lastSlotNum: 0,
|
||||
slotQueue: chanx.NewUnboundedChan[int64](context.Background(), 30),
|
||||
slotQueue: chanx.NewUnboundedChan[int](context.Background(), 30),
|
||||
client: utils.NewHttpClient(),
|
||||
}
|
||||
}
|
||||
@@ -88,7 +88,7 @@ func (s *solana) syncSlotForward(ctx context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
now := gjson.GetBytes(body, "result").Int()
|
||||
now := int(gjson.GetBytes(body, "result").Int())
|
||||
if now <= 0 {
|
||||
log.Task.Warn("syncSlotForward Error: invalid slot number:", now)
|
||||
|
||||
@@ -99,7 +99,7 @@ func (s *solana) syncSlotForward(ctx context.Context) {
|
||||
s.syncSlotBackward(now)
|
||||
}
|
||||
|
||||
if now-s.lastSlotNum > cast.ToInt64(model.GetC(model.BlockHeightMaxDiff)) { // 区块高度变化过大,强制丢块重扫
|
||||
if now-s.lastSlotNum > cast.ToInt(model.GetC(model.BlockHeightMaxDiff)) { // 区块高度变化过大,强制丢块重扫
|
||||
s.lastSlotNum = now
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ func (s *solana) syncSlotForward(ctx context.Context) {
|
||||
s.lastSlotNum = now
|
||||
}
|
||||
|
||||
func (s *solana) syncSlotBackward(now int64) {
|
||||
func (s *solana) syncSlotBackward(now int) {
|
||||
if now == 0 || s.lastSlotNum != 0 {
|
||||
|
||||
return
|
||||
@@ -132,13 +132,13 @@ func (s *solana) syncSlotBackward(now int64) {
|
||||
}
|
||||
|
||||
// Solana 大概1秒3个区块(大概值,实际存在波动)
|
||||
num := (time.Now().Unix() - o.CreatedAt.Time().Unix() + 1) * 3 // 计算需要反向扫描的区块数量
|
||||
num := int((time.Now().Unix() - o.CreatedAt.Time().Unix() + 1) * 3) // 计算需要反向扫描的区块数量
|
||||
|
||||
go func() {
|
||||
ticker := time.NewTicker(time.Millisecond * 125)
|
||||
defer ticker.Stop()
|
||||
|
||||
for i := int64(0); i < num; i++ {
|
||||
for i := 0; i < num; i++ {
|
||||
if syncBreak(conf.Solana, s.slotQueue.Len()) {
|
||||
|
||||
return
|
||||
@@ -179,7 +179,7 @@ func (s *solana) slotDispatch(ctx context.Context) {
|
||||
}
|
||||
|
||||
func (s *solana) slotParse(n any) {
|
||||
slot := n.(int64)
|
||||
slot := n.(int)
|
||||
post := []byte(fmt.Sprintf(`{"jsonrpc":"2.0","id":1,"method":"getBlock","params":[%d,{"encoding":"json","maxSupportedTransactionVersion":0,"transactionDetails":"full","rewards":false}]}`, slot))
|
||||
network := conf.Solana
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ type transfer struct {
|
||||
RecvAddress string
|
||||
Timestamp time.Time
|
||||
TradeType model.TradeType
|
||||
BlockNum int64
|
||||
BlockNum int
|
||||
}
|
||||
|
||||
type resource struct {
|
||||
@@ -40,7 +40,7 @@ var resourceQueue = chanx.NewUnboundedChan[[]resource](context.Background(), 30)
|
||||
var notOrderQueue = chanx.NewUnboundedChan[[]transfer](context.Background(), 30) // 非订单队列
|
||||
var transferQueue = chanx.NewUnboundedChan[[]transfer](context.Background(), 30) // 交易转账队列
|
||||
|
||||
const batchInterval = time.Second * 1 // 批处理缓解数据库读取压力
|
||||
const batchInterval = time.Second * 1 // 批处理缓解数据库读取压力
|
||||
const orderCheckInterval = time.Second * 10 // 订单过期检查间隔
|
||||
|
||||
func init() {
|
||||
|
||||
+15
-15
@@ -32,9 +32,9 @@ var usdtTrc20ContractAddress = []byte{0x41, 0xa6, 0x14, 0xf8, 0x03, 0xb6, 0xfd,
|
||||
var usdcTrc20ContractAddress = []byte{0x41, 0x34, 0x87, 0xb6, 0x3d, 0x30, 0xb5, 0xb2, 0xc8, 0x7f, 0xb7, 0xff, 0xa8, 0xbc, 0xfa, 0xde, 0x38, 0xea, 0xac, 0x1a, 0xbe}
|
||||
|
||||
type tron struct {
|
||||
lastBlockNum int64
|
||||
blockConfirmedOffset int64
|
||||
blockScanQueue *chanx.UnboundedChan[int64]
|
||||
lastBlockNum int
|
||||
blockConfirmedOffset int
|
||||
blockScanQueue *chanx.UnboundedChan[int]
|
||||
conn map[string]*grpc.ClientConn
|
||||
connMu sync.RWMutex
|
||||
}
|
||||
@@ -52,7 +52,7 @@ func newTron() tron {
|
||||
return tron{
|
||||
lastBlockNum: 0,
|
||||
blockConfirmedOffset: 30,
|
||||
blockScanQueue: chanx.NewUnboundedChan[int64](context.Background(), 30),
|
||||
blockScanQueue: chanx.NewUnboundedChan[int](context.Background(), 30),
|
||||
conn: make(map[string]*grpc.ClientConn),
|
||||
}
|
||||
}
|
||||
@@ -81,10 +81,10 @@ func (t *tron) syncBlocksForward(context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
var now = block.BlockHeader.RawData.Number
|
||||
var now = int(block.BlockHeader.RawData.Number)
|
||||
|
||||
// 区块高度变化过大,强制丢块重扫
|
||||
if now-t.lastBlockNum > cast.ToInt64(model.GetC(model.BlockHeightMaxDiff)) {
|
||||
if now-t.lastBlockNum > cast.ToInt(model.GetC(model.BlockHeightMaxDiff)) {
|
||||
t.syncBlocksBackward(now)
|
||||
t.lastBlockNum = now - 1
|
||||
}
|
||||
@@ -105,7 +105,7 @@ func (t *tron) syncBlocksForward(context.Context) {
|
||||
}
|
||||
|
||||
// syncBlocksBackward 反向同步区块,针对程序启动前就已经存在待支付订单时,补齐之前的区块数据,自适应偏移数量
|
||||
func (t *tron) syncBlocksBackward(now int64) {
|
||||
func (t *tron) syncBlocksBackward(now int) {
|
||||
var o model.Order
|
||||
trade := model.GetNetworkTrades(conf.Tron)
|
||||
model.Db.Model(&model.Order{}).Where("status = ? and trade_type in (?)", model.OrderStatusWaiting, trade).Order("created_at asc").Limit(1).Find(&o)
|
||||
@@ -116,7 +116,7 @@ func (t *tron) syncBlocksBackward(now int64) {
|
||||
|
||||
// 波场出块速度大概3秒一个,同时再冗余5个区块
|
||||
num := (time.Now().Unix() - o.CreatedAt.Time().Unix() + 1) / 3 // 计算需要反向扫描的区块数量
|
||||
start := now - num - 5 // 计算反向扫描的起始区块高度
|
||||
start := now - int(num) - 5 // 计算反向扫描的起始区块高度
|
||||
|
||||
go func() {
|
||||
ticker := time.NewTicker(time.Second)
|
||||
@@ -158,7 +158,7 @@ func (t *tron) blockDispatch(context.Context) {
|
||||
}
|
||||
|
||||
func (t *tron) blockParse(n any) {
|
||||
var num = n.(int64)
|
||||
var num = n.(int)
|
||||
|
||||
var conn *grpc.ClientConn
|
||||
var err error
|
||||
@@ -171,11 +171,11 @@ func (t *tron) blockParse(n any) {
|
||||
conf.RecordSuccess(conf.Tron)
|
||||
|
||||
var ctx, cancel = context.WithTimeout(context.Background(), time.Second*5)
|
||||
bok, err2 := api.NewWalletClient(conn).GetBlockByNum2(ctx, &api.NumberMessage{Num: num})
|
||||
bok, err2 := api.NewWalletClient(conn).GetBlockByNum2(ctx, &api.NumberMessage{Num: int64(num)})
|
||||
cancel()
|
||||
if err2 != nil {
|
||||
conf.RecordFailure(conf.Tron)
|
||||
t.blockScanQueue.In <- num
|
||||
t.blockScanQueue.In <- int(num)
|
||||
log.Task.Warn("GetBlockByNum2 ", err2)
|
||||
|
||||
return
|
||||
@@ -250,7 +250,7 @@ func (t *tron) blockParse(n any) {
|
||||
RecvAddress: t.base58CheckEncode(foo.ToAddress),
|
||||
Timestamp: timestamp,
|
||||
TradeType: model.TronTrx,
|
||||
BlockNum: cast.ToInt64(num),
|
||||
BlockNum: cast.ToInt(num),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -280,7 +280,7 @@ func (t *tron) blockParse(n any) {
|
||||
RecvAddress: receiver,
|
||||
Timestamp: timestamp,
|
||||
TradeType: model.UsdtTrc20,
|
||||
BlockNum: cast.ToInt64(num),
|
||||
BlockNum: cast.ToInt(num),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -306,7 +306,7 @@ func (t *tron) blockParse(n any) {
|
||||
RecvAddress: receiver,
|
||||
Timestamp: timestamp,
|
||||
TradeType: tradeType,
|
||||
BlockNum: cast.ToInt64(num),
|
||||
BlockNum: cast.ToInt(num),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -321,7 +321,7 @@ func (t *tron) blockParse(n any) {
|
||||
RecvAddress: to,
|
||||
Timestamp: timestamp,
|
||||
TradeType: tradeType,
|
||||
BlockNum: cast.ToInt64(num),
|
||||
BlockNum: cast.ToInt(num),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +44,10 @@ require (
|
||||
github.com/gorilla/context v1.1.2 // indirect
|
||||
github.com/gorilla/securecookie v1.1.2 // indirect
|
||||
github.com/gorilla/sessions v1.4.0 // indirect
|
||||
github.com/jackc/pgpassfile v1.0.0 // indirect
|
||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
|
||||
github.com/jackc/pgx/v5 v5.6.0 // indirect
|
||||
github.com/jackc/puddle/v2 v2.2.2 // indirect
|
||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||
github.com/jinzhu/now v1.1.5 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
@@ -71,8 +75,9 @@ require (
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20250324211829-b45e905df463 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250603155806-513f23925822 // indirect
|
||||
google.golang.org/protobuf v1.36.6 // indirect
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
gorm.io/driver/postgres v1.6.0 // indirect
|
||||
modernc.org/libc v1.65.10 // indirect
|
||||
modernc.org/mathutil v1.7.1 // indirect
|
||||
modernc.org/memory v1.11.0 // indirect
|
||||
|
||||
@@ -106,6 +106,14 @@ github.com/gorilla/sessions v1.4.0 h1:kpIYOp/oi6MG/p5PgxApU8srsSw9tuFbt46Lt7auzq
|
||||
github.com/gorilla/sessions v1.4.0/go.mod h1:FLWm50oby91+hl7p/wRxDth9bWSuk0qVL2emc7lT5ik=
|
||||
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
|
||||
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
|
||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
|
||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
|
||||
github.com/jackc/pgx/v5 v5.6.0 h1:SWJzexBzPL5jb0GEsrPMLIsi/3jOo7RHlzTjcAeDrPY=
|
||||
github.com/jackc/pgx/v5 v5.6.0/go.mod h1:DNZ/vlrUnhWCoFGxHAG8U2ljioxukquj7utPDgtQdTw=
|
||||
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
|
||||
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
|
||||
github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
|
||||
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
|
||||
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
|
||||
@@ -122,8 +130,11 @@ github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa02
|
||||
github.com/klauspost/cpuid/v2 v2.2.10 h1:tBs3QSyvjDyFTq3uoc/9xFpCuOsJQFNPiAhYdw2skhE=
|
||||
github.com/klauspost/cpuid/v2 v2.2.10/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
|
||||
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
|
||||
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
|
||||
@@ -276,6 +287,7 @@ google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
||||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
@@ -286,6 +298,8 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gorm.io/driver/mysql v1.6.0 h1:eNbLmNTpPpTOVZi8MMxCi2aaIm0ZpInbORNXDwyLGvg=
|
||||
gorm.io/driver/mysql v1.6.0/go.mod h1:D/oCC2GWK3M/dqoLxnOlaNKmXz8WNTfcS9y5ovaSqKo=
|
||||
gorm.io/driver/postgres v1.6.0 h1:2dxzU8xJ+ivvqTRph34QX+WrRaJlmfyPqXmoGVjMBa4=
|
||||
gorm.io/driver/postgres v1.6.0/go.mod h1:vUw0mrGgrTK+uPHEhAdV4sfFELrByKVGnaVRkXDhtWo=
|
||||
gorm.io/gorm v1.31.1 h1:7CA8FTFz/gRfgqgpeKIBcervUn3xSyPUmr6B2WXJ7kg=
|
||||
gorm.io/gorm v1.31.1/go.mod h1:XyQVbO2k6YkOis7C2437jSit3SsDK72s7n7rsSHd+Gs=
|
||||
modernc.org/cc/v4 v4.26.1 h1:+X5NtzVBn0KgsBCBe+xkDC7twLb/jNVj9FPgiwSQO3s=
|
||||
|
||||
@@ -51,7 +51,9 @@
|
||||
}
|
||||
|
||||
fetch('/payment/assets/locales/' + currentLang + '.json')
|
||||
.then(function (r) { return r.json(); })
|
||||
.then(function (r) {
|
||||
return r.json();
|
||||
})
|
||||
.then(function (translations) {
|
||||
i18next.addResourceBundle(currentLang, 'translation', translations);
|
||||
i18nInitialized = true;
|
||||
@@ -79,7 +81,9 @@
|
||||
|
||||
if (!hasLanguage) {
|
||||
fetch('/payment/assets/locales/' + lang + '.json')
|
||||
.then(function (r) { return r.json(); })
|
||||
.then(function (r) {
|
||||
return r.json();
|
||||
})
|
||||
.then(function (translations) {
|
||||
i18next.addResourceBundle(lang, 'translation', translations);
|
||||
return i18next.changeLanguage(lang);
|
||||
@@ -111,8 +115,8 @@
|
||||
const config = getPaymentConfig();
|
||||
|
||||
let token = (config.token || '--').toUpperCase();
|
||||
let network = (config.network || '--').toUpperCase();
|
||||
let networkName = (config.networkName || '--').toUpperCase();
|
||||
let network = selectedMethod ? (selectedMethod.network || '--').toUpperCase() : '--';
|
||||
let networkName = selectedMethod ? (selectedMethod.token_net_name || '--').toUpperCase() : '--';
|
||||
|
||||
if (selectedMethod) {
|
||||
token = selectedMethod.currency.toUpperCase();
|
||||
@@ -202,45 +206,17 @@
|
||||
// but the event listener for global click is needed once.
|
||||
}
|
||||
|
||||
function fetchPaymentMethods() {
|
||||
fetch('/api/v1/pay/methods', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
trade_id: tradeId
|
||||
})
|
||||
})
|
||||
.then(function (response) { return response.json(); })
|
||||
.then(function (res) {
|
||||
if (res.status_code === 200) {
|
||||
paymentMethods = res.data.methods;
|
||||
initSelection();
|
||||
} else {
|
||||
// Suppress alert for expired orders
|
||||
if (res.status_code === 400 && (res.message && (res.message.includes('过期') || res.message.toLowerCase().includes('expired')))) {
|
||||
showTimeoutMessage();
|
||||
return;
|
||||
}
|
||||
showMessage(res.message || t('payment.loadMethodsFailed', 'Failed to load payment methods'));
|
||||
}
|
||||
})
|
||||
.catch(function (err) {
|
||||
console.error('API Error:', err);
|
||||
showMessage(t('payment.networkError', 'Network error, please refresh'));
|
||||
});
|
||||
}
|
||||
|
||||
function initSelection() {
|
||||
if (!paymentMethods || paymentMethods.length === 0) return;
|
||||
|
||||
// Extract unique currencies
|
||||
const currencies = [...new Set(paymentMethods.map(function (m) { return m.currency; }))];
|
||||
const currencies = [...new Set(paymentMethods.map(function (m) {
|
||||
return m.currency;
|
||||
}))];
|
||||
|
||||
// Render Currency Options
|
||||
renderOptions(currencySelectEl, currencies.map(function (c) {
|
||||
return { value: c, label: c, badge: '' };
|
||||
return {value: c, label: c, badge: ''};
|
||||
}), function (val) {
|
||||
selectedCurrency = val;
|
||||
updateNetworkOptions();
|
||||
@@ -255,7 +231,9 @@
|
||||
|
||||
function updateNetworkOptions() {
|
||||
const networks = paymentMethods
|
||||
.filter(function (m) { return m.currency === selectedCurrency; })
|
||||
.filter(function (m) {
|
||||
return m.currency === selectedCurrency;
|
||||
})
|
||||
.map(function (m) {
|
||||
return {
|
||||
value: m.token_net_name,
|
||||
@@ -326,7 +304,9 @@
|
||||
if (!parent) return;
|
||||
|
||||
const items = parent.querySelectorAll('.option-item');
|
||||
items.forEach(function (item) { item.classList.remove('selected'); });
|
||||
items.forEach(function (item) {
|
||||
item.classList.remove('selected');
|
||||
});
|
||||
|
||||
let selected = null;
|
||||
items.forEach(function (item) {
|
||||
@@ -417,7 +397,9 @@
|
||||
network: selectedMethod.network
|
||||
})
|
||||
})
|
||||
.then(function (response) { return response.json(); })
|
||||
.then(function (response) {
|
||||
return response.json();
|
||||
})
|
||||
.then(function (res) {
|
||||
if (res.status_code === 200 && res.data.payment_url) {
|
||||
window.location.href = res.data.payment_url;
|
||||
@@ -670,7 +652,9 @@
|
||||
if (!tradeId) return;
|
||||
|
||||
fetch('/pay/check-status/' + tradeId)
|
||||
.then(function (r) { return r.json(); })
|
||||
.then(function (r) {
|
||||
return r.json();
|
||||
})
|
||||
.then(function (data) {
|
||||
// status: 1=pending, 2=success, 3=expired, 5=waiting_confirmation
|
||||
if (data.status === 1) {
|
||||
@@ -703,7 +687,9 @@
|
||||
// Close dropdowns when clicking outside
|
||||
document.addEventListener('click', function () {
|
||||
const selects = document.querySelectorAll('.coin-select');
|
||||
selects.forEach(function (el) { el.classList.remove('active'); });
|
||||
selects.forEach(function (el) {
|
||||
el.classList.remove('active');
|
||||
});
|
||||
});
|
||||
|
||||
setupDropdown(currencySelectEl);
|
||||
@@ -714,7 +700,13 @@
|
||||
}
|
||||
|
||||
initI18n().then(function () {
|
||||
fetchPaymentMethods();
|
||||
if (paymentConfig.network && Array.isArray(paymentConfig.network) && paymentConfig.network.length > 0) {
|
||||
paymentMethods = paymentConfig.network;
|
||||
initSelection();
|
||||
} else {
|
||||
showMessage(t('payment.loadPaymentNetworkFailed', 'Failed to load payment network, please check if the wallet has been added'));
|
||||
}
|
||||
|
||||
startCountdown();
|
||||
// Poll status every 5s
|
||||
statusCheckTimer = setInterval(checkPaymentStatus, 5000);
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
"estimatedTime": "Estimated confirmation time: 1-3 minutes",
|
||||
"paymentSuccess": "Payment Successful!",
|
||||
"transactionHash": "Your payment has been confirmed. Transaction hash:",
|
||||
"processing": "Processing..."
|
||||
"processing": "Processing...",
|
||||
"loadPaymentNetworkFailed": "Failed to load payment network, please check if wallet is added."
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
"estimatedTime": "预计确认时间:1-3分钟",
|
||||
"paymentSuccess": "支付成功!",
|
||||
"transactionHash": "您的支付已确认,交易哈希:",
|
||||
"processing": "处理中..."
|
||||
"processing": "处理中...",
|
||||
"loadPaymentNetworkFailed": "无法加载付款网络,请检查是否已经完成钱包地址添加。"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,9 +99,8 @@
|
||||
<ol>
|
||||
<li data-i18n="payment.cashierInstr1">请选择您喜欢的付款方式进行转账</li>
|
||||
<li data-i18n="payment.instruction2">转账完成后系统会自动确认到账</li>
|
||||
<li data-i18n="payment.instruction3">实际到账金额必须与本页面显示的金额完全一致,差一分钱都不行的!</li>
|
||||
<li data-i18n="payment.instruction4">如果有其它疑问,请联系电报 <a href="https://t.me/hellotaozi" target="_blank"
|
||||
rel="nofollow">@hellotaozi</a></li>
|
||||
<li data-i18n="payment.instruction3">转账金额必须与显示金额完全一致</li>
|
||||
<li data-i18n="payment.instruction4">如果有其它疑问,请联系客服处理</li>
|
||||
</ol>
|
||||
</div>
|
||||
<div class="footer-info">
|
||||
@@ -124,7 +123,8 @@
|
||||
name: "{{.name}}",
|
||||
trade_id: "{{.trade_id}}",
|
||||
order_id: "{{.order_id}}",
|
||||
return_url: "{{.return_url}}"
|
||||
return_url: "{{.return_url}}",
|
||||
network: {{.network}},
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user