cli: use AddressFlag for wallet sign

This commit is contained in:
Anna Shaleva 2021-04-16 11:12:51 +03:00
parent a642bc6bc6
commit 2dcc729c47
3 changed files with 13 additions and 7 deletions

View file

@ -91,6 +91,12 @@ func TestSignMultisigTx(t *testing.T) {
})
}
// missing address
e.RunWithError(t, "neo-go", "wallet", "sign",
"--rpc-endpoint", "http://"+e.RPC.Addr,
"--wallet", wallet2Path,
"--in", txPath, "--out", txPath)
e.In.WriteString("pass\r")
e.Run(t, "neo-go", "wallet", "sign",
"--rpc-endpoint", "http://"+e.RPC.Addr,
@ -127,7 +133,7 @@ func TestSignMultisigTx(t *testing.T) {
e.In.WriteString("pass\r")
e.Run(t, "neo-go", "contract", "invokefunction",
"--rpc-endpoint", "http://"+e.RPC.Addr,
"--wallet", wallet1Path, "--address", multisigAddr,
"--wallet", wallet1Path, "--address", multisigHash.StringLE(), // test with scripthash instead of address
"--out", txPath,
e.Chain.GoverningTokenHash().StringLE(), "transfer",
"bytes:"+multisigHash.StringBE(),

View file

@ -3,6 +3,7 @@ package wallet
import (
"fmt"
"github.com/nspcc-dev/neo-go/cli/flags"
"github.com/nspcc-dev/neo-go/cli/options"
"github.com/nspcc-dev/neo-go/cli/paramcontext"
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
@ -21,12 +22,11 @@ func signStoredTransaction(ctx *cli.Context) error {
if err != nil {
return cli.NewExitError(err, 1)
}
addr := ctx.String("address")
sh, err := address.StringToUint160(addr)
if err != nil {
return cli.NewExitError(fmt.Errorf("invalid address: %w", err), 1)
addrFlag := ctx.Generic("address").(*flags.Address)
if !addrFlag.IsSet {
return cli.NewExitError("address was not provided", 1)
}
acc, err := getDecryptedAccount(ctx, wall, sh)
acc, err := getDecryptedAccount(ctx, wall, addrFlag.Uint160())
if err != nil {
return cli.NewExitError(err, 1)
}

View file

@ -74,7 +74,7 @@ func NewCommands() []cli.Command {
walletPathFlag,
outFlag,
inFlag,
cli.StringFlag{
flags.AddressFlag{
Name: "address, a",
Usage: "Address to use",
},