MCPcopy Create free account
hub / github.com/dfinity/orbit / walkQuorumRules

Function walkQuorumRules

cli/src/audit/resolver.ts:30–87  ·  view source on GitHub ↗
(
  rule: RequestPolicyRule,
  namedRules: Map<UUID, NamedRule>,
  visit: (
    kind: 'Quorum' | 'QuorumPercentage',
    approvers: UserSpecifier,
    minApproved: number,
    path: string,
  ) => void,
  path: string = '',
  visited: Set<UUID> = new Set(),
)

Source from the content-addressed store, hash-verified

28 * `path` accumulates the human-readable breadcrumb to the rule for reporting.
29 */
30export const walkQuorumRules = (
31 rule: RequestPolicyRule,
32 namedRules: Map<UUID, NamedRule>,
33 visit: (
34 kind: 'Quorum' | 'QuorumPercentage',
35 approvers: UserSpecifier,
36 minApproved: number,
37 path: string,
38 ) => void,
39 path: string = '',
40 visited: Set<UUID> = new Set(),
41): void => {
42 if ('AutoApproved' in rule || 'AllowListed' in rule || 'AllowListedByMetadata' in rule) {
43 return;
44 }
45 if ('Quorum' in rule) {
46 visit('Quorum', rule.Quorum.approvers, rule.Quorum.min_approved, path || 'Quorum');
47 return;
48 }
49 if ('QuorumPercentage' in rule) {
50 visit(
51 'QuorumPercentage',
52 rule.QuorumPercentage.approvers,
53 rule.QuorumPercentage.min_approved,
54 path || 'QuorumPercentage',
55 );
56 return;
57 }
58 if ('AnyOf' in rule) {
59 rule.AnyOf.forEach((child, idx) =>
60 walkQuorumRules(child, namedRules, visit, joinPath(path, `AnyOf[${idx}]`), visited),
61 );
62 return;
63 }
64 if ('AllOf' in rule) {
65 rule.AllOf.forEach((child, idx) =>
66 walkQuorumRules(child, namedRules, visit, joinPath(path, `AllOf[${idx}]`), visited),
67 );
68 return;
69 }
70 if ('Not' in rule) {
71 walkQuorumRules(rule.Not, namedRules, visit, joinPath(path, 'Not'), visited);
72 return;
73 }
74 if ('NamedRule' in rule) {
75 const id = rule.NamedRule;
76 if (visited.has(id)) return;
77 const named = namedRules.get(id);
78 if (!named) return;
79 walkQuorumRules(
80 named.rule,
81 namedRules,
82 visit,
83 joinPath(path, `NamedRule("${named.name}")`),
84 new Set([...visited, id]),
85 );
86 }
87};

Callers 2

collectFunction · 0.90
quorumEmptyApproverSetFunction · 0.90

Calls 2

joinPathFunction · 0.85
getMethod · 0.45

Tested by 1

collectFunction · 0.72