From d5fc8fed377584ebc1b522889fed1dacf931fedc Mon Sep 17 00:00:00 2001 From: Jim McDonald Date: Mon, 12 Dec 2022 11:38:07 +0000 Subject: [PATCH] Remove ioutil. --- cmd/account/import/input.go | 4 ++-- cmd/depositverify.go | 7 +++---- cmd/exitverify.go | 5 ++--- cmd/validatorinfo.go | 4 ++-- cmd/wallet/delete/process_internal_test.go | 3 +-- cmd/wallet/export/process_internal_test.go | 3 +-- cmd/wallet/import/input.go | 4 ++-- cmd/wallet/sharedexport/process_internal_test.go | 5 ++--- cmd/wallet/sharedimport/input.go | 6 +++--- cmd/wallet/sharedimport/input_internal_test.go | 5 ++--- cmd/wallet/sharedimport/process_internal_test.go | 5 ++--- 11 files changed, 22 insertions(+), 29 deletions(-) diff --git a/cmd/account/import/input.go b/cmd/account/import/input.go index 125f425..be6b60b 100644 --- a/cmd/account/import/input.go +++ b/cmd/account/import/input.go @@ -16,7 +16,7 @@ package accountimport import ( "context" "encoding/hex" - "io/ioutil" + "os" "strings" "time" @@ -115,7 +115,7 @@ func obtainKeystore(input string) ([]byte, error) { data = []byte(input) } else { // Assume it's a path to JSON - data, err = ioutil.ReadFile(input) + data, err = os.ReadFile(input) if err != nil { return nil, errors.Wrap(err, "failed to find deposit data file") } diff --git a/cmd/depositverify.go b/cmd/depositverify.go index f09b42c..89f5632 100644 --- a/cmd/depositverify.go +++ b/cmd/depositverify.go @@ -1,4 +1,4 @@ -// Copyright © 2019-2021 Weald Technology Limited. +// Copyright © 2019-2022 Weald Technology Limited. // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at @@ -17,7 +17,6 @@ import ( "bytes" "encoding/hex" "fmt" - "io/ioutil" "os" "strings" @@ -64,7 +63,7 @@ In quiet mode this will return 0 if the the data is verified correctly, otherwis data = []byte(depositVerifyData) default: // Assume it's a path to JSON. - data, err = ioutil.ReadFile(depositVerifyData) + data, err = os.ReadFile(depositVerifyData) errCheck(err, "Failed to read deposit data file") if data[0] == '{' { data = []byte("[" + string(data) + "]") @@ -155,7 +154,7 @@ func validatorPubKeysFromInput(input string) (map[[48]byte]bool, error) { pubKeys[key] = true } else { // Assume it's a path to a file of public keys. - data, err = ioutil.ReadFile(input) + data, err = os.ReadFile(input) if err != nil { return nil, errors.Wrap(err, "failed to find public key file") } diff --git a/cmd/exitverify.go b/cmd/exitverify.go index 2959e8a..2b36bf5 100644 --- a/cmd/exitverify.go +++ b/cmd/exitverify.go @@ -1,4 +1,4 @@ -// Copyright © 2020 Weald Technology Trading +// Copyright © 2020, 2022 Weald Technology Trading // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at @@ -19,7 +19,6 @@ import ( "encoding/hex" "encoding/json" "fmt" - "io/ioutil" "os" "strings" @@ -97,7 +96,7 @@ func obtainExitData(input string) (*util.ValidatorExitData, error) { data = []byte(input) } else { // Assume it's a path to JSON - data, err = ioutil.ReadFile(input) + data, err = os.ReadFile(input) if err != nil { return nil, errors.Wrap(err, "failed to find deposit data file") } diff --git a/cmd/validatorinfo.go b/cmd/validatorinfo.go index 81f937b..eb4e0d4 100644 --- a/cmd/validatorinfo.go +++ b/cmd/validatorinfo.go @@ -18,7 +18,7 @@ import ( "context" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "os" "strconv" @@ -125,7 +125,7 @@ func graphData(network string, validatorPubKey []byte) (uint64, spec.Gwei, error return 0, 0, errors.Wrap(err, "failed to check if there is already a deposit for this validator") } defer graphResp.Body.Close() - body, err := ioutil.ReadAll(graphResp.Body) + body, err := io.ReadAll(graphResp.Body) if err != nil { return 0, 0, errors.Wrap(err, "bad information returned from existing deposit check") } diff --git a/cmd/wallet/delete/process_internal_test.go b/cmd/wallet/delete/process_internal_test.go index 07dcc30..0ee3029 100644 --- a/cmd/wallet/delete/process_internal_test.go +++ b/cmd/wallet/delete/process_internal_test.go @@ -15,7 +15,6 @@ package walletdelete import ( "context" - "io/ioutil" "os" "testing" "time" @@ -31,7 +30,7 @@ import ( func TestProcess(t *testing.T) { require.NoError(t, e2types.InitBLS()) - base, err := ioutil.TempDir("", "") + base, err := os.MkdirTemp("", "") require.NoError(t, err) defer os.RemoveAll(base) store := filesystem.New(filesystem.WithLocation(base)) diff --git a/cmd/wallet/export/process_internal_test.go b/cmd/wallet/export/process_internal_test.go index a77449a..742cf0a 100644 --- a/cmd/wallet/export/process_internal_test.go +++ b/cmd/wallet/export/process_internal_test.go @@ -15,7 +15,6 @@ package walletexport import ( "context" - "io/ioutil" "os" "testing" "time" @@ -31,7 +30,7 @@ import ( func TestProcess(t *testing.T) { require.NoError(t, e2types.InitBLS()) - base, err := ioutil.TempDir("", "") + base, err := os.MkdirTemp("", "") require.NoError(t, err) defer os.RemoveAll(base) store := filesystem.New(filesystem.WithLocation(base)) diff --git a/cmd/wallet/import/input.go b/cmd/wallet/import/input.go index 5fac14e..6e009c6 100644 --- a/cmd/wallet/import/input.go +++ b/cmd/wallet/import/input.go @@ -16,7 +16,7 @@ package walletimport import ( "context" "encoding/hex" - "io/ioutil" + "os" "strings" "time" @@ -58,7 +58,7 @@ func input(ctx context.Context) (*dataIn, error) { } if !strings.HasPrefix(viper.GetString("data"), "0x") { // Assume this is a path; read the file and replace the path with its contents. - fileData, err := ioutil.ReadFile(viper.GetString("data")) + fileData, err := os.ReadFile(viper.GetString("data")) if err != nil { return nil, errors.Wrap(err, "failed to read wallet import data") } diff --git a/cmd/wallet/sharedexport/process_internal_test.go b/cmd/wallet/sharedexport/process_internal_test.go index 8106cb6..5362e18 100644 --- a/cmd/wallet/sharedexport/process_internal_test.go +++ b/cmd/wallet/sharedexport/process_internal_test.go @@ -1,4 +1,4 @@ -// Copyright © 2021 Weald Technology Trading +// Copyright © 2021, 2022 Weald Technology Trading // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at @@ -15,7 +15,6 @@ package walletsharedexport import ( "context" - "io/ioutil" "os" "testing" "time" @@ -31,7 +30,7 @@ import ( func TestProcess(t *testing.T) { require.NoError(t, e2types.InitBLS()) - base, err := ioutil.TempDir("", "") + base, err := os.MkdirTemp("", "") require.NoError(t, err) defer os.RemoveAll(base) store := filesystem.New(filesystem.WithLocation(base)) diff --git a/cmd/wallet/sharedimport/input.go b/cmd/wallet/sharedimport/input.go index 25b1c77..a4e89b4 100644 --- a/cmd/wallet/sharedimport/input.go +++ b/cmd/wallet/sharedimport/input.go @@ -1,4 +1,4 @@ -// Copyright © 2021 Weald Technology Trading +// Copyright © 2021, 2022 Weald Technology Trading // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at @@ -15,7 +15,7 @@ package walletsharedimport import ( "context" - "io/ioutil" + "os" "time" "github.com/pkg/errors" @@ -52,7 +52,7 @@ func input(ctx context.Context) (*dataIn, error) { if viper.GetString("file") == "" { return nil, errors.New("file is required") } - data.file, err = ioutil.ReadFile(viper.GetString("file")) + data.file, err = os.ReadFile(viper.GetString("file")) if err != nil { return nil, errors.Wrap(err, "failed to read wallet import file") } diff --git a/cmd/wallet/sharedimport/input_internal_test.go b/cmd/wallet/sharedimport/input_internal_test.go index 2eba6cf..ea4fef5 100644 --- a/cmd/wallet/sharedimport/input_internal_test.go +++ b/cmd/wallet/sharedimport/input_internal_test.go @@ -1,4 +1,4 @@ -// Copyright © 2021 Weald Technology Trading +// Copyright © 2021, 2022 Weald Technology Trading // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at @@ -16,7 +16,6 @@ package walletsharedimport import ( "context" "fmt" - "io/ioutil" "os" "path/filepath" "testing" @@ -38,7 +37,7 @@ func TestInput(t *testing.T) { dir, err := os.MkdirTemp("", "") require.NoError(t, err) datFile := filepath.Join(dir, "backup.dat") - require.NoError(t, ioutil.WriteFile(datFile, []byte("dummy"), 0600)) + require.NoError(t, os.WriteFile(datFile, []byte("dummy"), 0600)) defer os.RemoveAll(dir) store := scratch.New() diff --git a/cmd/wallet/sharedimport/process_internal_test.go b/cmd/wallet/sharedimport/process_internal_test.go index c46d9de..212fc91 100644 --- a/cmd/wallet/sharedimport/process_internal_test.go +++ b/cmd/wallet/sharedimport/process_internal_test.go @@ -1,4 +1,4 @@ -// Copyright © 2021 Weald Technology Trading +// Copyright © 2021, 2022 Weald Technology Trading // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at @@ -15,7 +15,6 @@ package walletsharedimport import ( "context" - "io/ioutil" "os" "path/filepath" "testing" @@ -40,7 +39,7 @@ func TestProcess(t *testing.T) { dir, err := os.MkdirTemp("", "") require.NoError(t, err) datFile := filepath.Join(dir, "backup.dat") - require.NoError(t, ioutil.WriteFile(datFile, export, 0600)) + require.NoError(t, os.WriteFile(datFile, export, 0600)) defer os.RemoveAll(dir) tests := []struct {