Skip to content

Commit

Permalink
add types and plumbing for listing popular assets from stellard (keyb…
Browse files Browse the repository at this point in the history
  • Loading branch information
xgess authored Jun 13, 2019
1 parent d4abca6 commit b3bf6d3
Show file tree
Hide file tree
Showing 16 changed files with 193 additions and 0 deletions.
1 change: 1 addition & 0 deletions go/client/cmd_wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func newCmdWallet(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Comman
newCmdWalletHistory(cl, g),
newCmdWalletImport(cl, g),
newCmdWalletLookup(cl, g),
newCmdWalletPopularAssets(cl, g),
newCmdWalletRename(cl, g),
newCmdWalletRequest(cl, g),
newCmdWalletSend(cl, g),
Expand Down
62 changes: 62 additions & 0 deletions go/client/cmd_wallet_popular_assets.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package client

import (
"errors"

"github.com/keybase/cli"
"github.com/keybase/client/go/libcmdline"
"github.com/keybase/client/go/libkb"
"golang.org/x/net/context"
)

func (c *cmdWalletPopularAssets) GetUsage() libkb.Usage {
return libkb.Usage{
API: true,
KbKeyring: true,
Config: true,
}
}

type cmdWalletPopularAssets struct {
libkb.Contextified
}

func newCmdWalletPopularAssets(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
cmd := &cmdWalletPopularAssets{
Contextified: libkb.NewContextified(g),
}
return cli.Command{
Name: "popular-assets",
Usage: "List popular assets",
Action: func(c *cli.Context) {
cl.ChooseCommand(cmd, "popular-assets", c)
},
}
}

func (c *cmdWalletPopularAssets) ParseArgv(ctx *cli.Context) error {
if len(ctx.Args()) != 0 {
return errors.New("listing popular assets expects no args")
}
return nil
}

func (c *cmdWalletPopularAssets) Run() (err error) {
defer transformStellarCLIError(&err)

cli, err := GetWalletClient(c.G())
if err != nil {
return err
}

assets, err := cli.ListPopularAssetsLocal(context.Background(), 0)
if err != nil {
return err
}
dui := c.G().UI.GetDumbOutputUI()
dui.Printf("popular assets:\n")
for _, asset := range assets {
dui.Printf(buildOutputStringForAsset(asset) + "\n")
}
return nil
}
26 changes: 26 additions & 0 deletions go/protocol/stellar1/local.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions go/protocol/stellar1/remote.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions go/stellar/remote/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ type Remoter interface {
FindPaymentPath(mctx libkb.MetaContext, query stellar1.PaymentPathQuery) (stellar1.PaymentPath, error)
PostAnyTransaction(mctx libkb.MetaContext, signedTx string) error
FuzzyAssetSearch(mctx libkb.MetaContext, arg stellar1.FuzzyAssetSearchArg) ([]stellar1.Asset, error)
ListPopularAssets(mctx libkb.MetaContext, arg stellar1.ListPopularAssetsArg) ([]stellar1.Asset, error)
}
18 changes: 18 additions & 0 deletions go/stellar/remote/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -1133,3 +1133,21 @@ func FuzzyAssetSearch(mctx libkb.MetaContext, arg stellar1.FuzzyAssetSearchArg)
}
return apiRes.Assets, nil
}

type popularAssetsResult struct {
libkb.AppStatusEmbed
Assets []stellar1.Asset `json:"assets"`
}

func ListPopularAssets(mctx libkb.MetaContext, arg stellar1.ListPopularAssetsArg) ([]stellar1.Asset, error) {
apiArg := libkb.APIArg{
Endpoint: "stellar/list_popular_assets",
SessionType: libkb.APISessionTypeREQUIRED,
Args: libkb.HTTPArgs{},
}
var apiRes popularAssetsResult
if err := mctx.G().API.GetDecode(mctx, apiArg, &apiRes); err != nil {
return []stellar1.Asset{}, err
}
return apiRes.Assets, nil
}
4 changes: 4 additions & 0 deletions go/stellar/remote/remote_net.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,7 @@ func (r *RemoteNet) PostAnyTransaction(mctx libkb.MetaContext, signedTx string)
func (r *RemoteNet) FuzzyAssetSearch(mctx libkb.MetaContext, arg stellar1.FuzzyAssetSearchArg) ([]stellar1.Asset, error) {
return FuzzyAssetSearch(mctx, arg)
}

func (r *RemoteNet) ListPopularAssets(mctx libkb.MetaContext, arg stellar1.ListPopularAssetsArg) ([]stellar1.Asset, error) {
return ListPopularAssets(mctx, arg)
}
4 changes: 4 additions & 0 deletions go/stellar/stellar.go
Original file line number Diff line number Diff line change
Expand Up @@ -2327,3 +2327,7 @@ func FindPaymentPath(mctx libkb.MetaContext, remoter remote.Remoter, source stel
func FuzzyAssetSearch(mctx libkb.MetaContext, remoter remote.Remoter, arg stellar1.FuzzyAssetSearchArg) ([]stellar1.Asset, error) {
return remoter.FuzzyAssetSearch(mctx, arg)
}

func ListPopularAssets(mctx libkb.MetaContext, remoter remote.Remoter, arg stellar1.ListPopularAssetsArg) ([]stellar1.Asset, error) {
return remoter.ListPopularAssets(mctx, arg)
}
15 changes: 15 additions & 0 deletions go/stellar/stellarsvc/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -1236,3 +1236,18 @@ func (s *Server) FuzzyAssetSearchLocal(ctx context.Context, arg stellar1.FuzzyAs
}
return stellar.FuzzyAssetSearch(mctx, s.remoter, remoteArg)
}

func (s *Server) ListPopularAssetsLocal(ctx context.Context, sessionID int) (res []stellar1.Asset, err error) {
mctx, fin, err := s.Preamble(ctx, preambleArg{
RPCName: "ListPopularAssetsLocal",
Err: &err,
RequireWallet: true,
})
defer fin()
if err != nil {
return res, err
}

remoteArg := stellar1.ListPopularAssetsArg{}
return stellar.ListPopularAssets(mctx, s.remoter, remoteArg)
}
4 changes: 4 additions & 0 deletions go/stellar/stellarsvc/remote_mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,10 @@ func (r *RemoteClientMock) FuzzyAssetSearch(_ libkb.MetaContext, _ stellar1.Fuzz
return nil, errors.New("not mocked")
}

func (r *RemoteClientMock) ListPopularAssets(_ libkb.MetaContext, _ stellar1.ListPopularAssetsArg) ([]stellar1.Asset, error) {
return nil, errors.New("not mocked")
}

func (r *RemoteClientMock) PostAnyTransaction(_ libkb.MetaContext, _ string) error {
return errors.New("post any transaction is not mocked")
}
Expand Down
4 changes: 4 additions & 0 deletions go/systests/stellar_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -732,4 +732,8 @@ func (s *stellarRetryClient) FuzzyAssetSearchLocal(ctx context.Context, arg stel
return s.cli.FuzzyAssetSearchLocal(ctx, arg)
}

func (s *stellarRetryClient) ListPopularAssetsLocal(ctx context.Context, sessionID int) (res []stellar1.Asset, err error) {
return s.cli.ListPopularAssetsLocal(ctx, sessionID)
}

var _ stellar1.LocalInterface = (*stellarRetryClient)(nil)
1 change: 1 addition & 0 deletions protocol/avdl/stellar1/local.avdl
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ protocol local {

// search by user search string
array<Asset> fuzzyAssetSearchLocal(int sessionID, string searchString);
array<Asset> listPopularAssetsLocal(int sessionID);

// Trustline operations:
// In addTrustline, limit is optional, if not supplied, max limit will be used.
Expand Down
1 change: 1 addition & 0 deletions protocol/avdl/stellar1/remote.avdl
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ protocol remote {
array<Asset> assetSearch(string assetCode, string issuerAccountID);
// search by user search string
array<Asset> fuzzyAssetSearch(keybase1.UserVersion caller, string searchString);
array<Asset> listPopularAssets(keybase1.UserVersion caller);

void changeTrustline(keybase1.UserVersion caller, string signedTransaction);

Expand Down
12 changes: 12 additions & 0 deletions protocol/json/stellar1/local.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions protocol/json/stellar1/remote.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions shared/constants/types/rpc-stellar-gen.tsx

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b3bf6d3

Please sign in to comment.