Skip to content

Commit

Permalink
adding getMergedValidatorDetailsStakedMap/getStakedValidatorDetailsMap
Browse files Browse the repository at this point in the history
  • Loading branch information
karnthis committed Apr 11, 2023
1 parent 138b327 commit 73aa0cd
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 3 deletions.
32 changes: 30 additions & 2 deletions src/classes/govHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
IDelegationSummaryMap,
IStakingValidator,
IStakingValidatorExtendedMap,
IStakingValidatorMap
IStakingValidatorMap,
IStakingValidatorStakedMap
} from '@/interfaces'
import { TValidatorStatus } from '@/types/TValidatorStatus'

Expand Down Expand Up @@ -54,6 +55,19 @@ export default class GovHandler implements IGovHandler {
return acc
}, {})
}
async getStakedValidatorDetailsMap (): Promise<IStakingValidatorStakedMap> {
const allVals = await this.getCompleteMergedValidatorDetailsMap()
const staked = await this.getStakedMap()
const final: IStakingValidatorStakedMap = {}
for (let val in staked) {
if (allVals[val]) {
final[val] = { ...allVals[val], stakedDetails: staked[val] }
} else {
// do nothing
}
}
return final
}
async getDelegatorValidatorDetails (validatorAddress: string): Promise<IStakingValidator> {
const result = (await this.pH.stakingQuery.queryDelegatorValidator({
delegatorAddr: this.walletRef.getJackalAddress(),
Expand Down Expand Up @@ -105,7 +119,21 @@ export default class GovHandler implements IGovHandler {
const staked = await this.getAllDelegatorValidatorDetailsMap()
const allOfStatus = await this.getAllValidatorDetailsMap(status)
return flagStaked(allOfStatus, staked)

}
async getMergedValidatorDetailsStakedMap (status: TValidatorStatus): Promise<IStakingValidatorStakedMap> {
const staked = await this.getAllDelegatorValidatorDetailsMap()
const allOfStatus = await this.getAllValidatorDetailsMap(status)
const flagged = flagStaked(allOfStatus, staked)
const stakedMap = await this.getStakedMap()
const final: IStakingValidatorStakedMap = {}
for (let val in stakedMap) {
if (flagged[val]) {
final[val] = { ...flagged[val], stakedDetails: stakedMap[val] }
} else {
final[val] = { ...flagged[val] }
}
}
return final
}
async getCompleteMergedValidatorDetailsMap (): Promise<IStakingValidatorExtendedMap> {
const staked = await this.getAllDelegatorValidatorDetailsMap()
Expand Down
5 changes: 5 additions & 0 deletions src/interfaces/IStakingValidatorStaked.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { IDelegationSummary, IStakingValidatorExtended } from '@/interfaces'

export default interface IStakingValidatorStaked extends IStakingValidatorExtended {
stakedDetails?: IDelegationSummary
}
5 changes: 5 additions & 0 deletions src/interfaces/IStakingValidatorStakedMap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { IStakingValidatorStaked } from '@/interfaces'

export default interface IStakingValidatorStakedMap {
[key: string]: IStakingValidatorStaked
}
5 changes: 4 additions & 1 deletion src/interfaces/classes/IGovHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {
IDelegationSummaryMap,
IStakingValidator,
IStakingValidatorExtendedMap,
IStakingValidatorMap
IStakingValidatorMap,
IStakingValidatorStakedMap
} from '@/interfaces/'
import ICoin from '@/interfaces/ICoin'
import { TValidatorStatus } from '@/types/TValidatorStatus'
Expand All @@ -14,13 +15,15 @@ export default interface IGovHandler {
getRewards (validatorAddress: string): Promise<ICoin[]>
getTotalStaked (): Promise<number>
getStakedMap (): Promise<IDelegationSummaryMap>
getStakedValidatorDetailsMap (): Promise<IStakingValidatorStakedMap>
getDelegatorValidatorDetails (validatorAddress: string): Promise<IStakingValidator>
getAllDelegatorValidatorDetails (): Promise<IStakingValidator[]>
getAllDelegatorValidatorDetailsMap (): Promise<IStakingValidatorMap>
getValidatorDetails (validatorAddress: string): Promise<IStakingValidator>
getAllValidatorDetails (status: string): Promise<IStakingValidator[]>
getAllValidatorDetailsMap (status: TValidatorStatus): Promise<IStakingValidatorMap>
getMergedValidatorDetailsMap (status: TValidatorStatus): Promise<IStakingValidatorExtendedMap>
getMergedValidatorDetailsStakedMap (status: TValidatorStatus): Promise<IStakingValidatorStakedMap>
getCompleteMergedValidatorDetailsMap (): Promise<IStakingValidatorExtendedMap>
claimDelegatorRewards (validatorAddresses: string[]): Promise<void>
delegateTokens (validatorAddress: string, amount: number): Promise<void>
Expand Down
4 changes: 4 additions & 0 deletions src/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ import IStakingValidator from '@/interfaces/IStakingValidator'
import IStakingValidatorExtended from '@/interfaces/IStakingValidatorExtended'
import IStakingValidatorExtendedMap from '@/interfaces/IStakingValidatorExtendedMap'
import IStakingValidatorMap from '@/interfaces/IStakingValidatorMap'
import IStakingValidatorStaked from '@/interfaces/IStakingValidatorStaked'
import IStakingValidatorStakedMap from '@/interfaces/IStakingValidatorStakedMap'
import IStorageClientFree from '@/interfaces/IStorageClientFree'
import IStoragePaymentInfo from '@/interfaces/IStoragePaymentInfo'
import IStray from '@/interfaces/IStray'
Expand Down Expand Up @@ -102,6 +104,8 @@ export {
IStakingValidatorExtended,
IStakingValidatorExtendedMap,
IStakingValidatorMap,
IStakingValidatorStaked,
IStakingValidatorStakedMap,
IStorageClientFree,
IStoragePaymentInfo,
IStray,
Expand Down

0 comments on commit 73aa0cd

Please sign in to comment.