wallet: implement dump
command
Mostly a testing tool for the moment.
This commit is contained in:
parent
e96b4bc82e
commit
aad0d3792d
1 changed files with 33 additions and 6 deletions
|
@ -40,21 +40,48 @@ func NewCommands() []cli.Command {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "open",
|
Name: "dump",
|
||||||
Usage: "open a existing NEO wallet",
|
Usage: "check and dump an existing NEO wallet",
|
||||||
Action: openWallet,
|
Action: dumpWallet,
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "path, p",
|
Name: "path, p",
|
||||||
Usage: "Target location of the wallet file.",
|
Usage: "Target location of the wallet file.",
|
||||||
},
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "decrypt, d",
|
||||||
|
Usage: "Decrypt encrypted keys.",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
func openWallet(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)
|
||||||
|
if err != nil {
|
||||||
|
return cli.NewExitError(err, 1)
|
||||||
|
}
|
||||||
|
if ctx.Bool("decrypt") {
|
||||||
|
fmt.Print("Wallet password: ")
|
||||||
|
pass, err := terminal.ReadPassword(int(syscall.Stdin))
|
||||||
|
if err != nil {
|
||||||
|
return cli.NewExitError(err, 1)
|
||||||
|
}
|
||||||
|
for i := range wall.Accounts {
|
||||||
|
// Just testing the decryption here.
|
||||||
|
err := wall.Accounts[i].Decrypt(string(pass))
|
||||||
|
if err != nil {
|
||||||
|
return cli.NewExitError(err, 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fmtPrintWallet(wall)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,7 +104,7 @@ func createWallet(ctx *cli.Context) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dumpWallet(wall)
|
fmtPrintWallet(wall)
|
||||||
fmt.Printf("wallet successfully created, file location is %s\n", wall.Path())
|
fmt.Printf("wallet successfully created, file location is %s\n", wall.Path())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -110,7 +137,7 @@ func createAccount(ctx *cli.Context, wall *wallet.Wallet) error {
|
||||||
return wall.CreateAccount(name, phrase)
|
return wall.CreateAccount(name, phrase)
|
||||||
}
|
}
|
||||||
|
|
||||||
func dumpWallet(wall *wallet.Wallet) {
|
func fmtPrintWallet(wall *wallet.Wallet) {
|
||||||
b, _ := wall.JSON()
|
b, _ := wall.JSON()
|
||||||
fmt.Println("")
|
fmt.Println("")
|
||||||
fmt.Println(string(b))
|
fmt.Println(string(b))
|
||||||
|
|
Loading…
Reference in a new issue