Skip to content

Commit

Permalink
all: simplify switches (#17267)
Browse files Browse the repository at this point in the history
* all: simplify switches

* silly mistake
  • Loading branch information
cristaloleg authored and karalabe committed Jul 30, 2018
1 parent 273c7a9 commit d42ce0f
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 34 deletions.
3 changes: 1 addition & 2 deletions core/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions eth/filters/filter_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions eth/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
7 changes: 1 addition & 6 deletions eth/tracers/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions les/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 8 additions & 8 deletions metrics/exp/exp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
3 changes: 1 addition & 2 deletions p2p/nat/natpmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 2 additions & 5 deletions p2p/nat/natupnp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions p2p/simulations/adapters/inproc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions signer/core/abihelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit d42ce0f

Please sign in to comment.