-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathround.ts
More file actions
41 lines (31 loc) · 1.36 KB
/
round.ts
File metadata and controls
41 lines (31 loc) · 1.36 KB
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
import type { Types } from "@mainsail/api-common";
import type { Contracts } from "@mainsail/contracts";
import { Identifiers } from "@mainsail/constants";
import { inject, injectable } from "@mainsail/container";
import { Controller } from "./controller.js";
@injectable()
export class RoundController extends Controller {
@inject(Identifiers.ValidatorSet.Service)
private readonly validatorSet!: Contracts.ValidatorSet.Service;
@inject(Identifiers.BlockchainUtils.ProposerCalculator)
private readonly proposerCalculator!: Contracts.BlockchainUtils.ProposerCalculator;
@inject(Identifiers.BlockchainUtils.RoundCalculator)
private readonly roundCalculator!: Contracts.BlockchainUtils.RoundCalculator;
public async index(request: Types.HapiRequest): Promise<object> {
const roundValidators = this.validatorSet.getRoundValidators();
const orderedValidators = Array.from(
{ length: roundValidators.length },
(_, index) => roundValidators[this.proposerCalculator.getValidatorIndex(index)],
);
const blockNumber = this.stateStore.getBlockNumber();
return {
blockNumber,
...this.roundCalculator.calculateRound(blockNumber),
// Map the round validator set (static, vote-weighted, etc.) to actual proposal order
validators: orderedValidators.map((validator) => ({
voteBalance: validator.voteBalance.toString(),
wallet: validator,
})),
};
}
}