Skip to content

Commit 01e9fa1

Browse files
authored
Stellar: Inflation destination RPC and CLI (keybase#15105)
1 parent 1f621f5 commit 01e9fa1

21 files changed

Lines changed: 800 additions & 28 deletions

File tree

‎go/client/cmd_wallet.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ func newCmdWallet(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Comman
2323
newCmdWalletSetCurrency(cl, g),
2424
newCmdWalletSetMobileOnly(cl, g),
2525
newCmdWalletSetPrimary(cl, g),
26+
newCmdWalletSetInflation(cl, g),
27+
newCmdWalletGetInflation(cl, g),
2628
}
2729
subcommands = append(subcommands, getBuildSpecificWalletCommands(cl, g)...)
2830
return cli.Command{
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package client
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/keybase/cli"
7+
"github.com/keybase/client/go/libcmdline"
8+
"github.com/keybase/client/go/libkb"
9+
"github.com/keybase/client/go/protocol/stellar1"
10+
"golang.org/x/net/context"
11+
)
12+
13+
type cmdWalletGetInflation struct {
14+
libkb.Contextified
15+
accountID string
16+
}
17+
18+
func newCmdWalletGetInflation(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
19+
cmd := &cmdWalletGetInflation{
20+
Contextified: libkb.NewContextified(g),
21+
}
22+
return cli.Command{
23+
Name: "get-inflation",
24+
Usage: "Get inflation destination address of an account",
25+
ArgumentHelp: "<account id>",
26+
Action: func(c *cli.Context) {
27+
cl.ChooseCommand(cmd, "get-inflation", c)
28+
},
29+
}
30+
}
31+
32+
func (c *cmdWalletGetInflation) ParseArgv(ctx *cli.Context) error {
33+
args := ctx.Args()
34+
if len(args) != 1 {
35+
return fmt.Errorf("Expecting one argument")
36+
}
37+
c.accountID = args[0]
38+
return nil
39+
}
40+
41+
func (c *cmdWalletGetInflation) Run() (err error) {
42+
defer transformStellarCLIError(&err)
43+
accountID, err := libkb.ParseStellarAccountID(c.accountID)
44+
if err != nil {
45+
return err
46+
}
47+
48+
cli, err := GetWalletClient(c.G())
49+
if err != nil {
50+
return err
51+
}
52+
53+
dest, err := cli.GetInflationDestinationLocal(context.Background(), stellar1.GetInflationDestinationLocalArg{
54+
AccountID: accountID,
55+
})
56+
if err != nil {
57+
return err
58+
}
59+
60+
dui := c.G().UI.GetDumbOutputUI()
61+
var formatted string
62+
if dest.Destination != nil {
63+
formatted = dest.Destination.String()
64+
} else {
65+
formatted = "(not set)"
66+
}
67+
var maybeComment string
68+
if dest.Comment != "" {
69+
maybeComment = fmt.Sprintf(" (%s)", dest.Comment)
70+
}
71+
dui.Printf("Checking inflation destination for %s\n", accountID)
72+
dui.Printf("Inflation destination: %s%s\n", formatted, maybeComment)
73+
return nil
74+
}
75+
76+
func (c *cmdWalletGetInflation) GetUsage() libkb.Usage {
77+
return libkb.Usage{
78+
API: true,
79+
KbKeyring: true,
80+
Config: true,
81+
}
82+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
package client
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/keybase/cli"
7+
"github.com/keybase/client/go/libcmdline"
8+
"github.com/keybase/client/go/libkb"
9+
"github.com/keybase/client/go/protocol/stellar1"
10+
"golang.org/x/net/context"
11+
)
12+
13+
type cmdWalletSetInflation struct {
14+
libkb.Contextified
15+
accountID string
16+
destination string
17+
}
18+
19+
func newCmdWalletSetInflation(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
20+
cmd := &cmdWalletSetInflation{
21+
Contextified: libkb.NewContextified(g),
22+
}
23+
return cli.Command{
24+
Name: "set-inflation",
25+
Usage: "Set inflation destination address for an account",
26+
ArgumentHelp: "<account id> <destination address or label>",
27+
Action: func(c *cli.Context) {
28+
cl.ChooseCommand(cmd, "set-inflation", c)
29+
},
30+
Description: `Read more about Stellar inflation payouts:
31+
https://www.stellar.org/developers/guides/concepts/inflation.html
32+
33+
Destination can be either a user-chosen address (any Stellar account ID),
34+
or one of the following labels:
35+
36+
* "lumenaut" - Sets account's inflation destination to Lumenaut Pool. Read more
37+
on https://pool.lumenaut.net/
38+
39+
* "self" - Sets inflation destination to the source account ID.
40+
41+
Inflation destination cannot be removed or cleared from the account right
42+
now, but if you want to stop contributing to the currently set destination,
43+
use the "self" option.
44+
45+
keybase wallet set-inflation <account id> self
46+
`,
47+
}
48+
}
49+
50+
func (c *cmdWalletSetInflation) ParseArgv(ctx *cli.Context) error {
51+
args := ctx.Args()
52+
if len(args) != 2 {
53+
return fmt.Errorf("Expecting two arguments")
54+
}
55+
c.accountID = args[0]
56+
c.destination = args[1]
57+
return nil
58+
}
59+
60+
func (c *cmdWalletSetInflation) Run() (err error) {
61+
defer transformStellarCLIError(&err)
62+
accountID, err := libkb.ParseStellarAccountID(c.accountID)
63+
if err != nil {
64+
return err
65+
}
66+
67+
var destination stellar1.InflationDestination
68+
switch c.destination {
69+
case "self":
70+
destination = stellar1.NewInflationDestinationWithSelf()
71+
case "lumenaut":
72+
destination = stellar1.NewInflationDestinationWithLumenaut()
73+
default:
74+
acc, err := libkb.ParseStellarAccountID(c.destination)
75+
if err != nil {
76+
return fmt.Errorf("Error parsing Stellar address %q: %s", c.destination, err)
77+
}
78+
destination = stellar1.NewInflationDestinationWithAccountid(acc)
79+
}
80+
81+
cli, err := GetWalletClient(c.G())
82+
if err != nil {
83+
return err
84+
}
85+
86+
err = cli.SetInflationDestinationLocal(context.Background(), stellar1.SetInflationDestinationLocalArg{
87+
AccountID: accountID,
88+
Destination: destination,
89+
})
90+
if err != nil {
91+
return err
92+
}
93+
c.G().UI.GetDumbOutputUI().PrintfStderr("Inflation destination address changed.\n")
94+
return nil
95+
}
96+
97+
func (c *cmdWalletSetInflation) GetUsage() libkb.Usage {
98+
return libkb.Usage{
99+
API: true,
100+
KbKeyring: true,
101+
Config: true,
102+
}
103+
}

‎go/protocol/stellar1/local.go‎

Lines changed: 159 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)