Skip to content

Commit

Permalink
fix(namada): 10 type fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
egasimus committed Aug 30, 2024
1 parent 69a9450 commit 29907a0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
11 changes: 6 additions & 5 deletions packages/namada/NamadaBlock.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type * as Namada from './Namada'
import type { NamadaDecoder } from './NamadaDecode'
import { Decode } from './NamadaDecode'
import { Block, Transaction } from '@fadroma/cw'

Expand Down Expand Up @@ -32,8 +33,8 @@ class NamadaBlock extends Block {

/** Responses from block API endpoints. */
static async fetchByHeight (
{ url, decode = Decode, chain }: {
url: string|URL, decode?: typeof Decode, chain?: Namada.Chain
{ url, decode = Decode as unknown as NamadaDecoder, chain }: {
url: string|URL, decode?: NamadaDecoder, chain?: Namada.Chain
},
{ height, raw }: {
height?: number|string|bigint,
Expand All @@ -57,16 +58,16 @@ class NamadaBlock extends Block {
}

static async fetchByHash (
_1: { url: string|URL, decode?: typeof Decode, chain?: Namada.Chain },
_1: { url: string|URL, decode?: NamadaDecoder, chain?: Namada.Chain },
_2: { hash: string, raw?: boolean },
): Promise<NamadaBlock> {
throw new Error('NamadaBlock.fetchByHash: not implemented')
}

static fromResponses (
responses: NonNullable<NamadaBlock["responses"]>,
{ decode = Decode, chain, height, raw = false }: {
decode?: typeof Decode
{ decode = Decode as unknown as NamadaDecoder, chain, height, raw = false }: {
decode?: NamadaDecoder
chain?: Namada.Chain,
height?: string|number|bigint,
raw?: boolean
Expand Down
18 changes: 8 additions & 10 deletions packages/namada/NamadaChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Decode, initDecoder } from './NamadaDecode'
import type { NamadaDecoder } from './NamadaDecode'

export default class NamadaChain extends CW.Chain {
decode: NamadaDecoder = Decode as NamadaDecoder
decode: NamadaDecoder = Decode as unknown as NamadaDecoder

/** Connect to Namada over one or more endpoints. */
static async connect (
Expand Down Expand Up @@ -99,14 +99,12 @@ export default class NamadaChain extends CW.Chain {
}
if (options?.percentage) {
const totalStake = Number(await this.fetchTotalStaked())
validators = validators.map((v: Validator)=>Object.assign(v, {
validators = validators.map((v: Partial<Validator>)=>Object.assign(v, {
bondedStake: Number(v.bondedStake),
stakePercentage: (Number(v.bondedStake) / totalStake) * 100
}) as Validator)
}))
}
return validators.map((v: Validator)=>Object.assign(v, {
status: 'consensus'
}) as Validator)
return validators.map((v: Partial<Validator>)=>Object.assign(v, { status: 'consensus' }))
}
async fetchValidatorsBelowCapacity (options?: { max?: number, percentage?: boolean }) {
let validators = await this.getConnection().fetchValidatorsBelowCapacityImpl()
Expand All @@ -115,14 +113,14 @@ export default class NamadaChain extends CW.Chain {
}
if (options?.percentage) {
const totalStake = Number(await this.fetchTotalStaked())
validators = validators.map((v: Validator)=>Object.assign(v, {
validators = validators.map((v: Partial<Validator>)=>Object.assign(v, {
bondedStake: Number(v.bondedStake),
stakePercentage: (Number(v.bondedStake) / totalStake) * 100
}) as Validator)
}))
}
return validators.map((v: Validator)=>Object.assign(v, {
return validators.map((v: Partial<Validator>)=>Object.assign(v, {
status: 'below_capacity'
}) as Validator)
}))
}
fetchValidator (address: string) {
return this.getConnection().fetchValidatorImpl(address)
Expand Down
8 changes: 8 additions & 0 deletions packages/namada/NamadaDecode.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import init, { Decode } from './pkg/fadroma_namada.js'
import type NamadaBlock from './NamadaBlock'
import type { Transaction as NamadaTransaction } from './NamadaBlock'
import type * as PGF from './NamadaPGF'
import type * as PoS from './NamadaPoS'
import type * as Gov from './NamadaGov'
Expand Down Expand Up @@ -138,6 +140,12 @@ export interface NamadaDecoder {
vpAllowlist: string
}

block (blockResponse: unknown, resultsResponse: unknown): {
hash: string,
header: NamadaBlock["header"]
transactions: Array<Partial<NamadaTransaction> & {id: string}>
}

tx (): {
content: NamadaTxContent,
[key: string]: unknown
Expand Down

0 comments on commit 29907a0

Please sign in to comment.