path.go
1 package rpc 2 3 import ( 4 "context" 5 6 "github.com/ipfs/boxo/path" 7 cid "github.com/ipfs/go-cid" 8 ipld "github.com/ipfs/go-ipld-format" 9 ) 10 11 func (api *HttpApi) ResolvePath(ctx context.Context, p path.Path) (path.ImmutablePath, []string, error) { 12 var out struct { 13 Cid cid.Cid 14 RemPath string 15 } 16 17 var err error 18 if p.Namespace() == path.IPNSNamespace { 19 if p, err = api.Name().Resolve(ctx, p.String()); err != nil { 20 return path.ImmutablePath{}, nil, err 21 } 22 } 23 24 if err := api.Request("dag/resolve", p.String()).Exec(ctx, &out); err != nil { 25 return path.ImmutablePath{}, nil, err 26 } 27 28 p, err = path.NewPathFromSegments(p.Namespace(), out.Cid.String(), out.RemPath) 29 if err != nil { 30 return path.ImmutablePath{}, nil, err 31 } 32 33 imPath, err := path.NewImmutablePath(p) 34 if err != nil { 35 return path.ImmutablePath{}, nil, err 36 } 37 38 return imPath, path.StringToSegments(out.RemPath), nil 39 } 40 41 func (api *HttpApi) ResolveNode(ctx context.Context, p path.Path) (ipld.Node, error) { 42 rp, _, err := api.ResolvePath(ctx, p) 43 if err != nil { 44 return nil, err 45 } 46 47 return api.Dag().Get(ctx, rp.RootCid()) 48 }