|
|
|
@ -21,6 +21,7 @@ import ( |
|
|
|
|
"encoding/base64" |
|
|
|
|
"encoding/hex" |
|
|
|
|
"fmt" |
|
|
|
|
"io" |
|
|
|
|
"io/ioutil" |
|
|
|
|
"net" |
|
|
|
|
"os" |
|
|
|
@ -69,22 +70,30 @@ func enrdump(ctx *cli.Context) error { |
|
|
|
|
if err != nil { |
|
|
|
|
return fmt.Errorf("INVALID: %v", err) |
|
|
|
|
} |
|
|
|
|
fmt.Print(dumpRecord(r)) |
|
|
|
|
dumpRecord(os.Stdout, r) |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// dumpRecord creates a human-readable description of the given node record.
|
|
|
|
|
func dumpRecord(r *enr.Record) string { |
|
|
|
|
out := new(bytes.Buffer) |
|
|
|
|
if n, err := enode.New(enode.ValidSchemes, r); err != nil { |
|
|
|
|
func dumpRecord(out io.Writer, r *enr.Record) { |
|
|
|
|
n, err := enode.New(enode.ValidSchemes, r) |
|
|
|
|
if err != nil { |
|
|
|
|
fmt.Fprintf(out, "INVALID: %v\n", err) |
|
|
|
|
} else { |
|
|
|
|
fmt.Fprintf(out, "Node ID: %v\n", n.ID()) |
|
|
|
|
dumpNodeURL(out, n) |
|
|
|
|
} |
|
|
|
|
kv := r.AppendElements(nil)[1:] |
|
|
|
|
fmt.Fprintf(out, "Record has sequence number %d and %d key/value pairs.\n", r.Seq(), len(kv)/2) |
|
|
|
|
fmt.Fprint(out, dumpRecordKV(kv, 2)) |
|
|
|
|
return out.String() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func dumpNodeURL(out io.Writer, n *enode.Node) { |
|
|
|
|
var key enode.Secp256k1 |
|
|
|
|
if n.Load(&key) != nil { |
|
|
|
|
return // no secp256k1 public key
|
|
|
|
|
} |
|
|
|
|
fmt.Fprintf(out, "URLv4: %s\n", n.URLv4()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func dumpRecordKV(kv []interface{}, indent int) string { |
|
|
|
|