@@ -21,7 +21,7 @@ import { AccountId } from "@polkadot/types/interfaces"
2121import { PalletStakingRewardDestination } from "@polkadot/types/lookup"
2222import { Vec , U8 , StorageKey , Option } from "@polkadot/types/"
2323import { signFakeWithApi , signFake } from '@acala-network/chopsticks-utils'
24- import { IEvent , IEventData } from '@polkadot/types/types' ;
24+ import { IEvent , IEventData , Observable } from '@polkadot/types/types' ;
2525import UpdateManager from 'stdout-update' ;
2626
2727
@@ -157,8 +157,8 @@ export async function stakingStatsHandler(args: HandlerArgs): Promise<void> {
157157}
158158
159159export async function commandCenterHandler ( ) : Promise < void > {
160- const rcApi = await getApi ( "ws://localhost:9955 " ) ;
161- const ahApi = await getApi ( "ws://localhost:9966 " ) ;
160+ const rcApi = await getApi ( "ws://localhost:9945 " ) ;
161+ const ahApi = await getApi ( "ws://localhost:9946 " ) ;
162162
163163 const manager = UpdateManager . getInstance ( ) ;
164164 // manager.hook();
@@ -295,6 +295,55 @@ export async function fakeSignForChopsticks(api: ApiPromise, sender: string | Ac
295295 tx . signature . set ( mockSignature )
296296}
297297
298+ export async function isExposed ( ws : string , stash : string ) : Promise < void > {
299+ const api = await getApi ( ws ) ;
300+ const balance = ( x : BN ) => api . createType ( 'Balance' , x ) . toHuman ( ) ;
301+ const era = ( await api . query . staking . currentEra ( ) ) . unwrap ( ) ;
302+ console . log ( `era: ${ era } ` ) ;
303+ const overviews = ( await api . query . staking . erasStakersOverview . entries ( era ) ) . map ( ( [ key , value ] ) => {
304+ const stash = key . args [ 1 ] . toHuman ( ) ;
305+ const metadata = value . unwrap ( ) ;
306+ return { stash, metadata }
307+ } ) ;
308+ console . log ( `MaxExposurePageSize: ${ api . consts . staking . maxExposurePageSize } ` ) ;
309+ console . log ( `overviews/exposed validators: ${ overviews . length } ` ) ;
310+ for ( let overview of overviews ) {
311+ console . log ( `stash: ${ overview . stash } , page_count: ${ overview . metadata . pageCount . toNumber ( ) } , nominators: ${ overview . metadata . nominatorCount . toNumber ( ) } ` ) ;
312+ }
313+ const sumNominators = overviews . map ( ( { metadata} ) => metadata . nominatorCount . toNumber ( ) ) . reduce ( ( a , b ) => a + b , 0 ) ;
314+ console . log ( `sumNominators: ${ sumNominators } ` ) ;
315+
316+ // find them in the bags-list
317+ console . log ( `searching for ${ stash } in the bags-list` ) ;
318+ const node = await api . query . voterList . listNodes ( stash ) ;
319+ if ( node . isSome ) {
320+ const nodeData = node . unwrap ( ) ;
321+ console . log ( `found in bags-list: ${ nodeData . toString ( ) } ` ) ;
322+ console . log ( `score: ${ balance ( nodeData . score ) } ` ) ;
323+ console . log ( `bagUpper: ${ balance ( nodeData . bagUpper ) } ` ) ;
324+ } else {
325+ console . log ( `not found in bags-list` ) ;
326+ }
327+
328+ // search for stash in all pages of the exposure in the current era.
329+ const all_exposures = [ ] ;
330+ for ( let overview of overviews ) {
331+ for ( let page = 0 ; page < overview . metadata . pageCount . toNumber ( ) ; page ++ ) {
332+ let page_exposure = ( await api . query . staking . erasStakersPaged ( era , overview . stash , page ) ) . unwrap ( ) ;
333+ let backing = page_exposure . others . find ( ( x ) => {
334+ return x . who . toString ( ) == stash
335+ } ) ;
336+ all_exposures . push ( backing ) ;
337+ }
338+ }
339+
340+ all_exposures . forEach ( ( exposure ) => {
341+ if ( exposure ) {
342+ console . log ( `stash: ${ exposure . who . toString ( ) } , exposure: ${ exposure . value . toString ( ) } ` ) ;
343+ }
344+ } ) ;
345+ }
346+
298347export async function ExposureStats ( { ws } : HandlerArgs ) : Promise < void > {
299348 const api = await getApi ( ws ) ;
300349
@@ -329,5 +378,5 @@ export async function controllerStats({ ws }: HandlerArgs): Promise<void> {
329378}
330379
331380export async function playgroundHandler ( args : HandlerArgs ) : Promise < void > {
332- await ExposureStats ( args ) ;
381+ await isExposed ( args . ws , "5CMHncn3PkANkyXXcjvd7hN1yhuqbkntofr8o9uncqENCiAU" )
333382}
0 commit comments