diff --git a/packages/namada/NamadaChain.ts b/packages/namada/NamadaChain.ts index 3f5309c11a..e176ea75e3 100644 --- a/packages/namada/NamadaChain.ts +++ b/packages/namada/NamadaChain.ts @@ -145,6 +145,9 @@ export default class NamadaChain extends CW.Chain { fetchProposalInfo (id: number|bigint) { return this.getConnection().fetchProposalInfoImpl(id) } + fetchProposalWasm (id: number|bigint) { + return this.getConnection().fetchProposalWasmImpl(id) + } fetchEpoch (...args: Parameters) { return this.getConnection().fetchEpochImpl(...args) } diff --git a/packages/namada/NamadaConnection.ts b/packages/namada/NamadaConnection.ts index f9db4d6449..f68d95729a 100644 --- a/packages/namada/NamadaConnection.ts +++ b/packages/namada/NamadaConnection.ts @@ -58,6 +58,9 @@ export default class NamadaConnection extends CW.Connection { fetchProposalInfoImpl (id: number|bigint) { return Gov.fetchProposalInfo(this, id) } + fetchProposalWasmImpl (id: number|bigint) { + return Gov.fetchProposalWasm(this, id) + } fetchPGFParametersImpl () { return PGF.fetchPGFParameters(this) diff --git a/packages/namada/NamadaGov.ts b/packages/namada/NamadaGov.ts index aee6499d6d..19314cac03 100644 --- a/packages/namada/NamadaGov.ts +++ b/packages/namada/NamadaGov.ts @@ -33,21 +33,23 @@ export async function fetchProposalInfo ( : decodeResultResponse(connection.decode.gov_result(resultResponse.slice(1)) as Required>) - const bigId = BigInt(id) + return { id: BigInt(id), proposal, votes, result } +} + +export async function fetchProposalWasm ( + connection: Pick, id: number|bigint +) { + id = BigInt(id) const codeKey = connection.decode.gov_proposal_code_key(BigInt(id)) let wasm - if (proposal.type?.type === 'DefaultWithWasm') { - const hasKey = await connection.abciQuery(`/shell/has_key/${codeKey}`) - if (hasKey[0] === 1) { - wasm = await connection.abciQuery(`/shell/value/${codeKey}`) - wasm = wasm.slice(4) // trim length prefix - //const { writeFile } = await import('node:fs/promises') - //writeFile(`${bigId}.wasm`, wasm) - } else { - console.warn(`WASM for proposal ${id} was not found at key ${codeKey}`) - } + const hasKey = await connection.abciQuery(`/shell/has_key/${codeKey}`) + if (hasKey[0] === 1) { + wasm = await connection.abciQuery(`/shell/value/${codeKey}`) + wasm = wasm.slice(4) // trim length prefix + return { id, codeKey, wasm } + } else { + throw new Error(`WASM for proposal ${id} was not found at key ${codeKey}`) } - return { id: bigId, proposal, votes, result, codeKey, wasm } } const decodeResultResponse = ( @@ -77,6 +79,9 @@ interface NamadaGovernanceProposal { readonly proposal: ReturnType readonly votes: ReturnType readonly result: NamadaGovernanceProposalResult|null +} + +interface NamadaGovernanceProposalWasm { readonly codeKey: string readonly wasm?: Uint8Array }