Merge pull request #1483 from filecoin-project/feat/chain-get-pstate

chain get: /pstate prefix
This commit is contained in:
Whyrusleeping 2020-03-31 17:13:41 -07:00 committed by GitHub
commit 12f288016d

View File

@ -7,6 +7,7 @@ import (
"fmt" "fmt"
"os" "os"
"os/exec" "os/exec"
"path"
"strconv" "strconv"
"strings" "strings"
"time" "time"
@ -415,11 +416,19 @@ var chainGetCmd = &cli.Command{
Name: "as-type", Name: "as-type",
Usage: "specify type to interpret output as", Usage: "specify type to interpret output as",
}, },
&cli.BoolFlag{
Name: "verbose",
Value: false,
},
}, },
Description: `Get ipld node under a specified path: Description: `Get ipld node under a specified path:
lotus chain get /ipfs/[cid]/some/path lotus chain get /ipfs/[cid]/some/path
Path prefixes:
- /ipfs/[cid], /ipld/[cid] - traverse IPLD path
- /pstate - traverse from head.ParentStateRoot
Note: Note:
You can use special path elements to traverse through some data structures: You can use special path elements to traverse through some data structures:
- /ipfs/[cid]/@H:elem - get 'elem' from hamt - /ipfs/[cid]/@H:elem - get 'elem' from hamt
@ -434,7 +443,20 @@ var chainGetCmd = &cli.Command{
defer closer() defer closer()
ctx := ReqContext(cctx) ctx := ReqContext(cctx)
obj, err := api.ChainGetNode(ctx, cctx.Args().First()) p := path.Clean(cctx.Args().First())
if strings.HasPrefix(p, "/pstate") {
p = p[len("/pstate"):]
head, err := api.ChainHead(ctx)
if err != nil {
return err
}
p = "/ipfs/" + head.ParentState().String() + p
if cctx.Bool("verbose") {
fmt.Println(p)
}
}
obj, err := api.ChainGetNode(ctx, p)
if err != nil { if err != nil {
return err return err
} }