Skip to content

Commit fc798f6

Browse files
committed
chore: added number of nominators per validator and the individual nominators with their allocated stake
1 parent 2202fd6 commit fc798f6

File tree

3 files changed

+45
-5
lines changed

3 files changed

+45
-5
lines changed

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,19 @@ The tool generates the following JSON files in the specified output directory:
344344
"results": [
345345
{
346346
"account": "15roBmbe5NmRXb4imfmhKxSjH8k9J5xtHSrvYJKpmmCLoPqD",
347-
"total_stake": "2358096.6648553217 DOT",
348-
"self_stake": "0 DOT"
347+
"total_stake": "2372626.3933261476 DOT",
348+
"self_stake": "0 DOT",
349+
"nominator_count": 2,
350+
"nominators": [
351+
{
352+
"address": "121GCLDNk9ErAkCovjjuF3npDB3veo3i3myY6a5v2yNEgrZw",
353+
"allocated_stake": "769476 DOT"
354+
},
355+
{
356+
"address": "14mtWxmkUHsWqJLxMiRR8qrHTHyck712E5yjWpnxPBEh8Acb",
357+
"allocated_stake": "135680 DOT"
358+
},
359+
]
349360
}
350361
]
351362
}

src/commands/types.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,15 @@ pub(crate) struct ValidatorInfo {
146146
pub(crate) account: String,
147147
pub(crate) total_stake: String, // Token amount as string
148148
pub(crate) self_stake: String, // Token amount as string
149+
pub(crate) nominator_count: usize,
150+
pub(crate) nominators: Vec<NominatorAllocation>,
151+
}
152+
153+
/// Nominator allocation details for a validator
154+
#[derive(Debug, Clone, Serialize, Deserialize)]
155+
pub(crate) struct NominatorAllocation {
156+
pub(crate) address: String,
157+
pub(crate) allocated_stake: String, // Token amount as string
149158
}
150159

151160
/// Nominator prediction output

src/dynamic/election_data.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ use crate::{
1919
commands::{
2020
multi_block::types::{TargetSnapshotPageOf, Voter, VoterSnapshotPageOf},
2121
types::{
22-
ElectionDataSource, NominatorData, NominatorPrediction, NominatorsPrediction,
23-
PredictionMetadata, ValidatorData, ValidatorInfo, ValidatorStakeAllocation,
24-
ValidatorsPrediction,
22+
ElectionDataSource, NominatorAllocation, NominatorData, NominatorPrediction,
23+
NominatorsPrediction, PredictionMetadata, ValidatorData, ValidatorInfo,
24+
ValidatorStakeAllocation, ValidatorsPrediction,
2525
},
2626
},
2727
dynamic::staking::{fetch_candidates, fetch_nominators},
@@ -222,10 +222,30 @@ where
222222
.map(|(_, stake)| *stake)
223223
.unwrap_or(0);
224224

225+
// Collect nominators backing this validator (excluding self-votes)
226+
let mut validator_nominators: Vec<(AccountId, u128)> = support
227+
.voters
228+
.iter()
229+
.filter(|(who, _)| who != validator)
230+
.map(|(who, stake)| (who.clone(), *stake))
231+
.collect();
232+
// Sort by stake descending for consistent ordering
233+
validator_nominators.sort_by(|a, b| b.1.cmp(&a.1));
234+
235+
let nominator_allocations = validator_nominators
236+
.iter()
237+
.map(|(nominator, stake)| NominatorAllocation {
238+
address: encode_account_id(nominator, ctx.ss58_prefix),
239+
allocated_stake: planck_to_token(*stake, ctx.token_decimals, ctx.token_symbol),
240+
})
241+
.collect();
242+
225243
validator_infos.push(ValidatorInfo {
226244
account: encode_account_id(validator, ctx.ss58_prefix),
227245
total_stake: planck_to_token(support.total, ctx.token_decimals, ctx.token_symbol),
228246
self_stake: planck_to_token(self_stake, ctx.token_decimals, ctx.token_symbol),
247+
nominator_count: validator_nominators.len(),
248+
nominators: nominator_allocations,
229249
});
230250
}
231251

0 commit comments

Comments
 (0)