Browse Source

add script to get content-dir classes(id,name) from the chain

metmirr 4 years ago
parent
commit
99aca3000b
2 changed files with 23 additions and 1 deletions
  1. 2 1
      query-node/package.json
  2. 21 0
      query-node/scripts/get-class-id-and-name.ts

+ 2 - 1
query-node/package.json

@@ -21,7 +21,8 @@
 		"codegen:server": "hydra-cli codegen --no-indexer",
 		"docker:indexer:build": "docker build -t hydra-indexer -f docker/Dockerfile.indexer .",
 		"docker:server:build": "docker build -t hydra-graphql-server -f docker/Dockerfile.server .",
-		"docker:up": "docker-compose up -d"
+		"docker:up": "docker-compose up -d",
+		"cd-classes": "ts-node scripts/get-class-id-and-name.ts"
 	},
 	"author": "",
 	"license": "ISC",

+ 21 - 0
query-node/scripts/get-class-id-and-name.ts

@@ -0,0 +1,21 @@
+import { ApiPromise, WsProvider } from '@polkadot/api'
+import { types as joyTypes } from '@joystream/types'
+import * as BN from 'bn.js'
+
+async function main() {
+  // Initialize the api
+  const provider = new WsProvider('ws://127.0.0.1:9944')
+  const api = await ApiPromise.create({ provider, types: joyTypes })
+
+  const n = await api.query.contentDirectory.nextClassId()
+  const nextClassId = new BN(n.toJSON() as string).toNumber()
+  for (let id = 0; id < nextClassId; id++) {
+    const cls = await api.query.contentDirectory.classById(new BN(id))
+    const { name } = cls.toJSON() as never
+    console.log(id, name)
+  }
+}
+
+main()
+  .then(() => process.exit())
+  .catch(console.error)