-
Notifications
You must be signed in to change notification settings - Fork 6
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!: attach ipld view instead of single block #303
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -228,18 +228,20 @@ export class Delegation { | |
return data | ||
} | ||
/** | ||
* Attach a block to the delegation DAG so it would be included in the | ||
* block iterator. | ||
* Attach blocks from IPLD view to the delegation DAG so it would be included | ||
* in the block iterator. | ||
* ⚠️ You can only attach blocks that are referenced from the `capabilities` | ||
* or `facts`. | ||
* | ||
* @param {API.Block} block | ||
* @param {API.IPLDView} view | ||
*/ | ||
attach(block) { | ||
if (!this.attachedLinks.has(`${block.cid.link()}`)) { | ||
throw new Error(`given block with ${block.cid} is not an attached link`) | ||
attach(view) { | ||
for (const block of view.iterateIPLDBlocks()) { | ||
if (!this.attachedLinks.has(`${block.cid.link()}`)) { | ||
throw new Error(`given block with ${block.cid} is not an attached link`) | ||
} | ||
this.blocks.set(`${block.cid}`, block) | ||
} | ||
this.blocks.set(`${block.cid}`, block) | ||
} | ||
export() { | ||
return exportDAG(this.root, this.blocks, this.attachedLinks) | ||
|
@@ -407,9 +409,11 @@ export const delegate = async ( | |
const delegation = new Delegation({ cid, bytes }, blocks) | ||
Object.defineProperties(delegation, { proofs: { value: proofs } }) | ||
|
||
for (const block of attachedBlocks.values()) { | ||
delegation.attach(block) | ||
} | ||
const attached = Array.from(attachedBlocks.values()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I find this very confusing, can we have for (const view of attachments) {
delegation.attach(view)
} |
||
attached.length && delegation.attach({ | ||
iterateIPLDBlocks: () => attachedBlocks.values(), | ||
root: attached[0] | ||
}) | ||
|
||
return delegation | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,16 +87,17 @@ class IssuedInvocation { | |
} | ||
|
||
/** | ||
* Attach a block to the invocation DAG so it would be included in the | ||
* block iterator. | ||
* Attach block from IPLD View to the invocation DAG so it would be included | ||
* in the block iterator. | ||
* ⚠️ You should only attach blocks that are referenced from the `capabilities` | ||
* or `facts`, if that is not the case you probably should reconsider. | ||
* ⚠️ Once a delegation is de-serialized the attached blocks will not be re-attached. | ||
* or `facts`. | ||
* | ||
* @param {API.Block} block | ||
* @param {API.IPLDView} view | ||
*/ | ||
attach(block) { | ||
this.attachedBlocks.set(`${block.cid}`, block) | ||
attach(view) { | ||
for (const block of view.iterateIPLDBlocks()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be a lot cleaner if we stick blocks into |
||
this.attachedBlocks.set(`${block.cid}`, block) | ||
} | ||
} | ||
|
||
delegate() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think should only require that root is listed in the attachments, all the other blocks will be linked somewhere from that root.