From b88f2b389f58cbb36f23b0b9551050e0cec0f15f Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Tue, 1 Feb 2022 12:46:30 +0300 Subject: [PATCH] cli: check execution state while saving invoked tx --- cli/smartcontract/smart_contract.go | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/cli/smartcontract/smart_contract.go b/cli/smartcontract/smart_contract.go index 607f56bc8..058e0eee5 100644 --- a/cli/smartcontract/smart_contract.go +++ b/cli/smartcontract/smart_contract.go @@ -653,18 +653,30 @@ func invokeWithArgs(ctx *cli.Context, acc *wallet.Account, wall *wallet.Wallet, return sender, err } + out := ctx.String("out") resp, err = c.InvokeFunction(script, operation, params, cosigners) if err != nil { return sender, cli.NewExitError(err, 1) } - if signAndPush && resp.State != "HALT" { + if resp.State != "HALT" { errText := fmt.Sprintf("Warning: %s VM state returned from the RPC node: %s\n", resp.State, resp.FaultException) - if !ctx.Bool("force") { - return sender, cli.NewExitError(errText+". Use --force flag to send the transaction anyway.", 1) + action := "save" + process := "Saving" + if signAndPush { + if out != "" { + action += "and send" + process += "and sending" + } else { + action = "send" + process = "Sending" + } } - fmt.Fprintln(ctx.App.Writer, errText+". Sending transaction...") + if !ctx.Bool("force") { + return sender, cli.NewExitError(errText+". Use --force flag to "+action+" the transaction anyway.", 1) + } + fmt.Fprintln(ctx.App.Writer, errText+". "+process+" transaction...") } - if out := ctx.String("out"); out != "" { + if out != "" { tx, err := c.CreateTxFromScript(resp.Script, acc, resp.GasConsumed+int64(sysgas), int64(gas), cosignersAccounts) if err != nil { return sender, cli.NewExitError(fmt.Errorf("failed to create tx: %w", err), 1)