Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

ipld.get() should never give the direct result of resolver.util.deserialize() #142

Closed
Mr0grog opened this issue Aug 8, 2018 · 1 comment

Comments

@Mr0grog
Copy link

Mr0grog commented Aug 8, 2018

Calling ipld.get() should never result in the direct, deserialized value from a resolver’s util.deserialize() function. It should instead result in the equivalent of resolving the path / if no path is provided.

Right now, we explicitly return the result of resolver.util.deserialize(rawBlockData) if no path is specified:

js-ipld/src/index.js

Lines 138 to 148 in c81882e

if (path === '' || !path) {
return this._get(cid, (err, node) => {
if (err) {
return callback(err)
}
callback(null, {
value: node,
remainderPath: ''
})
})
}

(where ipld._get(cid) is just a wrapper for getResolverForCid(cid).util.deserialize(rawData))

Instead, we should always call resolver.resolver.resolve(rawBlockData, path) as part of ipld.get(), and the path we pass to the resolver should be / if no path was specified as an argument to ipld.get().

This is because get() should always return an object where the keys reflect paths that could be resolved — i.e. the IPLD focused concept of the DAG node, not some other underlying representation, like a BitcoinjsBlock from the Bitcoin library, for example. See the discussion in #141 for more about this.

@vmx
Copy link
Member

vmx commented May 8, 2019

With version 0.23 that's the case now. Though get() might have additional methods attached. This means that get() possible returns a superset of resolve('/') (or the same).

@vmx vmx closed this as completed May 8, 2019
@ghost ghost removed the status/ready Ready to be worked label May 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants