mirror of https://github.com/status-im/op-geth.git
all: simplify switches (#17267)
* all: simplify switches * silly mistake
This commit is contained in:
parent
273c7a9dc4
commit
d42ce0f2c1
|
@ -1146,8 +1146,7 @@ func TestEIP155Transition(t *testing.T) {
|
||||||
return types.SignTx(types.NewTransaction(block.TxNonce(address), common.Address{}, new(big.Int), 21000, new(big.Int), nil), signer, key)
|
return types.SignTx(types.NewTransaction(block.TxNonce(address), common.Address{}, new(big.Int), 21000, new(big.Int), nil), signer, key)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
switch i {
|
if i == 0 {
|
||||||
case 0:
|
|
||||||
tx, err = basicTx(types.NewEIP155Signer(big.NewInt(2)))
|
tx, err = basicTx(types.NewEIP155Signer(big.NewInt(2)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|
|
@ -338,8 +338,7 @@ func (es *EventSystem) broadcast(filters filterIndex, ev interface{}) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case *event.TypeMuxEvent:
|
case *event.TypeMuxEvent:
|
||||||
switch muxe := e.Data.(type) {
|
if muxe, ok := e.Data.(core.PendingLogsEvent); ok {
|
||||||
case core.PendingLogsEvent:
|
|
||||||
for _, f := range filters[PendingLogsSubscription] {
|
for _, f := range filters[PendingLogsSubscription] {
|
||||||
if e.Time.After(f.created) {
|
if e.Time.After(f.created) {
|
||||||
if matchedLogs := filterLogs(muxe.Logs, nil, f.logsCrit.ToBlock, f.logsCrit.Addresses, f.logsCrit.Topics); len(matchedLogs) > 0 {
|
if matchedLogs := filterLogs(muxe.Logs, nil, f.logsCrit.ToBlock, f.logsCrit.Addresses, f.logsCrit.Topics); len(matchedLogs) > 0 {
|
||||||
|
|
|
@ -744,8 +744,7 @@ func (pm *ProtocolManager) BroadcastTxs(txs types.Transactions) {
|
||||||
func (pm *ProtocolManager) minedBroadcastLoop() {
|
func (pm *ProtocolManager) minedBroadcastLoop() {
|
||||||
// automatically stops if unsubscribe
|
// automatically stops if unsubscribe
|
||||||
for obj := range pm.minedBlockSub.Chan() {
|
for obj := range pm.minedBlockSub.Chan() {
|
||||||
switch ev := obj.Data.(type) {
|
if ev, ok := obj.Data.(core.NewMinedBlockEvent); ok {
|
||||||
case core.NewMinedBlockEvent:
|
|
||||||
pm.BroadcastBlock(ev.Block, true) // First propagate block to peers
|
pm.BroadcastBlock(ev.Block, true) // First propagate block to peers
|
||||||
pm.BroadcastBlock(ev.Block, false) // Only then announce to the rest
|
pm.BroadcastBlock(ev.Block, false) // Only then announce to the rest
|
||||||
}
|
}
|
||||||
|
|
|
@ -486,12 +486,7 @@ func (jst *Tracer) call(method string, args ...string) (json.RawMessage, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func wrapError(context string, err error) error {
|
func wrapError(context string, err error) error {
|
||||||
var message string
|
return fmt.Errorf("%v in server-side tracer function '%v'", err, context)
|
||||||
switch err := err.(type) {
|
|
||||||
default:
|
|
||||||
message = err.Error()
|
|
||||||
}
|
|
||||||
return fmt.Errorf("%v in server-side tracer function '%v'", message, context)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CaptureStart implements the Tracer interface to initialize the tracing operation.
|
// CaptureStart implements the Tracer interface to initialize the tracing operation.
|
||||||
|
|
|
@ -1158,8 +1158,7 @@ func (pm *ProtocolManager) getHelperTrie(id uint, idx uint64) (common.Hash, stri
|
||||||
|
|
||||||
// getHelperTrieAuxData returns requested auxiliary data for the given HelperTrie request
|
// getHelperTrieAuxData returns requested auxiliary data for the given HelperTrie request
|
||||||
func (pm *ProtocolManager) getHelperTrieAuxData(req HelperTrieReq) []byte {
|
func (pm *ProtocolManager) getHelperTrieAuxData(req HelperTrieReq) []byte {
|
||||||
switch {
|
if req.Type == htCanonical && req.AuxReq == auxHeader && len(req.Key) == 8 {
|
||||||
case req.Type == htCanonical && req.AuxReq == auxHeader && len(req.Key) == 8:
|
|
||||||
blockNum := binary.BigEndian.Uint64(req.Key)
|
blockNum := binary.BigEndian.Uint64(req.Key)
|
||||||
hash := rawdb.ReadCanonicalHash(pm.chainDb, blockNum)
|
hash := rawdb.ReadCanonicalHash(pm.chainDb, blockNum)
|
||||||
return rawdb.ReadHeaderRLP(pm.chainDb, hash, blockNum)
|
return rawdb.ReadHeaderRLP(pm.chainDb, hash, blockNum)
|
||||||
|
|
|
@ -147,21 +147,21 @@ func (exp *exp) publishResettingTimer(name string, metric metrics.ResettingTimer
|
||||||
|
|
||||||
func (exp *exp) syncToExpvar() {
|
func (exp *exp) syncToExpvar() {
|
||||||
exp.registry.Each(func(name string, i interface{}) {
|
exp.registry.Each(func(name string, i interface{}) {
|
||||||
switch i.(type) {
|
switch i := i.(type) {
|
||||||
case metrics.Counter:
|
case metrics.Counter:
|
||||||
exp.publishCounter(name, i.(metrics.Counter))
|
exp.publishCounter(name, i)
|
||||||
case metrics.Gauge:
|
case metrics.Gauge:
|
||||||
exp.publishGauge(name, i.(metrics.Gauge))
|
exp.publishGauge(name, i)
|
||||||
case metrics.GaugeFloat64:
|
case metrics.GaugeFloat64:
|
||||||
exp.publishGaugeFloat64(name, i.(metrics.GaugeFloat64))
|
exp.publishGaugeFloat64(name, i)
|
||||||
case metrics.Histogram:
|
case metrics.Histogram:
|
||||||
exp.publishHistogram(name, i.(metrics.Histogram))
|
exp.publishHistogram(name, i)
|
||||||
case metrics.Meter:
|
case metrics.Meter:
|
||||||
exp.publishMeter(name, i.(metrics.Meter))
|
exp.publishMeter(name, i)
|
||||||
case metrics.Timer:
|
case metrics.Timer:
|
||||||
exp.publishTimer(name, i.(metrics.Timer))
|
exp.publishTimer(name, i)
|
||||||
case metrics.ResettingTimer:
|
case metrics.ResettingTimer:
|
||||||
exp.publishResettingTimer(name, i.(metrics.ResettingTimer))
|
exp.publishResettingTimer(name, i)
|
||||||
default:
|
default:
|
||||||
panic(fmt.Sprintf("unsupported type for '%s': %T", name, i))
|
panic(fmt.Sprintf("unsupported type for '%s': %T", name, i))
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,8 +115,7 @@ func potentialGateways() (gws []net.IP) {
|
||||||
return gws
|
return gws
|
||||||
}
|
}
|
||||||
for _, addr := range ifaddrs {
|
for _, addr := range ifaddrs {
|
||||||
switch x := addr.(type) {
|
if x, ok := addr.(*net.IPNet); ok {
|
||||||
case *net.IPNet:
|
|
||||||
if lan10.Contains(x.IP) || lan176.Contains(x.IP) || lan192.Contains(x.IP) {
|
if lan10.Contains(x.IP) || lan176.Contains(x.IP) || lan192.Contains(x.IP) {
|
||||||
ip := x.IP.Mask(x.Mask).To4()
|
ip := x.IP.Mask(x.Mask).To4()
|
||||||
if ip != nil {
|
if ip != nil {
|
||||||
|
|
|
@ -81,14 +81,11 @@ func (n *upnp) internalAddress() (net.IP, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
for _, addr := range addrs {
|
for _, addr := range addrs {
|
||||||
switch x := addr.(type) {
|
if x, ok := addr.(*net.IPNet); ok && x.Contains(devaddr.IP) {
|
||||||
case *net.IPNet:
|
|
||||||
if x.Contains(devaddr.IP) {
|
|
||||||
return x.IP, nil
|
return x.IP, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return nil, fmt.Errorf("could not find local address in same net as %v", devaddr)
|
return nil, fmt.Errorf("could not find local address in same net as %v", devaddr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -353,8 +353,7 @@ func (sn *SimNode) NodeInfo() *p2p.NodeInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
func setSocketBuffer(conn net.Conn, socketReadBuffer int, socketWriteBuffer int) error {
|
func setSocketBuffer(conn net.Conn, socketReadBuffer int, socketWriteBuffer int) error {
|
||||||
switch v := conn.(type) {
|
if v, ok := conn.(*net.UnixConn); ok {
|
||||||
case *net.UnixConn:
|
|
||||||
err := v.SetReadBuffer(socketReadBuffer)
|
err := v.SetReadBuffer(socketReadBuffer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -43,11 +43,11 @@ type decodedCallData struct {
|
||||||
// String implements stringer interface, tries to use the underlying value-type
|
// String implements stringer interface, tries to use the underlying value-type
|
||||||
func (arg decodedArgument) String() string {
|
func (arg decodedArgument) String() string {
|
||||||
var value string
|
var value string
|
||||||
switch arg.value.(type) {
|
switch val := arg.value.(type) {
|
||||||
case fmt.Stringer:
|
case fmt.Stringer:
|
||||||
value = arg.value.(fmt.Stringer).String()
|
value = val.String()
|
||||||
default:
|
default:
|
||||||
value = fmt.Sprintf("%v", arg.value)
|
value = fmt.Sprintf("%v", val)
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("%v: %v", arg.soltype.Type.String(), value)
|
return fmt.Sprintf("%v: %v", arg.soltype.Type.String(), value)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue