Skip to content

Commit e24e05d

Browse files
adamschmidegfjl
andauthored
cmd/devp2p: print enode:// URL in enrdump (#21270)
Co-authored-by: Felix Lange <[email protected]>
1 parent 90dedea commit e24e05d

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

cmd/devp2p/enrcmd.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"encoding/base64"
2222
"encoding/hex"
2323
"fmt"
24+
"io"
2425
"io/ioutil"
2526
"net"
2627
"os"
@@ -69,22 +70,30 @@ func enrdump(ctx *cli.Context) error {
6970
if err != nil {
7071
return fmt.Errorf("INVALID: %v", err)
7172
}
72-
fmt.Print(dumpRecord(r))
73+
dumpRecord(os.Stdout, r)
7374
return nil
7475
}
7576

7677
// dumpRecord creates a human-readable description of the given node record.
77-
func dumpRecord(r *enr.Record) string {
78-
out := new(bytes.Buffer)
79-
if n, err := enode.New(enode.ValidSchemes, r); err != nil {
78+
func dumpRecord(out io.Writer, r *enr.Record) {
79+
n, err := enode.New(enode.ValidSchemes, r)
80+
if err != nil {
8081
fmt.Fprintf(out, "INVALID: %v\n", err)
8182
} else {
8283
fmt.Fprintf(out, "Node ID: %v\n", n.ID())
84+
dumpNodeURL(out, n)
8385
}
8486
kv := r.AppendElements(nil)[1:]
8587
fmt.Fprintf(out, "Record has sequence number %d and %d key/value pairs.\n", r.Seq(), len(kv)/2)
8688
fmt.Fprint(out, dumpRecordKV(kv, 2))
87-
return out.String()
89+
}
90+
91+
func dumpNodeURL(out io.Writer, n *enode.Node) {
92+
var key enode.Secp256k1
93+
if n.Load(&key) != nil {
94+
return // no secp256k1 public key
95+
}
96+
fmt.Fprintf(out, "URLv4: %s\n", n.URLv4())
8897
}
8998

9099
func dumpRecordKV(kv []interface{}, indent int) string {

0 commit comments

Comments
 (0)