Skip to content

Commit

Permalink
fix: some validation for filecoin deal info
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Shaw committed Nov 15, 2023
1 parent 052e85d commit c43c0a7
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
41 changes: 40 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@ipld/dag-json": "^10.1.5",
"@ucanto/validator": "^9.0.0",
"@web3-storage/access": "^17.1.0",
"@web3-storage/data-segment": "^5.0.0",
"@web3-storage/w3up-client": "^11.0.0",
"adventure": "^2.11.1",
"execa": "^8.0.1",
Expand Down
28 changes: 28 additions & 0 deletions problems/7-commp/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,38 @@ export const verify = (args, cb) => {
return console.error(`Failed to parse deal info: ${err.message}`)
}

if (!info.piece) {
cb(false)
return console.error(`Invalid deal info: missing piece`)
}
if (!Array.isArray(info.deals)) {
cb(false)
return console.error(`Invalid deal info: non-array deals`)
}

console.log(`\n Piece: ${info.piece}\n`)
for (const deal of info.deals) {
if (!deal || typeof deal !== 'object') {
cb(false)
return console.error(`Invalid deal info: non-object deal`)
}

if (!deal.provider) {
cb(false)
return console.error(`Invalid deal info: missing provider`)
}
console.log(`Storage Provider: f0${deal.provider}`)

if (!deal.aggregate) {
cb(false)
return console.error(`Invalid deal info: missing aggregate CID`)
}
console.log(` Aggregate: ${deal.aggregate}`)

if (!deal.aux?.dataSource?.dealID) {
cb(false)
return console.error(`Invalid deal info: missing deal ID`)
}
console.log(` Deal ID: ${deal.aux.dataSource.dealID}\n`)
}

Expand Down

0 comments on commit c43c0a7

Please sign in to comment.