Skip to content

Commit

Permalink
integrate fil markets pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
aarshkshah1992 committed Mar 26, 2021
1 parent 4ee233d commit 3693168
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 17 deletions.
2 changes: 1 addition & 1 deletion api/api_full.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ type FullNode interface {
// ClientGetDealInfo returns the latest information about a given deal.
ClientGetDealInfo(context.Context, cid.Cid) (*DealInfo, error) //perm:read
// ClientListDeals returns information about the deals made by the local client.
ClientListDeals(ctx context.Context) ([]DealInfo, error) //perm:write
ClientListDeals(ctx context.Context, filter ...storagemarket.ListDealsPageParams) ([]DealInfo, error) //perm:write
// ClientGetDealUpdates returns the status of updated deals
ClientGetDealUpdates(ctx context.Context) (<-chan DealInfo, error) //perm:write
// ClientGetDealStatus returns status given a code
Expand Down
6 changes: 3 additions & 3 deletions api/apistruct/struct.go

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

54 changes: 43 additions & 11 deletions cli/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1524,8 +1524,9 @@ var clientQueryAskCmd = &cli.Command{
}

var clientListDeals = &cli.Command{
Name: "list-deals",
Usage: "List storage market deals",
Name: "list-deals",
Usage: "List storage market deals",
UsageText: "also supports pagination, please see supported options for more details",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "verbose",
Expand All @@ -1537,14 +1538,34 @@ var clientListDeals = &cli.Command{
Usage: "use color in display output",
Value: true,
},
&cli.BoolFlag{
Name: "show-failed",
Usage: "show failed/failing deals",
},
&cli.BoolFlag{
Name: "watch",
Usage: "watch deal updates in real-time, rather than a one time list",
},
&cli.BoolFlag{
Name: "hide-failed",
Usage: "hide failed/failing deals",
},
&cli.Int64Flag{
Name: "creation-time-offset",
Usage: "unix epoch seconds specifying the minimum creation time offset of the deals to include in the deal list page",
DefaultText: "no-op",
},
&cli.IntFlag{
Name: "deals-per-page",
Usage: "number of deals to show in the deal list page",
DefaultText: "defaults to all deals that match the given criteria",
},
&cli.Int64Flag{
Name: "min-start-epoch",
Usage: "minimum start epoch of the deals to include in the deal list page",
DefaultText: "no-op",
},
&cli.Int64Flag{
Name: "max-end-epoch",
Usage: "maximum end epoch of the deals to include in the deal list page",
DefaultText: "no-op",
},
},
Action: func(cctx *cli.Context) error {
api, closer, err := GetFullNodeAPI(cctx)
Expand All @@ -1557,9 +1578,22 @@ var clientListDeals = &cli.Command{
verbose := cctx.Bool("verbose")
color := cctx.Bool("color")
watch := cctx.Bool("watch")
showFailed := cctx.Bool("show-failed")

localDeals, err := api.ClientListDeals(ctx)
ctOffset := cctx.Int64("creation-time-offset")
nDeals := cctx.Int("deals-per-page")
minStart := cctx.Int64("min-start-epoch")
maxEnd := cctx.Int64("max-end-epoch")
hideFailed := cctx.Bool("hide-failed")

filter := storagemarket.ListDealsPageParams{
CreationTimePageOffset: time.Unix(ctOffset, 0),
DealsPerPage: nDeals,
MinStartEpoch: abi.ChainEpoch(minStart),
MaxEndEpoch: abi.ChainEpoch(maxEnd),
HideDealsInErrorState: hideFailed,
}

localDeals, err := api.ClientListDeals(ctx, filter)
if err != nil {
return err
}
Expand Down Expand Up @@ -1635,9 +1669,7 @@ func outputStorageDeals(ctx context.Context, out io.Writer, full lapi.FullNode,

var deals []deal
for _, localDeal := range localDeals {
if showFailed || localDeal.State != storagemarket.StorageDealError {
deals = append(deals, dealFromDealInfo(ctx, full, head, localDeal))
}
deals = append(deals, dealFromDealInfo(ctx, full, head, localDeal))
}

if verbose {
Expand Down
4 changes: 2 additions & 2 deletions node/impl/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ func (a *API) ClientStartDeal(ctx context.Context, params *api.StartDealParams)
return &result.ProposalCid, nil
}

func (a *API) ClientListDeals(ctx context.Context) ([]api.DealInfo, error) {
deals, err := a.SMDealClient.ListLocalDeals(ctx)
func (a *API) ClientListDeals(ctx context.Context, filter ...storagemarket.ListDealsPageParams) ([]api.DealInfo, error) {
deals, err := a.SMDealClient.ListLocalDeals(ctx, filter...)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 3693168

Please sign in to comment.