@@ -5,59 +5,25 @@ import { ZERO } from "../utils";
55
66// This function calculates the "effective" stake, which is the specific stake
77// 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 {
99 let court = Court . load ( courtID ) ;
1010 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 ) ;
3215 }
3316}
3417
3518// This function calculates the "effective" numberStakedJurors, which is the specific numberStakedJurors
3619// 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 {
3821 let court = Court . load ( courtID ) ;
3922 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 ) ;
6127 }
6228}
6329
0 commit comments