Commit c3edc3cd authored by vicotor's avatar vicotor

add fee and limit info.

parent b0d6c0b4
......@@ -71,6 +71,19 @@ func (s *ChainSync) GetReceiveToken(token common.Address, toChainId int64) (stri
return strings.ToLower(param.ReceiveToken.Hex()), nil
}
func (s *ChainSync) GetOutConfig(token common.Address, toChainId int64) (outConfig bridge.BridgeOutConfig, err error) {
callOpt := &bind.CallOpts{
BlockNumber: nil,
From: common.HexToAddress(s.chain.BridgeContract),
Context: context.TODO(),
}
outConfig, err = s.bridgeCa.OutConfiguration(callOpt, token, big.NewInt(toChainId))
if err != nil {
return outConfig, err
}
return outConfig, nil
}
func NewChainSync(_chain *config.ChainConfig, _d *dao.Dao) (sync *ChainSync) {
bridgeCa, err := bridge.NewBridgeContract(common.HexToAddress(_chain.BridgeContract), _d.ChainClient(_chain.ChainId))
if err != nil {
......
......@@ -25,6 +25,7 @@ type ChainInterface interface {
ParseTokenConfigChanged(log *types.Log) (*bridge.BridgeContractTokenOutConfigChanged, error)
ParseSwapConfigChanged(log *types.Log) (*bridge.BridgeContractSwapConfigChanged, error)
GetReceiveToken(token common.Address, toChainId int64) (string, error)
GetOutConfig(token common.Address, toChainId int64) (outConfig bridge.BridgeOutConfig, err error)
}
var (
......
......@@ -3,10 +3,12 @@ package dao
import (
"code.wuban.net.cn/movabridge/bridge-backend/chainlist"
"code.wuban.net.cn/movabridge/bridge-backend/config"
"code.wuban.net.cn/movabridge/bridge-backend/contract/bridge"
"code.wuban.net.cn/movabridge/bridge-backend/tokenrepo"
"context"
"crypto/ecdsa"
"fmt"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
......@@ -107,3 +109,18 @@ func (d *Dao) AddSyncer(chainId int64, syncer ChainInterface) {
defer d.handleMux.Unlock()
d.syncer[chainId] = syncer
}
func (d *Dao) GetSyncer(chainId int64) (syncer ChainInterface, ok bool) {
d.handleMux.Lock()
defer d.handleMux.Unlock()
syncer, ok = d.syncer[chainId]
return
}
func (d *Dao) GetOutConfig(chainId int64, token common.Address, toChainId int64) (bridge.BridgeOutConfig, error) {
syncer, ok := d.GetSyncer(chainId)
if !ok {
return bridge.BridgeOutConfig{}, fmt.Errorf("chain %d syncer not found", chainId)
}
return syncer.GetOutConfig(token, toChainId)
}
......@@ -4,6 +4,7 @@ import (
"code.wuban.net.cn/movabridge/bridge-backend/constant"
apiModel "code.wuban.net.cn/movabridge/bridge-backend/model/api"
"context"
"github.com/ethereum/go-ethereum/common"
log "github.com/sirupsen/logrus"
"sort"
"time"
......@@ -115,12 +116,19 @@ func (d *Dao) GetBridgeConfig() (config apiModel.BridgeConfig, err error) {
"error": err,
}).Error("not found token info with tokenrepo, skip symbol info")
}
chainConfig.SupportTokens[info.TokenName] = apiModel.ToToken{
tokenInfo := apiModel.ToToken{
TokenContract: info.Token,
ToChainId: info.ToChainId,
ToToken: info.ToToken,
ToTokenSymbol: toTokenInfo.Symbol,
}
outConfig, err := d.GetOutConfig(info.ChainId, common.HexToAddress(info.Token), info.ToChainId)
if err == nil {
tokenInfo.Fee = outConfig.Fee.String()
tokenInfo.MaxLimit = outConfig.Limit.String()
}
chainConfig.SupportTokens[info.TokenName] = tokenInfo
config.Chains[chainInfo.Name] = chainConfig
}
......
......@@ -5,6 +5,8 @@ type ToToken struct {
ToChainId int64 `json:"to_chain_id" bson:"to_chain_id"`
ToToken string `json:"to_token" bson:"to_token"`
ToTokenSymbol string `json:"to_token_symbol" bson:"to_token_symbol"`
Fee string `json:"fee" bson:"fee"`
MaxLimit string `json:"max_limit" bson:"max_limit"`
}
type ChainConfig struct {
Chain string `json:"chain" bson:"chain"`
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment