Prechádzať zdrojové kódy

Proposal 127, KPI 6.9: fixing community scripts

singulart 3 rokov pred
rodič
commit
4b9fc1980c

+ 29 - 7
joystream-api/README.md

@@ -24,9 +24,9 @@ Open the file ```node_modules/@joystream/types/content-working-group/index.d.ts`
 Save the changes and re-run ```yarn && yarn build``` again, the build should work fine. 
 
 
-### Scripts
+## Example Scripts
 
-#### general.js
+### [general.js](src/examples/general.ts)
 
 Ideal for newcomers. Contains the very basic APIs usage examples: get the last blockchain finalized block, get total coin issuance. 
 Also shows how to iterate the events inside a given block.
@@ -35,7 +35,15 @@ Also shows how to iterate the events inside a given block.
 node lib/examples/general.js
 ```
 
-#### get-media-change.js
+### [status.js](src/general/status.ts)
+
+Another good starting point for newcomers to understand how APIs are called.
+
+```
+node lib/general/status.js
+```
+
+### [get-media-change.js](src/curators/get-media-change.ts)
 
 Shows how to work with Substrate events and Extrinsics to get the information about Joystream media uploads. 
 
@@ -43,7 +51,7 @@ Shows how to work with Substrate events and Extrinsics to get the information ab
 node lib/curators/get-media-change.js
 ```
 
-#### council.js
+### [council.js](src/examples/council.ts)
 
 Shows how to use ```councilElection```, ```minting```, ```council``` APIs. 
 
@@ -51,7 +59,7 @@ Shows how to use ```councilElection```, ```minting```, ```council``` APIs.
 node lib/examples/council.js
 ```
 
-#### get-events-and-extrinsics.js
+### [get-events-and-extrinsics.js](src/examples/get-events-and-extrinsics.ts)
 
 Shows the variety of Substrate event Extrinsic types within a given range of blocks. 
 
@@ -59,7 +67,7 @@ Shows the variety of Substrate event Extrinsic types within a given range of blo
 node lib/examples/get-events-and-extrinsics.js
 ```
 
-#### working-groups.js
+### [working-groups.js](src/examples/working-groups.ts)
 
 Shows how to use a set of APIs related to Joystream working groups: ```storageWorkingGroup```, ```recurringRewards```, ```contentDirectoryWorkingGroup```. 
 
@@ -67,7 +75,7 @@ Shows how to use a set of APIs related to Joystream working groups: ```storageWo
 node lib/examples/working-groups.js
 ```
 
-#### proposals.js
+### [proposals.js](src/examples/proposals.ts)
 
 Shows how to use a APIs related to Joystream DAO proposals ```proposalsEngine```, ```staking```, ```members```. 
 
@@ -75,3 +83,17 @@ Shows how to use a APIs related to Joystream DAO proposals ```proposalsEngine```
 node lib/examples/proposals.js
 ```
 
+### Javascript scripts
+
+There are some untyped Javascript scripts available for working with the data directory. You can run them using yarn: 
+
+```
+//shows the available scripts
+yarn script index
+
+yarn script exportDataDirectory
+yarn script listDataDirectory
+
+```
+
+or execute them in [Pioneer JS Toolbox](https://testnet.joystream.org/#/js) 

+ 2 - 2
joystream-api/package.json

@@ -5,8 +5,8 @@
   "license": "MIT",
   "scripts": {
     "build": "tsc --build tsconfig.json",
-    "status": "node lib/status",
-    "script": "node lib/script",
+    "status": "node lib/general/status",
+    "script": "node lib/general/script",
     "postinstall": "yarn build"
   },
   "dependencies": {

+ 11 - 22
joystream-api/scripts/export-data-directory.js

@@ -7,32 +7,21 @@
 // https://testnet.joystream.org/#/js
 
 const script = async ({ api, hashing, keyring, types, util }) => {
-  const runtimeSpecVersion = api.runtimeVersion.specVersion
 
-  const ownerAccountToMemberId = async (accountId) => {
-    const memberIds = await api.query.members.memberIdsByRootAccountId(accountId)
-    return memberIds[0] || null
-  }
+  console.log('Getting information from data directory. This may take a while')
+  const dataDirObjects = await api.query.dataDirectory.dataByContentId.entries()
 
-  const ids = await api.query.dataDirectory.knownContentIds()
-
-  // When a BTreeMap is constructed for injection the node will fail to decode
-  // it if its not sorted.
-  ids.sort()
-
-  let transformed = await Promise.all(ids.map(async (id) => {
-    let obj = await api.query.dataDirectory.dataObjectByContentId(id)
+  let transformed = await Promise.all(dataDirObjects.map(async (obj) => {
     if (obj.isNone) { return null }
-    obj = obj.unwrap()
 
-    return [id, {
-      owner: runtimeSpecVersion <= 15 ? await ownerAccountToMemberId(obj.owner) : obj.owner,
-      added_at: obj.added_at,
-      type_id: obj.type_id,
-      size: obj.size_in_bytes,
-      liaison: runtimeSpecVersion <= 15 ? new types.u64(0) : obj.liaison,
-      liaison_judgement: obj.liaison_judgement,
-      ipfs_content_id: obj.ipfs_content_id }]
+    return [obj[0], {
+      owner: obj[1].owner,
+      added_at: obj[1].added_at,
+      type_id: obj[1].type_id,
+      size: obj[1].size,
+      liaison_judgement: obj[1].liaison,
+      liaison_judgement: obj[1].liaison_judgement,
+      ipfs_content_id: obj[1].ipfs_content_id }]
   }))
 
   console.log(JSON.stringify(transformed))

+ 0 - 1
joystream-api/scripts/index.js

@@ -4,7 +4,6 @@ const exportedScripts = {}
 
 exportedScripts.example = require('./example.js')
 exportedScripts.exportDataDirectory = require('./export-data-directory.js')
-exportedScripts.injectDataObjects = require('./inject-data-objects.js')
 exportedScripts.listDataDirectory = require('./list-data-directory.js')
 
 module.exports = exportedScripts

Rozdielové dáta súboru neboli zobrazené, pretože súbor je príliš veľký
+ 0 - 17
joystream-api/scripts/inject-data-objects.js


+ 5 - 6
joystream-api/scripts/list-data-directory.js

@@ -8,16 +8,15 @@
 // requires nicaea release+
 
 const script = async ({ api, joy }) => {
-  const ids = await api.query.dataDirectory.knownContentIds()
+  console.log('Getting information from data directory. This may take a while')
+  const dataDirObjects = await api.query.dataDirectory.dataByContentId.entries()
 
-  await Promise.all(ids.map(async (id) => {
-    let obj = await api.query.dataDirectory.dataObjectByContentId(id)
+  await Promise.all(dataDirObjects.map(async (obj) => {
     if (obj.isNone) { return }
-    obj = obj.unwrap()
-    console.log(`contentId: ${new joy.media.ContentId(id).encode()}, ipfs: ${obj.ipfs_content_id}`)
+    console.log(`contentId: ${obj[0]}, ipfs: ${obj[1].ipfs_content_id}`)
   }))
 
-  console.error(`Data Directory contains ${ids.length} objects`)
+  console.error(`Data Directory contains ${dataDirObjects.length} objects`)
 }
 
 if (typeof module === 'undefined') {

+ 2 - 1
joystream-api/src/general/script.ts

@@ -8,7 +8,7 @@ import * as joy from '@joystream/types'
 import * as hashing from '@polkadot/util-crypto'
 import { Keyring } from '@polkadot/keyring'
 
-const scripts = require('../scripts')
+const scripts = require('../../scripts')
 
 async function main () {
   
@@ -23,6 +23,7 @@ async function main () {
   }
 
   const provider = new WsProvider('ws://127.0.0.1:9944')
+  // const provider = new WsProvider('wss://testnet-rpc-2-singapore.joystream.org')
 
   const api = await ApiPromise.create({ provider, types: joyTypes })
 

Niektoré súbory nie sú zobrazené, pretože je v týchto rozdielových dátach zmenené mnoho súborov