From a1ea5bee63dd3df73e083c239c5fe7eb9b3c1370 Mon Sep 17 00:00:00 2001 From: simlecode <69969590+simlecode@users.noreply.github.com> Date: Thu, 16 Mar 2023 16:16:03 +0800 Subject: [PATCH] feat: add command to print signer deal detail --- api/impl/venus_market.go | 21 ++++++++ cli/retrieval-deals.go | 83 +++++++++++++++++++++++++++++++ cli/storage-deals.go | 105 +++++++++++++++++++++++++++++++++++++++ go.mod | 6 +-- go.sum | 11 ++-- 5 files changed, 218 insertions(+), 8 deletions(-) diff --git a/api/impl/venus_market.go b/api/impl/venus_market.go index bc440f79..8f9b6c60 100644 --- a/api/impl/venus_market.go +++ b/api/impl/venus_market.go @@ -242,6 +242,18 @@ func (m *MarketNodeImpl) MarketListDeals(ctx context.Context, addrs []address.Ad return m.listDeals(ctx, addrs) } +func (m *MarketNodeImpl) MarketGetDeal(ctx context.Context, dealPropCid cid.Cid) (*types.MinerDeal, error) { + deal, err := m.Repo.StorageDealRepo().GetDeal(ctx, dealPropCid) + if err != nil { + return nil, err + } + if err := jwtclient.CheckPermissionByMiner(ctx, m.AuthClient, deal.Proposal.Provider); err != nil { + return nil, err + } + + return deal, nil +} + // MarketListRetrievalDeals todo add user isolate when is available to get miner from retrieve deal // 检索订单没法按 `miner address` 过滤 func (m *MarketNodeImpl) MarketListRetrievalDeals(ctx context.Context) ([]types.ProviderDealState, error) { @@ -262,6 +274,15 @@ func (m *MarketNodeImpl) MarketListRetrievalDeals(ctx context.Context) ([]types. return out, nil } +func (m *MarketNodeImpl) MarketGetRetrievalDeal(ctx context.Context, receiver peer.ID, dealID uint64) (*types.ProviderDealState, error) { + deal, err := m.Repo.RetrievalDealRepo().GetDeal(ctx, receiver, retrievalmarket.DealID(dealID)) + if err != nil { + return nil, err + } + + return deal, nil +} + func (m *MarketNodeImpl) MarketGetDealUpdates(ctx context.Context) (<-chan types.MinerDeal, error) { results := make(chan types.MinerDeal) unsub := m.StorageProvider.SubscribeToEvents(func(evt storagemarket.ProviderEvent, deal *types.MinerDeal) { diff --git a/cli/retrieval-deals.go b/cli/retrieval-deals.go index a0207374..a3c8bdfe 100644 --- a/cli/retrieval-deals.go +++ b/cli/retrieval-deals.go @@ -3,9 +3,13 @@ package cli import ( "fmt" "os" + "strconv" "text/tabwriter" + "time" "github.com/filecoin-project/go-fil-markets/retrievalmarket" + "github.com/filecoin-project/venus/venus-shared/types/market" + "github.com/libp2p/go-libp2p/core/peer" "github.com/urfave/cli/v2" ) @@ -24,6 +28,7 @@ var retrievalDealsCmds = &cli.Command{ Usage: "Manage retrieval deals and related configuration", Subcommands: []*cli.Command{ retrievalDealsListCmd, + getRetrievalDealCmd, }, } @@ -65,3 +70,81 @@ var retrievalDealsListCmd = &cli.Command{ return w.Flush() }, } + +var getRetrievalDealCmd = &cli.Command{ + Name: "get", + Usage: "Print a retrieval deal", + ArgsUsage: " ", + Action: func(cliCtx *cli.Context) error { + api, closer, err := NewMarketNode(cliCtx) + if err != nil { + return err + } + defer closer() + + if cliCtx.NArg() != 2 { + return fmt.Errorf("expected 2 arguments") + } + + receiver, err := peer.Decode(cliCtx.Args().First()) + if err != nil { + return err + } + dealID, err := strconv.ParseUint(cliCtx.Args().Get(1), 10, 64) + if err != nil { + return err + } + + ctx := ReqContext(cliCtx) + deal, err := api.MarketGetRetrievalDeal(ctx, receiver, dealID) + if err != nil { + return err + } + + return outputRetrievalDeal(deal) + }, +} + +func outputRetrievalDeal(deal *market.ProviderDealState) error { + var channelID, pieceCID string + var raw []byte + if deal.ChannelID != nil { + channelID = deal.ChannelID.String() + } + if deal.PieceCID != nil { + pieceCID = deal.PieceCID.String() + } + if deal.Selector != nil { + raw = deal.Selector.Raw + } + data := []kv{ + {"Receiver", deal.Receiver}, + {"DealID", deal.ID}, + {"PayloadCID", deal.PayloadCID}, + {"Status", retrievalmarket.DealStatuses[deal.Status]}, + {"PricePerByte", deal.PricePerByte.String()}, + {"BytesSent", deal.TotalSent}, + {"Paid", deal.FundsReceived}, + {"Interval", deal.CurrentInterval}, + {"Message", deal.Message}, + {"ChannelID", channelID}, + {"StoreID", deal.StoreID}, + {"SelStorageProposalCid", deal.SelStorageProposalCid}, + {"PieceCID", pieceCID}, + {"PaymentIntervalIncrease", deal.PaymentIntervalIncrease}, + {"UnsealPrice", deal.UnsealPrice}, + {"Selector", raw}, + {"CreatedAt", time.Unix(int64(deal.CreatedAt), 0).Format(time.RFC3339)}, + {"UpdatedAt", time.Unix(int64(deal.UpdatedAt), 0).Format(time.RFC3339)}, + } + + maxLen := len("PaymentIntervalIncrease") + for _, d := range data { + for i := len(d.k); i < maxLen; i++ { + d.k += " " + } + fmt.Println(d.k, d.v) + } + + return nil +} diff --git a/cli/storage-deals.go b/cli/storage-deals.go index 73368ea6..d3a72b05 100644 --- a/cli/storage-deals.go +++ b/cli/storage-deals.go @@ -45,6 +45,7 @@ var storageDealsCmds = &cli.Command{ dealsListCmd, updateStorageDealStateCmd, dealsPendingPublish, + getDealCmd, }, } @@ -362,6 +363,37 @@ var dealsPendingPublish = &cli.Command{ }, } +var getDealCmd = &cli.Command{ + Name: "get", + Usage: "Print a storage deal", + ArgsUsage: "", + Action: func(cliCtx *cli.Context) error { + if cliCtx.NArg() != 1 { + return fmt.Errorf("expected 1 arguments") + } + + api, closer, err := NewMarketNode(cliCtx) + if err != nil { + return err + } + defer closer() + + proposalCid, err := cid.Decode(cliCtx.Args().First()) + if err != nil { + return err + } + + ctx := ReqContext(cliCtx) + + deal, err := api.MarketGetDeal(ctx, proposalCid) + if err != nil { + return err + } + + return outputStorageDeal(deal) + }, +} + func outputStorageDeals(out io.Writer, deals []market.MinerDeal, verbose bool) error { sort.Slice(deals, func(i, j int) bool { return deals[i].CreationTime.Time().Before(deals[j].CreationTime.Time()) @@ -416,3 +448,76 @@ func outputStorageDeals(out io.Writer, deals []market.MinerDeal, verbose bool) e return w.Flush() } + +type kv struct { + k string + v interface{} +} + +func outputStorageDeal(deal *market.MinerDeal) error { + var err error + var transferChannelID, label, addFundsCid, publishCid string + + if deal.TransferChannelID != nil { + transferChannelID = deal.TransferChannelID.String() + } + label, err = deal.Proposal.Label.ToString() + if err != nil { + return err + } + if deal.AddFundsCid != nil { + addFundsCid = deal.AddFundsCid.String() + } + if deal.PublishCid != nil { + publishCid = deal.PublishCid.String() + } + fil := types.FIL(types.BigMul(deal.Proposal.StoragePricePerEpoch, types.NewInt(uint64(deal.Proposal.Duration())))) + + data := []kv{ + {"Creation", deal.CreationTime.Time().Format(time.RFC3339)}, + {"State", storagemarket.DealStates[deal.State]}, + {"VerifiedDeal", deal.Proposal.VerifiedDeal}, + {"DealID", deal.DealID}, + {"PieceCID", deal.Proposal.PieceCID}, + {"PieceStatus", deal.PieceStatus}, + {"Provider", deal.Proposal.Provider}, + {"PieceSize", units.BytesSize(float64(deal.Proposal.PieceSize))}, + {"Price", fil}, + {"Duration", deal.Proposal.Duration()}, + {"Offset", deal.Offset}, + {"Client", deal.Proposal.Client}, + {"TransferID", transferChannelID}, + {"AddFundsCid", addFundsCid}, + {"PublishCid", publishCid}, + {"Message", deal.Message}, + {"TransferType", deal.Ref.TransferType}, + {"PayloadCID", deal.Ref.Root}, + {"PayloadSize", deal.PayloadSize}, + {"StartEpoch", deal.Proposal.StartEpoch}, + {"EndEpoch", deal.Proposal.EndEpoch}, + {"SlashEpoch", deal.SlashEpoch}, + {"StoragePricePerEpoch", deal.Proposal.StoragePricePerEpoch}, + {"ProviderCollateral", deal.Proposal.ProviderCollateral}, + {"ClientCollateral", deal.Proposal.ClientCollateral}, + {"Label", label}, + {"MinerPeerID", deal.Miner.Pretty()}, + {"ClientPeerID", deal.Client.Pretty()}, + {"FundsReserved", deal.FundsReserved}, + {"AvailableForRetrieval", deal.AvailableForRetrieval}, + {"SectorNumber", deal.SectorNumber}, + {"PiecePath", deal.PiecePath}, + {"MetadataPath", deal.MetadataPath}, + {"FastRetrieval", deal.FastRetrieval}, + {"InboundCAR", deal.InboundCAR}, + {"UpdatedAt", time.Unix(int64(deal.UpdatedAt), 0).Format(time.RFC3339)}, + } + maxLen := len("AvailableForRetrieval") + for _, d := range data { + for i := len(d.k); i < maxLen; i++ { + d.k += " " + } + fmt.Println(d.k, d.v) + } + + return nil +} diff --git a/go.mod b/go.mod index 7f386f60..f399738a 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.10.2-0.20230309014040-73746cec80e4 + github.com/filecoin-project/venus v1.10.2-0.20230316084941-2180049a244b github.com/filecoin-project/venus-auth v1.10.2-0.20230308100319-913815325d5e github.com/filecoin-project/venus-messager v1.10.2-0.20230309071456-7cd8d49c6e9a github.com/golang/mock v1.6.0 @@ -82,7 +82,7 @@ require ( github.com/whyrusleeping/multiaddr-filter v0.0.0-20160516205228-e903e4adabd7 go.mongodb.org/mongo-driver v1.8.4 go.opencensus.io v0.23.0 - go.uber.org/fx v1.15.0 + go.uber.org/fx v1.17.1 go.uber.org/multierr v1.8.0 golang.org/x/sync v0.0.0-20220907140024-f12130a52804 golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 @@ -289,7 +289,7 @@ require ( go.opentelemetry.io/otel v1.10.0 // indirect go.opentelemetry.io/otel/trace v1.10.0 // indirect go.uber.org/atomic v1.10.0 // indirect - go.uber.org/dig v1.12.0 // indirect + go.uber.org/dig v1.14.1 // indirect go.uber.org/zap v1.23.0 // indirect go4.org v0.0.0-20200411211856-f5505b9728dd // indirect golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect diff --git a/go.sum b/go.sum index 1aac63ea..57d9b509 100644 --- a/go.sum +++ b/go.sum @@ -463,8 +463,8 @@ github.com/filecoin-project/storetheindex v0.4.30-0.20221114113647-683091f8e893 github.com/filecoin-project/storetheindex v0.4.30-0.20221114113647-683091f8e893/go.mod h1:S7590oDimBvXMUtzWsBXoshu9HtYKwtXl47zAK9rcP8= github.com/filecoin-project/test-vectors/schema v0.0.5/go.mod h1:iQ9QXLpYWL3m7warwvK1JC/pTri8mnfEmKygNDqqY6E= github.com/filecoin-project/venus v1.2.4/go.mod h1:hJULXHGAnWuq5S5KRtPkwbT8DqgM9II7NwyNU7t59D0= -github.com/filecoin-project/venus v1.10.2-0.20230309014040-73746cec80e4 h1:yLcesIYnlrkLc9dVgIfMtNu11+sF5jeQP1ykTOhjCDg= -github.com/filecoin-project/venus v1.10.2-0.20230309014040-73746cec80e4/go.mod h1:d6XlyUBZd+SHydYimTTkUr3O5rjYOHQTsydI4Nxy6U8= +github.com/filecoin-project/venus v1.10.2-0.20230316084941-2180049a244b h1:T0TIlKIFsOvOKDIADN4P7xBC+coJ7YlbUqift11TCIE= +github.com/filecoin-project/venus v1.10.2-0.20230316084941-2180049a244b/go.mod h1:d6XlyUBZd+SHydYimTTkUr3O5rjYOHQTsydI4Nxy6U8= github.com/filecoin-project/venus-auth v1.3.2/go.mod h1:m5Jog2GYxztwP7w3m/iJdv/V1/bTcAVU9rm/CbhxRQU= github.com/filecoin-project/venus-auth v1.10.2-0.20230308100319-913815325d5e h1:Bxpt1AzPeNxmUnFT2Y8rpabr9x0wIC0Q87DeRmjL2co= github.com/filecoin-project/venus-auth v1.10.2-0.20230308100319-913815325d5e/go.mod h1:aBfIfNxQkdcY8Rk5wrQn9qRtJpH4RTDdc10Ac+ferzs= @@ -2275,10 +2275,12 @@ go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ= go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= -go.uber.org/dig v1.12.0 h1:l1GQeZpEbss0/M4l/ZotuBndCrkMdjnygzgcuOjAdaY= go.uber.org/dig v1.12.0/go.mod h1:X34SnWGr8Fyla9zQNO2GSO2D+TIuqB14OS8JhYocIyw= -go.uber.org/fx v1.15.0 h1:kcfBpAm98n0ksanyyZLFE/Q3T7yPi13Ge2liu3TxR+A= +go.uber.org/dig v1.14.1 h1:fyakRgZDdi2F8FgwJJoRGangMSPTIxPSLGzR3Oh0/54= +go.uber.org/dig v1.14.1/go.mod h1:52EKx/Vjdpz9EzeNcweC4YMsTrDdFn9mS/+Uw5ZnVTI= go.uber.org/fx v1.15.0/go.mod h1:jI3RazQUhGv5KkpZIRv+kuP4CcgX3fnc0qX8bLnzbx8= +go.uber.org/fx v1.17.1 h1:S42dZ6Pok8hQ3jxKwo6ZMYcCgHQA/wAS/gnpRa1Pksg= +go.uber.org/fx v1.17.1/go.mod h1:yO7KN5rhlARljyo4LR047AjaV6J+KFzd/Z7rnTbEn0A= go.uber.org/goleak v1.0.0/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A= go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A= go.uber.org/goleak v1.1.11-0.20210813005559-691160354723/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= @@ -2403,7 +2405,6 @@ golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRu golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= -golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 h1:VLliZ0d+/avPrXXH+OakdXhpJuEoBZuwh1m2j7U6Iug= golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=