*: always close the wallet after use

Fix #2631.
This commit is contained in:
Roman Khimov 2022-09-01 21:44:49 +03:00
parent ee5f8b6c21
commit 58dc8d0c9b
11 changed files with 29 additions and 1 deletions

View file

@ -37,10 +37,11 @@ func manifestAddGroup(ctx *cli.Context) error {
h := state.CreateContractHash(sender, nf.Checksum, m.Name)
gAcc, _, err := getAccFromContext(ctx)
gAcc, w, err := getAccFromContext(ctx)
if err != nil {
return cli.NewExitError(fmt.Errorf("can't get account to sign group with: %w", err), 1)
}
defer w.Close()
var found bool

View file

@ -650,6 +650,7 @@ func invokeInternal(ctx *cli.Context, signAndPush bool) error {
if err != nil {
return cli.NewExitError(err, 1)
}
defer w.Close()
}
_, err = invokeWithArgs(ctx, acc, w, script, operation, params, cosigners)
@ -949,6 +950,7 @@ func contractDeploy(ctx *cli.Context) error {
if err != nil {
return cli.NewExitError(fmt.Errorf("can't get sender address: %w", err), 1)
}
defer w.Close()
cosigners, sgnErr := cmdargs.GetSignersFromContext(ctx, signOffset)
if sgnErr != nil {

View file

@ -25,6 +25,7 @@ func signStoredTransaction(ctx *cli.Context) error {
if err != nil {
return cli.NewExitError(err, 1)
}
defer wall.Close()
pc, err := paramcontext.Read(ctx.String("in"))
if err != nil {

View file

@ -222,6 +222,7 @@ func getNEPBalance(ctx *cli.Context, standard string, accHandler func(*cli.Conte
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 {
@ -387,6 +388,7 @@ 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 {
@ -455,6 +457,7 @@ 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)
@ -490,6 +493,7 @@ 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 {
@ -513,6 +517,7 @@ 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)
@ -608,6 +613,7 @@ 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)

View file

@ -94,6 +94,7 @@ func handleNeoAction(ctx *cli.Context, mkTx func(*neo.Contract, util.Uint160, *w
if err != nil {
return cli.NewExitError(err, 1)
}
defer wall.Close()
addrFlag := ctx.Generic("address").(*flags.Address)
if !addrFlag.IsSet {

View file

@ -347,6 +347,7 @@ 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 {
@ -388,6 +389,7 @@ func changePassword(ctx *cli.Context) error {
if err != nil {
return cli.NewExitError(err, 1)
}
defer wall.Close()
if len(wall.Accounts) == 0 {
return cli.NewExitError("wallet has no accounts", 1)
}
@ -483,6 +485,7 @@ func addAccount(ctx *cli.Context) error {
if err != nil {
return cli.NewExitError(err, 1)
}
defer wall.Close()
if err := createAccount(wall, pass); err != nil {
return cli.NewExitError(err, 1)
@ -496,6 +499,7 @@ func exportKeys(ctx *cli.Context) error {
if err != nil {
return cli.NewExitError(err, 1)
}
defer wall.Close()
var addr string
@ -557,6 +561,7 @@ func importMultisig(ctx *cli.Context) error {
if err != nil {
return cli.NewExitError(err, 1)
}
defer wall.Close()
m := ctx.Int("min")
if ctx.NArg() < m {
@ -600,6 +605,7 @@ func importDeployed(ctx *cli.Context) error {
if err != nil {
return cli.NewExitError(err, 1)
}
defer wall.Close()
rawHash := ctx.Generic("contract").(*flags.Address)
if !rawHash.IsSet {
@ -656,6 +662,7 @@ 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 {
@ -688,6 +695,7 @@ 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 {
@ -734,6 +742,7 @@ func dumpWallet(ctx *cli.Context) error {
if err != nil {
return cli.NewExitError(err, 1)
}
defer wall.Close()
if ctx.Bool("decrypt") {
if pass == nil {
password, err := input.ReadPassword(EnterPasswordPrompt)
@ -762,6 +771,7 @@ func dumpKeys(ctx *cli.Context) error {
if err != nil {
return cli.NewExitError(err, 1)
}
defer wall.Close()
accounts := wall.Accounts
addrFlag := ctx.Generic("address").(*flags.Address)
@ -812,6 +822,7 @@ func stripKeys(ctx *cli.Context) error {
if err != nil {
return cli.NewExitError(err, 1)
}
defer wall.Close()
if !ctx.Bool("force") {
fmt.Fprintln(ctx.App.Writer, "All private keys for all accounts will be removed from the wallet. This action is irreversible.")
if ok := askForConsent(ctx.App.Writer); !ok {
@ -861,6 +872,7 @@ func createWallet(ctx *cli.Context) error {
if err := createAccount(wall, pass); err != nil {
return cli.NewExitError(err, 1)
}
defer wall.Close()
}
fmtPrintWallet(ctx.App.Writer, wall)

View file

@ -276,6 +276,7 @@ func (s *service) Shutdown() {
s.log.Info("stopping consensus service")
close(s.quit)
<-s.finished
s.wallet.Close()
}
}

View file

@ -222,6 +222,7 @@ func (n *Notary) Shutdown() {
n.Config.Log.Info("stopping notary service")
close(n.stopCh)
<-n.done
n.wallet.Close()
}
// OnNewRequest is a callback method which is called after a new notary request is added to the notary request pool.

View file

@ -191,6 +191,7 @@ func (o *Oracle) Shutdown() {
close(o.close)
o.ResponseHandler.Shutdown()
<-o.done
o.wallet.Close()
}
// Start runs the oracle service in a separate goroutine.

View file

@ -74,6 +74,7 @@ func (s *service) Shutdown() {
s.log.Info("stopping state validation service")
close(s.stopCh)
<-s.done
s.wallet.Close()
}
func (s *service) signAndSend(r *state.MPTRoot) error {

View file

@ -33,6 +33,7 @@ func ExampleBuilder() {
b.Reset() // Copy the old script above if you need it!
w, _ := wallet.NewWalletFromFile("somewhere")
defer w.Close()
// Assuming there is one Account inside
a, _ := actor.NewSimple(c, w.Accounts[0])
from := w.Accounts[0].Contract.ScriptHash() // Assuming Contract is present.