diff --git a/packages/namada/NamadaBlock.ts b/packages/namada/NamadaBlock.ts index 4f7bcd84e7..2e8afcb90d 100644 --- a/packages/namada/NamadaBlock.ts +++ b/packages/namada/NamadaBlock.ts @@ -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' @@ -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, @@ -57,7 +58,7 @@ 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 { throw new Error('NamadaBlock.fetchByHash: not implemented') @@ -65,8 +66,8 @@ class NamadaBlock extends Block { static fromResponses ( responses: NonNullable, - { 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 diff --git a/packages/namada/NamadaChain.ts b/packages/namada/NamadaChain.ts index e176ea75e3..a49fb67a3d 100644 --- a/packages/namada/NamadaChain.ts +++ b/packages/namada/NamadaChain.ts @@ -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 ( @@ -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)=>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)=>Object.assign(v, { status: 'consensus' })) } async fetchValidatorsBelowCapacity (options?: { max?: number, percentage?: boolean }) { let validators = await this.getConnection().fetchValidatorsBelowCapacityImpl() @@ -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)=>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)=>Object.assign(v, { status: 'below_capacity' - }) as Validator) + })) } fetchValidator (address: string) { return this.getConnection().fetchValidatorImpl(address) diff --git a/packages/namada/NamadaDecode.ts b/packages/namada/NamadaDecode.ts index 919c9ffa49..c6d0949a57 100644 --- a/packages/namada/NamadaDecode.ts +++ b/packages/namada/NamadaDecode.ts @@ -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' @@ -138,6 +140,12 @@ export interface NamadaDecoder { vpAllowlist: string } + block (blockResponse: unknown, resultsResponse: unknown): { + hash: string, + header: NamadaBlock["header"] + transactions: Array & {id: string}> + } + tx (): { content: NamadaTxContent, [key: string]: unknown