cmd/tools/convert-node-id: tool for node id conversions
Change-Id: I3d18a051131135dfdbfd9c54002efbc853e4004d
This commit is contained in:
parent
04411e6871
commit
3b7d8e8798
53
cmd/tools/convert-node-id/main.go
Normal file
53
cmd/tools/convert-node-id/main.go
Normal file
@ -0,0 +1,53 @@
|
||||
// Copyright (C) 2022 Storj, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"storj.io/common/storj"
|
||||
)
|
||||
|
||||
func usage() {
|
||||
fmt.Fprintf(os.Stderr, "usage: %s <nodeid>\n", os.Args[0])
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
func output(id storj.NodeID) {
|
||||
fmt.Printf("base58 id: %s\n", id.String())
|
||||
fmt.Printf("hex id: %x\n", id.Bytes())
|
||||
fmt.Printf("version: %d\n", id.Version().Number)
|
||||
diff, err := id.Difficulty()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "error getting difficulty: %v\n", err)
|
||||
} else {
|
||||
fmt.Printf("difficulty: %d\n", diff)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
if len(os.Args) != 2 {
|
||||
usage()
|
||||
}
|
||||
|
||||
id, err := storj.NodeIDFromString(os.Args[1])
|
||||
if err == nil {
|
||||
output(id)
|
||||
return
|
||||
}
|
||||
|
||||
idBytes, err := hex.DecodeString(os.Args[1])
|
||||
if err == nil {
|
||||
id, err := storj.NodeIDFromBytes(idBytes)
|
||||
if err == nil {
|
||||
output(id)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Fprintf(os.Stderr, "unknown argument: %q", os.Args[1])
|
||||
usage()
|
||||
}
|
Loading…
Reference in New Issue
Block a user