@@ -5,59 +5,25 @@ import { ZERO } from "../utils";
5
5
6
6
// This function calculates the "effective" stake, which is the specific stake
7
7
// of the current court + the specific stake of all of its children courts
8
- export function updateEffectiveStake ( courtID : string ) : void {
8
+ export function updateEffectiveStake ( courtID : string , delta : BigInt ) : void {
9
9
let court = Court . load ( courtID ) ;
10
10
if ( ! court ) return ;
11
-
12
- while ( court ) {
13
- let totalStake = court . stake ;
14
-
15
- const childrenCourts = court . children . load ( ) ;
16
-
17
- for ( let i = 0 ; i < childrenCourts . length ; i ++ ) {
18
- const childCourt = Court . load ( childrenCourts [ i ] . id ) ;
19
- if ( childCourt ) {
20
- totalStake = totalStake . plus ( childCourt . effectiveStake ) ;
21
- }
22
- }
23
-
24
- court . effectiveStake = totalStake ;
25
- court . save ( ) ;
26
-
27
- if ( court . parent && court . parent !== null ) {
28
- court = Court . load ( court . parent as string ) ;
29
- } else {
30
- break ;
31
- }
11
+ court . effectiveStake = court . effectiveStake . plus ( delta ) ;
12
+ court . save ( ) ;
13
+ if ( court . parent ) {
14
+ updateEffectiveStake ( court . parent as string , delta ) ;
32
15
}
33
16
}
34
17
35
18
// This function calculates the "effective" numberStakedJurors, which is the specific numberStakedJurors
36
19
// of the current court + the specific numberStakedJurors of all of its children courts
37
- export function updateEffectiveNumberStakedJurors ( courtID : string ) : void {
20
+ export function updateEffectiveNumberStakedJurors ( courtID : string , delta : BigInt ) : void {
38
21
let court = Court . load ( courtID ) ;
39
22
if ( ! court ) return ;
40
-
41
- while ( court ) {
42
- let totalJurors = court . numberStakedJurors ;
43
-
44
- const childrenCourts = court . children . load ( ) ;
45
-
46
- for ( let i = 0 ; i < childrenCourts . length ; i ++ ) {
47
- const childCourt = Court . load ( childrenCourts [ i ] . id ) ;
48
- if ( childCourt ) {
49
- totalJurors = totalJurors . plus ( childCourt . effectiveNumberStakedJurors ) ;
50
- }
51
- }
52
-
53
- court . effectiveNumberStakedJurors = totalJurors ;
54
- court . save ( ) ;
55
-
56
- if ( court . parent && court . parent !== null ) {
57
- court = Court . load ( court . parent as string ) ;
58
- } else {
59
- break ;
60
- }
23
+ court . effectiveNumberStakedJurors = court . effectiveNumberStakedJurors . plus ( delta ) ;
24
+ court . save ( ) ;
25
+ if ( court . parent ) {
26
+ updateEffectiveNumberStakedJurors ( court . parent as string , delta ) ;
61
27
}
62
28
}
63
29
0 commit comments