Browse Source

Support for static:wg bag ids

Leszek Wiesner 3 years ago
parent
commit
4b865b28ce

+ 5 - 0
distributor-node/scripts/test-commands.sh

@@ -12,6 +12,11 @@ ${CLI} leader:set-buckets-per-bag-limit -l 10
 FAMILY_ID=`${CLI} leader:create-bucket-family`
 BUCKET_ID=`${CLI} leader:create-bucket -f ${FAMILY_ID} -a yes`
 ${CLI} leader:update-bag -b static:council -f ${FAMILY_ID} -a ${BUCKET_ID}
+${CLI} leader:update-bag -b static:wg:storage -f ${FAMILY_ID} -a ${BUCKET_ID}
+${CLI} leader:update-bag -b static:wg:content -f ${FAMILY_ID} -a ${BUCKET_ID}
+${CLI} leader:update-bag -b static:wg:operations -f ${FAMILY_ID} -a ${BUCKET_ID}
+${CLI} leader:update-bag -b static:wg:gateway -f ${FAMILY_ID} -a ${BUCKET_ID}
+${CLI} leader:update-bag -b static:wg:distribution -f ${FAMILY_ID} -a ${BUCKET_ID}
 ${CLI} leader:update-bucket-status -f ${FAMILY_ID} -B ${BUCKET_ID}  --acceptingBags yes
 ${CLI} leader:update-bucket-mode -f ${FAMILY_ID} -B ${BUCKET_ID} --mode on
 ${CLI} leader:update-dynamic-bag-policy -t Member -p ${FAMILY_ID}:5

+ 16 - 0
distributor-node/src/services/parsers/BagIdParserService.ts

@@ -2,6 +2,7 @@ import { BagId } from '@joystream/types/storage'
 import { registry } from '@joystream/types'
 import { createType } from '@polkadot/types'
 import { InterfaceTypes } from '@polkadot/types/types'
+import { WorkingGroup } from '@joystream/types/common'
 
 export class BagIdParserService {
   private createType<T extends keyof InterfaceTypes>(type: T, value: any) {
@@ -27,6 +28,7 @@ export class BagIdParserService {
   }
 
   public parseStaticBagId(bagId: string, bagIdParts: string[]): BagId {
+    // Try to construct static council bag ID.
     if (bagIdParts[1] === 'council') {
       if (bagIdParts.length === 2) {
         const staticBagId = this.createType('StaticBagId', 'Council')
@@ -38,6 +40,20 @@ export class BagIdParserService {
       }
     }
 
+    // Try to construct static working group bag ID.
+    if (bagIdParts[1] === 'wg' && bagIdParts.length === 3) {
+      const groups = Object.keys(WorkingGroup.typeDefinitions)
+      const inputGroup = bagIdParts[2]
+
+      if (groups.find((g) => g.toLocaleLowerCase() === inputGroup)) {
+        return this.createType('BagId', {
+          Static: {
+            WorkingGroup: inputGroup,
+          },
+        })
+      }
+    }
+
     throw new Error(`Invalid bagId: ${bagId}`)
   }