Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor chain-selector to use chain specific chainID #65

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ import (
)

func main() {
// Getting selector based on ChainId
selector, err := chainselectors.SelectorFromChainId(420)
// Getting selector based on ChainId and family
selector, err := chainselectors.SelectorFromChainIdAndFamily(420, "evm")

// Getting ChainId based on ChainSelector
chainId, err := chainselectors.ChainIdFromSelector(2664363617261496610)

// Getting ChainName based on ChainId
chainName, err := chainselectors.NameFromChainId(420)
chainName, err := chainselectors.NameFromChainIdAndFamily(420, "evm")

// Getting ChainId based on the ChainName
chainId, err := chainselectors.ChainIdFromName("binance_smart_chain-testnet")
// Getting ChainId based on the ChainName and family
chainId, err := chainselectors.ChainIdFromNameAndFamily("binance_smart_chain-testnet", "evm")

// Accessing mapping directly
lookupChainId := uint64(1337)
Expand Down
38 changes: 23 additions & 15 deletions genchains.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,27 @@ import (
const filename = "generated_chains.go"

type chain struct {
EvmChainID uint64
Selector uint64
Name string
VarName string
ChainID string
Selector uint64
Name string
Family string
VarName string
}

var chainTemplate, _ = template.New("").Parse(`// Code generated by go generate please DO NOT EDIT
package chain_selectors

type Chain struct {
EvmChainID uint64
Selector uint64
Name string
ChainID string
Family string
VarName string
}

var (
{{ range . }}
{{.VarName}} = Chain{EvmChainID: {{ .EvmChainID }}, Selector: {{ .Selector }}, Name: "{{ .Name }}"}{{ end }}
{{.VarName}} = Chain{ChainID: "{{ .ChainID }}", Selector: {{ .Selector }}, Family: "{{ .Family }}", Name: "{{ .Name }}"}{{ end }}
)

var ALL = []Chain{
Expand Down Expand Up @@ -78,17 +80,23 @@ func genChainsSourceCode() (string, error) {
var wr = new(bytes.Buffer)
chains := make([]chain, 0)

for evmChainID, chainSel := range chain_selectors.EvmChainIdToChainSelector() {
name, err := chain_selectors.NameFromChainId(evmChainID)
if err != nil {
return "", err
}
for chainSelector, chainDetails := range chain_selectors.ChainSelectorToChainDetails() {
chains = append(chains, chain{
ChainID: chainDetails.ChainID,
Selector: chainSelector,
Name: chainDetails.Name,
Family: chainDetails.Family,
VarName: toVarName(chainDetails.Name, chainSelector),
})
}

for chainSelector, chainDetails := range chain_selectors.TestChainSelectorToChainDetails() {
chains = append(chains, chain{
EvmChainID: evmChainID,
Selector: chainSel,
Name: name,
VarName: toVarName(name, chainSel),
ChainID: chainDetails.ChainID,
Selector: chainSelector,
Name: chainDetails.Name,
Family: chainDetails.Family,
VarName: toVarName(chainDetails.Name, chainSelector),
})
}

Expand Down
705 changes: 356 additions & 349 deletions generated_chains.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion selector_families.yml
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ selector_families:
family: evm
name: ronin-testnet-saigon
1948510578179542068:
family: evm
family: evm
name: "bitcoin-testnet-bsquared-1"
3789623672476206327:
family: evm
Expand Down
Loading
Loading