88 lcli "github.com/filecoin-project/lotus/cli"
99 "github.com/google/uuid"
1010 "github.com/ipfs/go-cid"
11+ "github.com/multiformats/go-multihash"
1112 "github.com/urfave/cli/v2"
1213)
1314
@@ -45,16 +46,11 @@ var indexProvAnnounceAllCmd = &cli.Command{
4546
4647var indexProvListMultihashesCmd = & cli.Command {
4748 Name : "list-multihashes" ,
48- Usage : "list-multihashes <proposal cid>" ,
49- UsageText : "List multihashes for a deal by proposal cid" ,
49+ Usage : "list-multihashes <proposal cid / deal UUID >" ,
50+ UsageText : "List multihashes for a deal by proposal cid or deal UUID " ,
5051 Action : func (cctx * cli.Context ) error {
5152 if cctx .NArg () != 1 {
52- return fmt .Errorf ("must supply proposal cid" )
53- }
54-
55- propCid , err := cid .Parse (cctx .Args ().First ())
56- if err != nil {
57- return fmt .Errorf ("parsing proposal cid %s: %w" , cctx .Args ().First (), err )
53+ return fmt .Errorf ("must supply a proposal cid or deal UUID" )
5854 }
5955
6056 ctx := lcli .ReqContext (cctx )
@@ -66,13 +62,46 @@ var indexProvListMultihashesCmd = &cli.Command{
6662 }
6763 defer closer ()
6864
69- // get list of multihashes
70- mhs , err := napi .BoostIndexerListMultihashes (ctx , propCid )
65+ if cctx .Args ().Len () != 1 {
66+ return fmt .Errorf ("must specify only one proposal CID / deal UUID" )
67+ }
68+
69+ id := cctx .Args ().Get (0 )
70+
71+ var proposalCid cid.Cid
72+ var mhs []multihash.Multihash
73+ dealUuid , err := uuid .Parse (id )
74+ if err != nil {
75+ propCid , err := cid .Decode (id )
76+ if err != nil {
77+ return fmt .Errorf ("could not parse '%s' as deal uuid or proposal cid" , id )
78+ }
79+ proposalCid = propCid
80+ }
81+
82+ if ! proposalCid .Defined () {
83+ contextID , err := dealUuid .MarshalBinary ()
84+ if err != nil {
85+ return fmt .Errorf ("parsing UUID to bytes: %w" , err )
86+ }
87+ mhs , err = napi .BoostIndexerListMultihashes (ctx , contextID )
88+ if err != nil {
89+ return err
90+ }
91+ fmt .Printf ("Found %d multihashes for deal with ID %s:\n " , len (mhs ), id )
92+ for _ , mh := range mhs {
93+ fmt .Println (" " + mh .String ())
94+ }
95+
96+ return nil
97+ }
98+
99+ mhs , err = napi .BoostIndexerListMultihashes (ctx , proposalCid .Bytes ())
71100 if err != nil {
72101 return err
73102 }
74103
75- fmt .Printf ("Found %d multihashes for deal with proposal cid %s:\n " , len (mhs ), propCid )
104+ fmt .Printf ("Found %d multihashes for deal with ID %s:\n " , len (mhs ), id )
76105 for _ , mh := range mhs {
77106 fmt .Println (" " + mh .String ())
78107 }
0 commit comments