Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: list links of a block that _is a_ CID #226

Merged
merged 2 commits into from
Jan 2, 2023

Conversation

alanshaw
Copy link
Member

@alanshaw alanshaw commented Dec 5, 2022

If a block is a CID, it is not listed by the block .links() method. This PR fixes that.

For example, this is a block that is a CID:

$ echo '{ "/": "bafyreihlhgo2srya7ihdyc5ae76rki47irecf4thjfjhsmrjyeurlyhbua" }' | ipfs dag put
bafyreiexxrljy6el4v7phukkux3ukhzuiuajsilzd63576oysy3vhll3ia

P.S. I also removed the npm run lint command from the test script since the no-only-tests rule was in the way of me being able to test my work. It is run in CI already. I can revert if anyone feels strongly in the opposite direction.


As an aside:

It looks like there's not really a way to path through these kind of blocks, at least not with go/js ipfs.

For example, here's a tree with node => CID node => node:

$ echo '{ "bar": "Hello World!" }' | ipfs dag put
bafyreihlhgo2srya7ihdyc5ae76rki47irecf4thjfjhsmrjyeurlyhbua

$ echo '{ "/": "bafyreihlhgo2srya7ihdyc5ae76rki47irecf4thjfjhsmrjyeurlyhbua" }' | ipfs dag put
bafyreiexxrljy6el4v7phukkux3ukhzuiuajsilzd63576oysy3vhll3ia

$ echo '{ "foo": { "/": "bafyreiexxrljy6el4v7phukkux3ukhzuiuajsilzd63576oysy3vhll3ia" } }' | ipfs dag put
bafyreidb7fynlo5246wst4tyl3wucfoskujuuq4523srgc73c6xlvnah2i

You cannot path to "Hello World!" from bafyreidb7fynlo5246wst4tyl3wucfoskujuuq4523srgc73c6xlvnah2i:

$ ipfs dag get bafyreidb7fynlo5246wst4tyl3wucfoskujuuq4523srgc73c6xlvnah2i/foo
{"/":"bafyreihlhgo2srya7ihdyc5ae76rki47irecf4thjfjhsmrjyeurlyhbua"}

$ ipfs dag get bafyreidb7fynlo5246wst4tyl3wucfoskujuuq4523srgc73c6xlvnah2i/foo/bar
Error: func called on wrong kind: "LookupBySegment" called on a link node (kind: link), but only makes sense on map or list

$ ipfs dag get bafyreidb7fynlo5246wst4tyl3wucfoskujuuq4523srgc73c6xlvnah2i/foo//bar
Error: func called on wrong kind: "LookupBySegment" called on a link node (kind: link), but only makes sense on map or list

Similarly in js-ipfs:

$ ipfs dag get bafyreidb7fynlo5246wst4tyl3wucfoskujuuq4523srgc73c6xlvnah2i/foo/bar
dag get failed: Error: no link named "bar" under bafyreiexxrljy6el4v7phukkux3ukhzuiuajsilzd63576oysy3vhll3ia

refs ipld/ipld#250

Copy link
Contributor

@Gozala Gozala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, I’ll let @rvagg decide on lint change.

@rvagg rvagg self-assigned this Dec 6, 2022
package.json Outdated Show resolved Hide resolved
@rvagg rvagg merged commit c17673d into master Jan 2, 2023
@rvagg rvagg deleted the fix/links-of-block-that-is-a-cid branch January 2, 2023 06:06
github-actions bot pushed a commit that referenced this pull request Jan 2, 2023
## [11.0.0](v10.0.3...v11.0.0) (2023-01-02)

### ⚠ BREAKING CHANGES

* Make link.toJSON return a DAG-JSON link

### Features

* Make link.toJSON return a DAG-JSON link ([9e087d6](9e087d6))

### Bug Fixes

* build browser bundle ([2ee6012](2ee6012)), closes [#234](#234)
* list links of a block that _is a_ CID ([#226](#226)) ([c17673d](c17673d))

### Documentation

* fix typos in jsdoc comments ([a246054](a246054))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants