From 823250bf27f6963b34457fee0e11e037ed1aac53 Mon Sep 17 00:00:00 2001 From: Jakub Matys Date: Fri, 10 Aug 2018 10:46:32 +0200 Subject: [PATCH] Added script that checks registered ports --- CONTRIBUTING.md | 5 +- contrib/scripts/check-ports.go | 83 ++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 3 deletions(-) create mode 100755 contrib/scripts/check-ports.go diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1e3973d5..9e59e4b5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -63,13 +63,12 @@ In section *blockbook* update information how to build and configure Blockbook s Update *package_maintainer* and *package_maintainer_email* options in section *meta*. +Execute script *contrib/scripts/check-ports.go* that will check mandatory ports and uniquity of registered ports. + Execute script *contrib/scripts/generate-port-registry.go* that will update *docs/ports.md*. Now you can try generate package definitions as described above in order to check outputs. -TODO: -* script that checks unique port numbers - #### Add coin implementation #### Add tests diff --git a/contrib/scripts/check-ports.go b/contrib/scripts/check-ports.go new file mode 100755 index 00000000..1e509de1 --- /dev/null +++ b/contrib/scripts/check-ports.go @@ -0,0 +1,83 @@ +//usr/bin/go run $0 $@ ; exit +package main + +import ( + "encoding/json" + "fmt" + "io/ioutil" + "os" + "path/filepath" +) + +const configDir = "configs/coins" + +type Config struct { + Coin struct { + Name string `json:"name"` + } + Ports map[string]uint16 `json:"ports"` +} + +func main() { + ports := make(map[uint16][]string) + status := 0 + + files, err := ioutil.ReadDir(configDir) + if err != nil { + panic(err) + } + + for _, fi := range files { + if fi.IsDir() || fi.Name()[0] == '.' { + continue + } + + path := filepath.Join(configDir, fi.Name()) + f, err := os.Open(path) + if err != nil { + panic(fmt.Errorf("%s: %s", path, err)) + } + defer f.Close() + + v := Config{} + d := json.NewDecoder(f) + err = d.Decode(&v) + if err != nil { + panic(fmt.Errorf("%s: json: %s", path, err)) + } + + if _, ok := v.Ports["blockbook_internal"]; !ok { + fmt.Printf("%s: missing blockbook_internal port\n", v.Coin.Name) + status = 1 + } + if _, ok := v.Ports["blockbook_public"]; !ok { + fmt.Printf("%s: missing blockbook_public port\n", v.Coin.Name) + status = 1 + } + if _, ok := v.Ports["backend_rpc"]; !ok { + fmt.Printf("%s: missing backend_rpc port\n", v.Coin.Name) + status = 1 + } + + for _, port := range v.Ports { + if port > 0 { + ports[port] = append(ports[port], v.Coin.Name) + } + } + } + + for port, coins := range ports { + if len(coins) > 1 { + fmt.Printf("port %d: registered by %q\n", port, coins) + status = 1 + } + } + + if status == 0 { + fmt.Println("OK") + } else { + fmt.Println("Got some errors") + } + + os.Exit(status) +}