mirror of
https://github.com/GMWalletApp/epusdt.git
synced 2026-07-07 02:06:16 +00:00
更新Api接口,并将最小支付小数点修正为2位数
This commit is contained in:
@@ -21,10 +21,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
CnyMinimumPaymentAmount = 0.01 // cny最低支付金额
|
CnyMinimumPaymentAmount = 0.01 // cny最低支付金额
|
||||||
UsdtMinimumPaymentAmount = 0.001 // usdt最低支付金额
|
UsdtMinimumPaymentAmount = 0.01 // usdt最低支付金额
|
||||||
UsdtAmountPerIncrement = 0.001 // usdt每次递增金额
|
UsdtAmountPerIncrement = 0.01 // usdt每次递增金额
|
||||||
IncrementalMaximumNumber = 100 // 最大递增次数
|
IncrementalMaximumNumber = 100 // 最大递增次数
|
||||||
)
|
)
|
||||||
|
|
||||||
var gCreateTransactionLock sync.Mutex
|
var gCreateTransactionLock sync.Mutex
|
||||||
@@ -62,7 +62,7 @@ func CreateTransaction(req *request.CreateTransactionRequest) (*response.CreateT
|
|||||||
if len(walletAddress) <= 0 {
|
if len(walletAddress) <= 0 {
|
||||||
return nil, constant.NotAvailableWalletAddress
|
return nil, constant.NotAvailableWalletAddress
|
||||||
}
|
}
|
||||||
amount := math.MustParsePrecFloat64(decimalUsdt.InexactFloat64(), 3)
|
amount := math.MustParsePrecFloat64(decimalUsdt.InexactFloat64(), 2)
|
||||||
availableToken, availableAmount, err := CalculateAvailableWalletAndAmount(amount, walletAddress)
|
availableToken, availableAmount, err := CalculateAvailableWalletAndAmount(amount, walletAddress)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -18,12 +18,12 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
const UsdtTrc20ApiUri = "https://apilist.tronscan.org/api/token_trc20/transfers"
|
const UsdtTrc20ApiUri = "https://apilist.tronscanapi.com/api/transfer/trc20"
|
||||||
|
|
||||||
type UsdtTrc20Resp struct {
|
type UsdtTrc20Resp struct {
|
||||||
Total int `json:"total"`
|
PageSize int `json:"page_size"`
|
||||||
RangeTotal int `json:"rangeTotal"`
|
Code int `json:"code"`
|
||||||
TokenTransfers []TokenTransfers `json:"token_transfers"`
|
Data []Data `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type TokenInfo struct {
|
type TokenInfo struct {
|
||||||
@@ -35,26 +35,29 @@ type TokenInfo struct {
|
|||||||
TokenType string `json:"tokenType"`
|
TokenType string `json:"tokenType"`
|
||||||
TokenLogo string `json:"tokenLogo"`
|
TokenLogo string `json:"tokenLogo"`
|
||||||
TokenLevel string `json:"tokenLevel"`
|
TokenLevel string `json:"tokenLevel"`
|
||||||
|
IssuerAddr string `json:"issuerAddr"`
|
||||||
Vip bool `json:"vip"`
|
Vip bool `json:"vip"`
|
||||||
}
|
}
|
||||||
type TokenTransfers struct {
|
|
||||||
TransactionID string `json:"transaction_id"`
|
type Data struct {
|
||||||
BlockTs int64 `json:"block_ts"`
|
Amount string `json:"amount"`
|
||||||
FromAddress string `json:"from_address"`
|
ApprovalAmount string `json:"approval_amount"`
|
||||||
ToAddress string `json:"to_address"`
|
BlockTimestamp int64 `json:"block_timestamp"`
|
||||||
Block int `json:"block"`
|
Block int `json:"block"`
|
||||||
ContractAddress string `json:"contract_address"`
|
From string `json:"from"`
|
||||||
Quant string `json:"quant"`
|
To string `json:"to"`
|
||||||
ApprovalAmount string `json:"approval_amount"`
|
Hash string `json:"hash"`
|
||||||
EventType string `json:"event_type"`
|
Confirmed int `json:"confirmed"`
|
||||||
ContractType string `json:"contract_type"`
|
ContractType string `json:"contract_type"`
|
||||||
Confirmed bool `json:"confirmed"`
|
ContracTType int `json:"contractType"`
|
||||||
ContractRet string `json:"contractRet"`
|
Revert int `json:"revert"`
|
||||||
FinalResult string `json:"finalResult"`
|
ContractRet string `json:"contract_ret"`
|
||||||
TokenInfo TokenInfo `json:"tokenInfo"`
|
EventType string `json:"event_type"`
|
||||||
FromAddressIsContract bool `json:"fromAddressIsContract"`
|
IssueAddress string `json:"issue_address"`
|
||||||
ToAddressIsContract bool `json:"toAddressIsContract"`
|
Decimals int `json:"decimals"`
|
||||||
Revert bool `json:"revert"`
|
TokenName string `json:"token_name"`
|
||||||
|
ID string `json:"id"`
|
||||||
|
Direction int `json:"direction"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trc20CallBack trc20回调
|
// Trc20CallBack trc20回调
|
||||||
@@ -69,11 +72,13 @@ func Trc20CallBack(token string, wg *sync.WaitGroup) {
|
|||||||
startTime := carbon.Now().AddHours(-24).TimestampWithMillisecond()
|
startTime := carbon.Now().AddHours(-24).TimestampWithMillisecond()
|
||||||
endTime := carbon.Now().TimestampWithMillisecond()
|
endTime := carbon.Now().TimestampWithMillisecond()
|
||||||
resp, err := client.R().SetQueryParams(map[string]string{
|
resp, err := client.R().SetQueryParams(map[string]string{
|
||||||
"limit": "200",
|
"sort": "-timestamp",
|
||||||
|
"limit": "500",
|
||||||
"start": "0",
|
"start": "0",
|
||||||
"direction": "in",
|
"direction": "2",
|
||||||
"tokens": "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
|
"db_version": "1",
|
||||||
"relatedAddress": token,
|
"trc20Id": "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
|
||||||
|
"address": token,
|
||||||
"start_timestamp": stdutil.ToString(startTime),
|
"start_timestamp": stdutil.ToString(startTime),
|
||||||
"end_timestamp": stdutil.ToString(endTime),
|
"end_timestamp": stdutil.ToString(endTime),
|
||||||
}).Get(UsdtTrc20ApiUri)
|
}).Get(UsdtTrc20ApiUri)
|
||||||
@@ -88,14 +93,14 @@ func Trc20CallBack(token string, wg *sync.WaitGroup) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
if trc20Resp.Total <= 0 {
|
if trc20Resp.PageSize <= 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, transfer := range trc20Resp.TokenTransfers {
|
for _, transfer := range trc20Resp.Data {
|
||||||
if transfer.ToAddress != token || transfer.FinalResult != "SUCCESS" {
|
if transfer.To != token || transfer.ContractRet != "SUCCESS" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
decimalQuant, err := decimal.NewFromString(transfer.Quant)
|
decimalQuant, err := decimal.NewFromString(transfer.Amount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@@ -114,7 +119,7 @@ func Trc20CallBack(token string, wg *sync.WaitGroup) {
|
|||||||
}
|
}
|
||||||
// 区块的确认时间必须在订单创建时间之后
|
// 区块的确认时间必须在订单创建时间之后
|
||||||
createTime := order.CreatedAt.TimestampWithMillisecond()
|
createTime := order.CreatedAt.TimestampWithMillisecond()
|
||||||
if transfer.BlockTs < createTime {
|
if transfer.BlockTimestamp < createTime {
|
||||||
panic("Orders cannot actually be matched")
|
panic("Orders cannot actually be matched")
|
||||||
}
|
}
|
||||||
// 到这一步就完全算是支付成功了
|
// 到这一步就完全算是支付成功了
|
||||||
@@ -122,7 +127,7 @@ func Trc20CallBack(token string, wg *sync.WaitGroup) {
|
|||||||
Token: token,
|
Token: token,
|
||||||
TradeId: tradeId,
|
TradeId: tradeId,
|
||||||
Amount: amount,
|
Amount: amount,
|
||||||
BlockTransactionId: transfer.TransactionID,
|
BlockTransactionId: transfer.Hash,
|
||||||
}
|
}
|
||||||
err = OrderProcessing(req)
|
err = OrderProcessing(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user