list-data-directory.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /* global api, hashing, keyring, types, util, joy */
  2. // run this script with:
  3. // yarn workspace api-scripts script list-data-directory
  4. //
  5. // or copy and paste the code into the pioneer javascript toolbox at:
  6. // https://testnet.joystream.org/#/js
  7. // requires nicaea release+
  8. const script = async ({ api }) => {
  9. const entries = await api.query.dataDirectory.dataByContentId.entries()
  10. console.error(`Data Directory contains ${entries.length} objects`)
  11. const acceptedEntries = entries.filter(([, dataObject]) => dataObject.liaison_judgement.type === 'Accepted')
  12. acceptedEntries.forEach(
  13. ([
  14. {
  15. args: [id],
  16. },
  17. obj,
  18. ]) => {
  19. console.log(`contentId: ${api.createType('ContentId', id).encode()}, ipfs: ${obj.ipfs_content_id}`)
  20. }
  21. )
  22. console.error(`Data Directory contains ${acceptedEntries.length} Accepted objects`)
  23. }
  24. if (typeof module === 'undefined') {
  25. // Pioneer js-toolbox
  26. script({ api, hashing, keyring, types, util, joy })
  27. } else {
  28. // Node
  29. module.exports = script
  30. }