Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
huangzhen1997 committed Nov 4, 2024
1 parent 22c47b8 commit ff1c395
Showing 1 changed file with 31 additions and 24 deletions.
55 changes: 31 additions & 24 deletions selectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,22 +90,6 @@ func loadChainDetailsBySelector() map[uint64]ChainDetails {
return data.Selectors
}

func GetSelectorFamily(selector uint64) (string, error) {
// previously selector_families.yml includes both real and test chains, therefore we check both maps
details, exist := selectorToChainDetails[selector]
if exist {
return details.Family, nil

}

details, exist = testSelectorToChainDetailsMap[selector]
if exist {
return details.Family, nil
}

return "", fmt.Errorf("chain detail not found for selector %d", selector)
}

func ChainSelectorToChainDetails() map[uint64]ChainDetails {
copyMap := make(map[uint64]ChainDetails, len(selectorToChainDetails))
for k, v := range selectorToChainDetails {
Expand All @@ -124,12 +108,34 @@ func TestChainSelectorToChainDetails() map[uint64]ChainDetails {
return copyMap
}

func GetSelectorFamily(selector uint64) (string, error) {
// previously selector_families.yml includes both real and test chains, therefore we check both maps
details, exist := selectorToChainDetails[selector]
if exist {
return details.Family, nil

}

details, exist = testSelectorToChainDetailsMap[selector]
if exist {
return details.Family, nil
}

return "", fmt.Errorf("chain detail not found for selector %d", selector)
}

func ChainIdFromSelector(chainSelectorId uint64) (string, error) {
chainDetail, ok := selectorToChainDetails[chainSelectorId]
if !ok {
return "0", fmt.Errorf("chain not found for chain selector %d", chainSelectorId)
if ok {
return chainDetail.ChainID, nil
}

chainDetail, ok = testSelectorToChainDetailsMap[chainSelectorId]
if ok {
return chainDetail.ChainID, nil
}
return chainDetail.ChainID, nil

return "0", fmt.Errorf("chain not found for chain selector %d", chainSelectorId)
}

func SelectorFromChainIdAndFamily(chainId string, family string) (uint64, error) {
Expand All @@ -145,7 +151,7 @@ func SelectorFromChainIdAndFamily(chainId string, family string) (uint64, error)

selector, exist := selectorMap[chainId]
if !exist {
return 0, fmt.Errorf("chain selector not found for chainID %v", chainId)
return 0, fmt.Errorf("chain selector not found for chainID %v, family %v", chainId, family)
}

return selector, nil
Expand All @@ -159,19 +165,20 @@ func NameFromChainIdAndFamily(chainId string, family string) (string, error) {

selectorMap, exist := chainIDToSelectorMapForFamily[family]
if !exist {
return "", fmt.Errorf("chain family not found for chain %v, %v", chainId, family)
return "", fmt.Errorf("chain family not found for chain %v, family %v", chainId, family)
}

selector, exist := selectorMap[chainId]
if !exist {
return "", fmt.Errorf("chain selector not found for chain %v, %v", chainId, family)
return "", fmt.Errorf("chain selector not found for chain %v, family %v", chainId, family)
}

details, exist := selectorToChainDetails[selector]
if !exist {
return "", fmt.Errorf("chain details not found for chain %v, %v", chainId, family)
return "", fmt.Errorf("chain details not found for chain %v, family %v", chainId, family)
}

// when name is missing use chainID
if details.Name == "" {
return chainId, nil
}
Expand All @@ -190,7 +197,7 @@ func ChainIdFromNameAndFamily(name string, family string) (string, error) {
}
}

return "0", fmt.Errorf("chain not found for name %s", name)
return "0", fmt.Errorf("chain not found for name %s and family %s", name, family)
}

func TestChainIds() []uint64 {
Expand Down

0 comments on commit ff1c395

Please sign in to comment.