package Ġjp . co . sor am its u . feature _ staking _ impl . domain . validators Ċ Ċ import Ġjp . co . sor am its u . common . utils . to Address Ċ import Ġjp . co . sor am its u . common . utils . to Hex AccountId Ċ import Ġjp . co . sor am its u . fe ar less _ utils . extensions . from Hex Ċ import Ġjp . co . sor am its u . feature _ account _ api . domain . interfaces . Account Repository Ċ import Ġjp . co . sor am its u . feature _ account _ api . domain . interfaces . current Network Type Ċ import Ġjp . co . sor am its u . feature _ staking _ api . domain . api . AccountId Map Ċ import Ġjp . co . sor am its u . feature _ staking _ api . domain . api . Identity Repository Ċ import Ġjp . co . sor am its u . feature _ staking _ api . domain . api . St aking Repository Ċ import Ġjp . co . sor am its u . feature _ staking _ api . domain . api . getActive Elect ed Validators Ex pos ures Ċ import Ġjp . co . sor am its u . feature _ staking _ api . domain . model . Exposure Ċ import Ġjp . co . sor am its u . feature _ staking _ api . domain . model . Validator Ċ import Ġjp . co . sor am its u . feature _ staking _ impl . data . repository . St aking Constants Repository Ċ import Ġjp . co . sor am its u . feature _ staking _ impl . domain . rewards . Reward Calculator Factory Ċ Ċ sealed Ġclass ĠValidator Source Ġ{ ĊĊĠĠĠ Ġobject ĠElect ed Ġ: ĠValidator Source () ĊĊĠĠĠ Ġclass ĠCustom ( val Ġvalidator Ids : ĠList < String >) Ġ: ĠValidator Source () Ċ } Ċ Ċ class ĠValidator Provider ( ĊĠĠĠ Ġprivate Ġval Ġst aking Repository : ĠSt aking Repository , ĊĠĠĠ Ġprivate Ġval Ġidentity Repository : ĠIdentity Repository , ĊĠĠĠ Ġprivate Ġval Ġaccount Repository : ĠAccount Repository , ĊĠĠĠ Ġprivate Ġval Ġreward Calculator Factory : ĠRew ard Calculator Factory , ĊĠĠĠ Ġprivate Ġval Ġst aking Constants Repository : ĠSt aking Constants Repository , Ċ ) Ġ{ ĊĊĠĠĠ Ġsuspend Ġfun Ġget Validators ( ĊĠĠĠĠĠĠĠ Ġsource : ĠValidator Source , ĊĠĠĠĠĠĠĠ Ġcached Ex pos ures : ĠAccount Id Map < Exposure >? Ġ= Ġnull , ĊĠĠĠ Ġ): ĠList < Validator > Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġnetwork Type Ġ= Ġaccount Repository . current Network Type () ĊĠĠĠĠĠĠĠ Ġval Ġelect ed Validator Ex pos ures Ġ= Ġcached Ex pos ures Ġ?: Ġst aking Repository . getActive Elect ed Validators Ex pos ures () ĊĊĠĠĠĠĠĠĠ Ġval Ġrequested Validator Ids Ġ= Ġwhen Ġ( source ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠValidator Source . Elect ed Ġ-> Ġelect ed Validator Ex pos ures . keys . toList () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġis ĠValidator Source . Custom Ġ-> Ġsource . validator Ids ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġval Ġvalidator Ids To Query Prefs Ġ= Ġelect ed Validator Ex pos ures . keys Ġ+ Ġrequested Validator Ids ĊĊĠĠĠĠĠĠĠ Ġval Ġvalidator Prefs Ġ= Ġst aking Repository . get Validator Prefs ( validator Ids To Query Prefs . toList ()) ĊĊĠĠĠĠĠĠĠ Ġval Ġident ities Ġ= Ġidentity Repository . getId entities From Ids ( requested Validator Ids ) ĊĠĠĠĠĠĠĠ Ġval Ġsl ashes Ġ= Ġst aking Repository . get Sl ashes ( requested Validator Ids ) ĊĊĠĠĠĠĠĠĠ Ġval Ġreward Calculator Ġ= Ġreward Calculator Factory . create ( elect ed Validator Ex pos ures , Ġvalidator Prefs ) ĊĠĠĠĠĠĠĠ Ġval Ġmax Nom in ators Ġ= Ġst aking Constants Repository . max Rew arded Nom inator Per Validator () ĊĊĠĠĠĠĠĠĠ Ġreturn Ġrequested Validator Ids . map Ġ{ ĠaccountId Hex Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġprefs Ġ= Ġvalidator Prefs [ accountId Hex ] ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġelect ed Info Ġ= Ġelect ed Validator Ex pos ures [ accountId Hex ]?. let Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠValidator . Elect ed Info ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġtotal Stake Ġ= Ġit . total , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġown Stake Ġ= Ġit . own , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġnom inator St akes Ġ= Ġit . others , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġa py Ġ= Ġreward Calculator . get A py For ( accountId Hex ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġis Over subscribed Ġ= Ġit . others . size Ġ> Ġmax Nom in ators ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠĠĠĠĠ ĠValidator ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġsl ashed Ġ= Ġsl ashes . get OrDefault ( accountId Hex , Ġfalse ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠaccountId Hex Ġ= ĠaccountId Hex , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġelect ed Info Ġ= Ġelect ed Info , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġprefs Ġ= Ġprefs , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġidentity Ġ= Ġident ities [ accountId Hex ], ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġaddress Ġ= ĠaccountId Hex . from Hex (). to Address ( network Type ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġsuspend Ġfun Ġget Validator Without Elect ed Info ( address : ĠString ): ĠValidator Ġ{ ĊĠĠĠĠĠĠĠ Ġval ĠaccountId Ġ= Ġaddress . to Hex AccountId () ĊĊĠĠĠĠĠĠĠ Ġval ĠaccountId B rid ged Ġ= ĠlistOf ( accountId ) ĊĊĠĠĠĠĠĠĠ Ġval Ġprefs Ġ= Ġst aking Repository . get Validator Prefs ( accountId B rid ged )[ accountId ] ĊĠĠĠĠĠĠĠ Ġval Ġidentity Ġ= Ġidentity Repository . getId entities From Ids ( accountId B rid ged )[ accountId ] ĊĊĠĠĠĠĠĠĠ Ġval Ġsl ashes Ġ= Ġst aking Repository . get Sl ashes ( accountId B rid ged ) ĊĊĠĠĠĠĠĠĠ Ġreturn ĠValidator ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġsl ashed Ġ= Ġsl ashes . get OrDefault ( accountId , Ġfalse ), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠaccountId Hex Ġ= ĠaccountId , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġaddress Ġ= Ġaddress , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġprefs Ġ= Ġprefs , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġidentity Ġ= Ġidentity , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġelect ed Info Ġ= Ġnull ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} Ċ } Ċ