From 74f2a77e64853bb7d4c210a1c3b4af5a1d55b0be Mon Sep 17 00:00:00 2001 From: rain <206131521@qq.com> Date: Fri, 24 Sep 2021 11:02:05 +0800 Subject: [PATCH] check fee polyproxy --- bridgesdk/bridge_sdk.go | 25 +++++++++++++------------ http/fee_controller.go | 16 +++++++++++++++- http/mysql.go | 9 +++++++++ 3 files changed, 37 insertions(+), 13 deletions(-) diff --git a/bridgesdk/bridge_sdk.go b/bridgesdk/bridge_sdk.go index b54c0ec5..e112f43f 100644 --- a/bridgesdk/bridge_sdk.go +++ b/bridgesdk/bridge_sdk.go @@ -26,9 +26,10 @@ import ( ) var ( - STATE_NOTPAY = -1 - STATE_NOTCHECK = 0 - STATE_HASPAY = 1 + STATE_NOTPOLYPROXY = -2 + STATE_NOTPAY = -1 + STATE_NOTCHECK = 0 + STATE_HASPAY = 1 ) type PolySwapResp struct { @@ -65,15 +66,15 @@ type GetFeeRsp struct { UsdtAmount string TokenAmount string TokenAmountWithPrecision string - SwapTokenHash string - Balance string - BalanceWithPrecision string + SwapTokenHash string + Balance string + BalanceWithPrecision string } type GetFeeReq struct { - SrcChainId uint64 - Hash string - DstChainId uint64 + SrcChainId uint64 + Hash string + DstChainId uint64 SwapTokenHash string } @@ -120,9 +121,9 @@ func (sdk *BridgeSdk) CheckFee(checks []*CheckFeeReq) ([]*CheckFeeRsp, error) { func (sdk *BridgeSdk) GetFee(srcChainId uint64, dstChainId uint64, feeTokenHash string, swapTokenHash string) (*GetFeeRsp, error) { getFeesReq := &GetFeeReq{ - SrcChainId: srcChainId, - DstChainId: dstChainId, - Hash: feeTokenHash, + SrcChainId: srcChainId, + DstChainId: dstChainId, + Hash: feeTokenHash, SwapTokenHash: swapTokenHash, } requestJson, err := json.Marshal(getFeesReq) diff --git a/http/fee_controller.go b/http/fee_controller.go index 29ddca7d..5660d043 100644 --- a/http/fee_controller.go +++ b/http/fee_controller.go @@ -22,6 +22,7 @@ import ( "fmt" "math/big" "poly-bridge/cacheRedis" + "strings" "poly-bridge/basedef" "poly-bridge/common" @@ -175,8 +176,15 @@ func (c *FeeController) checkFee(Checks []*models.CheckFeeReq) []*models.CheckFe srcTransactions := make([]*models.SrcTransaction, 0) db.Model(&models.SrcTransaction{}).Where("(`key` in ? or `hash` in ?)", requestHashs, requestHashs).Find(&srcTransactions) key2Txhash := make(map[string]string, 0) + isPolyProxy := make(map[string]bool, 0) + for _, srcTransaction := range srcTransactions { prefix := srcTransaction.Key[0:8] + if _, in := polyProxy[strings.ToUpper(srcTransaction.Contract)]; in { + isPolyProxy[srcTransaction.Key] = true + isPolyProxy[srcTransaction.Hash] = true + isPolyProxy[basedef.HexStringReverse(srcTransaction.Hash)] = true + } if prefix == "00000000" { chainId, ok := hash2ChainId[srcTransaction.Key] if ok && chainId == srcTransaction.ChainId { @@ -213,7 +221,13 @@ func (c *FeeController) checkFee(Checks []*models.CheckFeeReq) []*models.CheckFe checkFee.ChainId = check.ChainId checkFee.Amount = new(big.Float).SetInt64(0) checkFee.MinProxyFee = new(big.Float).SetInt64(0) - _, ok := chain2Fees[check.ChainId] + _, ok := isPolyProxy[check.Hash] + if !ok { + checkFee.PayState = -2 + checkFees = append(checkFees, checkFee) + continue + } + _, ok = chain2Fees[check.ChainId] if !ok { checkFee.PayState = -1 checkFees = append(checkFees, checkFee) diff --git a/http/mysql.go b/http/mysql.go index db748890..f6cce512 100644 --- a/http/mysql.go +++ b/http/mysql.go @@ -19,7 +19,9 @@ package http import ( "fmt" + "poly-bridge/basedef" "poly-bridge/conf" + "strings" "gorm.io/driver/mysql" "gorm.io/gorm" @@ -27,6 +29,7 @@ import ( ) var db *gorm.DB +var polyProxy map[string]bool func Init() { config := conf.GlobalConfig.DBConfig @@ -41,4 +44,10 @@ func Init() { if err != nil { panic(err) } + + proxyConfigs := conf.GlobalConfig.ChainListenConfig + for _, v := range proxyConfigs { + polyProxy[strings.ToUpper(v.ProxyContract)] = true + polyProxy[strings.ToUpper(basedef.HexStringReverse(v.ProxyContract))] = true + } }