forked from TrueCloudLab/neoneo-go
cli: provide separate function for opening wallet
This commit is contained in:
parent
3d67d52537
commit
2fc6375958
1 changed files with 12 additions and 29 deletions
|
@ -117,12 +117,7 @@ func NewCommands() []cli.Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
func addAccount(ctx *cli.Context) error {
|
func addAccount(ctx *cli.Context) error {
|
||||||
path := ctx.String("path")
|
wall, err := openWallet(ctx.String("path"))
|
||||||
if len(path) == 0 {
|
|
||||||
return cli.NewExitError(errNoPath, 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
wall, err := wallet.NewWalletFromFile(path)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cli.NewExitError(err, 1)
|
return cli.NewExitError(err, 1)
|
||||||
}
|
}
|
||||||
|
@ -137,12 +132,7 @@ func addAccount(ctx *cli.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func exportKeys(ctx *cli.Context) error {
|
func exportKeys(ctx *cli.Context) error {
|
||||||
path := ctx.String("path")
|
wall, err := openWallet(ctx.String("path"))
|
||||||
if len(path) == 0 {
|
|
||||||
return cli.NewExitError(errNoPath, 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
wall, err := wallet.NewWalletFromFile(path)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cli.NewExitError(err, 1)
|
return cli.NewExitError(err, 1)
|
||||||
}
|
}
|
||||||
|
@ -200,12 +190,7 @@ loop:
|
||||||
}
|
}
|
||||||
|
|
||||||
func importMultisig(ctx *cli.Context) error {
|
func importMultisig(ctx *cli.Context) error {
|
||||||
path := ctx.String("path")
|
wall, err := openWallet(ctx.String("path"))
|
||||||
if len(path) == 0 {
|
|
||||||
return cli.NewExitError(errNoPath, 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
wall, err := wallet.NewWalletFromFile(path)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cli.NewExitError(err, 1)
|
return cli.NewExitError(err, 1)
|
||||||
}
|
}
|
||||||
|
@ -244,12 +229,7 @@ func importMultisig(ctx *cli.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func importWallet(ctx *cli.Context) error {
|
func importWallet(ctx *cli.Context) error {
|
||||||
path := ctx.String("path")
|
wall, err := openWallet(ctx.String("path"))
|
||||||
if len(path) == 0 {
|
|
||||||
return cli.NewExitError(errNoPath, 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
wall, err := wallet.NewWalletFromFile(path)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cli.NewExitError(err, 1)
|
return cli.NewExitError(err, 1)
|
||||||
}
|
}
|
||||||
|
@ -270,11 +250,7 @@ func importWallet(ctx *cli.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func dumpWallet(ctx *cli.Context) error {
|
func dumpWallet(ctx *cli.Context) error {
|
||||||
path := ctx.String("path")
|
wall, err := openWallet(ctx.String("path"))
|
||||||
if len(path) == 0 {
|
|
||||||
return cli.NewExitError(errNoPath, 1)
|
|
||||||
}
|
|
||||||
wall, err := wallet.NewWalletFromFile(path)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cli.NewExitError(err, 1)
|
return cli.NewExitError(err, 1)
|
||||||
}
|
}
|
||||||
|
@ -348,6 +324,13 @@ func createAccount(ctx *cli.Context, wall *wallet.Wallet) error {
|
||||||
return wall.CreateAccount(name, phrase)
|
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) {
|
func newAccountFromWIF(wif string) (*wallet.Account, error) {
|
||||||
// note: NEP2 strings always have length of 58 even though
|
// note: NEP2 strings always have length of 58 even though
|
||||||
// base58 strings can have different lengths even if slice lengths are equal
|
// base58 strings can have different lengths even if slice lengths are equal
|
||||||
|
|
Loading…
Reference in a new issue