@@ -75,17 +75,20 @@ impl Policy {
7575 url : entity. 1 . clone ( ) ,
7676 } )
7777 }
78-
79- pub fn quorum ( & self ) -> Option < String > {
80- todo ! ( )
81- }
8278}
8379
8480// Quorum is an internal enum that represent possible quorum values, i.e. witnesses and groups.
8581#[ derive( Debug , Eq , PartialEq ) ]
8682enum Quorum {
83+ // A single witness, identified by its keyhash.
84+ // Invariant: if Witness(h) is in Policy.quorums, then h must be in Policy.witnesses.
8785 Witness ( Hash ) ,
88- Group ( usize , Vec < String > ) ,
86+
87+ // A Group that requires at least k of its subquorums to pass.
88+ // Invariant: k <= length(members)
89+ // Invariant: if a group is in Policy.quorums, then all its members must be in
90+ // Policy.quorums as well.
91+ Group { k : usize , members : Vec < String > } ,
8992}
9093
9194// Entity is a struct that is used internally to keep track of log/witness keys and URLs.
@@ -168,7 +171,7 @@ impl PolicyBuilder {
168171 return Err ( PolicyError :: UnknownName ( name. into ( ) ) ) ;
169172 }
170173 }
171- self . 0 . quorums . insert ( name, Quorum :: Group ( k, members) ) ;
174+ self . 0 . quorums . insert ( name, Quorum :: Group { k, members } ) ;
172175 Ok ( ( ) )
173176 }
174177
@@ -297,7 +300,10 @@ mod tests {
297300 ) ,
298301 (
299302 "mygroup" . into ( ) ,
300- Quorum :: Group ( 2 , vec ! [ "witness01" . into( ) , "witness02" . into( ) ] ) ,
303+ Quorum :: Group {
304+ k : 2 ,
305+ members : vec ! [ "witness01" . into( ) , "witness02" . into( ) ] ,
306+ } ,
301307 ) ,
302308 ] ) ,
303309 quorum : Some ( "mygroup" . into ( ) ) ,
0 commit comments