-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
96 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package gotmpl | ||
|
||
import ( | ||
"bytes" | ||
"sort" | ||
"text/template" | ||
|
||
chain_selectors "github.com/smartcontractkit/chain-selectors" | ||
) | ||
|
||
type NameEncoder interface { | ||
VarName(name string, chainSel uint64) string | ||
} | ||
|
||
type chain struct { | ||
EvmChainID uint64 | ||
Selector uint64 | ||
Name string | ||
VarName string | ||
} | ||
|
||
func Run(tmpl *template.Template, enc NameEncoder) (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 | ||
} | ||
|
||
chains = append(chains, chain{ | ||
EvmChainID: evmChainID, | ||
Selector: chainSel, | ||
Name: name, | ||
VarName: enc.VarName(name, chainSel), | ||
}) | ||
} | ||
|
||
sort.Slice(chains, func(i, j int) bool { return chains[i].VarName < chains[j].VarName }) | ||
|
||
if err := tmpl.Execute(wr, chains); err != nil { | ||
return "", err | ||
} | ||
|
||
return wr.String(), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters