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.In.WriteString("pass\r")
e.Run(t, "neo-go", "wallet", "sign", e.Run(t, "neo-go", "wallet", "sign",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addr,
@ -127,7 +133,7 @@ func TestSignMultisigTx(t *testing.T) {
e.In.WriteString("pass\r") e.In.WriteString("pass\r")
e.Run(t, "neo-go", "contract", "invokefunction", e.Run(t, "neo-go", "contract", "invokefunction",
"--rpc-endpoint", "http://"+e.RPC.Addr, "--rpc-endpoint", "http://"+e.RPC.Addr,
"--wallet", wallet1Path, "--address", multisigAddr, "--wallet", wallet1Path, "--address", multisigHash.StringLE(), // test with scripthash instead of address
"--out", txPath, "--out", txPath,
e.Chain.GoverningTokenHash().StringLE(), "transfer", e.Chain.GoverningTokenHash().StringLE(), "transfer",
"bytes:"+multisigHash.StringBE(), "bytes:"+multisigHash.StringBE(),

View file

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

View file

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