From b2def7420575587bd359d7962b421d9a49864861 Mon Sep 17 00:00:00 2001 From: Bolek <1416262+bolekk@users.noreply.github.com> Date: Thu, 28 Mar 2024 08:09:47 -0700 Subject: [PATCH] Script for fetching node keys (#12609) --- core/scripts/functions/main.go | 1 + core/scripts/functions/src/fetch_keys.go | 44 ++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 core/scripts/functions/src/fetch_keys.go diff --git a/core/scripts/functions/main.go b/core/scripts/functions/main.go index 2bf35828c91..cf496542b05 100644 --- a/core/scripts/functions/main.go +++ b/core/scripts/functions/main.go @@ -19,6 +19,7 @@ func main() { src.NewGenerateJobSpecsCommand(), src.NewDeployJobSpecsCommand(), src.NewDeleteJobsCommand(), + src.NewFetchKeysCommand(), } commandsList := func(commands []command) string { diff --git a/core/scripts/functions/src/fetch_keys.go b/core/scripts/functions/src/fetch_keys.go new file mode 100644 index 00000000000..4c3b11a7e28 --- /dev/null +++ b/core/scripts/functions/src/fetch_keys.go @@ -0,0 +1,44 @@ +package src + +import ( + "encoding/json" + "flag" + "fmt" + "os" +) + +type fetchKeys struct { +} + +func NewFetchKeysCommand() *fetchKeys { + return &fetchKeys{} +} + +func (g *fetchKeys) Name() string { + return "fetch-keys" +} + +func (g *fetchKeys) Run(args []string) { + fs := flag.NewFlagSet(g.Name(), flag.ContinueOnError) + nodesFile := fs.String("nodes", "", "a file containing nodes urls, logins and passwords") + chainID := fs.Int64("chainid", 80001, "chain id") + if err := fs.Parse(args); err != nil || *nodesFile == "" || *chainID == 0 { + fs.Usage() + os.Exit(1) + } + + nodes := mustReadNodesList(*nodesFile) + nca := mustFetchNodesKeys(*chainID, nodes) + + nodePublicKeys, err := json.MarshalIndent(nca, "", " ") + if err != nil { + panic(err) + } + filepath := "PublicKeys.json" + err = os.WriteFile(filepath, nodePublicKeys, 0600) + if err != nil { + panic(err) + } + fmt.Println("Functions OCR2 public keys have been saved to:", filepath) + +}