generated from PolymeshAssociation/typescript-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 11
/
KnownPermissionGroup.ts
105 lines (91 loc) · 2.64 KB
/
KnownPermissionGroup.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import { Context, PermissionGroup } from '~/internal';
import { GroupPermissions, ModuleName, PermissionGroupType, PermissionType, TxTags } from '~/types';
import { transactionPermissionsToTxGroups } from '~/utils/conversion';
import { toHumanReadable } from '~/utils/internal';
export interface HumanReadable {
type: PermissionGroupType;
ticker: string;
}
export interface UniqueIdentifiers {
type: PermissionGroupType;
ticker: string;
}
/**
* Represents a pre-defined group of permissions for an Asset
*/
export class KnownPermissionGroup extends PermissionGroup {
/**
* @hidden
* Check if a value is of type {@link UniqueIdentifiers}
*/
public static override isUniqueIdentifiers(identifier: unknown): identifier is UniqueIdentifiers {
const { type, ticker } = identifier as UniqueIdentifiers;
return type in PermissionGroupType && typeof ticker === 'string';
}
public type: PermissionGroupType;
/**
* @hidden
*/
public constructor(identifiers: UniqueIdentifiers, context: Context) {
super(identifiers, context);
const { type } = identifiers;
this.type = type;
}
/**
* Retrieve the Permissions associated with this Permission Group
*/
public async getPermissions(): Promise<GroupPermissions> {
const { type } = this;
let transactions;
switch (type) {
case PermissionGroupType.ExceptMeta:
transactions = { values: [ModuleName.ExternalAgents], type: PermissionType.Exclude };
break;
case PermissionGroupType.PolymeshV1Caa:
transactions = {
values: [
ModuleName.CapitalDistribution,
ModuleName.CorporateAction,
ModuleName.CorporateBallot,
],
type: PermissionType.Include,
};
break;
case PermissionGroupType.PolymeshV1Pia:
transactions = {
values: [
TxTags.asset.ControllerTransfer,
TxTags.asset.Issue,
TxTags.asset.Redeem,
ModuleName.Sto,
],
exceptions: [TxTags.sto.Invest],
type: PermissionType.Include,
};
break;
default:
transactions = null;
break;
}
return {
transactions,
transactionGroups: transactions ? transactionPermissionsToTxGroups(transactions) : [],
};
}
/**
* Determine whether this Known Permission Group exists on chain
*/
public async exists(): Promise<boolean> {
return true;
}
/**
* Return the KnownPermissionGroup's static data
*/
public toHuman(): HumanReadable {
const { type, asset } = this;
return toHumanReadable({
type,
ticker: asset,
});
}
}