Skip to content

Commit

Permalink
cli: provide separate function for opening wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
fyrchik committed Feb 21, 2020
1 parent a7995bf commit 5c837e7
Showing 1 changed file with 12 additions and 29 deletions.
41 changes: 12 additions & 29 deletions cli/wallet/wallet.go
Expand Up @@ -114,12 +114,7 @@ func NewCommands() []cli.Command {
}

func addAccount(ctx *cli.Context) error {
path := ctx.String("path")
if len(path) == 0 {
return cli.NewExitError(errNoPath, 1)
}

wall, err := wallet.NewWalletFromFile(path)
wall, err := openWallet(ctx.String("path"))
if err != nil {
return cli.NewExitError(err, 1)
}
Expand All @@ -134,12 +129,7 @@ func addAccount(ctx *cli.Context) error {
}

func exportKeys(ctx *cli.Context) error {
path := ctx.String("path")
if len(path) == 0 {
return cli.NewExitError(errNoPath, 1)
}

wall, err := wallet.NewWalletFromFile(path)
wall, err := openWallet(ctx.String("path"))
if err != nil {
return cli.NewExitError(err, 1)
}
Expand Down Expand Up @@ -197,12 +187,7 @@ loop:
}

func importMultisig(ctx *cli.Context) error {
path := ctx.String("path")
if len(path) == 0 {
return cli.NewExitError(errNoPath, 1)
}

wall, err := wallet.NewWalletFromFile(path)
wall, err := openWallet(ctx.String("path"))
if err != nil {
return cli.NewExitError(err, 1)
}
Expand Down Expand Up @@ -241,12 +226,7 @@ func importMultisig(ctx *cli.Context) error {
}

func importWallet(ctx *cli.Context) error {
path := ctx.String("path")
if len(path) == 0 {
return cli.NewExitError(errNoPath, 1)
}

wall, err := wallet.NewWalletFromFile(path)
wall, err := openWallet(ctx.String("path"))
if err != nil {
return cli.NewExitError(err, 1)
}
Expand All @@ -267,11 +247,7 @@ func importWallet(ctx *cli.Context) error {
}

func dumpWallet(ctx *cli.Context) error {
path := ctx.String("path")
if len(path) == 0 {
return cli.NewExitError(errNoPath, 1)
}
wall, err := wallet.NewWalletFromFile(path)
wall, err := openWallet(ctx.String("path"))
if err != nil {
return cli.NewExitError(err, 1)
}
Expand Down Expand Up @@ -345,6 +321,13 @@ func createAccount(ctx *cli.Context, wall *wallet.Wallet) error {
return wall.CreateAccount(name, phrase)
}

func openWallet(path string) (*wallet.Wallet, error) {
if len(path) == 0 {
return nil, errNoPath
}
return wallet.NewWalletFromFile(path)
}

func newAccountFromWIF(wif string) (*wallet.Account, error) {
// note: NEP2 strings always have length of 58 even though
// base58 strings can have different lengths even if slice lengths are equal
Expand Down

0 comments on commit 5c837e7

Please sign in to comment.