github.com/keybase/client/go@v0.0.0-20240520164431-4f512a4c85a3/client/cmd_wallet_lookup.go (about) 1 package client 2 3 import ( 4 "errors" 5 6 "github.com/keybase/cli" 7 "github.com/keybase/client/go/libcmdline" 8 "github.com/keybase/client/go/libkb" 9 "github.com/keybase/go-framed-msgpack-rpc/rpc" 10 "golang.org/x/net/context" 11 ) 12 13 type CmdWalletLookup struct { 14 libkb.Contextified 15 Name string 16 } 17 18 func newCmdWalletLookup(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command { 19 cmd := &CmdWalletLookup{ 20 Contextified: libkb.NewContextified(g), 21 } 22 return cli.Command{ 23 Name: "lookup", 24 Usage: "Look up Stellar account ID based on Keybase name or Stellar federation address.", 25 ArgumentHelp: "<name>", 26 Action: func(c *cli.Context) { 27 cl.ChooseCommand(cmd, "lookup", c) 28 }, 29 } 30 } 31 32 func (c *CmdWalletLookup) ParseArgv(ctx *cli.Context) error { 33 if len(ctx.Args()) != 1 { 34 return errors.New("lookup requires one argument (name)") 35 } 36 c.Name = ctx.Args()[0] 37 return nil 38 } 39 40 func (c *CmdWalletLookup) Run() (err error) { 41 defer transformStellarCLIError(&err) 42 cli, err := GetWalletClient(c.G()) 43 if err != nil { 44 return err 45 } 46 47 protocols := []rpc.Protocol{ 48 NewIdentifyUIProtocol(c.G()), 49 } 50 if err := RegisterProtocolsWithContext(protocols, c.G()); err != nil { 51 return err 52 } 53 54 dui := c.G().UI.GetDumbOutputUI() 55 res, err := cli.LookupCLILocal(context.Background(), c.Name) 56 if err != nil { 57 return err 58 } 59 60 dui.Printf("Account ID for %q: ", c.Name) 61 _, _ = dui.PrintfUnescaped("%s\n", ColorString(c.G(), "green", string(res.AccountID))) 62 if res.Username != nil && *res.Username != c.Name { 63 _, _ = dui.PrintfStderr("Belongs to Keybase user: %s\n", ColorString(c.G(), "green", *res.Username)) 64 } 65 return nil 66 } 67 68 func (c *CmdWalletLookup) GetUsage() libkb.Usage { 69 return libkb.Usage{ 70 Config: true, 71 API: true, 72 KbKeyring: true, 73 } 74 }