This repository has been archived by the owner on May 10, 2023. It is now read-only.
/
list.go
74 lines (60 loc) · 1.67 KB
/
list.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package cmd
import (
"encoding/json"
"errors"
"fmt"
storev1 "code.vegaprotocol.io/go-wallet/store/v1"
"code.vegaprotocol.io/go-wallet/wallet"
"github.com/spf13/cobra"
)
var (
listArgs struct {
walletOwner string
passphrase string
}
// listCmd represents the list command
listCmd = &cobra.Command{
Use: "list",
Short: "List keypairs of a wallet",
Long: "List all the keypairs for a given wallet",
RunE: runList,
}
)
func init() {
rootCmd.AddCommand(listCmd)
listCmd.Flags().StringVarP(&listArgs.walletOwner, "name", "n", "", "Name of the wallet to use")
listCmd.Flags().StringVarP(&listArgs.passphrase, "passphrase", "p", "", "Passphrase to access the wallet")
}
func runList(cmd *cobra.Command, args []string) error {
store, err := storev1.NewStore(rootArgs.rootPath)
if err != nil {
return err
}
handler := wallet.NewHandler(store)
if len(listArgs.walletOwner) == 0 {
return errors.New("wallet name is required")
}
if len(listArgs.passphrase) == 0 {
var err error
listArgs.passphrase, err = promptForPassphrase()
if err != nil {
return fmt.Errorf("could not get passphrase: %v", err)
}
}
err = handler.LoginWallet(listArgs.walletOwner, listArgs.passphrase)
if err != nil {
return fmt.Errorf("could not login to the wallet: %v", err)
}
keys, err := handler.ListPublicKeys(listArgs.walletOwner)
if err != nil {
return fmt.Errorf("could not list the public keys: %v", err)
}
buf, err := json.MarshalIndent(keys, " ", " ")
if err != nil {
return fmt.Errorf("unable to marshal message: %v", err)
}
// print the new keys for user info
fmt.Printf("List of all your keypairs:\n")
fmt.Printf("%v\n", string(buf))
return nil
}