Leszek Wiesner пре 4 година
родитељ
комит
5d1bf00bb9

+ 14 - 13
cli/src/Api.ts

@@ -12,13 +12,12 @@ import {
     AccountSummary,
     CouncilInfoObj, CouncilInfoTuple, createCouncilInfoObj,
     WorkingGroups,
-    GroupLeadWithProfile,
     GroupMember,
 } from './Types';
 import { DerivedFees, DerivedBalances } from '@polkadot/api-derive/types';
 import { CLIError } from '@oclif/errors';
 import ExitCodes from './ExitCodes';
-import { Worker, Lead as WorkerLead, WorkerId, WorkerRoleStakeProfile } from '@joystream/types/lib/working-group';
+import { Worker, WorkerId, RoleStakeProfile } from '@joystream/types/lib/working-group';
 import { MemberId, Profile } from '@joystream/types/lib/members';
 import { RewardRelationship, RewardRelationshipId } from '@joystream/types/lib/recurring-rewards';
 import { Stake, StakeId } from '@joystream/types/lib/stake';
@@ -166,21 +165,23 @@ export default class Api {
         return profile.unwrapOr(null);
     }
 
-    async groupLead (group: WorkingGroups): Promise <GroupLeadWithProfile | null> {
-        const optLead = (await this.workingGroupApiQuery(group).currentLead()) as Option<WorkerLead>;
+    async groupLead(group: WorkingGroups): Promise<GroupMember | null> {
+        const optLeadId = (await this.workingGroupApiQuery(group).currentLead()) as Option<WorkerId>;
 
-        if (!optLead.isSome) {
-          return null;
+        if (!optLeadId.isSome) {
+            return null;
         }
 
-        const lead = optLead.unwrap();
-        const profile = await this.memberProfileById(lead.member_id);
+        const leadWorkerId = optLeadId.unwrap();
+        const leadWorker = this.singleLinkageResult<Worker>(
+            await this.workingGroupApiQuery(group).workerById(leadWorkerId) as LinkageResult
+        );
 
-        if (!profile) {
-            throw new Error(`Group lead profile not found! (member id: ${lead.member_id.toNumber()})`);
+        if (!leadWorker.is_active) {
+            return null;
         }
 
-        return { lead, profile };
+        return await this.groupMember(leadWorkerId, leadWorker);
     }
 
     protected async stakeValue (stakeId: StakeId): Promise<Balance> {
@@ -188,7 +189,7 @@ export default class Api {
         return stake.value;
     }
 
-    protected async workerStake (stakeProfile: WorkerRoleStakeProfile): Promise<Balance> {
+    protected async workerStake (stakeProfile: RoleStakeProfile): Promise<Balance> {
         return this.stakeValue(stakeProfile.stake_id);
     }
 
@@ -203,7 +204,7 @@ export default class Api {
         id: WorkerId,
         worker: Worker
       ): Promise<GroupMember> {
-        const roleAccount = worker.role_account;
+        const roleAccount = worker.role_account_id;
         const memberId = worker.member_id;
 
         const profile = await this.memberProfileById(memberId);

+ 0 - 5
cli/src/Types.ts

@@ -75,11 +75,6 @@ export const AvailableGroups: readonly WorkingGroups[] = [
 ] as const;
 
 // Compound working group types
-export type GroupLeadWithProfile = {
-    lead: Lead;
-    profile: Profile;
-}
-
 export type GroupMember = {
     workerId: WorkerId;
     memberId: MemberId;

+ 3 - 3
cli/src/base/WorkingGroupsCommandBase.ts

@@ -1,7 +1,7 @@
 import ExitCodes from '../ExitCodes';
 import AccountsCommandBase from './AccountsCommandBase';
 import { flags } from '@oclif/command';
-import { WorkingGroups, AvailableGroups, NamedKeyringPair, GroupLeadWithProfile, GroupMember } from '../Types';
+import { WorkingGroups, AvailableGroups, NamedKeyringPair, GroupMember } from '../Types';
 import { CLIError } from '@oclif/errors';
 import inquirer from 'inquirer';
 
@@ -25,11 +25,11 @@ export default abstract class WorkingGroupsCommandBase extends AccountsCommandBa
     };
 
     // Use when lead access is required in given command
-    async getRequiredLead(): Promise<GroupLeadWithProfile> {
+    async getRequiredLead(): Promise<GroupMember> {
         let selectedAccount: NamedKeyringPair = await this.getRequiredSelectedAccount();
         let lead = await this.getApi().groupLead(this.group);
 
-        if (!lead || lead.lead.role_account_id.toString() !== selectedAccount.address) {
+        if (!lead || lead.roleAccount.toString() !== selectedAccount.address) {
             this.error('Lead access required for this command!', { exit: ExitCodes.AccessDenied });
         }
 

+ 2 - 2
cli/src/commands/working-groups/overview.ts

@@ -16,9 +16,9 @@ export default class WorkingGroupsOverview extends WorkingGroupsCommandBase {
         displayHeader('Group lead');
         if (lead) {
             displayNameValueTable([
-                { name: 'Member id:', value: lead.lead.member_id.toString() },
+                { name: 'Member id:', value: lead.memberId.toString() },
                 { name: 'Member handle:', value: lead.profile.handle.toString() },
-                { name: 'Role account:', value: lead.lead.role_account_id.toString() },
+                { name: 'Role account:', value: lead.roleAccount.toString() },
             ]);
         }
         else {

+ 17 - 7
pioneer/packages/joy-roles/src/transport.substrate.ts

@@ -27,8 +27,7 @@ import {
   Application as WGApplication,
   Opening as WGOpening,
   Worker, WorkerId,
-  RoleStakeProfile,
-  Lead as LeadOf
+  RoleStakeProfile
 } from '@joystream/types/working-group';
 
 import { Application, Opening, OpeningId, ApplicationId } from '@joystream/types/hiring';
@@ -79,7 +78,7 @@ type GroupOpeningId = CuratorOpeningId | OpeningId;
 type GroupWorker = Worker | Curator;
 type GroupWorkerId = CuratorId | WorkerId;
 type GroupWorkerStakeProfile = RoleStakeProfile | CuratorRoleStakeProfile;
-type GroupLead = Lead | LeadOf;
+type GroupLead = Lead | Worker;
 type GroupLeadWithMemberId = {
   lead: GroupLead;
   memberId: MemberId;
@@ -291,15 +290,26 @@ export class Transport extends TransportBase implements ITransport {
   }
 
   protected async currentStorageLead (): Promise <GroupLeadWithMemberId | null> {
-    const optLead = (await this.cachedApi.query.storageWorkingGroup.currentLead()) as Option<LeadOf>;
+    const optLeadId = (await this.cachedApi.query.storageWorkingGroup.currentLead()) as Option<WorkerId>;
 
-    if (!optLead.isSome) {
+    if (!optLeadId.isSome) {
       return null;
     }
 
+    const leadWorkerId = optLeadId.unwrap();
+    const leadWorkerLink = new SingleLinkedMapEntry(
+      Worker,
+      await this.cachedApi.query.storageWorkingGroup.workerById(leadWorkerId)
+    );
+    const leadWorker = leadWorkerLink.value;
+
+    if (!leadWorker.is_active) {
+        return null;
+    }
+
     return {
-      lead: optLead.unwrap(),
-      memberId: optLead.unwrap().member_id
+      lead: leadWorker,
+      memberId: leadWorker.member_id
     };
   }
 

+ 1 - 1
types/src/content-working-group/index.ts

@@ -306,7 +306,7 @@ export class CuratorApplication extends JoyStruct<ICuratorApplication> {
 
   // Helper for working-group compatibility
   get opening_id(): CuratorOpeningId {
-    return this.opening_id;
+    return this.curator_opening_id;
   }
 
   get member_id(): MemberId {

+ 3 - 31
types/src/working-group/index.ts

@@ -7,31 +7,6 @@ import { RewardRelationshipId } from '../recurring-rewards';
 import { StakeId } from '../stake';
 import { ApplicationId, OpeningId, ApplicationRationingPolicy, StakingPolicy } from '../hiring';
 
-export type ILead = {
-  member_id: MemberId,
-  role_account_id: AccountId
-};
-
-// This type is also defined in /content-workig-group (and those are incosistent), but here
-// it is beeing registered as "LeadOf" (which is an alias used by the runtime working-group module),
-// so it shouldn't cause any conflicts
-export class Lead extends JoyStruct<ILead> {
-  constructor (value?: ILead) {
-    super({
-      member_id: MemberId,
-      role_account_id: "AccountId"
-    }, value);
-  }
-
-  get member_id(): MemberId {
-    return this.getField<MemberId>('member_id')
-  }
-
-  get role_account_id(): AccountId {
-    return this.getField<AccountId>('role_account_id')
-  }
-};
-
 export class RationaleText extends Bytes { };
 
 export type IApplication = {
@@ -269,16 +244,16 @@ export class WorkingGroupOpeningPolicyCommitment extends JoyStruct<IWorkingGroup
 };
 
 export enum OpeningTypeKeys {
-  Worker = 'Worker',
-  Leader = 'Leader'
+  Leader = 'Leader',
+  Worker = 'Worker'
 };
 
 export class OpeningType extends Enum {
   constructor (value?: any, index?: number) {
     super(
       {
-        Worker: Null,
         Leader: Null,
+        Worker: Null
       },
       value, index
     );
@@ -325,9 +300,6 @@ export class Opening extends JoyStruct<IOpening> {
 export function registerWorkingGroupTypes() {
   try {
     getTypeRegistry().register({
-      // Note that it actually HAS TO be "LeadOf" in the runtime,
-      // otherwise there would be conflicts with the current content-workig-group module
-      LeadOf: Lead,
       RationaleText,
       ApplicationOf: Application,
       ApplicationIdSet,