get-first-content-id.js 838 B

1234567891011121314151617181920212223242526272829
  1. /* global api, hashing, keyring, types, util, joy */
  2. // run this script with:
  3. // yarn workspace api-scripts script get-first-content-id
  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. const acceptedEntries = entries.filter(([, dataObject]) => dataObject.liaison_judgement.type === 'Accepted')
  11. if (acceptedEntries.length) {
  12. const [
  13. {
  14. args: [id],
  15. },
  16. ] = acceptedEntries[0]
  17. console.log(`${api.createType('ContentId', id).encode()}`)
  18. }
  19. }
  20. if (typeof module === 'undefined') {
  21. // Pioneer js-toolbox
  22. script({ api, hashing, keyring, types, util, joy })
  23. } else {
  24. // Node
  25. module.exports = script
  26. }