diff --git a/cli/contract_test.go b/cli/contract_test.go index 1e8bc956e..a45680a1b 100644 --- a/cli/contract_test.go +++ b/cli/contract_test.go @@ -447,9 +447,8 @@ func TestContractManifestGroups(t *testing.T) { config.Version = "0.90.0-test" tmpDir := t.TempDir() - w, err := wallet.NewWalletFromFile(testWalletPath) + _, err := wallet.NewWalletFromFile(testWalletPath) require.NoError(t, err) - defer w.Close() nefName := filepath.Join(tmpDir, "deploy.nef") manifestName := filepath.Join(tmpDir, "deploy.manifest.json") diff --git a/cli/nep17_test.go b/cli/nep17_test.go index 32ef5be5f..ea313a527 100644 --- a/cli/nep17_test.go +++ b/cli/nep17_test.go @@ -113,7 +113,6 @@ func TestNEP17Balance(t *testing.T) { func TestNEP17Transfer(t *testing.T) { w, err := wallet.NewWalletFromFile("testdata/testwallet.json") require.NoError(t, err) - defer w.Close() e := newExecutor(t, true) args := []string{ diff --git a/cli/query_test.go b/cli/query_test.go index 32c658939..02a29e36d 100644 --- a/cli/query_test.go +++ b/cli/query_test.go @@ -25,7 +25,6 @@ func TestQueryTx(t *testing.T) { w, err := wallet.NewWalletFromFile("testdata/testwallet.json") require.NoError(t, err) - defer w.Close() transferArgs := []string{ "neo-go", "wallet", "nep17", "transfer", diff --git a/cli/wallet/multisig.go b/cli/wallet/multisig.go index 2c7e021b9..611b95e20 100644 --- a/cli/wallet/multisig.go +++ b/cli/wallet/multisig.go @@ -16,7 +16,6 @@ func signStoredTransaction(ctx *cli.Context) error { if err != nil { return cli.NewExitError(err, 1) } - defer wall.Close() c, err := paramcontext.Read(ctx.String("in")) if err != nil { diff --git a/cli/wallet/nep11.go b/cli/wallet/nep11.go index 6ccebf811..1a413dbc6 100644 --- a/cli/wallet/nep11.go +++ b/cli/wallet/nep11.go @@ -167,7 +167,6 @@ func getNEP11Balance(ctx *cli.Context) error { if err != nil { return cli.NewExitError(fmt.Errorf("bad wallet: %w", err), 1) } - defer wall.Close() addrFlag := ctx.Generic("address").(*flags.Address) if addrFlag.IsSet { diff --git a/cli/wallet/nep17.go b/cli/wallet/nep17.go index bd45db8f7..7b045b3c0 100644 --- a/cli/wallet/nep17.go +++ b/cli/wallet/nep17.go @@ -155,7 +155,6 @@ func getNEP17Balance(ctx *cli.Context) error { if err != nil { return cli.NewExitError(fmt.Errorf("bad wallet: %w", err), 1) } - defer wall.Close() addrFlag := ctx.Generic("address").(*flags.Address) if addrFlag.IsSet { @@ -354,7 +353,6 @@ func importNEPToken(ctx *cli.Context, standard string) error { if err != nil { return cli.NewExitError(err, 1) } - defer wall.Close() tokenHashFlag := ctx.Generic("token").(*flags.Address) if !tokenHashFlag.IsSet { @@ -417,7 +415,6 @@ func printNEPInfo(ctx *cli.Context, standard string) error { if err != nil { return cli.NewExitError(err, 1) } - defer wall.Close() if name := ctx.String("token"); name != "" { token, err := getMatchingToken(ctx, wall, name, standard) @@ -450,7 +447,6 @@ func removeNEPToken(ctx *cli.Context, standard string) error { if err != nil { return cli.NewExitError(err, 1) } - defer wall.Close() token, err := getMatchingToken(ctx, wall, ctx.String("token"), standard) if err != nil { @@ -474,7 +470,6 @@ func multiTransferNEP17(ctx *cli.Context) error { if err != nil { return cli.NewExitError(err, 1) } - defer wall.Close() fromFlag := ctx.Generic("from").(*flags.Address) from, err := getDefaultAddress(fromFlag, wall) @@ -560,7 +555,6 @@ func transferNEP(ctx *cli.Context, standard string) error { if err != nil { return cli.NewExitError(err, 1) } - defer wall.Close() fromFlag := ctx.Generic("from").(*flags.Address) from, err := getDefaultAddress(fromFlag, wall) diff --git a/cli/wallet/validator.go b/cli/wallet/validator.go index aed1dbda8..dc0511ff4 100644 --- a/cli/wallet/validator.go +++ b/cli/wallet/validator.go @@ -90,7 +90,6 @@ func handleCandidate(ctx *cli.Context, method string, sysGas int64) error { if err != nil { return cli.NewExitError(err, 1) } - defer wall.Close() addrFlag := ctx.Generic("address").(*flags.Address) if !addrFlag.IsSet { @@ -145,7 +144,6 @@ func handleVote(ctx *cli.Context) error { if err != nil { return cli.NewExitError(err, 1) } - defer wall.Close() addrFlag := ctx.Generic("address").(*flags.Address) if !addrFlag.IsSet { diff --git a/cli/wallet/wallet.go b/cli/wallet/wallet.go index 6cf9aba47..e1a2bb8cd 100644 --- a/cli/wallet/wallet.go +++ b/cli/wallet/wallet.go @@ -299,7 +299,6 @@ func claimGas(ctx *cli.Context) error { if err != nil { return cli.NewExitError(err, 1) } - defer wall.Close() addrFlag := ctx.Generic("address").(*flags.Address) if !addrFlag.IsSet { @@ -398,7 +397,6 @@ func convertWallet(ctx *cli.Context) error { if err != nil { return cli.NewExitError(err, 1) } - defer newWallet.Close() newWallet.Scrypt = wall.Scrypt for _, acc := range wall.Accounts { @@ -428,8 +426,6 @@ func addAccount(ctx *cli.Context) error { return cli.NewExitError(err, 1) } - defer wall.Close() - if err := createAccount(wall, pass); err != nil { return cli.NewExitError(err, 1) } @@ -504,8 +500,6 @@ func importMultisig(ctx *cli.Context) error { return cli.NewExitError(err, 1) } - defer wall.Close() - m := ctx.Int("min") if ctx.NArg() < m { return cli.NewExitError(errors.New("insufficient number of public keys"), 1) @@ -546,8 +540,6 @@ func importDeployed(ctx *cli.Context) error { return cli.NewExitError(err, 1) } - defer wall.Close() - rawHash := ctx.Generic("contract").(*flags.Address) if !rawHash.IsSet { return cli.NewExitError("contract hash was not provided", 1) @@ -600,7 +592,6 @@ func importWallet(ctx *cli.Context) error { if err != nil { return cli.NewExitError(err, 1) } - defer wall.Close() acc, err := newAccountFromWIF(ctx.App.Writer, ctx.String("wif"), wall.Scrypt) if err != nil { @@ -630,7 +621,6 @@ func removeAccount(ctx *cli.Context) error { if err != nil { return cli.NewExitError(err, 1) } - defer wall.Close() addr := ctx.Generic("address").(*flags.Address) if !addr.IsSet { diff --git a/cli/wallet_test.go b/cli/wallet_test.go index 5e3d6083b..09519bbb9 100644 --- a/cli/wallet_test.go +++ b/cli/wallet_test.go @@ -221,7 +221,6 @@ func TestWalletInit(t *testing.T) { require.Len(t, w.Accounts, 1) require.Equal(t, "букandmore", w.Accounts[0].Label) require.NoError(t, w.Accounts[0].Decrypt("пароль", w.Scrypt)) - w.Close() }) t.Run("CreateAccount", func(t *testing.T) { @@ -244,7 +243,6 @@ func TestWalletInit(t *testing.T) { require.Len(t, w.Accounts, 1) require.Equal(t, w.Accounts[0].Label, "testname") require.NoError(t, w.Accounts[0].Decrypt("testpass", w.Scrypt)) - w.Close() t.Run("RemoveAccount", func(t *testing.T) { sh := w.Accounts[0].Contract.ScriptHash() @@ -255,7 +253,6 @@ func TestWalletInit(t *testing.T) { w, err := wallet.NewWalletFromFile(walletPath) require.NoError(t, err) require.Nil(t, w.GetAccount(sh)) - w.Close() }) }) @@ -274,7 +271,6 @@ func TestWalletInit(t *testing.T) { w, err := wallet.NewWalletFromFile(walletPath) require.NoError(t, err) - t.Cleanup(w.Close) acc := w.GetAccount(priv.GetScriptHash()) require.NotNil(t, acc) require.Equal(t, "test_account", acc.Label) @@ -302,7 +298,6 @@ func TestWalletInit(t *testing.T) { check := func(t *testing.T, expectedLabel string, pass string) { w, err := wallet.NewWalletFromFile(walletPath) require.NoError(t, err) - t.Cleanup(w.Close) acc := w.GetAccount(priv.GetScriptHash()) require.NotNil(t, acc) require.Equal(t, expectedLabel, acc.Label) @@ -355,7 +350,6 @@ func TestWalletInit(t *testing.T) { w, err := wallet.NewWalletFromFile(walletPath) require.NoError(t, err) - t.Cleanup(w.Close) actual := w.GetAccount(acc.PrivateKey().GetScriptHash()) require.NotNil(t, actual) require.NoError(t, actual.Decrypt("somepass", w.Scrypt)) @@ -410,7 +404,6 @@ func TestWalletInit(t *testing.T) { w, err := wallet.NewWalletFromFile(walletPath) require.NoError(t, err) - t.Cleanup(w.Close) actual := w.GetAccount(hash.Hash160(script)) require.NotNil(t, actual) require.NoError(t, actual.Decrypt("multipass", w.Scrypt)) @@ -595,9 +588,6 @@ func TestWalletImportDeployed(t *testing.T) { "--contract", h.StringLE()) w, err := wallet.NewWalletFromFile(walletPath) - t.Cleanup(func() { - w.Close() - }) require.NoError(t, err) require.Equal(t, 1, len(w.Accounts)) contractAddr := w.Accounts[0].Address diff --git a/pkg/consensus/consensus.go b/pkg/consensus/consensus.go index 816d278f1..c00e07306 100644 --- a/pkg/consensus/consensus.go +++ b/pkg/consensus/consensus.go @@ -168,8 +168,6 @@ func NewService(cfg Config) (Service, error) { return nil, errors.New("no account with provided password was found") } - defer srv.wallet.Close() - srv.dbft = dbft.New( dbft.WithLogger(srv.log), dbft.WithSecondsPerBlock(cfg.TimePerBlock), diff --git a/pkg/services/stateroot/service_test.go b/pkg/services/stateroot/service_test.go index 3d11debaf..047138c76 100644 --- a/pkg/services/stateroot/service_test.go +++ b/pkg/services/stateroot/service_test.go @@ -197,7 +197,6 @@ func createAndWriteWallet(t *testing.T, acc *wallet.Account, path, password stri require.NoError(t, acc.Encrypt(password, w.Scrypt)) w.AddAccount(acc) require.NoError(t, w.Save()) - w.Close() return w } diff --git a/pkg/wallet/regenerate_test.go b/pkg/wallet/regenerate_test.go index 7faaba8e3..c8e1b0a66 100644 --- a/pkg/wallet/regenerate_test.go +++ b/pkg/wallet/regenerate_test.go @@ -202,7 +202,6 @@ func createWallet(t *testing.T, path string, accs ...*Account) { w.AddAccount(acc) } require.NoError(t, w.SavePretty()) - w.Close() } func TestRegenerateCLIWallet1_solo(t *testing.T) { diff --git a/pkg/wallet/wallet.go b/pkg/wallet/wallet.go index ef8fe5684..f0801ffd0 100644 --- a/pkg/wallet/wallet.go +++ b/pkg/wallet/wallet.go @@ -168,9 +168,9 @@ func (w *Wallet) JSON() ([]byte, error) { return json.MarshalIndent(w, " ", " ") } -// Close closes the internal rw if its an io.ReadCloser. -func (w *Wallet) Close() { -} +// Deprecated: Close is deprecated. +// Close performs nothing and is left for backwards compatibility. +func (w *Wallet) Close() {} // GetAccount returns an account corresponding to the provided scripthash. func (w *Wallet) GetAccount(h util.Uint160) *Account {