From a073c8d1bb1761eee064d9623ff8be455b3c1a17 Mon Sep 17 00:00:00 2001 From: ucwong Date: Wed, 22 Jan 2025 19:15:19 +0800 Subject: [PATCH] toml config file supported --- go.mod | 2 +- go.sum | 4 +- p2p/config.go | 144 ++++++++++++++++ p2p/config_toml.go | 165 +++++++++++++++++++ p2p/nat/nat.go | 15 +- p2p/nat/natpmp.go | 4 + p2p/server.go | 99 ----------- vendor/github.com/fjl/gencodec/generate.go | 15 +- vendor/github.com/fjl/gencodec/main.go | 46 +++++- vendor/github.com/fjl/gencodec/types_util.go | 15 +- vendor/modules.txt | 4 +- 11 files changed, 397 insertions(+), 116 deletions(-) create mode 100644 p2p/config.go create mode 100644 p2p/config_toml.go diff --git a/go.mod b/go.mod index ffa75d68c6..ab79aa3e8a 100644 --- a/go.mod +++ b/go.mod @@ -25,7 +25,7 @@ require ( github.com/dop251/goja v0.0.0-20250114131315-46d383d606d3 github.com/ethereum/c-kzg-4844 v1.0.3 github.com/ethereum/go-verkle v0.2.2 - github.com/fjl/gencodec v0.0.0-20230517082657-f9840df7b83e + github.com/fjl/gencodec v0.1.0 github.com/fogleman/ease v0.0.0-20170301025033-8da417bf1776 github.com/fsnotify/fsnotify v1.8.0 github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08 diff --git a/go.sum b/go.sum index bd9ff84fb6..cce12c419a 100644 --- a/go.sum +++ b/go.sum @@ -463,8 +463,8 @@ github.com/ethereum/c-kzg-4844 v1.0.3/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1 github.com/ethereum/go-verkle v0.2.2 h1:I2W0WjnrFUIzzVPwm8ykY+7pL2d4VhlsePn4j7cnFk8= github.com/ethereum/go-verkle v0.2.2/go.mod h1:M3b90YRnzqKyyzBEWJGqj8Qff4IDeXnzFw0P9bFw3uk= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= -github.com/fjl/gencodec v0.0.0-20230517082657-f9840df7b83e h1:bBLctRc7kr01YGvaDfgLbTwjFNW5jdp5y5rj8XXBHfY= -github.com/fjl/gencodec v0.0.0-20230517082657-f9840df7b83e/go.mod h1:AzA8Lj6YtixmJWL+wkKoBGsLWy9gFrAzi4g+5bCKwpY= +github.com/fjl/gencodec v0.1.0 h1:B3K0xPfc52cw52BBgUbSPxYo+HlLfAgWMVKRWXUXBcs= +github.com/fjl/gencodec v0.1.0/go.mod h1:Um1dFHPONZGTHog1qD1NaWjXJW/SPB38wPv0O8uZ2fI= github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= github.com/fogleman/ease v0.0.0-20170301025033-8da417bf1776 h1:VRIbnDWRmAh5yBdz+J6yFMF5vso1It6vn+WmM/5l7MA= diff --git a/p2p/config.go b/p2p/config.go new file mode 100644 index 0000000000..c9c339077b --- /dev/null +++ b/p2p/config.go @@ -0,0 +1,144 @@ +// Copyright 2025 The go-ethereum Authors +// This file is part of the go-ethereum library. +// +// The go-ethereum library is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// The go-ethereum library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with the go-ethereum library. If not, see . +package p2p + +import ( + "crypto/ecdsa" + "fmt" + + "github.com/CortexFoundation/CortexTheseus/common/mclock" + "github.com/CortexFoundation/CortexTheseus/log" + "github.com/CortexFoundation/CortexTheseus/p2p/enode" + "github.com/CortexFoundation/CortexTheseus/p2p/nat" + "github.com/CortexFoundation/CortexTheseus/p2p/netutil" +) + +//go:generate go run github.com/fjl/gencodec -type Config -field-override configMarshaling -formats toml -out config_toml.go + +// Config holds Server options. +type Config struct { + // This field must be set to a valid secp256k1 private key. + PrivateKey *ecdsa.PrivateKey `toml:"-"` + + // MaxPeers is the maximum number of peers that can be + // connected. It must be greater than zero. + MaxPeers int + + // MaxPendingPeers is the maximum number of peers that can be pending in the + // handshake phase, counted separately for inbound and outbound connections. + // Zero defaults to preset values. + MaxPendingPeers int `toml:",omitempty"` + + // DialRatio controls the ratio of inbound to dialed connections. + // Example: a DialRatio of 2 allows 1/2 of connections to be dialed. + // Setting DialRatio to zero defaults it to 3. + DialRatio int `toml:",omitempty"` + + // NoDiscovery can be used to disable the peer discovery mechanism. + // Disabling is useful for protocol debugging (manual topology). + NoDiscovery bool + + // DiscoveryV4 specifies whether V4 discovery should be started. + DiscoveryV4 bool `toml:",omitempty"` + + // DiscoveryV5 specifies whether the new topic-discovery based V5 discovery + // protocol should be started or not. + DiscoveryV5 bool `toml:",omitempty"` + + // Name sets the node name of this server. + Name string `toml:"-"` + + // BootstrapNodes are used to establish connectivity + // with the rest of the network. + BootstrapNodes []*enode.Node + + // BootstrapNodesV5 are used to establish connectivity + // with the rest of the network using the V5 discovery + // protocol. + BootstrapNodesV5 []*enode.Node `toml:",omitempty"` + + // Static nodes are used as pre-configured connections which are always + // maintained and re-connected on disconnects. + StaticNodes []*enode.Node + + // Trusted nodes are used as pre-configured connections which are always + // allowed to connect, even above the peer limit. + TrustedNodes []*enode.Node + + // Connectivity can be restricted to certain IP networks. + // If this option is set to a non-nil value, only hosts which match one of the + // IP networks contained in the list are considered. + NetRestrict *netutil.Netlist `toml:",omitempty"` + + // NodeDatabase is the path to the database containing the previously seen + // live nodes in the network. + NodeDatabase string `toml:",omitempty"` + + // Protocols should contain the protocols supported + // by the server. Matching protocols are launched for + // each peer. + Protocols []Protocol `toml:"-" json:"-"` + + // If ListenAddr is set to a non-nil address, the server + // will listen for incoming connections. + // + // If the port is zero, the operating system will pick a port. The + // ListenAddr field will be updated with the actual address when + // the server is started. + ListenAddr string + + // If DiscAddr is set to a non-nil value, the server will use ListenAddr + // for TCP and DiscAddr for the UDP discovery protocol. + DiscAddr string + + // If set to a non-nil value, the given NAT port mapper + // is used to make the listening port available to the + // Internet. + NAT nat.Interface `toml:",omitempty"` + + // If Dialer is set to a non-nil value, the given Dialer + // is used to dial outbound peer connections. + Dialer NodeDialer `toml:"-"` + + // If NoDial is true, the server will not dial any peers. + NoDial bool `toml:",omitempty"` + + // If EnableMsgEvents is set then the server will emit PeerEvents + // whenever a message is sent to or received from a peer + EnableMsgEvents bool + + // Logger is a custom logger to use with the p2p.Server. + Logger log.Logger `toml:"-"` + + clock mclock.Clock +} + +type configMarshaling struct { + NAT configNAT +} + +type configNAT struct { + nat.Interface +} + +func (w *configNAT) UnmarshalText(input []byte) error { + n, err := nat.Parse(string(input)) + if err != nil { + return fmt.Errorf("invalid NAT specification: %v", err) + } + w.Interface = n + return nil +} diff --git a/p2p/config_toml.go b/p2p/config_toml.go new file mode 100644 index 0000000000..e9710b6b27 --- /dev/null +++ b/p2p/config_toml.go @@ -0,0 +1,165 @@ +// Code generated by github.com/fjl/gencodec. DO NOT EDIT. + +package p2p + +import ( + "crypto/ecdsa" + + "github.com/CortexFoundation/CortexTheseus/log" + "github.com/CortexFoundation/CortexTheseus/p2p/enode" + "github.com/CortexFoundation/CortexTheseus/p2p/nat" + "github.com/CortexFoundation/CortexTheseus/p2p/netutil" +) + +var _ = (*configMarshaling)(nil) + +// MarshalTOML marshals as TOML. +func (c Config) MarshalTOML() (interface{}, error) { + type Config struct { + PrivateKey *ecdsa.PrivateKey `toml:"-"` + MaxPeers int + MaxPendingPeers int `toml:",omitempty"` + DialRatio int `toml:",omitempty"` + NoDiscovery bool + DiscoveryV4 bool `toml:",omitempty"` + DiscoveryV5 bool `toml:",omitempty"` + Name string `toml:"-"` + BootstrapNodes []*enode.Node + BootstrapNodesV5 []*enode.Node `toml:",omitempty"` + StaticNodes []*enode.Node + TrustedNodes []*enode.Node + NetRestrict *netutil.Netlist `toml:",omitempty"` + NodeDatabase string `toml:",omitempty"` + Protocols []Protocol `toml:"-" json:"-"` + ListenAddr string + DiscAddr string + NAT nat.Interface `toml:",omitempty"` + Dialer NodeDialer `toml:"-"` + NoDial bool `toml:",omitempty"` + EnableMsgEvents bool + Logger log.Logger `toml:"-"` + } + var enc Config + enc.PrivateKey = c.PrivateKey + enc.MaxPeers = c.MaxPeers + enc.MaxPendingPeers = c.MaxPendingPeers + enc.DialRatio = c.DialRatio + enc.NoDiscovery = c.NoDiscovery + enc.DiscoveryV4 = c.DiscoveryV4 + enc.DiscoveryV5 = c.DiscoveryV5 + enc.Name = c.Name + enc.BootstrapNodes = c.BootstrapNodes + enc.BootstrapNodesV5 = c.BootstrapNodesV5 + enc.StaticNodes = c.StaticNodes + enc.TrustedNodes = c.TrustedNodes + enc.NetRestrict = c.NetRestrict + enc.NodeDatabase = c.NodeDatabase + enc.Protocols = c.Protocols + enc.ListenAddr = c.ListenAddr + enc.DiscAddr = c.DiscAddr + enc.NAT = c.NAT + enc.Dialer = c.Dialer + enc.NoDial = c.NoDial + enc.EnableMsgEvents = c.EnableMsgEvents + enc.Logger = c.Logger + return &enc, nil +} + +// UnmarshalTOML unmarshals from TOML. +func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error { + type Config struct { + PrivateKey *ecdsa.PrivateKey `toml:"-"` + MaxPeers *int + MaxPendingPeers *int `toml:",omitempty"` + DialRatio *int `toml:",omitempty"` + NoDiscovery *bool + DiscoveryV4 *bool `toml:",omitempty"` + DiscoveryV5 *bool `toml:",omitempty"` + Name *string `toml:"-"` + BootstrapNodes []*enode.Node + BootstrapNodesV5 []*enode.Node `toml:",omitempty"` + StaticNodes []*enode.Node + TrustedNodes []*enode.Node + NetRestrict *netutil.Netlist `toml:",omitempty"` + NodeDatabase *string `toml:",omitempty"` + Protocols []Protocol `toml:"-" json:"-"` + ListenAddr *string + DiscAddr *string + NAT *configNAT `toml:",omitempty"` + Dialer NodeDialer `toml:"-"` + NoDial *bool `toml:",omitempty"` + EnableMsgEvents *bool + Logger log.Logger `toml:"-"` + } + var dec Config + if err := unmarshal(&dec); err != nil { + return err + } + if dec.PrivateKey != nil { + c.PrivateKey = dec.PrivateKey + } + if dec.MaxPeers != nil { + c.MaxPeers = *dec.MaxPeers + } + if dec.MaxPendingPeers != nil { + c.MaxPendingPeers = *dec.MaxPendingPeers + } + if dec.DialRatio != nil { + c.DialRatio = *dec.DialRatio + } + if dec.NoDiscovery != nil { + c.NoDiscovery = *dec.NoDiscovery + } + if dec.DiscoveryV4 != nil { + c.DiscoveryV4 = *dec.DiscoveryV4 + } + if dec.DiscoveryV5 != nil { + c.DiscoveryV5 = *dec.DiscoveryV5 + } + if dec.Name != nil { + c.Name = *dec.Name + } + if dec.BootstrapNodes != nil { + c.BootstrapNodes = dec.BootstrapNodes + } + if dec.BootstrapNodesV5 != nil { + c.BootstrapNodesV5 = dec.BootstrapNodesV5 + } + if dec.StaticNodes != nil { + c.StaticNodes = dec.StaticNodes + } + if dec.TrustedNodes != nil { + c.TrustedNodes = dec.TrustedNodes + } + if dec.NetRestrict != nil { + c.NetRestrict = dec.NetRestrict + } + if dec.NodeDatabase != nil { + c.NodeDatabase = *dec.NodeDatabase + } + if dec.Protocols != nil { + c.Protocols = dec.Protocols + } + if dec.ListenAddr != nil { + c.ListenAddr = *dec.ListenAddr + } + if dec.DiscAddr != nil { + c.DiscAddr = *dec.DiscAddr + } + if dec.NAT != nil { + c.NAT = dec.NAT + } + if dec.Dialer != nil { + c.Dialer = dec.Dialer + } + if dec.NoDial != nil { + c.NoDial = *dec.NoDial + } + if dec.EnableMsgEvents != nil { + c.EnableMsgEvents = *dec.EnableMsgEvents + } + if dec.Logger != nil { + c.Logger = dec.Logger + } + return nil +} diff --git a/p2p/nat/nat.go b/p2p/nat/nat.go index 2c9f8c1610..7c9616e537 100644 --- a/p2p/nat/nat.go +++ b/p2p/nat/nat.go @@ -133,8 +133,9 @@ func Map(m Interface, c <-chan struct{}, protocol string, extport, intport int, // Mapping operations will not return an error but won't actually do anything. type ExtIP net.IP -func (n ExtIP) ExternalIP() (net.IP, error) { return net.IP(n), nil } -func (n ExtIP) String() string { return fmt.Sprintf("ExtIP(%v)", net.IP(n)) } +func (n ExtIP) ExternalIP() (net.IP, error) { return net.IP(n), nil } +func (n ExtIP) String() string { return fmt.Sprintf("ExtIP(%v)", net.IP(n)) } +func (n ExtIP) MarshalText() ([]byte, error) { return []byte(fmt.Sprintf("extip:%v", net.IP(n))), nil } // These do nothing. @@ -148,7 +149,7 @@ func (ExtIP) DeleteMapping(string, int, int) error { return nil } func Any() Interface { // TODO: attempt to discover whether the local machine has an // Internet-class address. Return ExtIP in this case. - return startautodisc("UPnP or NAT-PMP", func() Interface { + return startautodisc("any", func() Interface { found := make(chan Interface, 2) go func() { found <- discoverUPnP() }() go func() { found <- discoverPMP() }() @@ -164,7 +165,7 @@ func Any() Interface { // UPnP returns a port mapper that uses UPnP. It will attempt to // discover the address of your router using UDP broadcasts. func UPnP() Interface { - return startautodisc("UPnP", discoverUPnP) + return startautodisc("upnp", discoverUPnP) } // PMP returns a port mapper that uses NAT-PMP. The provided gateway @@ -174,7 +175,7 @@ func PMP(gateway net.IP) Interface { if gateway != nil { return &pmp{gw: gateway, c: natpmp.NewClient(gateway)} } - return startautodisc("NAT-PMP", discoverPMP) + return startautodisc("natpmp", discoverPMP) } // autodisc represents a port mapping mechanism that is still being @@ -228,6 +229,10 @@ func (n *autodisc) String() string { return n.found.String() } +func (n *autodisc) MarshalText() ([]byte, error) { + return []byte(n.what), nil +} + // wait blocks until auto-discovery has been performed. func (n *autodisc) wait() error { n.once.Do(func() { diff --git a/p2p/nat/natpmp.go b/p2p/nat/natpmp.go index 6768dc08c0..9f16c19ad0 100644 --- a/p2p/nat/natpmp.go +++ b/p2p/nat/natpmp.go @@ -69,6 +69,10 @@ func (n *pmp) DeleteMapping(protocol string, extport, intport int) (err error) { return err } +func (n *pmp) MarshalText() ([]byte, error) { + return []byte(fmt.Sprintf("natpmp:%v", n.gw)), nil +} + func discoverPMP() Interface { // run external address lookups on all potential gateways gws := potentialGateways() diff --git a/p2p/server.go b/p2p/server.go index d665b56c7f..c771e2f5c6 100644 --- a/p2p/server.go +++ b/p2p/server.go @@ -39,7 +39,6 @@ import ( "github.com/CortexFoundation/CortexTheseus/p2p/discover" "github.com/CortexFoundation/CortexTheseus/p2p/enode" "github.com/CortexFoundation/CortexTheseus/p2p/enr" - "github.com/CortexFoundation/CortexTheseus/p2p/nat" "github.com/CortexFoundation/CortexTheseus/p2p/netutil" ) @@ -72,104 +71,6 @@ var ( errProtoHandshakeError = errors.New("rlpx proto error") ) -// Config holds Server options. -type Config struct { - // This field must be set to a valid secp256k1 private key. - PrivateKey *ecdsa.PrivateKey `toml:"-"` - - // MaxPeers is the maximum number of peers that can be - // connected. It must be greater than zero. - MaxPeers int - - // MaxPendingPeers is the maximum number of peers that can be pending in the - // handshake phase, counted separately for inbound and outbound connections. - // Zero defaults to preset values. - MaxPendingPeers int `toml:",omitempty"` - - // DialRatio controls the ratio of inbound to dialed connections. - // Example: a DialRatio of 2 allows 1/2 of connections to be dialed. - // Setting DialRatio to zero defaults it to 3. - DialRatio int `toml:",omitempty"` - - // NoDiscovery can be used to disable the peer discovery mechanism. - // Disabling is useful for protocol debugging (manual topology). - NoDiscovery bool - - // DiscoveryV4 specifies whether V4 discovery should be started. - DiscoveryV4 bool `toml:",omitempty"` - - // DiscoveryV5 specifies whether the new topic-discovery based V5 discovery - // protocol should be started or not. - DiscoveryV5 bool `toml:",omitempty"` - - // Name sets the node name of this server. - Name string `toml:"-"` - - // BootstrapNodes are used to establish connectivity - // with the rest of the network. - BootstrapNodes []*enode.Node - - // BootstrapNodesV5 are used to establish connectivity - // with the rest of the network using the V5 discovery - // protocol. - BootstrapNodesV5 []*enode.Node `toml:",omitempty"` - - // Static nodes are used as pre-configured connections which are always - // maintained and re-connected on disconnects. - StaticNodes []*enode.Node - - // Trusted nodes are used as pre-configured connections which are always - // allowed to connect, even above the peer limit. - TrustedNodes []*enode.Node - - // Connectivity can be restricted to certain IP networks. - // If this option is set to a non-nil value, only hosts which match one of the - // IP networks contained in the list are considered. - NetRestrict *netutil.Netlist `toml:",omitempty"` - - // NodeDatabase is the path to the database containing the previously seen - // live nodes in the network. - NodeDatabase string `toml:",omitempty"` - - // Protocols should contain the protocols supported - // by the server. Matching protocols are launched for - // each peer. - Protocols []Protocol `toml:"-" json:"-"` - - // If ListenAddr is set to a non-nil address, the server - // will listen for incoming connections. - // - // If the port is zero, the operating system will pick a port. The - // ListenAddr field will be updated with the actual address when - // the server is started. - ListenAddr string - - // If DiscAddr is set to a non-nil value, the server will use ListenAddr - // for TCP and DiscAddr for the UDP discovery protocol. - DiscAddr string - - // If set to a non-nil value, the given NAT port mapper - // is used to make the listening port available to the - // Internet. - NAT nat.Interface `toml:",omitempty"` - - // If Dialer is set to a non-nil value, the given Dialer - // is used to dial outbound peer connections. - Dialer NodeDialer `toml:"-"` - - // If NoDial is true, the server will not dial any peers. - NoDial bool `toml:",omitempty"` - - // If EnableMsgEvents is set then the server will emit PeerEvents - // whenever a message is sent to or received from a peer - EnableMsgEvents bool - - // Logger is a custom logger to use with the p2p.Server. - Logger log.Logger `toml:",omitempty"` - - clock mclock.Clock -} - // Server manages all peer connections. type Server struct { // Config fields may not be modified while the server is running. diff --git a/vendor/github.com/fjl/gencodec/generate.go b/vendor/github.com/fjl/gencodec/generate.go index 2ee7112322..4e0cdd814a 100644 --- a/vendor/github.com/fjl/gencodec/generate.go +++ b/vendor/github.com/fjl/gencodec/generate.go @@ -186,6 +186,10 @@ func (m *marshalMethod) intermediateType(name string) Struct { typ := f.typ if m.isUnmarshal { typ = ensureNilCheckable(typ) + } else if isNonEmptyInterface(f.origTyp) { + // Non-empty interface is left as-is for Marshal*, i.e. we let the + // interface value handle its own marshaling. + typ = f.origTyp } s.Fields = append(s.Fields, Field{ Name: f.name, @@ -237,14 +241,21 @@ func (m *marshalMethod) marshalConversions(from, to Var, fieldName string) (s [] if f.function != nil { value = CallFunction{Func: accessFrom} } - s = append(s, m.convert(value, accessTo, f.origTyp, f.typ, fieldName)...) + // Non-empty interface values are handled differently between Marshal* and Unmarshal*. + // The conversion is only applied in the Unmarshal* method. + // For Marshal*, we let the value handle its own encoding, i.e. conversion is skipped. + var fieldType = f.typ + if isNonEmptyInterface(f.origTyp) { + fieldType = f.origTyp + } + s = append(s, m.convert(value, accessTo, f.origTyp, fieldType, fieldName)...) } return s } func (m *marshalMethod) convert(from, to Expression, fromtyp, totyp types.Type, fieldName string) (s []Statement) { // Remove pointer introduced by ensureNilCheckable during field building. - if isPointer(fromtyp) && !isPointer(totyp) { + if isPointer(fromtyp) && !isPointer(totyp) && !isInterface(totyp) { from = Star{Value: from} fromtyp = fromtyp.(*types.Pointer).Elem() } else if !isPointer(fromtyp) && isPointer(totyp) { diff --git a/vendor/github.com/fjl/gencodec/main.go b/vendor/github.com/fjl/gencodec/main.go index 35f942760b..795587f117 100644 --- a/vendor/github.com/fjl/gencodec/main.go +++ b/vendor/github.com/fjl/gencodec/main.go @@ -89,6 +89,8 @@ The generated code will contain: ... } +# Array/Slice/Map conversions + If the fields are of map or slice type and the element (and key) types are convertible, a simple loop is emitted. Example input code: @@ -123,6 +125,47 @@ The generated code is similar to this snippet: } ... } + +# Non-empty interfaces + +For some use cases, like configuration loading, you may wish to work with structs +containing fields with a non-empty interface type. Package json supports encoding such +types (it simply encodes the concrete type contained in the interface), but decoding is +not supported. With gencodec, you can use the override struct to assign a concrete type +that will be used for the interface. + +In the example below, the encoded struct has a field of type io.Writer. During decoding, +the input is verified to be "stdout" or "stderr", and the appropriate writer is inserted. + + //go:generate gencodec -type Config -field-override configMarshaling -formats json -out output.go + + type Config struct{ + Output io.Writer + } + + type configMarshaling struct{ + Output configWriter + } + + type configWriter struct{ + io.Writer + } + + func (w *configWriter) UnmarshalJSON(input []byte) error { + var outputName string + if err := json.Unmarshal(input, &outputName); err != nil { + return err + } + switch outputName { + case "stdout": + w.Writer = os.Stdout + case "stderr": + w.Writer = os.Stderr + default: + return errors.New("invalid output name") + } + return nil + } */ package main @@ -134,7 +177,6 @@ import ( "go/token" "go/types" "io" - "io/ioutil" "os" "reflect" "strings" @@ -165,7 +207,7 @@ func main() { } if *output == "-" { os.Stdout.Write(code) - } else if err := ioutil.WriteFile(*output, code, 0644); err != nil { + } else if err := os.WriteFile(*output, code, 0644); err != nil { fatal(err) } } diff --git a/vendor/github.com/fjl/gencodec/types_util.go b/vendor/github.com/fjl/gencodec/types_util.go index 891c1b9951..77d1b54782 100644 --- a/vendor/github.com/fjl/gencodec/types_util.go +++ b/vendor/github.com/fjl/gencodec/types_util.go @@ -72,6 +72,15 @@ func isPointer(typ types.Type) bool { return ok } +func isNonEmptyInterface(typ types.Type) bool { + iftype := underlying[*types.Interface](typ) + return iftype != nil && iftype.NumMethods() > 0 +} + +func isInterface(typ types.Type) bool { + return underlying[*types.Interface](typ) != nil +} + func underlyingArray(typ types.Type) *types.Array { return underlying[*types.Array](typ) } @@ -86,11 +95,11 @@ func underlyingMap(typ types.Type) *types.Map { func underlying[T types.Type](typ types.Type) T { for { - switch typ.(type) { + switch t := typ.(type) { case *types.Named: - typ = typ.Underlying() + typ = t.Underlying() case T: - return typ.(T) + return t default: var zero T return zero diff --git a/vendor/modules.txt b/vendor/modules.txt index 455fc80886..195bff64b4 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -537,8 +537,8 @@ github.com/ethereum/c-kzg-4844/bindings/go # github.com/ethereum/go-verkle v0.2.2 ## explicit; go 1.22 github.com/ethereum/go-verkle -# github.com/fjl/gencodec v0.0.0-20230517082657-f9840df7b83e -## explicit; go 1.18 +# github.com/fjl/gencodec v0.1.0 +## explicit; go 1.22.0 github.com/fjl/gencodec # github.com/fogleman/ease v0.0.0-20170301025033-8da417bf1776 ## explicit