Explorar el Código

invite-bucket-operator, cancel-invitation

Leszek Wiesner hace 3 años
padre
commit
7b3ad71072

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

@@ -7,6 +7,7 @@ export AUTO_CONFIRM=true
 export CONFIG_PATH="../config.yml"
 CLI=../bin/run
 
+${CLI} dev:init
 ${CLI} leader:set-buckets-per-bag-limit -l 10
 FAMILY_ID=`${CLI} leader:create-bucket-family ${CONFIG}`
 BUCKET_ID=`${CLI} leader:create-bucket -f ${FAMILY_ID} -a yes`
@@ -15,5 +16,7 @@ ${CLI} leader:update-bucket-status -f ${FAMILY_ID} -B ${BUCKET_ID}  --acceptingB
 ${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
 ${CLI} leader:update-dynamic-bag-policy -t Member
+${CLI} leader:invite-bucket-operator -f ${FAMILY_ID} -B ${BUCKET_ID} -w 0
+${CLI} leader:cancel-invitation -f ${FAMILY_ID} -B ${BUCKET_ID} -w 0
 ${CLI} leader:delete-bucket -f ${FAMILY_ID} -B ${BUCKET_ID}
 ${CLI} leader:delete-bucket-family -f ${FAMILY_ID}

+ 38 - 0
distributor-node/src/commands/leader/cancel-invitation.ts

@@ -0,0 +1,38 @@
+import AccountsCommandBase from '../../command-base/accounts'
+import DefaultCommandBase, { flags } from '../../command-base/default'
+
+export default class LeaderCancelInvitation extends AccountsCommandBase {
+  static description = `Cancel pending distribution bucket operator invitation.
+  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,
+    }),
+    workerId: flags.integer({
+      char: 'w',
+      description: 'ID of the invited operator (distribution group worker)',
+      required: true,
+    }),
+    ...DefaultCommandBase.flags,
+  }
+
+  async run(): Promise<void> {
+    const { bucketId, familyId, workerId } = this.parse(LeaderCancelInvitation).flags
+    const leadKey = await this.getDistributorLeadKey()
+
+    this.log(`Canceling distribution bucket operator invitation (bucket: ${bucketId}, worker: ${workerId})...`)
+    await this.sendAndFollowTx(
+      await this.getDecodedPair(leadKey),
+      this.api.tx.storage.cancelDistributionBucketOperatorInvite(familyId, bucketId, workerId)
+    )
+    this.log('Invitation succesfully canceled!')
+  }
+}

+ 39 - 0
distributor-node/src/commands/leader/invite-bucket-operator.ts

@@ -0,0 +1,39 @@
+import AccountsCommandBase from '../../command-base/accounts'
+import DefaultCommandBase, { flags } from '../../command-base/default'
+
+export default class LeaderInviteBucketOperator extends AccountsCommandBase {
+  static description = `Invite distribution bucket operator (distribution group worker).
+  The specified bucket must not have any operator currently.
+  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,
+    }),
+    workerId: flags.integer({
+      char: 'w',
+      description: 'ID of the distribution group worker to invite as bucket operator',
+      required: true,
+    }),
+    ...DefaultCommandBase.flags,
+  }
+
+  async run(): Promise<void> {
+    const { bucketId, familyId, workerId } = this.parse(LeaderInviteBucketOperator).flags
+    const leadKey = await this.getDistributorLeadKey()
+
+    this.log(`Inviting distribution bucket operator (bucket: ${bucketId}, worker: ${workerId})...`)
+    await this.sendAndFollowTx(
+      await this.getDecodedPair(leadKey),
+      this.api.tx.storage.inviteDistributionBucketOperator(familyId, bucketId, workerId)
+    )
+    this.log('Bucket operator succesfully invited!')
+  }
+}