Newer
Older
match len {
0 => { /* not supporting this validator at all. */ },
1 => sum += individual[0].value,
_ =>
return Err(
"nominator cannot back a validator more than once.".into()
),
};
Ok(())
})
.collect::<Result<Vec<_>, _>>()?;
// We take total instead of active as the nominator might have requested to unbond
// some of their stake that is still exposed in the current era.
if sum <= Self::ledger(Stash(nominator.clone()))?.total {
// This can happen when there is a slash in the current era so we only warn.
log!(warn, "nominator stake exceeds what is bonded.");
}
.collect::<Result<Vec<_>, _>>()?;
Ok(())
}
fn ensure_is_stash(who: &T::AccountId) -> Result<(), &'static str> {
ensure!(Self::bonded(who).is_some(), "Not a stash.");
Ok(())
}
fn ensure_ledger_consistent(ctrl: T::AccountId) -> Result<(), TryRuntimeError> {
// ensures ledger.total == ledger.active + sum(ledger.unlocking).
let ledger = Self::ledger(StakingAccount::Controller(ctrl.clone()))?;
let real_total: BalanceOf<T> =
ledger.unlocking.iter().fold(ledger.active, |a, c| a + c.value);
ensure!(real_total == ledger.total, "ledger.total corrupt");
Ok(())
}
}