From bb71c38a39f65e205512c754b6af4f7160227739 Mon Sep 17 00:00:00 2001 From: Agost Biro <5764438+agostbiro@users.noreply.github.com> Date: Thu, 4 Jan 2024 23:48:00 +0100 Subject: [PATCH] Add CLI flag to print peer id from config (#34) * Add CLI flag to print peer id from config * Add printing peer id instructions to readme --- README.md | 8 ++++++++ node/main.go | 16 ++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/README.md b/README.md index c4f1ab5..629afd5 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,14 @@ If you do not, or have already run the above, run: GOEXPERIMENT=arenas go run ./... +## Peer ID + +In order to find the peer id of a running node, execute the following command from the `node/` folder: + + GOEXPERIMENT=arenas go run ./... --peer-id + +The peer id will be printed to stdout. + ## EXPERIMENTAL – gRPC/REST Support If you want to enable gRPC/REST, add the following entries to your config.yml: diff --git a/node/main.go b/node/main.go index 7467094..c2bd6b9 100644 --- a/node/main.go +++ b/node/main.go @@ -38,11 +38,27 @@ var ( false, "starts the node in database console mode", ) + + peerId = flag.Bool( + "peer-id", + false, + "print the peer id to stdout from the config and exit", + ) ) func main() { flag.Parse() + if *peerId { + config, err := config.LoadConfig(*configDirectory, "") + if err != nil { + panic(err) + } + + printPeerID(config.P2P) + return + } + if *importPrivKey != "" { config, err := config.LoadConfig(*configDirectory, *importPrivKey) if err != nil {