Skip to content

Commit

Permalink
fix review optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
weiqiang.fan committed Apr 26, 2024
1 parent ea2302f commit f43e013
Show file tree
Hide file tree
Showing 7 changed files with 638 additions and 568 deletions.
1,167 changes: 616 additions & 551 deletions bridgectrl/pb/query.pb.go

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions proto/src/proto/bridge/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,14 @@ message Transaction {
uint64 blockNumber = 18;
string globalIndex = 19;
string destContractAddr = 20;
string symbol = 21;
string tokenName = 22;
string logoOssUrl = 23;
uint32 decimal = 24;
TokenLogoInfo logoInfo = 21;
}

message TokenLogoInfo {
string symbol = 1;
string tokenName = 2;
string logoOssUrl = 3;
uint32 decimal = 4;
}

// Monitored tx
Expand Down
2 changes: 1 addition & 1 deletion redisstorage/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type RedisStorage interface {
RPopVerifyTime(ctx context.Context) (int64, error)

// token logo storage
SetTokenLogoInfo(ctx context.Context, keySuffix string, logoInfo *tokenlogoinfo.TokenLogoInfo) error
SetTokenLogoInfo(ctx context.Context, keySuffix string, logoInfo tokenlogoinfo.TokenLogoInfo) error
GetTokenLogoInfo(ctx context.Context, keySuffix string) (*tokenlogoinfo.TokenLogoInfo, error)
}

Expand Down
2 changes: 1 addition & 1 deletion redisstorage/redisstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ func (s *redisStorageImpl) rPopIntCacheFoundation(ctx context.Context, key strin
return num, nil
}

func (s *redisStorageImpl) SetTokenLogoInfo(ctx context.Context, keySuffix string, logoInfo *tokenlogoinfo.TokenLogoInfo) error {
func (s *redisStorageImpl) SetTokenLogoInfo(ctx context.Context, keySuffix string, logoInfo tokenlogoinfo.TokenLogoInfo) error {
value, err := json.Marshal(logoInfo)
if err != nil {
return errors.Wrap(err, "failed to convert logoInfo to string")
Expand Down
19 changes: 10 additions & 9 deletions server/service_xlayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,12 +576,11 @@ func (s *bridgeService) fillLogoInfos(ctx context.Context, transactionMap map[st
if !errors.Is(err, redis.Nil) {
log.Errorf("get token logo info failed, so use rpc to fetch, chainId: %v, token: %v, error: %v", v[0].FromChainId, v[0].BridgeToken, err)
}
noCacheTokenMap := make(map[uint32][]string, len(transactionMap))
noCacheTokenMap[v[0].FromChainId] = append(noCacheTokenMap[v[0].FromChainId], v[0].BridgeToken)
continue
}
for _, tx := range v {
s.fillOneTxLogoInfo(tx, logoInfo)
s.fillOneTxLogoInfo(tx, *logoInfo)
}
}
if len(noCacheTokenMap) == 0 {
Expand All @@ -599,9 +598,9 @@ func (s *bridgeService) fillLogoInfos(ctx context.Context, transactionMap map[st
}
for k, v := range tokenLogoMap {
for _, tx := range transactionMap[k] {
s.fillOneTxLogoInfo(tx, &v)
s.fillOneTxLogoInfo(tx, v)
}
err = s.redisStorage.SetTokenLogoInfo(ctx, k, &v)
err = s.redisStorage.SetTokenLogoInfo(ctx, k, v)
if err != nil {
log.Errorf("failed to set logo info cache for token: %v", v.TokenContractAddress)
}
Expand All @@ -621,9 +620,11 @@ func (s *bridgeService) buildQueryLogoParams(noCacheTokenMap map[uint32][]string
return logoParams
}

func (s *bridgeService) fillOneTxLogoInfo(tx *pb.Transaction, logoInfo *tokenlogoinfo.TokenLogoInfo) {
tx.Symbol = logoInfo.TokenSymbol
tx.TokenName = logoInfo.TokenName
tx.LogoOssUrl = logoInfo.LogoOssUrl
tx.Decimal = logoInfo.Unit
func (s *bridgeService) fillOneTxLogoInfo(tx *pb.Transaction, logoInfo tokenlogoinfo.TokenLogoInfo) {
tx.LogoInfo = &pb.TokenLogoInfo{
Symbol: logoInfo.TokenSymbol,
TokenName: logoInfo.TokenName,
LogoOssUrl: logoInfo.LogoOssUrl,
Decimal: logoInfo.Unit,
}
}
2 changes: 1 addition & 1 deletion server/tokenlogoinfo/Client.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (c *Client) GetTokenLogoInfos(tokenAddArr []*QueryLogoParam) (map[string]To
log.Errorf("[getTokenLogoInfos] failed to read resp body err[%v]", err)
return nil, err
}
respStruct := &CheckCountryLimitResponse{}
respStruct := &GetTokenLogosResponse{}
err = json.Unmarshal(respBody, respStruct)
if err != nil {
log.Errorf("[getTokenLogoInfos] failed to convert resp to struct, resp [%v] err[%v]", string(respBody), err)
Expand Down
2 changes: 1 addition & 1 deletion server/tokenlogoinfo/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type TokenLogoInfo struct {
TokenName string `json:"tokenName"`
}

type CheckCountryLimitResponse struct {
type GetTokenLogosResponse struct {
Code int `json:"code"`
Msg string `json:"msg"`
ErrorCode string `json:"error_code"`
Expand Down

0 comments on commit f43e013

Please sign in to comment.