Added script that checks registered ports
parent
5a0d0b2fe1
commit
823250bf27
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
Loading…
Reference in New Issue