/
cmd_wallet_lookup.go
73 lines (63 loc) · 1.67 KB
/
cmd_wallet_lookup.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
package client
import (
"errors"
"github.com/keybase/cli"
"github.com/keybase/client/go/libcmdline"
"github.com/keybase/client/go/libkb"
"github.com/keybase/go-framed-msgpack-rpc/rpc"
"golang.org/x/net/context"
)
type CmdWalletLookup struct {
libkb.Contextified
Name string
}
func newCmdWalletLookup(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
cmd := &CmdWalletLookup{
Contextified: libkb.NewContextified(g),
}
return cli.Command{
Name: "lookup",
Usage: "Look up Stellar account ID based on Keybase name or Stellar federation address.",
ArgumentHelp: "<name>",
Action: func(c *cli.Context) {
cl.ChooseCommand(cmd, "lookup", c)
},
}
}
func (c *CmdWalletLookup) ParseArgv(ctx *cli.Context) error {
if len(ctx.Args()) != 1 {
return errors.New("lookup requires one argument (name)")
}
c.Name = ctx.Args()[0]
return nil
}
func (c *CmdWalletLookup) Run() error {
cli, err := GetWalletClient(c.G())
if err != nil {
return err
}
protocols := []rpc.Protocol{
NewIdentifyUIProtocol(c.G()),
}
if err := RegisterProtocolsWithContext(protocols, c.G()); err != nil {
return err
}
dui := c.G().UI.GetDumbOutputUI()
res, err := cli.LookupCLILocal(context.Background(), c.Name)
if err != nil {
return err
}
dui.Printf("Account ID for %q: ", c.Name)
dui.PrintfUnescaped("%s\n", ColorString(c.G(), "green", string(res.AccountID)))
if res.Username != nil && *res.Username != c.Name {
dui.PrintfStderr("Belongs to Keybase user: %s\n", ColorString(c.G(), "green", *res.Username))
}
return nil
}
func (c *CmdWalletLookup) GetUsage() libkb.Usage {
return libkb.Usage{
Config: true,
API: true,
KbKeyring: true,
}
}