Skip to content

Commit

Permalink
support ok inner chain id
Browse files Browse the repository at this point in the history
  • Loading branch information
weiqiang.fan committed Feb 20, 2024
1 parent 83f4d34 commit ebd2f3a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
12 changes: 12 additions & 0 deletions server/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,10 @@ func (s *bridgeService) GetTokenWrapped(ctx context.Context, req *pb.GetTokenWra
// GetCoinPrice returns the price for each coin symbol in the request
// Bridge rest API endpoint
func (s *bridgeService) GetCoinPrice(ctx context.Context, req *pb.GetCoinPriceRequest) (*pb.CommonCoinPricesResponse, error) {
// convert inner chainId to standard chain id

This comment has been minimized.

Copy link
@trunghai95

trunghai95 Feb 21, 2024

Collaborator

@fanweiqiang Will it affect other modules too? (currently we're also using chain ids in "main coins" and "get transactions" modules)

for _, symbol := range req.SymbolInfos {
symbol.ChainId = utils.GetChainIdByInnerId(symbol.ChainId)
}
priceList, err := s.redisStorage.GetCoinPrice(ctx, req.SymbolInfos)
if err != nil {
log.Errorf("get coin price from redis failed for symbol: %v, error: %v", req.SymbolInfos, err)
Expand All @@ -430,6 +434,10 @@ func (s *bridgeService) GetCoinPrice(ctx context.Context, req *pb.GetCoinPriceRe
Msg: gerror.ErrInternalErrorForRpcCall.Error(),
}, nil
}
// convert standard chainId to ok inner chainId
for _, priceInfo := range priceList {
priceInfo.ChainId = utils.GetInnerChainIdByChainId(priceInfo.ChainId)
}
return &pb.CommonCoinPricesResponse{
Code: defaultSuccessCode,
Data: priceList,
Expand All @@ -448,6 +456,10 @@ func (s *bridgeService) GetMainCoins(ctx context.Context, req *pb.GetMainCoinsRe
Msg: gerror.ErrInternalErrorForRpcCall.Error(),
}, nil
}
// use ok inner chain id
for _, coinInfo := range coins {
coinInfo.ChainId = utils.GetInnerChainIdByChainId(coinInfo.ChainId)
}
return &pb.CommonCoinsResponse{
Code: defaultSuccessCode,
Data: coins,
Expand Down
38 changes: 38 additions & 0 deletions utils/innerchainIdmanager.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package utils

var (
x1TestNetMapper = createChainIdMapper(19500, 195)

This comment has been minimized.

Copy link
@trunghai95

trunghai95 Feb 21, 2024

Collaborator

@fanweiqiang I think we can put the ids in the config (can use IntSliceEntry to store the pair of ids)
(also, with the ids in the config, we won't need to use different variables for mainnet and testnet, so the code will be simpler)

//x1MainNetMapper = createChainIdMapper(196, 196)
)

type ChainIdMapper struct {
InnerChainId uint64
ChainId uint64
}

func createChainIdMapper(innerChainId uint64, chanId uint64) *ChainIdMapper {
return &ChainIdMapper{
InnerChainId: innerChainId,
ChainId: chanId,
}
}

func GetChainIdByInnerId(innerChainId uint64) uint64 {
if x1TestNetMapper.InnerChainId == innerChainId {
return x1TestNetMapper.ChainId
}
//if x1MainNetMapper.InnerChainId == innerChainId {
// return x1MainNetMapper.ChainId
//}
return innerChainId
}

func GetInnerChainIdByChainId(chainId uint64) uint64 {
if x1TestNetMapper.ChainId == chainId {
return x1TestNetMapper.InnerChainId
}
//if x1MainNetMapper.ChainId == chainId {
// return x1MainNetMapper.InnerChainId
//}
return chainId
}

0 comments on commit ebd2f3a

Please sign in to comment.