Преглед на файлове

update-bucket-mode, update-bucket-status

Leszek Wiesner преди 3 години
родител
ревизия
fcfce698a8

+ 3 - 1
distributor-node/scripts/test-commands.sh

@@ -7,7 +7,9 @@ CLI=../bin/run
 CONFIG_PATH="../config.yml"
 ${CLI} leader:set-buckets-per-bag-limit -l 10 -c ${CONFIG_PATH} -y
 FAMILY_ID=`${CLI} leader:create-bucket-family -c "${CONFIG_PATH}" -y`
-BUCKET_ID=`${CLI} leader:create-bucket -f "${FAMILY_ID}" -a -c "${CONFIG_PATH}" -y`
+BUCKET_ID=`${CLI} leader:create-bucket -f "${FAMILY_ID}" -a yes -c "${CONFIG_PATH}" -y`
 ${CLI} leader:update-bag -b static:council -f "${FAMILY_ID}" -a "${BUCKET_ID}" -c "${CONFIG_PATH}" -y
+${CLI} leader:update-bucket-status -f "${FAMILY_ID}" -B "${BUCKET_ID}"  --acceptingBags yes -c "${CONFIG_PATH}" -y
+${CLI} leader:update-bucket-mode -f "${FAMILY_ID}" -B "${BUCKET_ID}" --mode on -c "${CONFIG_PATH}" -y
 ${CLI} leader:delete-bucket -f "${FAMILY_ID}" -B "${BUCKET_ID}" -c "${CONFIG_PATH}" -y
 ${CLI} leader:delete-bucket-family -f "${FAMILY_ID}" -c "${CONFIG_PATH}" -y

+ 6 - 5
distributor-node/src/commands/leader/create-bucket.ts

@@ -11,22 +11,23 @@ export default class LeaderCreateBucket extends AccountsCommandBase {
       description: 'Distribution bucket family id',
       required: true,
     }),
-    acceptBags: flags.boolean({
+    acceptingBags: flags.enum({
       char: 'a',
-      description: 'Whether the new bucket should accept new bags',
-      default: false,
+      description: 'Whether the created bucket should accept new bags',
+      options: ['yes', 'no'],
+      default: 'no',
     }),
     ...DefaultCommandBase.flags,
   }
 
   async run(): Promise<void> {
-    const { familyId, acceptBags } = this.parse(LeaderCreateBucket).flags
+    const { familyId, acceptingBags } = this.parse(LeaderCreateBucket).flags
     const leadKey = await this.getDistributorLeadKey()
 
     this.log('Creating new distribution bucket...')
     const result = await this.sendAndFollowTx(
       await this.getDecodedPair(leadKey),
-      this.api.tx.storage.createDistributionBucket(familyId, acceptBags)
+      this.api.tx.storage.createDistributionBucket(familyId, acceptingBags === 'yes')
     )
     const event = this.api.getEvent(result, 'storage', 'DistributionBucketCreated')
 

+ 38 - 0
distributor-node/src/commands/leader/update-bucket-mode.ts

@@ -0,0 +1,38 @@
+import AccountsCommandBase from '../../command-base/accounts'
+import DefaultCommandBase, { flags } from '../../command-base/default'
+
+export default class LeaderUpdateBucketMode extends AccountsCommandBase {
+  static description = `Update distribution bucket mode ("distributing" flag). Requires distribution working group leader permissions.`
+
+  static flags = {
+    bucketId: flags.integer({
+      char: 'B',
+      description: 'Distribution bucket id',
+      required: true,
+    }),
+    familyId: flags.integer({
+      char: 'f',
+      description: 'Distribution bucket family id',
+      required: true,
+    }),
+    mode: flags.enum<'on' | 'off'>({
+      char: 'd',
+      description: 'Whether the bucket should be "on" (distributing) or "off" (not distributing)',
+      required: true,
+      options: ['on', 'off'],
+    }),
+    ...DefaultCommandBase.flags,
+  }
+
+  async run(): Promise<void> {
+    const { bucketId, familyId, mode } = this.parse(LeaderUpdateBucketMode).flags
+    const leadKey = await this.getDistributorLeadKey()
+
+    this.log(`Updating distribution bucket mode (${bucketId}, distributing: ${mode})...`)
+    await this.sendAndFollowTx(
+      await this.getDecodedPair(leadKey),
+      this.api.tx.storage.updateDistributionBucketMode(familyId, bucketId, mode === 'on')
+    )
+    this.log('Bucket mode succesfully updated!')
+  }
+}

+ 39 - 0
distributor-node/src/commands/leader/update-bucket-status.ts

@@ -0,0 +1,39 @@
+import { flags } from '@oclif/command'
+import AccountsCommandBase from '../../command-base/accounts'
+import DefaultCommandBase from '../../command-base/default'
+
+export default class LeaderUpdateBucketStatus extends AccountsCommandBase {
+  static description = `Update distribution bucket status ("acceptingNewBags" flag). Requires distribution working group leader permissions.`
+
+  static flags = {
+    bucketId: flags.integer({
+      char: 'B',
+      description: 'Distribution bucket id',
+      required: true,
+    }),
+    familyId: flags.integer({
+      char: 'f',
+      description: 'Distribution bucket family id',
+      required: true,
+    }),
+    acceptingBags: flags.enum<'yes' | 'no'>({
+      char: 'a',
+      description: 'Whether the bucket should accept new bags',
+      options: ['yes', 'no'],
+      required: true,
+    }),
+    ...DefaultCommandBase.flags,
+  }
+
+  async run(): Promise<void> {
+    const { bucketId, familyId, acceptingBags } = this.parse(LeaderUpdateBucketStatus).flags
+    const leadKey = await this.getDistributorLeadKey()
+
+    this.log(`Updating distribution bucket status (${bucketId}, acceptingNewBags: ${acceptingBags})...`)
+    await this.sendAndFollowTx(
+      await this.getDecodedPair(leadKey),
+      this.api.tx.storage.updateDistributionBucketStatus(familyId, bucketId, acceptingBags === 'yes')
+    )
+    this.log('Bucket status succesfully updated!')
+  }
+}