aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOleg Kovalov <iamolegkovalov@gmail.com>2018-07-30 17:30:09 +0800
committerPéter Szilágyi <peterke@gmail.com>2018-07-30 17:30:09 +0800
commitd42ce0f2c1b52e26cce475e411d97165fb975577 (patch)
tree03043c37becf49145b23f4824f563e3443335698
parent273c7a9dc4e8961e96e51bd8274436ff983a21ef (diff)
downloaddexon-d42ce0f2c1b52e26cce475e411d97165fb975577.tar
dexon-d42ce0f2c1b52e26cce475e411d97165fb975577.tar.gz
dexon-d42ce0f2c1b52e26cce475e411d97165fb975577.tar.bz2
dexon-d42ce0f2c1b52e26cce475e411d97165fb975577.tar.lz
dexon-d42ce0f2c1b52e26cce475e411d97165fb975577.tar.xz
dexon-d42ce0f2c1b52e26cce475e411d97165fb975577.tar.zst
dexon-d42ce0f2c1b52e26cce475e411d97165fb975577.zip
all: simplify switches (#17267)
* all: simplify switches * silly mistake
-rw-r--r--core/blockchain_test.go3
-rw-r--r--eth/filters/filter_system.go3
-rw-r--r--eth/handler.go3
-rw-r--r--eth/tracers/tracer.go7
-rw-r--r--les/handler.go3
-rw-r--r--metrics/exp/exp.go16
-rw-r--r--p2p/nat/natpmp.go3
-rw-r--r--p2p/nat/natupnp.go7
-rw-r--r--p2p/simulations/adapters/inproc.go3
-rw-r--r--signer/core/abihelper.go6
10 files changed, 20 insertions, 34 deletions
diff --git a/core/blockchain_test.go b/core/blockchain_test.go
index 687209bfa..e452d6936 100644
--- a/core/blockchain_test.go
+++ b/core/blockchain_test.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)
diff --git a/eth/filters/filter_system.go b/eth/filters/filter_system.go
index 4e999cda8..70139c1a9 100644
--- a/eth/filters/filter_system.go
+++ b/eth/filters/filter_system.go
@@ -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 {
diff --git a/eth/handler.go b/eth/handler.go
index f2d2eaf1c..f89f68c9d 100644
--- a/eth/handler.go
+++ b/eth/handler.go
@@ -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
}
diff --git a/eth/tracers/tracer.go b/eth/tracers/tracer.go
index 4cec9e633..feb57e060 100644
--- a/eth/tracers/tracer.go
+++ b/eth/tracers/tracer.go
@@ -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.
diff --git a/les/handler.go b/les/handler.go
index a1c16cb87..2fc4cde34 100644
--- a/les/handler.go
+++ b/les/handler.go
@@ -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)
diff --git a/metrics/exp/exp.go b/metrics/exp/exp.go
index 625ffd4e8..325a193c7 100644
--- a/metrics/exp/exp.go
+++ b/metrics/exp/exp.go
@@ -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))
}
diff --git a/p2p/nat/natpmp.go b/p2p/nat/natpmp.go
index 577a424fb..8ba971472 100644
--- a/p2p/nat/natpmp.go
+++ b/p2p/nat/natpmp.go
@@ -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 {
diff --git a/p2p/nat/natupnp.go b/p2p/nat/natupnp.go
index 69099ac04..029143b7b 100644
--- a/p2p/nat/natupnp.go
+++ b/p2p/nat/natupnp.go
@@ -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
}
}
}
diff --git a/p2p/simulations/adapters/inproc.go b/p2p/simulations/adapters/inproc.go
index c1b032a0d..b0fdf49b9 100644
--- a/p2p/simulations/adapters/inproc.go
+++ b/p2p/simulations/adapters/inproc.go
@@ -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
diff --git a/signer/core/abihelper.go b/signer/core/abihelper.go
index 1d4fbc7dc..0fef24939 100644
--- a/signer/core/abihelper.go
+++ b/signer/core/abihelper.go
@@ -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)
}