Skip to content

Commit

Permalink
feat(namada): fetch validator from specified epoch
Browse files Browse the repository at this point in the history
  • Loading branch information
egasimus committed Sep 19, 2024
1 parent e8e03d7 commit 1eb6c03
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
5 changes: 3 additions & 2 deletions packages/namada/NamadaChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import NamadaConnection from './NamadaConnection'
import type { Validator } from './NamadaPoS'
import { Decode, initDecoder } from './NamadaDecode'
import type { NamadaDecoder } from './NamadaDecode'
import type { Epoch } from './Namada'

export default class NamadaChain extends CW.Chain {
decode: NamadaDecoder = Decode as unknown as NamadaDecoder
Expand Down Expand Up @@ -123,8 +124,8 @@ export default class NamadaChain extends CW.Chain {
status: 'below_capacity'
}))
}
fetchValidator (address: string) {
return this.getConnection().fetchValidatorImpl(address)
fetchValidator (address: string, options?: { epoch?: Epoch }) {
return this.getConnection().fetchValidatorImpl(address, options)
}
fetchValidatorStake (address: string, epoch?: number|string|bigint) {
return this.getConnection().fetchValidatorStakeImpl(address, epoch)
Expand Down
6 changes: 3 additions & 3 deletions packages/namada/NamadaConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as PoS from './NamadaPoS'
import * as PGF from './NamadaPGF'
import * as Gov from './NamadaGov'
import * as Epoch from './NamadaEpoch'
import type { Chain as Namada } from './Namada'
import type { Chain as Namada, Epoch } from './Namada'
import { decode, u256 } from '@hackbg/borshest'

export default class NamadaConnection extends CW.Connection {
Expand Down Expand Up @@ -109,8 +109,8 @@ export default class NamadaConnection extends CW.Connection {
fetchValidatorAddressesImpl () {
return PoS.fetchValidatorAddresses(this)
}
fetchValidatorImpl (address: string) {
return PoS.fetchValidator(this, address)
fetchValidatorImpl (address: string, options?: { epoch?: Epoch }) {
return PoS.fetchValidator(this, address, options)
}
fetchValidatorsImpl (options?: {
epoch?: string|number|bigint,
Expand Down
11 changes: 3 additions & 8 deletions packages/namada/NamadaPoS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,10 @@ const byBondedStake = (a: {bondedStake: number|bigint}, b: {bondedStake: number|

/** Fetch details about one validator. */
export async function fetchValidator (
connection: NamadaConnection, namadaAddress: Address, epoch?: Epoch
connection: NamadaConnection, namadaAddress: Address, options?: { epoch?: Epoch }
) {
return await new NamadaValidator({
chain: connection.chain,
address: null as any, // FIXME
namadaAddress
}).fetchDetails({
epoch
})
const base = { chain: connection.chain, address: null as any, namadaAddress }
return await new NamadaValidator(base).fetchDetails(options)
}

/** Describes a Namada validator. */
Expand Down

0 comments on commit 1eb6c03

Please sign in to comment.