@@ -21,6 +21,7 @@ import (
21
21
"encoding/base64"
22
22
"encoding/hex"
23
23
"fmt"
24
+ "io"
24
25
"io/ioutil"
25
26
"net"
26
27
"os"
@@ -69,22 +70,30 @@ func enrdump(ctx *cli.Context) error {
69
70
if err != nil {
70
71
return fmt .Errorf ("INVALID: %v" , err )
71
72
}
72
- fmt . Print ( dumpRecord (r ) )
73
+ dumpRecord (os . Stdout , r )
73
74
return nil
74
75
}
75
76
76
77
// 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 {
80
81
fmt .Fprintf (out , "INVALID: %v\n " , err )
81
82
} else {
82
83
fmt .Fprintf (out , "Node ID: %v\n " , n .ID ())
84
+ dumpNodeURL (out , n )
83
85
}
84
86
kv := r .AppendElements (nil )[1 :]
85
87
fmt .Fprintf (out , "Record has sequence number %d and %d key/value pairs.\n " , r .Seq (), len (kv )/ 2 )
86
88
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 ())
88
97
}
89
98
90
99
func dumpRecordKV (kv []interface {}, indent int ) string {
0 commit comments