/
cmd_wallet_dump.go
83 lines (75 loc) · 2.01 KB
/
cmd_wallet_dump.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
75
76
77
78
79
80
81
82
83
package client
import (
"encoding/base64"
"github.com/keybase/cli"
"github.com/adamwalz/keybase-client/go/libcmdline"
"github.com/adamwalz/keybase-client/go/libkb"
"github.com/keybase/go-framed-msgpack-rpc/rpc"
"golang.org/x/net/context"
)
type cmdWalletDump struct {
libkb.Contextified
}
func newCmdWalletDump(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
cmd := &cmdWalletDump{
Contextified: libkb.NewContextified(g),
}
return cli.Command{
Name: "dump",
Usage: "Display wallet account keys",
Action: func(c *cli.Context) {
cl.ChooseCommand(cmd, "dump", c)
},
}
}
func (c *cmdWalletDump) ParseArgv(ctx *cli.Context) error {
return nil
}
func (c *cmdWalletDump) Run() (err error) {
defer transformStellarCLIError(&err)
protocols := []rpc.Protocol{
NewSecretUIProtocol(c.G()),
}
if err := RegisterProtocolsWithContext(protocols, c.G()); err != nil {
return err
}
cli, err := GetWalletClient(c.G())
if err != nil {
return err
}
bundle, err := cli.WalletDumpLocal(context.Background())
if err != nil {
return err
}
dui := c.G().UI.GetDumbOutputUI()
dui.Printf("Revision: %v\n", bundle.Revision)
dui.Printf("Prev: %v\n", base64.StdEncoding.EncodeToString(bundle.Prev))
dui.Printf("OwnHash: %v\n", base64.StdEncoding.EncodeToString(bundle.OwnHash))
for i, account := range bundle.Accounts {
if account.IsPrimary {
dui.Printf("\n[%v] PRIMARY\n", i)
} else {
dui.Printf("\n[%v]\n", i)
}
if len(account.Name) > 0 {
dui.Printf("Name: %v\n", account.Name)
}
dui.Printf("AccountID: %v\n", account.AccountID)
accountBundle := bundle.AccountBundles[account.AccountID]
for j, signer := range accountBundle.Signers {
dui.Printf("Signers[%v]: %v\n", j, signer.SecureNoLogString())
}
if len(accountBundle.Signers) == 0 {
dui.Printf("Signers[0]: not present in bundle\n")
}
dui.Printf("Mode: %v\n", account.Mode)
}
return nil
}
func (c *cmdWalletDump) GetUsage() libkb.Usage {
return libkb.Usage{
Config: true,
API: true,
KbKeyring: true,
}
}