Forráskód Böngészése

Proposal 127, KPI 6.9: fixing community scripts

singulart 3 éve
szülő
commit
94a8ee473b

+ 11 - 9
joystream-api/package.json

@@ -10,17 +10,19 @@
     "postinstall": "yarn build"
   },
   "dependencies": {
-    "@joystream/types": "^0.14.0",
-    "@polkadot/api": "1.26.1",
-    "@polkadot/keyring": "^3.0.1",
-    "@polkadot/types": "1.26.1",
-    "@polkadot/util": "^3.0.1",
-    "@polkadot/util-crypto": "^3.0.1",
-    "@types/bn.js": "^4.11.5",
-    "bn.js": "^4.11.8"
+    "@joystream/types": "^0.16.1",
+    "@polkadot/api": "4.2.1",
+    "@polkadot/api-contract": "4.2.1",
+    "@polkadot/keyring": "^6.0.5",
+    "@polkadot/types": "4.2.1",
+    "@polkadot/util": "^6.0.5",
+    "@polkadot/util-crypto": "^6.0.5",
+    "@polkadot/wasm-crypto": "^4.0.2",
+    "@types/bn.js": "^4.11.6",
+    "bn.js": "^5.1.2"
   },
   "devDependencies": {
-    "@polkadot/ts": "^0.1.56",
+    "@polkadot/ts": "^0.3.62",
     "typescript": "^3.9.7"
   }
 }

+ 14 - 21
joystream-api/src/curators/functions.ts

@@ -1,4 +1,4 @@
-import { Actor, CreateEntityOperation, EntityId, Entity, OperationType, UpdatePropertyValuesOperation } from "@joystream/types/content-directory";
+import { Actor, CreateEntityOperation, OperationType, UpdatePropertyValuesOperation } from "@joystream/types/content-directory";
 import { ApiPromise } from "@polkadot/api";
 import { u64, Vec } from "@polkadot/types";
 import { EventRecord, Extrinsic, Hash, SignedBlock } from "@polkadot/types/interfaces";
@@ -14,11 +14,10 @@ interface NewBatch {
   actor: AnyJson
 }
 
-interface Removed {
+interface ActionData {
   blockHeight: number,
   action: string,
   entityId: number,
-  classOfEntity: number,
   signer: string,
   actor: AnyJson
 }
@@ -27,8 +26,8 @@ export async function getBatchAction(api: ApiPromise, blockHeight:number, blockH
   const getBlock = await api.rpc.chain.getBlock(blockHash) as SignedBlock
   const extrinsics = getBlock.block.extrinsics as Vec<Extrinsic>
   for (let n=0; n<extrinsics.length; n++) {
-    const extSection = extrinsics[n].method.sectionName
-    const extMethod = extrinsics[n].method.methodName
+    const extSection = extrinsics[n].method.section
+    const extMethod = extrinsics[n].method.method
     let extrinscIndex = 0
     if (extSection == "contentDirectory" && extMethod == "transaction") {
       extrinscIndex +=1
@@ -77,35 +76,29 @@ export async function getBatchAction(api: ApiPromise, blockHeight:number, blockH
   return null
 }
 
-export async function getRemovedAction(api: ApiPromise, blockHeight:number, blockHash:Hash, removIndex: number, event: EventRecord): Promise<Removed|null> {
+export async function getChangeAction(api: ApiPromise, method: string, blockHeight:number, blockHash:Hash, eventIndex: number, event: EventRecord): Promise<ActionData|null> {
   const getBlock = await api.rpc.chain.getBlock(blockHash) as SignedBlock
   const extrinsics = getBlock.block.extrinsics as Vec<Extrinsic>
   for (let n=0; n<extrinsics.length; n++) {
-    const extSection = extrinsics[n].method.sectionName
-    const extMethod = extrinsics[n].method.methodName
+    const extSection = extrinsics[n].method.section
+    const extMethod = extrinsics[n].method.method
     let extrinscIndex = 0
-    if (extSection == "contentDirectory" && extMethod == "removeEntity") {
+    console.log(`Extrinsics section=${extSection}, Event method=${extMethod}`)
+    if (extSection == "content" && extMethod == method) {
       extrinscIndex +=1
-      if (removIndex == extrinscIndex) {
+      if (eventIndex == extrinscIndex) {
         const extrinsic = extrinsics[n]
         const actor = extrinsic.args[0] as Actor
-        let entityId:number = -1
-        let classOfEntity:number = -1
         const ent = event.event.data[1]
-        if (ent instanceof EntityId) {
-          entityId = ent.toNumber()
-          const previousBlockHash = await api.rpc.chain.getBlockHash(blockHeight-1) as Hash
-          classOfEntity = (await api.query.contentDirectory.entityById.at(previousBlockHash,entityId) as Entity).class_id.toNumber()
-        }
-        const removedEntity:Removed = {
+        let entityId:number = +(ent.toString())
+        const video:ActionData = {
           blockHeight,
-          action: "Entity removed",
+          action: method,
           entityId,
-          classOfEntity,
           signer: extrinsic.signer.toString(),
           actor: actor.toHuman()
         }
-        return removedEntity
+        return video
       }
     }
   }

+ 21 - 17
joystream-api/src/curators/get-media-change.ts

@@ -2,7 +2,7 @@ import { WsProvider, ApiPromise } from "@polkadot/api";
 import { types } from "@joystream/types";
 import {  Vec } from "@polkadot/types";
 import { EventRecord, Hash } from "@polkadot/types/interfaces";
-import { getBatchAction, getRemovedAction } from "./functions";
+import { getChangeAction } from "./functions";
 
 
 async function main() {
@@ -19,32 +19,36 @@ async function main() {
       const blockHash = await api.rpc.chain.getBlockHash(blockHeight) as Hash
       const events = await api.query.system.events.at(blockHash) as Vec<EventRecord>;
       const eventsArray: EventRecord[] = []
-      let index = 0
-      let removIndex = 0
+      let eventIndex = 0
       for (let i=0; i<events.length; i++) {
         const section = events[i].event.section
         const method = events[i].event.method
-        if (section == "contentDirectory") {
+        if(section == 'content') {
+          console.log(`Event section=${section}, Event method=${method}`)
           eventsArray.push(events[i])
-          if (method == "EntityCreated") {
-          }
-          if (method == "EntitySchemaSupportAdded") {
+          if (method == "VideoCreated") {
+            eventIndex+=1
+            const cdChange = await getChangeAction(api, 'createVideo', blockHeight, blockHash, eventIndex, events[i])
+            console.log("Change",JSON.stringify(cdChange, null, 4))
           }
-          if (method == "EntityPropertyValuesUpdated") {
+          if (method == "VideoUpdated") {
+            eventIndex+=1
+            const cdChange = await getChangeAction(api, 'updateVideo', blockHeight, blockHash, eventIndex, events[i])
+            console.log("Change",JSON.stringify(cdChange, null, 4))
           }
-          if (method == "EntityRemoved") {
-            removIndex+=1
-            const cdChange = await getRemovedAction(api, blockHeight, blockHash, removIndex, events[i])
+          if (method == "VideoDeleted") {
+            eventIndex+=1
+            const cdChange = await getChangeAction(api, 'deleteVideo', blockHeight, blockHash, eventIndex, events[i])
             console.log("Change",JSON.stringify(cdChange, null, 4))
           }
-          if (method == "TransactionCompleted") {
-            index+=1
-            const cdChange = await getBatchAction(api, blockHeight, blockHash, index, eventsArray, method)
+          if (method == "ChannelCreated") {
+            eventIndex+=1
+            const cdChange = await getChangeAction(api, 'createChannel', blockHeight, blockHash, eventIndex, events[i])
             console.log("Change",JSON.stringify(cdChange, null, 4))
           }
-          if (method == "TransactionFailed") {
-            index+=1
-            const cdChange = await getBatchAction(api, blockHeight, blockHash, index, eventsArray, method)
+          if (method == "ChannelUpdated") {
+            eventIndex+=1
+            const cdChange = await getChangeAction(api, 'updateChannel', blockHeight, blockHash, eventIndex, events[i])
             console.log("Change",JSON.stringify(cdChange, null, 4))
           }
         }

+ 1 - 1
joystream-api/src/examples/functions.ts

@@ -1,7 +1,7 @@
 import { MemberId, Membership } from "@joystream/types/members";
 import { ApiPromise } from "@polkadot/api";
 import { Vec } from "@polkadot/types";
-import AccountId from "@polkadot/types/generic/AccountId";
+import { AccountId } from "@polkadot/types/interfaces";
 import { Hash } from "@polkadot/types/interfaces";
 import { Participant } from './interfaces';
 

+ 2 - 2
joystream-api/src/examples/general.ts

@@ -57,8 +57,8 @@ async function main() {
     const getLatestBlock = await api.rpc.chain.getBlock(finalizedHeadHash) as SignedBlock
     const extrinsics = getLatestBlock.block.extrinsics as Vec<Extrinsic>
     for (let i=0; i<extrinsics.length; i++) {
-      const section = extrinsics[i].method.sectionName
-      const method = extrinsics[i].method.methodName
+      const section = extrinsics[i].method.section
+      const method = extrinsics[i].method.method
       console.log("section",section)
       console.log("method",method)
       console.log("")

+ 2 - 2
joystream-api/src/examples/get-events-and-extrinsics.ts

@@ -39,8 +39,8 @@ async function main() {
         }
       }
       for (let i=0; i<extrinsics.length; i++) {
-        const section = extrinsics[i].method.sectionName
-        const method = extrinsics[i].method.methodName
+        const section = extrinsics[i].method.section
+        const method = extrinsics[i].method.method
         const extrinsicType = section+`:`+method
         if (!extrinsicTypes.includes(extrinsicType)) {
           extrinsicTypes.push(extrinsicType)