From 37d4ed3844dcb843870e90c9604523e15de1c708 Mon Sep 17 00:00:00 2001 From: Ashang Date: Thu, 29 Sep 2022 10:06:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0Api=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=EF=BC=8C=E5=B9=B6=E5=B0=86=E6=9C=80=E5=B0=8F=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E5=B0=8F=E6=95=B0=E7=82=B9=E4=BF=AE=E6=AD=A3=E4=B8=BA2?= =?UTF-8?q?=E4=BD=8D=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/model/service/order_service.go | 10 ++--- src/model/service/task_service.go | 69 ++++++++++++++++-------------- 2 files changed, 42 insertions(+), 37 deletions(-) diff --git a/src/model/service/order_service.go b/src/model/service/order_service.go index 81a1858..397a92b 100644 --- a/src/model/service/order_service.go +++ b/src/model/service/order_service.go @@ -21,10 +21,10 @@ import ( ) const ( - CnyMinimumPaymentAmount = 0.01 // cny最低支付金额 - UsdtMinimumPaymentAmount = 0.001 // usdt最低支付金额 - UsdtAmountPerIncrement = 0.001 // usdt每次递增金额 - IncrementalMaximumNumber = 100 // 最大递增次数 + CnyMinimumPaymentAmount = 0.01 // cny最低支付金额 + UsdtMinimumPaymentAmount = 0.01 // usdt最低支付金额 + UsdtAmountPerIncrement = 0.01 // usdt每次递增金额 + IncrementalMaximumNumber = 100 // 最大递增次数 ) var gCreateTransactionLock sync.Mutex @@ -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 diff --git a/src/model/service/task_service.go b/src/model/service/task_service.go index 804d0d1..1596af0 100644 --- a/src/model/service/task_service.go +++ b/src/model/service/task_service.go @@ -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"` - ApprovalAmount string `json:"approval_amount"` - EventType string `json:"event_type"` - 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"` + +type Data struct { + Amount string `json:"amount"` + ApprovalAmount string `json:"approval_amount"` + 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"` + 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 {