diff --git a/cli/storage-deals.go b/cli/storage-deals.go index 30d6a1be..891096f5 100644 --- a/cli/storage-deals.go +++ b/cli/storage-deals.go @@ -367,6 +367,10 @@ part states: Name: "watch", Usage: "watch deal updates in real-time, rather than a one time list", }, + &cli.BoolFlag{ + Name: "oldest", + Usage: "sort by oldest first", + }, }, Action: func(cctx *cli.Context) error { api, closer, err := NewMarketNode(cctx) @@ -398,6 +402,9 @@ part states: Limit: cctx.Int(limitFlag.Name), }, } + if cctx.Bool("oldest") { + params.Asc = true + } ctx := ReqContext(cctx) deals, err := api.MarketListIncompleteDeals(ctx, ¶ms) diff --git a/go.mod b/go.mod index 4d06a4fd..71b06e53 100644 --- a/go.mod +++ b/go.mod @@ -30,7 +30,7 @@ require ( github.com/filecoin-project/go-statestore v0.2.0 github.com/filecoin-project/specs-actors/v2 v2.3.6 github.com/filecoin-project/specs-actors/v7 v7.0.1 - github.com/filecoin-project/venus v1.13.1-0.20230918055732-dd01c6722800 + github.com/filecoin-project/venus v1.13.1-0.20230922072850-5a527ea220b8 github.com/golang/mock v1.6.0 github.com/google/uuid v1.3.0 github.com/gorilla/mux v1.8.0 diff --git a/go.sum b/go.sum index aad3e636..166e00c5 100644 --- a/go.sum +++ b/go.sum @@ -821,8 +821,8 @@ github.com/filecoin-project/specs-storage v0.4.1 h1:yvLEaLZj8f+uByhNC4mFOtCUyL2w github.com/filecoin-project/specs-storage v0.4.1/go.mod h1:Z2eK6uMwAOSLjek6+sy0jNV2DSsMEENziMUz0GHRFBw= github.com/filecoin-project/test-vectors/schema v0.0.5/go.mod h1:iQ9QXLpYWL3m7warwvK1JC/pTri8mnfEmKygNDqqY6E= github.com/filecoin-project/venus v1.11.1/go.mod h1:H8A3djsrHKRWuKnJI/8Y6xZRudbV9V2x5NIP8/PVPfQ= -github.com/filecoin-project/venus v1.13.1-0.20230918055732-dd01c6722800 h1:fHJQPqCNUrGYODltBjOvzU5rIRy7y5SAh2NFh/2qibA= -github.com/filecoin-project/venus v1.13.1-0.20230918055732-dd01c6722800/go.mod h1:RtrF8fCy1xrCytfaVMvPU2J3JrcMqapzvJpvK5CKdTA= +github.com/filecoin-project/venus v1.13.1-0.20230922072850-5a527ea220b8 h1:Wj4hMLDQb5B+ibssYQpOZ3KFoA6hK2UdaG+4pE5zB/E= +github.com/filecoin-project/venus v1.13.1-0.20230922072850-5a527ea220b8/go.mod h1:RtrF8fCy1xrCytfaVMvPU2J3JrcMqapzvJpvK5CKdTA= github.com/filecoin-project/venus-auth v1.11.0/go.mod h1:aBfIfNxQkdcY8Rk5wrQn9qRtJpH4RTDdc10Ac+ferzs= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= github.com/flynn/noise v0.0.0-20180327030543-2492fe189ae6/go.mod h1:1i71OnUq3iUe1ma7Lr6yG6/rjvM3emb6yoL7xLFzcVQ= diff --git a/models/badger/storage_deal.go b/models/badger/storage_deal.go index a5e78030..b7c50e08 100644 --- a/models/badger/storage_deal.go +++ b/models/badger/storage_deal.go @@ -3,6 +3,7 @@ package badger import ( "bytes" "context" + "sort" "github.com/filecoin-project/go-address" cborrpc "github.com/filecoin-project/go-cbor-util" @@ -270,6 +271,11 @@ func (sdr *storageDealRepo) ListDeal(ctx context.Context, params *types.StorageD return nil, err } + // sort by time + sort.Slice(storageDeals, func(i, j int) bool { + return (storageDeals[i].TimeStamp.CreatedAt < storageDeals[j].TimeStamp.CreatedAt) == params.Asc + }) + return storageDeals, nil } diff --git a/models/mysql/storage_deal.go b/models/mysql/storage_deal.go index 2b997d2e..bad4ef3a 100644 --- a/models/mysql/storage_deal.go +++ b/models/mysql/storage_deal.go @@ -495,6 +495,11 @@ func (sdr *storageDealRepo) ListDeal(ctx context.Context, params *types.StorageD state != storagemarket.StorageDealExpired && state != storagemarket.StorageDealError } query := sdr.Table(storageDealTableName).Offset(params.Offset).Limit(params.Limit) + if params.Asc { + query.Order("created_at asc") + } else { + query.Order("created_at desc") + } if !params.Miner.Empty() { query.Where("cdp_provider = ?", DBAddress(params.Miner).String()) } diff --git a/models/mysql/storage_deal_test.go b/models/mysql/storage_deal_test.go index c7336c05..8477856a 100644 --- a/models/mysql/storage_deal_test.go +++ b/models/mysql/storage_deal_test.go @@ -255,7 +255,7 @@ func TestListDeal(t *testing.T) { caseCount := len(storageDealCases) defPage := types.Page{Limit: caseCount} newQuery := func() *gorm.DB { - return db.Table((&storageDeal{}).TableName()) + return db.Table((&storageDeal{}).TableName()).Order("created_at desc") } // empty params