Merge pull request #1367 from filecoin-project/feat/chainget-hamtaddr

chain get: hamt-address type
This commit is contained in:
Whyrusleeping 2020-03-09 00:05:32 -07:00 committed by GitHub
commit e6ba4a227a

View File

@ -12,6 +12,7 @@ import (
"time"
"github.com/docker/go-units"
"github.com/filecoin-project/go-address"
cborutil "github.com/filecoin-project/go-cbor-util"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/builtin"
@ -462,6 +463,8 @@ var chainGetCmd = &cli.Command{
return handleAmt(ctx, api, obj.Cid)
case "hamt-epoch":
return handleHamtEpoch(ctx, api, obj.Cid)
case "hamt-address":
return handleHamtAddress(ctx, api, obj.Cid)
case "cronevent":
cbu = new(power.CronEvent)
default:
@ -539,6 +542,20 @@ func handleHamtEpoch(ctx context.Context, api api.FullNode, r cid.Cid) error {
})
}
func handleHamtAddress(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 {
addr, err := address.NewFromBytes([]byte(key))
if err != nil {
return err
}
fmt.Printf("%s\n", addr)
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))