all: simplify switches (#17267)

* all: simplify switches

* silly mistake
pull/17088/merge
Oleg Kovalov 6 years ago committed by Péter Szilágyi
parent 273c7a9dc4
commit d42ce0f2c1
  1. 3
      core/blockchain_test.go
  2. 3
      eth/filters/filter_system.go
  3. 3
      eth/handler.go
  4. 7
      eth/tracers/tracer.go
  5. 3
      les/handler.go
  6. 16
      metrics/exp/exp.go
  7. 3
      p2p/nat/natpmp.go
  8. 7
      p2p/nat/natupnp.go
  9. 3
      p2p/simulations/adapters/inproc.go
  10. 6
      signer/core/abihelper.go

@ -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)
}
)
switch i {
case 0:
if i == 0 {
tx, err = basicTx(types.NewEIP155Signer(big.NewInt(2)))
if err != nil {
t.Fatal(err)

@ -338,8 +338,7 @@ func (es *EventSystem) broadcast(filters filterIndex, ev interface{}) {
}
}
case *event.TypeMuxEvent:
switch muxe := e.Data.(type) {
case core.PendingLogsEvent:
if muxe, ok := e.Data.(core.PendingLogsEvent); ok {
for _, f := range filters[PendingLogsSubscription] {
if e.Time.After(f.created) {
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() {
// automatically stops if unsubscribe
for obj := range pm.minedBlockSub.Chan() {
switch ev := obj.Data.(type) {
case core.NewMinedBlockEvent:
if ev, ok := obj.Data.(core.NewMinedBlockEvent); ok {
pm.BroadcastBlock(ev.Block, true) // First propagate block to peers
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 {
var message string
switch err := err.(type) {
default:
message = err.Error()
}
return fmt.Errorf("%v in server-side tracer function '%v'", message, context)
return fmt.Errorf("%v in server-side tracer function '%v'", err, context)
}
// 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
func (pm *ProtocolManager) getHelperTrieAuxData(req HelperTrieReq) []byte {
switch {
case req.Type == htCanonical && req.AuxReq == auxHeader && len(req.Key) == 8:
if req.Type == htCanonical && req.AuxReq == auxHeader && len(req.Key) == 8 {
blockNum := binary.BigEndian.Uint64(req.Key)
hash := rawdb.ReadCanonicalHash(pm.chainDb, 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() {
exp.registry.Each(func(name string, i interface{}) {
switch i.(type) {
switch i := i.(type) {
case metrics.Counter:
exp.publishCounter(name, i.(metrics.Counter))
exp.publishCounter(name, i)
case metrics.Gauge:
exp.publishGauge(name, i.(metrics.Gauge))
exp.publishGauge(name, i)
case metrics.GaugeFloat64:
exp.publishGaugeFloat64(name, i.(metrics.GaugeFloat64))
exp.publishGaugeFloat64(name, i)
case metrics.Histogram:
exp.publishHistogram(name, i.(metrics.Histogram))
exp.publishHistogram(name, i)
case metrics.Meter:
exp.publishMeter(name, i.(metrics.Meter))
exp.publishMeter(name, i)
case metrics.Timer:
exp.publishTimer(name, i.(metrics.Timer))
exp.publishTimer(name, i)
case metrics.ResettingTimer:
exp.publishResettingTimer(name, i.(metrics.ResettingTimer))
exp.publishResettingTimer(name, i)
default:
panic(fmt.Sprintf("unsupported type for '%s': %T", name, i))
}

@ -115,8 +115,7 @@ func potentialGateways() (gws []net.IP) {
return gws
}
for _, addr := range ifaddrs {
switch x := addr.(type) {
case *net.IPNet:
if x, ok := addr.(*net.IPNet); ok {
if lan10.Contains(x.IP) || lan176.Contains(x.IP) || lan192.Contains(x.IP) {
ip := x.IP.Mask(x.Mask).To4()
if ip != nil {

@ -81,11 +81,8 @@ func (n *upnp) internalAddress() (net.IP, error) {
return nil, err
}
for _, addr := range addrs {
switch x := addr.(type) {
case *net.IPNet:
if x.Contains(devaddr.IP) {
return x.IP, nil
}
if x, ok := addr.(*net.IPNet); ok && x.Contains(devaddr.IP) {
return x.IP, nil
}
}
}

@ -353,8 +353,7 @@ func (sn *SimNode) NodeInfo() *p2p.NodeInfo {
}
func setSocketBuffer(conn net.Conn, socketReadBuffer int, socketWriteBuffer int) error {
switch v := conn.(type) {
case *net.UnixConn:
if v, ok := conn.(*net.UnixConn); ok {
err := v.SetReadBuffer(socketReadBuffer)
if err != nil {
return err

@ -43,11 +43,11 @@ type decodedCallData struct {
// String implements stringer interface, tries to use the underlying value-type
func (arg decodedArgument) String() string {
var value string
switch arg.value.(type) {
switch val := arg.value.(type) {
case fmt.Stringer:
value = arg.value.(fmt.Stringer).String()
value = val.String()
default:
value = fmt.Sprintf("%v", arg.value)
value = fmt.Sprintf("%v", val)
}
return fmt.Sprintf("%v: %v", arg.soltype.Type.String(), value)
}

Loading…
Cancel
Save