import { DeriveStakingQuery } from '@polkadot/api-derive/types' ; import { InjectedAccountWithMeta } from '@polkadot/extension-inject/types' ; import { Option } from '@polkadot/types' ; import { AccountId , StakingLedger } from '@polkadot/types/interfaces' ; function getControllers ( accounts , stashControllerMap ) { const allStakingInfo = Object . values ( stashControllerMap ) ; const allControllers = [ ] ; accounts . forEach ( account => { allStakingInfo . forEach ( staking => { if ( staking . controllerId && staking . controllerId . toHuman && staking . controllerId . toHuman ( ) === account . address ) { allControllers . push ( account ) ; } } ) ; } ) ; return allControllers ; } function getStashes ( allAccounts , ownBonded , ownLedger ) { const result = [ ] ; ownBonded . forEach ( ( value , index ) : void => { value . isSome && result . push ( allAccounts [ index ] ) ; } ) ; ownLedger . forEach ( ( ledger ) : void => { if ( ledger . isSome ) { const stashId = ledger . unwrap ( ) . stash . toString ( ) ; ! result . some ( ( [ accountId ] ) : boolean => accountId === stashId ) && result . push ( stashId ) ; } } ) ; return result ; } export { getControllers , getStashes } ;