/
cmd_wallet_get_inflation.go
84 lines (74 loc) · 1.98 KB
/
cmd_wallet_get_inflation.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
84
package client
import (
"fmt"
"github.com/keybase/cli"
"github.com/adamwalz/keybase-client/go/libcmdline"
"github.com/adamwalz/keybase-client/go/libkb"
"github.com/adamwalz/keybase-client/go/protocol/stellar1"
"golang.org/x/net/context"
)
type cmdWalletGetInflation struct {
libkb.Contextified
accountID string
}
func newCmdWalletGetInflation(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
cmd := &cmdWalletGetInflation{
Contextified: libkb.NewContextified(g),
}
return cli.Command{
Name: "get-inflation",
Usage: "Get inflation destination address of an account",
ArgumentHelp: "<account id>",
Action: func(c *cli.Context) {
cl.ChooseCommand(cmd, "get-inflation", c)
},
}
}
func (c *cmdWalletGetInflation) ParseArgv(ctx *cli.Context) error {
args := ctx.Args()
if len(args) != 1 {
return fmt.Errorf("Expecting one argument")
}
c.accountID = args[0]
return nil
}
func (c *cmdWalletGetInflation) Run() (err error) {
defer transformStellarCLIError(&err)
accountID, err := libkb.ParseStellarAccountID(c.accountID)
if err != nil {
return err
}
cli, err := GetWalletClient(c.G())
if err != nil {
return err
}
dest, err := cli.GetInflationDestinationLocal(context.Background(), stellar1.GetInflationDestinationLocalArg{
AccountID: accountID,
})
if err != nil {
return err
}
dui := c.G().UI.GetDumbOutputUI()
var formatted string
if dest.Destination != nil {
formatted = dest.Destination.String()
} else {
formatted = "(not set)"
}
var maybeComment string
if dest.Self {
maybeComment = " (self)"
} else if dest.KnownDestination != nil {
maybeComment = fmt.Sprintf(" (%s, %s)", dest.KnownDestination.Name, dest.KnownDestination.Url)
}
dui.Printf("Checking inflation destination for %s\n", accountID)
dui.Printf("Inflation destination: %s%s\n", formatted, maybeComment)
return nil
}
func (c *cmdWalletGetInflation) GetUsage() libkb.Usage {
return libkb.Usage{
API: true,
KbKeyring: true,
Config: true,
}
}