Skip to content

Commit

Permalink
Merge pull request #120 from rain-zxn/master
Browse files Browse the repository at this point in the history
check fee polyproxy
  • Loading branch information
rain-zxn committed Sep 24, 2021
2 parents 571e5de + 74f2a77 commit 232d83c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 13 deletions.
25 changes: 13 additions & 12 deletions bridgesdk/bridge_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
Expand Down
16 changes: 15 additions & 1 deletion http/fee_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"math/big"
"poly-bridge/cacheRedis"
"strings"

"poly-bridge/basedef"
"poly-bridge/common"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions http/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@ package http

import (
"fmt"
"poly-bridge/basedef"
"poly-bridge/conf"
"strings"

"gorm.io/driver/mysql"
"gorm.io/gorm"
"gorm.io/gorm/logger"
)

var db *gorm.DB
var polyProxy map[string]bool

func Init() {
config := conf.GlobalConfig.DBConfig
Expand All @@ -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
}
}

0 comments on commit 232d83c

Please sign in to comment.