Skip to content

Commit b3bf6d3

Browse files
authored
add types and plumbing for listing popular assets from stellard (keybase#17920)
1 parent d4abca6 commit b3bf6d3

16 files changed

Lines changed: 193 additions & 0 deletions

File tree

‎go/client/cmd_wallet.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ func newCmdWallet(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Comman
2525
newCmdWalletHistory(cl, g),
2626
newCmdWalletImport(cl, g),
2727
newCmdWalletLookup(cl, g),
28+
newCmdWalletPopularAssets(cl, g),
2829
newCmdWalletRename(cl, g),
2930
newCmdWalletRequest(cl, g),
3031
newCmdWalletSend(cl, g),
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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+
"golang.org/x/net/context"
10+
)
11+
12+
func (c *cmdWalletPopularAssets) GetUsage() libkb.Usage {
13+
return libkb.Usage{
14+
API: true,
15+
KbKeyring: true,
16+
Config: true,
17+
}
18+
}
19+
20+
type cmdWalletPopularAssets struct {
21+
libkb.Contextified
22+
}
23+
24+
func newCmdWalletPopularAssets(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
25+
cmd := &cmdWalletPopularAssets{
26+
Contextified: libkb.NewContextified(g),
27+
}
28+
return cli.Command{
29+
Name: "popular-assets",
30+
Usage: "List popular assets",
31+
Action: func(c *cli.Context) {
32+
cl.ChooseCommand(cmd, "popular-assets", c)
33+
},
34+
}
35+
}
36+
37+
func (c *cmdWalletPopularAssets) ParseArgv(ctx *cli.Context) error {
38+
if len(ctx.Args()) != 0 {
39+
return errors.New("listing popular assets expects no args")
40+
}
41+
return nil
42+
}
43+
44+
func (c *cmdWalletPopularAssets) Run() (err error) {
45+
defer transformStellarCLIError(&err)
46+
47+
cli, err := GetWalletClient(c.G())
48+
if err != nil {
49+
return err
50+
}
51+
52+
assets, err := cli.ListPopularAssetsLocal(context.Background(), 0)
53+
if err != nil {
54+
return err
55+
}
56+
dui := c.G().UI.GetDumbOutputUI()
57+
dui.Printf("popular assets:\n")
58+
for _, asset := range assets {
59+
dui.Printf(buildOutputStringForAsset(asset) + "\n")
60+
}
61+
return nil
62+
}

‎go/protocol/stellar1/local.go‎

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

‎go/protocol/stellar1/remote.go‎

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

‎go/stellar/remote/interface.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,5 @@ type Remoter interface {
4949
FindPaymentPath(mctx libkb.MetaContext, query stellar1.PaymentPathQuery) (stellar1.PaymentPath, error)
5050
PostAnyTransaction(mctx libkb.MetaContext, signedTx string) error
5151
FuzzyAssetSearch(mctx libkb.MetaContext, arg stellar1.FuzzyAssetSearchArg) ([]stellar1.Asset, error)
52+
ListPopularAssets(mctx libkb.MetaContext, arg stellar1.ListPopularAssetsArg) ([]stellar1.Asset, error)
5253
}

‎go/stellar/remote/remote.go‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,3 +1133,21 @@ func FuzzyAssetSearch(mctx libkb.MetaContext, arg stellar1.FuzzyAssetSearchArg)
11331133
}
11341134
return apiRes.Assets, nil
11351135
}
1136+
1137+
type popularAssetsResult struct {
1138+
libkb.AppStatusEmbed
1139+
Assets []stellar1.Asset `json:"assets"`
1140+
}
1141+
1142+
func ListPopularAssets(mctx libkb.MetaContext, arg stellar1.ListPopularAssetsArg) ([]stellar1.Asset, error) {
1143+
apiArg := libkb.APIArg{
1144+
Endpoint: "stellar/list_popular_assets",
1145+
SessionType: libkb.APISessionTypeREQUIRED,
1146+
Args: libkb.HTTPArgs{},
1147+
}
1148+
var apiRes popularAssetsResult
1149+
if err := mctx.G().API.GetDecode(mctx, apiArg, &apiRes); err != nil {
1150+
return []stellar1.Asset{}, err
1151+
}
1152+
return apiRes.Assets, nil
1153+
}

‎go/stellar/remote/remote_net.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,7 @@ func (r *RemoteNet) PostAnyTransaction(mctx libkb.MetaContext, signedTx string)
149149
func (r *RemoteNet) FuzzyAssetSearch(mctx libkb.MetaContext, arg stellar1.FuzzyAssetSearchArg) ([]stellar1.Asset, error) {
150150
return FuzzyAssetSearch(mctx, arg)
151151
}
152+
153+
func (r *RemoteNet) ListPopularAssets(mctx libkb.MetaContext, arg stellar1.ListPopularAssetsArg) ([]stellar1.Asset, error) {
154+
return ListPopularAssets(mctx, arg)
155+
}

‎go/stellar/stellar.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2327,3 +2327,7 @@ func FindPaymentPath(mctx libkb.MetaContext, remoter remote.Remoter, source stel
23272327
func FuzzyAssetSearch(mctx libkb.MetaContext, remoter remote.Remoter, arg stellar1.FuzzyAssetSearchArg) ([]stellar1.Asset, error) {
23282328
return remoter.FuzzyAssetSearch(mctx, arg)
23292329
}
2330+
2331+
func ListPopularAssets(mctx libkb.MetaContext, remoter remote.Remoter, arg stellar1.ListPopularAssetsArg) ([]stellar1.Asset, error) {
2332+
return remoter.ListPopularAssets(mctx, arg)
2333+
}

‎go/stellar/stellarsvc/frontend.go‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,3 +1236,18 @@ func (s *Server) FuzzyAssetSearchLocal(ctx context.Context, arg stellar1.FuzzyAs
12361236
}
12371237
return stellar.FuzzyAssetSearch(mctx, s.remoter, remoteArg)
12381238
}
1239+
1240+
func (s *Server) ListPopularAssetsLocal(ctx context.Context, sessionID int) (res []stellar1.Asset, err error) {
1241+
mctx, fin, err := s.Preamble(ctx, preambleArg{
1242+
RPCName: "ListPopularAssetsLocal",
1243+
Err: &err,
1244+
RequireWallet: true,
1245+
})
1246+
defer fin()
1247+
if err != nil {
1248+
return res, err
1249+
}
1250+
1251+
remoteArg := stellar1.ListPopularAssetsArg{}
1252+
return stellar.ListPopularAssets(mctx, s.remoter, remoteArg)
1253+
}

‎go/stellar/stellarsvc/remote_mock_test.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,10 @@ func (r *RemoteClientMock) FuzzyAssetSearch(_ libkb.MetaContext, _ stellar1.Fuzz
570570
return nil, errors.New("not mocked")
571571
}
572572

573+
func (r *RemoteClientMock) ListPopularAssets(_ libkb.MetaContext, _ stellar1.ListPopularAssetsArg) ([]stellar1.Asset, error) {
574+
return nil, errors.New("not mocked")
575+
}
576+
573577
func (r *RemoteClientMock) PostAnyTransaction(_ libkb.MetaContext, _ string) error {
574578
return errors.New("post any transaction is not mocked")
575579
}

0 commit comments

Comments
 (0)