Help us shape the future of Go! Take the 2026 Go Developer Survey

enr

package
v0.1.118 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 27, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ENRCmd = &cobra.Command{
	Use:   "enr [flags]",
	Short: "Convert between ENR and Enode format.",
	Long:  usage,
	RunE: func(cmd *cobra.Command, args []string) error {
		rawData, err := getInputData(cmd, args)
		if err != nil {
			log.Error().Err(err).Msg("Unable to read input")
			return err
		}
		lines := strings.SplitSeq(string(rawData), "\n")

		for l := range lines {
			var node *enode.Node
			var err error
			l = strings.TrimSpace(l)
			if l == "" {
				continue
			}
			isENR := false
			genericNode := make(map[string]any, 0)

			if strings.HasPrefix(l, "enr:") {
				isENR = true
				node, err = enode.Parse(enode.V4ID{}, l)
				if err != nil {
					log.Error().Err(err).Str("line", l).Msg("Unable to parse enr record")
					continue
				}
				var eth struct {
					ForkID forkid.ID
					Tail   []rlp.RawValue `rlp:"tail"`
				}
				_ = node.Load(enr.WithEntry("eth", &eth))
				genericNode["forkid"] = ForkIDToString(eth.ForkID)
			} else {
				node, err = enode.ParseV4(l)
				if err != nil {
					log.Error().Err(err).Str("line", l).Msg("Unable to parse node record")
					continue
				}
			}

			if isENR {
				genericNode["enr"] = node.String()
			}
			genericNode["enode"] = node.URLv4()
			genericNode["id"] = node.ID().String()
			genericNode["ip"] = node.IP().String()
			genericNode["seq"] = node.Seq()
			genericNode["tcp"] = fmt.Sprintf("%d", node.TCP())
			genericNode["udp"] = fmt.Sprintf("%d", node.UDP())
			jsonOut, err := json.Marshal(genericNode)
			if err != nil {
				log.Error().Err(err).Msg("Unable to convert node to json")
				continue
			}
			fmt.Println(string(jsonOut))
		}
		return nil
	},
	Args: func(cmd *cobra.Command, args []string) error {
		return nil
	},
}

Functions

func ForkIDToString

func ForkIDToString(id forkid.ID) string

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL