-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
cmd_wallet_set_inflation.go
123 lines (104 loc) · 3.22 KB
/
cmd_wallet_set_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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package client
import (
"fmt"
"github.com/keybase/cli"
"github.com/keybase/client/go/libcmdline"
"github.com/keybase/client/go/libkb"
"github.com/keybase/client/go/protocol/stellar1"
"golang.org/x/net/context"
)
type cmdWalletSetInflation struct {
libkb.Contextified
accountID string
destination string
}
func newCmdWalletSetInflation(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
cmd := &cmdWalletSetInflation{
Contextified: libkb.NewContextified(g),
}
return cli.Command{
Name: "set-inflation",
Usage: "Set inflation destination address for an account",
ArgumentHelp: "<account id> <destination address or label>",
Action: func(c *cli.Context) {
cl.ChooseCommand(cmd, "set-inflation", c)
},
Description: `Read more about Stellar inflation payouts:
https://www.stellar.org/developers/guides/concepts/inflation.html
Destination can be either a user-chosen address (any Stellar account ID),
or one of the following labels:
* "lumenaut" - Sets account's inflation destination to Lumenaut Pool. Read more
on https://pool.lumenaut.net/
* "self" - Sets inflation destination to the source account ID.
Inflation destination cannot be removed or cleared from the account right
now, but if you want to stop contributing to the currently set destination,
use the "self" option.
keybase wallet set-inflation <account id> self
`,
}
}
func (c *cmdWalletSetInflation) ParseArgv(ctx *cli.Context) error {
args := ctx.Args()
if len(args) != 2 {
return fmt.Errorf("Expecting two arguments")
}
c.accountID = args[0]
c.destination = args[1]
return nil
}
func getInflationDestinationAddrFromString(cli stellar1.LocalClient, accountID stellar1.AccountID,
destination string) (res stellar1.AccountID, err error) {
inputAcc, err := libkb.ParseStellarAccountID(destination)
if err == nil {
// User passed destination AccountID
return inputAcc, nil
}
// Something else, we have to figure out what it is
if destination == "self" {
return accountID, nil
}
// Might be a tag for predefined destination.
destinations, err := cli.GetPredefinedInflationDestinationsLocal(context.Background(), 0)
if err != nil {
return res, err
}
for _, dest := range destinations {
if string(dest.Tag) == destination {
return dest.AccountID, nil
}
}
return res, fmt.Errorf(
"unknown inflation destination %q: not an account ID or known destination name",
destination)
}
func (c *cmdWalletSetInflation) 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
}
destination, err := getInflationDestinationAddrFromString(cli, accountID, c.destination)
if err != nil {
return err
}
err = cli.SetInflationDestinationLocal(context.Background(), stellar1.SetInflationDestinationLocalArg{
AccountID: accountID,
Destination: destination,
})
if err != nil {
return err
}
_, _ = c.G().UI.GetDumbOutputUI().PrintfStderr("Inflation destination address changed.\n")
return nil
}
func (c *cmdWalletSetInflation) GetUsage() libkb.Usage {
return libkb.Usage{
API: true,
KbKeyring: true,
Config: true,
}
}