all: fix some go-critic linter warnings (#23709)
This doesn't fix all go-critic warnings, just the most serious ones. Co-authored-by: Felix Lange <fjl@twurst.com> Co-authored-by: Martin Holst Swende <martin@swende.se>
This commit is contained in:
parent
e4f570fcc6
commit
778ff94794
|
@ -123,16 +123,9 @@ func set(dst, src reflect.Value) error {
|
|||
func setSlice(dst, src reflect.Value) error {
|
||||
slice := reflect.MakeSlice(dst.Type(), src.Len(), src.Len())
|
||||
for i := 0; i < src.Len(); i++ {
|
||||
if src.Index(i).Kind() == reflect.Struct {
|
||||
if err := set(slice.Index(i), src.Index(i)); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
// e.g. [][32]uint8 to []common.Hash
|
||||
if err := set(slice.Index(i), src.Index(i)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
if dst.CanSet() {
|
||||
dst.Set(slice)
|
||||
|
|
|
@ -419,7 +419,7 @@ func dispatchOutput(ctx *cli.Context, baseDir string, result *ExecutionResult, a
|
|||
return NewError(ErrorJson, fmt.Errorf("failed marshalling output: %v", err))
|
||||
}
|
||||
os.Stdout.Write(b)
|
||||
os.Stdout.Write([]byte("\n"))
|
||||
os.Stdout.WriteString("\n")
|
||||
}
|
||||
if len(stdErrObject) > 0 {
|
||||
b, err := json.MarshalIndent(stdErrObject, "", " ")
|
||||
|
@ -427,7 +427,7 @@ func dispatchOutput(ctx *cli.Context, baseDir string, result *ExecutionResult, a
|
|||
return NewError(ErrorJson, fmt.Errorf("failed marshalling output: %v", err))
|
||||
}
|
||||
os.Stderr.Write(b)
|
||||
os.Stderr.Write([]byte("\n"))
|
||||
os.Stderr.WriteString("\n")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -741,7 +741,7 @@ func authTwitter(url string, tokenV1, tokenV2 string) (string, string, string, c
|
|||
return "", "", "", common.Address{}, errors.New("No Ethereum address found to fund")
|
||||
}
|
||||
var avatar string
|
||||
if parts = regexp.MustCompile("src=\"([^\"]+twimg.com/profile_images[^\"]+)\"").FindStringSubmatch(string(body)); len(parts) == 2 {
|
||||
if parts = regexp.MustCompile(`src="([^"]+twimg\.com/profile_images[^"]+)"`).FindStringSubmatch(string(body)); len(parts) == 2 {
|
||||
avatar = parts[1]
|
||||
}
|
||||
return username + "@twitter", username, avatar, address, nil
|
||||
|
@ -867,7 +867,7 @@ func authFacebook(url string) (string, string, common.Address, error) {
|
|||
return "", "", common.Address{}, errors.New("No Ethereum address found to fund")
|
||||
}
|
||||
var avatar string
|
||||
if parts = regexp.MustCompile("src=\"([^\"]+fbcdn.net[^\"]+)\"").FindStringSubmatch(string(body)); len(parts) == 2 {
|
||||
if parts = regexp.MustCompile(`src="([^"]+fbcdn\.net[^"]+)"`).FindStringSubmatch(string(body)); len(parts) == 2 {
|
||||
avatar = parts[1]
|
||||
}
|
||||
return username + "@facebook", avatar, address, nil
|
||||
|
|
|
@ -70,7 +70,7 @@ func BenchmarkGenerator(b *testing.B) {
|
|||
if err != nil {
|
||||
b.Fatalf("failed to create bloombit generator: %v", err)
|
||||
}
|
||||
for j, bloom := range input {
|
||||
for j, bloom := range &input {
|
||||
if err := gen.AddBloom(uint(j), bloom); err != nil {
|
||||
b.Fatalf("bloom %d: failed to add: %v", i, err)
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ func BenchmarkGenerator(b *testing.B) {
|
|||
if err != nil {
|
||||
b.Fatalf("failed to create bloombit generator: %v", err)
|
||||
}
|
||||
for j, bloom := range input {
|
||||
for j, bloom := range &input {
|
||||
if err := gen.AddBloom(uint(j), bloom); err != nil {
|
||||
b.Fatalf("bloom %d: failed to add: %v", i, err)
|
||||
}
|
||||
|
|
|
@ -385,7 +385,7 @@ func testGetNodeData(t *testing.T, protocol uint) {
|
|||
acc2Addr := crypto.PubkeyToAddress(acc2Key.PublicKey)
|
||||
|
||||
signer := types.HomesteadSigner{}
|
||||
// Create a chain generator with some simple transactions (blatantly stolen from @fjl/chain_markets_test)
|
||||
// Create a chain generator with some simple transactions (blatantly stolen from @fjl/chain_makers_test)
|
||||
generator := func(i int, block *core.BlockGen) {
|
||||
switch i {
|
||||
case 0:
|
||||
|
@ -420,9 +420,8 @@ func testGetNodeData(t *testing.T, protocol uint) {
|
|||
peer, _ := newTestPeer("peer", protocol, backend)
|
||||
defer peer.close()
|
||||
|
||||
// Fetch for now the entire chain db
|
||||
// Collect all state tree hashes.
|
||||
var hashes []common.Hash
|
||||
|
||||
it := backend.db.NewIterator(nil, nil)
|
||||
for it.Next() {
|
||||
if key := it.Key(); len(key) == common.HashLength {
|
||||
|
@ -431,6 +430,7 @@ func testGetNodeData(t *testing.T, protocol uint) {
|
|||
}
|
||||
it.Release()
|
||||
|
||||
// Request all hashes.
|
||||
p2p.Send(peer.app, GetNodeDataMsg, GetNodeDataPacket66{
|
||||
RequestId: 123,
|
||||
GetNodeDataPacket: hashes,
|
||||
|
@ -442,38 +442,40 @@ func testGetNodeData(t *testing.T, protocol uint) {
|
|||
if msg.Code != NodeDataMsg {
|
||||
t.Fatalf("response packet code mismatch: have %x, want %x", msg.Code, NodeDataMsg)
|
||||
}
|
||||
var (
|
||||
data [][]byte
|
||||
res NodeDataPacket66
|
||||
)
|
||||
var res NodeDataPacket66
|
||||
if err := msg.Decode(&res); err != nil {
|
||||
t.Fatalf("failed to decode response node data: %v", err)
|
||||
}
|
||||
data = res.NodeDataPacket
|
||||
// Verify that all hashes correspond to the requested data, and reconstruct a state tree
|
||||
|
||||
// Verify that all hashes correspond to the requested data.
|
||||
data := res.NodeDataPacket
|
||||
for i, want := range hashes {
|
||||
if hash := crypto.Keccak256Hash(data[i]); hash != want {
|
||||
t.Errorf("data hash mismatch: have %x, want %x", hash, want)
|
||||
}
|
||||
}
|
||||
statedb := rawdb.NewMemoryDatabase()
|
||||
|
||||
// Reconstruct state tree from the received data.
|
||||
reconstructDB := rawdb.NewMemoryDatabase()
|
||||
for i := 0; i < len(data); i++ {
|
||||
statedb.Put(hashes[i].Bytes(), data[i])
|
||||
rawdb.WriteTrieNode(reconstructDB, hashes[i], data[i])
|
||||
}
|
||||
|
||||
// Sanity check whether all state matches.
|
||||
accounts := []common.Address{testAddr, acc1Addr, acc2Addr}
|
||||
for i := uint64(0); i <= backend.chain.CurrentBlock().NumberU64(); i++ {
|
||||
trie, _ := state.New(backend.chain.GetBlockByNumber(i).Root(), state.NewDatabase(statedb), nil)
|
||||
|
||||
root := backend.chain.GetBlockByNumber(i).Root()
|
||||
reconstructed, _ := state.New(root, state.NewDatabase(reconstructDB), nil)
|
||||
for j, acc := range accounts {
|
||||
state, _ := backend.chain.State()
|
||||
state, _ := backend.chain.StateAt(root)
|
||||
bw := state.GetBalance(acc)
|
||||
bh := trie.GetBalance(acc)
|
||||
bh := reconstructed.GetBalance(acc)
|
||||
|
||||
if (bw != nil && bh == nil) || (bw == nil && bh != nil) {
|
||||
t.Errorf("test %d, account %d: balance mismatch: have %v, want %v", i, j, bh, bw)
|
||||
if (bw == nil) != (bh == nil) {
|
||||
t.Errorf("block %d, account %d: balance mismatch: have %v, want %v", i, j, bh, bw)
|
||||
}
|
||||
if bw != nil && bh != nil && bw.Cmp(bw) != 0 {
|
||||
t.Errorf("test %d, account %d: balance mismatch: have %v, want %v", i, j, bh, bw)
|
||||
if bw != nil && bh != nil && bw.Cmp(bh) != 0 {
|
||||
t.Errorf("block %d, account %d: balance mismatch: have %v, want %v", i, j, bh, bw)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -218,7 +218,7 @@ func (api *privateAdminAPI) StartHTTP(host *string, port *int, cors *string, api
|
|||
}
|
||||
|
||||
// StartRPC starts the HTTP RPC API server.
|
||||
// This method is deprecated. Use StartHTTP instead.
|
||||
// Deprecated: use StartHTTP instead.
|
||||
func (api *privateAdminAPI) StartRPC(host *string, port *int, cors *string, apis *string, vhosts *string) (bool, error) {
|
||||
log.Warn("Deprecation warning", "method", "admin.StartRPC", "use-instead", "admin.StartHTTP")
|
||||
return api.StartHTTP(host, port, cors, apis, vhosts)
|
||||
|
@ -231,7 +231,7 @@ func (api *privateAdminAPI) StopHTTP() (bool, error) {
|
|||
}
|
||||
|
||||
// StopRPC shuts down the HTTP server.
|
||||
// This method is deprecated. Use StopHTTP instead.
|
||||
// Deprecated: use StopHTTP instead.
|
||||
func (api *privateAdminAPI) StopRPC() (bool, error) {
|
||||
log.Warn("Deprecation warning", "method", "admin.StopRPC", "use-instead", "admin.StopHTTP")
|
||||
return api.StopHTTP()
|
||||
|
|
|
@ -29,6 +29,7 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/ethereum/go-ethereum/accounts"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
|
@ -100,7 +101,8 @@ func (t *Type) isReferenceType() bool {
|
|||
return false
|
||||
}
|
||||
// Reference types must have a leading uppercase character
|
||||
return unicode.IsUpper([]rune(t.Type)[0])
|
||||
r, _ := utf8.DecodeRuneInString(t.Type)
|
||||
return unicode.IsUpper(r)
|
||||
}
|
||||
|
||||
type Types map[string][]Type
|
||||
|
|
|
@ -21,7 +21,7 @@ import (
|
|||
"regexp"
|
||||
)
|
||||
|
||||
var printable7BitAscii = regexp.MustCompile("^[A-Za-z0-9!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ ]+$")
|
||||
var printable7BitAscii = regexp.MustCompile("^[A-Za-z0-9!\"#$%&'()*+,\\-./:;<=>?@[\\]^_`{|}~ ]+$")
|
||||
|
||||
// ValidatePasswordFormat returns an error if the password is too short, or consists of characters
|
||||
// outside the range of the printable 7bit ascii set
|
||||
|
|
Loading…
Reference in New Issue