Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
huangzhen1997 committed Nov 1, 2024
1 parent dbbf2df commit 45d54c9
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 25 deletions.
2 changes: 0 additions & 2 deletions generated_chains.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions selector_restructured.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
selector_families:
selectors:
176199025415897437:
family: evm
222782988166878823:
Expand Down Expand Up @@ -512,10 +512,6 @@ selector_families:
family: evm
10106333385848939617:
family: evm
10199579733509604193:
family: evm
name: plume-testnet
chain_id: "161221135"
10344971235874465080:
family: evm
name: ethereum-testnet-sepolia-base-1
Expand Down
46 changes: 28 additions & 18 deletions selectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@ import (

//go:generate go run genchains.go

//go:embed selectors.yml
var selectorsYml []byte

//go:embed test_selectors.yml
var testSelectorsYml []byte

//go:embed selector_restructured.yml
var selectorFamiliesYml []byte
var selectorYml []byte

type newChainDetails struct {
type chainDetails struct {
Family string `yaml:"family"`
Name string `yaml:"name"`
ChainID string `yaml:"chain_id"`
Expand All @@ -34,14 +31,28 @@ const (

var chainIDToSelectorMapForFamily = make(map[string]map[string]uint64)
var selectorToChainDetails = loadChainDetailsBySelector()
var testSelectorsMap = loadTestChains()

func loadChainDetailsBySelector() map[uint64]newChainDetails {
func loadTestChains() map[uint64]chainDetails {
type yamlData struct {
SelectorFamilies map[uint64]newChainDetails `yaml:"selector_families"`
SelectorFamilies map[uint64]chainDetails `yaml:"selectors"`
}

var data yamlData
err := yaml.Unmarshal(selectorFamiliesYml, &data)
err := yaml.Unmarshal(testSelectorsYml, &data)
if err != nil {
panic(err)
}
return data.SelectorFamilies
}

func loadChainDetailsBySelector() map[uint64]chainDetails {
type yamlData struct {
SelectorFamilies map[uint64]chainDetails `yaml:"selectors"`
}

var data yamlData
err := yaml.Unmarshal(selectorYml, &data)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -72,8 +83,8 @@ func GetSelectorFamily(selector uint64) (string, error) {
return details.Family, nil
}

func ChainSelectorToChainDetails() map[uint64]newChainDetails {
copyMap := make(map[uint64]newChainDetails, len(selectorToChainDetails))
func ChainSelectorToChainDetails() map[uint64]chainDetails {
copyMap := make(map[uint64]chainDetails, len(selectorToChainDetails))
for k, v := range selectorToChainDetails {
copyMap[k] = v
}
Expand Down Expand Up @@ -149,14 +160,13 @@ func ChainIdFromNameAndFamily(name string, family string) (string, error) {
return "0", fmt.Errorf("chain not found for name %s", name)
}

//TODO fix after code gen
//func TestChainIds() []uint64 {
// chainIds := make([]uint64, 0, len(testSelectorsMap))
// for k := range testSelectorsMap {
// chainIds = append(chainIds, k)
// }
// return chainIds
//}
func TestChainIds() []uint64 {
chainIds := make([]uint64, 0, len(testSelectorsMap))
for k := range testSelectorsMap {
chainIds = append(chainIds, k)
}
return chainIds
}

var chainsBySelector = make(map[uint64]Chain)
var chainsByEvmChainID = make(map[string]Chain)
Expand Down

0 comments on commit 45d54c9

Please sign in to comment.