Return sessionIds & nextSessionIds in staking.info (#1272)
* Return sessionIds & nextSessionIds in staking.info * Simplify
This commit is contained in:
@@ -84,27 +84,32 @@ function redeemableSum (stakingLedger: StakingLedger | undefined, eraLength: BN,
|
||||
);
|
||||
}
|
||||
|
||||
function unwrapSessionIds (stashId: AccountId, queuedKeys: Option<AccountId> | Vec<[AccountId, Keys] & Codec>, nextKeys: Option<Keys>): { nextSessionId?: AccountId; sessionId?: AccountId } {
|
||||
function unwrapSessionIds (stashId: AccountId, queuedKeys: Option<AccountId> | Vec<[AccountId, Keys] & Codec>, nextKeys: Option<Keys>): { nextSessionIds: AccountId[]; nextSessionId?: AccountId; sessionIds: AccountId[]; sessionId?: AccountId } {
|
||||
// for 2.x we have a Vec<(ValidatorId,Keys)> of the keys
|
||||
if (Array.isArray(queuedKeys)) {
|
||||
const [, { ed25519: sessionId }] = queuedKeys.find(([currentId]): boolean => currentId.eq(stashId)) || [undefined, { ed25519: undefined }];
|
||||
const sessionIds = (queuedKeys.find(([currentId]): boolean => currentId.eq(stashId)) || [undefined, { toArray: (): AccountId[] => [] }])[1].toArray() as AccountId[];
|
||||
const nextSessionIds = nextKeys.isSome
|
||||
? nextKeys.unwrap().toArray() as AccountId[]
|
||||
: [];
|
||||
|
||||
return {
|
||||
nextSessionId: nextKeys.isSome
|
||||
? nextKeys.unwrap().ed25519
|
||||
: undefined,
|
||||
sessionId
|
||||
nextSessionId: nextSessionIds[0],
|
||||
nextSessionIds,
|
||||
sessionId: sessionIds[0],
|
||||
sessionIds
|
||||
};
|
||||
}
|
||||
|
||||
// substrate 1.x
|
||||
const nextSessionId = queuedKeys.isSome
|
||||
? queuedKeys.unwrap()
|
||||
: undefined;
|
||||
const nextSessionIds = queuedKeys.isSome
|
||||
? [queuedKeys.unwrap()]
|
||||
: [];
|
||||
|
||||
return {
|
||||
nextSessionId,
|
||||
sessionId: nextSessionId
|
||||
nextSessionId: nextSessionIds[0],
|
||||
nextSessionIds,
|
||||
sessionId: nextSessionIds[0],
|
||||
sessionIds: nextSessionIds
|
||||
};
|
||||
}
|
||||
|
||||
@@ -177,7 +182,7 @@ export function info (api: ApiInterfaceRx): (_accountId: Uint8Array | string) =>
|
||||
? retrieveInfo(api, accountId, controllerId.unwrap())
|
||||
: stakingLedger.isSome
|
||||
? retrieveInfo(api, stakingLedger.unwrap().stash, accountId)
|
||||
: of({ accountId })
|
||||
: of({ accountId, nextSessionIds: [], sessionIds: [] })
|
||||
),
|
||||
drr()
|
||||
);
|
||||
|
||||
@@ -95,11 +95,15 @@ export interface DerivedStakingOnlineStatus {
|
||||
export interface DerivedStaking extends DerivedStakingOnlineStatus {
|
||||
accountId: AccountId;
|
||||
controllerId?: AccountId;
|
||||
// @deprecated Use nextSessionIds instead
|
||||
nextSessionId?: AccountId;
|
||||
nextSessionIds: AccountId[];
|
||||
nominators?: AccountId[];
|
||||
redeemable?: BN;
|
||||
rewardDestination?: RewardDestination;
|
||||
// @deprecated Use sessionIds instead
|
||||
sessionId?: AccountId;
|
||||
sessionIds: AccountId[];
|
||||
stakers?: Exposure;
|
||||
stakingLedger?: StakingLedger;
|
||||
stashId?: AccountId;
|
||||
|
||||
Reference in New Issue
Block a user