Add more chain get types
This commit is contained in:
parent
85f01e4ded
commit
9216a1eb07
60
cli/chain.go
60
cli/chain.go
@ -16,6 +16,7 @@ import (
|
||||
"github.com/filecoin-project/specs-actors/actors/abi"
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin"
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin/power"
|
||||
"github.com/filecoin-project/specs-actors/actors/util/adt"
|
||||
cid "github.com/ipfs/go-cid"
|
||||
cbg "github.com/whyrusleeping/cbor-gen"
|
||||
"golang.org/x/xerrors"
|
||||
@ -457,6 +458,12 @@ var chainGetCmd = &cli.Command{
|
||||
cbu = new(types.SignedMessage)
|
||||
case "actor":
|
||||
cbu = new(types.Actor)
|
||||
case "amt":
|
||||
return handleAmt(ctx, api, obj.Cid)
|
||||
case "hamt-epoch":
|
||||
return handleHamtEpoch(ctx, api, obj.Cid)
|
||||
case "cronevent":
|
||||
cbu = new(power.CronEvent)
|
||||
default:
|
||||
return fmt.Errorf("unknown type: %q", t)
|
||||
}
|
||||
@ -479,6 +486,59 @@ var chainGetCmd = &cli.Command{
|
||||
},
|
||||
}
|
||||
|
||||
type apiIpldStore struct {
|
||||
ctx context.Context
|
||||
api api.FullNode
|
||||
}
|
||||
|
||||
func (ht *apiIpldStore) Context() context.Context {
|
||||
return ht.ctx
|
||||
}
|
||||
|
||||
func (ht *apiIpldStore) Get(ctx context.Context, c cid.Cid, out interface{}) error {
|
||||
raw, err := ht.api.ChainReadObj(ctx, c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cu, ok := out.(cbg.CBORUnmarshaler)
|
||||
if ok {
|
||||
if err := cu.UnmarshalCBOR(bytes.NewReader(raw)); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
return fmt.Errorf("Object does not implement CBORUnmarshaler")
|
||||
}
|
||||
|
||||
func (ht *apiIpldStore) Put(ctx context.Context, v interface{}) (cid.Cid, error) {
|
||||
panic("No mutations allowed")
|
||||
}
|
||||
|
||||
func handleAmt(ctx context.Context, api api.FullNode, r cid.Cid) error {
|
||||
s := &apiIpldStore{ctx, api}
|
||||
mp := adt.AsArray(s, r)
|
||||
return mp.ForEach(nil, func(key int64) error {
|
||||
fmt.Printf("%d\n", key)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func handleHamtEpoch(ctx context.Context, api api.FullNode, r cid.Cid) error {
|
||||
s := &apiIpldStore{ctx, api}
|
||||
mp := adt.AsMap(s, r)
|
||||
return mp.ForEach(nil, func(key string) error {
|
||||
ik, err := adt.ParseIntKey(key)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("%d\n", ik)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func printTipSet(format string, ts *types.TipSet) {
|
||||
format = strings.ReplaceAll(format, "<height>", fmt.Sprint(ts.Height()))
|
||||
format = strings.ReplaceAll(format, "<time>", time.Unix(int64(ts.MinTimestamp()), 0).Format(time.Stamp))
|
||||
|
@ -12,6 +12,7 @@ import (
|
||||
commcid "github.com/filecoin-project/go-fil-commcid"
|
||||
"github.com/filecoin-project/specs-actors/actors/abi"
|
||||
"github.com/filecoin-project/specs-actors/actors/crypto"
|
||||
"github.com/filecoin-project/specs-actors/actors/util/adt"
|
||||
"github.com/ipfs/go-blockservice"
|
||||
"github.com/ipfs/go-cid"
|
||||
"github.com/ipfs/go-hamt-ipld"
|
||||
@ -271,6 +272,17 @@ func resolveOnce(bs blockstore.Blockstore) func(ctx context.Context, ds ipld.Nod
|
||||
names[0] = "@H:" + string(addr.Bytes())
|
||||
}
|
||||
|
||||
if strings.HasPrefix(names[0], "@Hi:") {
|
||||
i, err := strconv.ParseInt(names[0][4:], 10, 64)
|
||||
if err != nil {
|
||||
return nil, nil, xerrors.Errorf("parsing int64: %w", err)
|
||||
}
|
||||
|
||||
ik := adt.IntKey(i)
|
||||
|
||||
names[0] = "@H:" + ik.Key()
|
||||
}
|
||||
|
||||
if strings.HasPrefix(names[0], "@H:") {
|
||||
cst := cbor.NewCborStore(bs)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user