更新Api接口,并将最小支付小数点修正为2位数

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