Merge pull request #1559 from filecoin-project/fix/commp-convert-cmd
parse input as hex
This commit is contained in:
commit
bb7bb2600a
@ -1,7 +1,9 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
commcid "github.com/filecoin-project/go-fil-commcid"
|
commcid "github.com/filecoin-project/go-fil-commcid"
|
||||||
"gopkg.in/urfave/cli.v2"
|
"gopkg.in/urfave/cli.v2"
|
||||||
)
|
)
|
||||||
@ -10,8 +12,16 @@ var commpToCidCmd = &cli.Command{
|
|||||||
Name: "commp-to-cid",
|
Name: "commp-to-cid",
|
||||||
Description: "Convert a raw commP to a piece-Cid",
|
Description: "Convert a raw commP to a piece-Cid",
|
||||||
Action: func(cctx *cli.Context) error {
|
Action: func(cctx *cli.Context) error {
|
||||||
cp := []byte(cctx.Args().Get(0))
|
if !cctx.Args().Present() {
|
||||||
fmt.Println(commcid.PieceCommitmentV1ToCID(cp))
|
return fmt.Errorf("must specify commP to convert")
|
||||||
|
}
|
||||||
|
|
||||||
|
dec, err := hex.DecodeString(cctx.Args().First())
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to decode input as hex string: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(commcid.PieceCommitmentV1ToCID(dec))
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user