chain get: @Hu: for uvaring hamt keys

This commit is contained in:
Łukasz Magiera 2020-04-04 03:49:42 +02:00
parent 4d92798f5b
commit 9a7aa3fc87
2 changed files with 13 additions and 0 deletions

View File

@ -433,6 +433,8 @@ var chainGetCmd = &cli.Command{
Note:
You can use special path elements to traverse through some data structures:
- /ipfs/[cid]/@H:elem - get 'elem' from hamt
- /ipfs/[cid]/@Hi:123 - get varint elem 123 from hamt
- /ipfs/[cid]/@Hu:123 - get uvarint elem 123 from hamt
- /ipfs/[cid]/@Ha:t01 - get element under Addr(t01).Bytes
- /ipfs/[cid]/@A:10 - get 10th amt element
`,

View File

@ -285,6 +285,17 @@ func resolveOnce(bs blockstore.Blockstore) func(ctx context.Context, ds ipld.Nod
names[0] = "@H:" + ik.Key()
}
if strings.HasPrefix(names[0], "@Hu:") {
i, err := strconv.ParseUint(names[0][4:], 10, 64)
if err != nil {
return nil, nil, xerrors.Errorf("parsing int64: %w", err)
}
ik := adt.UIntKey(i)
names[0] = "@H:" + ik.Key()
}
if strings.HasPrefix(names[0], "@H:") {
cst := cbor.NewCborStore(bs)