Unite scripts for port checking and registry of ports to one
parent
d50198cbff
commit
fe4b366875
|
@ -81,9 +81,8 @@ 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*.
|
||||
Execute script *go run contrib/scripts/check-and-generate-port-registry.go -w* that checks mandatory ports and
|
||||
uniqueness of ports and updates registry of ports *docs/ports.md*.
|
||||
|
||||
Now you can try generate package definitions as described above in order to check outputs.
|
||||
|
||||
|
|
|
@ -36,6 +36,67 @@ type Config struct {
|
|||
Ports map[string]uint16 `json:"ports"`
|
||||
}
|
||||
|
||||
func checkPorts() int {
|
||||
ports := make(map[uint16][]string)
|
||||
status := 0
|
||||
|
||||
files, err := ioutil.ReadDir(inputDir)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
for _, fi := range files {
|
||||
if fi.IsDir() || fi.Name()[0] == '.' {
|
||||
continue
|
||||
}
|
||||
|
||||
path := filepath.Join(inputDir, 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("Got some errors")
|
||||
}
|
||||
return status
|
||||
}
|
||||
|
||||
func main() {
|
||||
output := "stdout"
|
||||
if len(os.Args) > 1 {
|
||||
|
@ -48,6 +109,11 @@ func main() {
|
|||
}
|
||||
}
|
||||
|
||||
status := checkPorts()
|
||||
if status != 0 {
|
||||
os.Exit(status)
|
||||
}
|
||||
|
||||
slice, err := loadPortInfo(inputDir)
|
||||
if err != nil {
|
||||
panic(err)
|
|
@ -1,83 +0,0 @@
|
|||
//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)
|
||||
}
|
|
@ -8,7 +8,7 @@
|
|||
| Dash | 9033 | 9133 | 8033 | 38333 |
|
||||
| Litecoin | 9034 | 9134 | 8034 | 38334 |
|
||||
| Bgold | 9035 | 9135 | 8035 | 38335 |
|
||||
| Ethereum | 9036 | 9136 | 8036 | 38336 p2p, 8136 http |
|
||||
| Ethereum | 9036 | 9136 | 8036 | 8136 http, 38336 p2p |
|
||||
| Ethereum Classic | 9037 | 9137 | 8037 | |
|
||||
| Dogecoin | 9038 | 9138 | 8038 | 38338 |
|
||||
| Namecoin | 9039 | 9139 | 8039 | 38339 |
|
||||
|
|
Loading…
Reference in New Issue