diff --git a/packages/sdk/src/cosmwasmclient.ts b/packages/sdk/src/cosmwasmclient.ts index 370ce332..9c62f69d 100644 --- a/packages/sdk/src/cosmwasmclient.ts +++ b/packages/sdk/src/cosmwasmclient.ts @@ -279,7 +279,7 @@ export class CosmWasmClient { (entry): Code => ({ id: entry.id, creator: entry.creator, - checksum: Encoding.toHex(Encoding.fromHex(entry.code_hash)), + checksum: Encoding.toHex(Encoding.fromHex(entry.data_hash)), source: entry.source || undefined, builder: entry.builder || undefined, }), @@ -287,15 +287,15 @@ export class CosmWasmClient { } public async getCodeDetails(codeId: number): Promise { - // TODO: implement as one request when https://github.com/cosmwasm/wasmd/issues/90 is done - const [codeInfos, getCodeResult] = await Promise.all([this.getCodes(), this.restClient.getCode(codeId)]); - - const codeInfo = codeInfos.find(code => code.id === codeId); - if (!codeInfo) throw new Error("No code info found"); + const getCodeResult = await this.restClient.getCode(codeId); return { - ...codeInfo, - data: getCodeResult, + id: getCodeResult.id, + creator: getCodeResult.creator, + checksum: Encoding.toHex(Encoding.fromHex(getCodeResult.data_hash)), + source: getCodeResult.source || undefined, + builder: getCodeResult.builder || undefined, + data: Encoding.fromBase64(getCodeResult.data), }; } diff --git a/packages/sdk/src/restclient.spec.ts b/packages/sdk/src/restclient.spec.ts index 28e95ce1..09e13e63 100644 --- a/packages/sdk/src/restclient.spec.ts +++ b/packages/sdk/src/restclient.spec.ts @@ -68,7 +68,7 @@ async function uploadCustomContract( sender: faucet.address, wasm_byte_code: toBase64(wasmCode), source: "https://github.com/confio/cosmwasm/raw/0.7/lib/vm/testdata/contract_0.6.wasm", - builder: "cosmwasm-opt:0.6.2", + builder: "confio/cosmwasm-opt:0.6.2", }, }; const fee: StdFee = { @@ -733,15 +733,15 @@ describe("RestClient", () => { expect(lastInfo.source).toEqual( "https://github.com/confio/cosmwasm/raw/0.7/lib/vm/testdata/contract_0.6.wasm", ); - expect(lastInfo.builder).toEqual("cosmwasm-opt:0.6.2"); + expect(lastInfo.builder).toEqual("confio/cosmwasm-opt:0.6.2"); // check code hash matches expectation const wasmHash = new Sha256(wasmCode).digest(); - expect(lastInfo.code_hash.toLowerCase()).toEqual(toHex(wasmHash)); + expect(lastInfo.data_hash.toLowerCase()).toEqual(toHex(wasmHash)); // download code and check against auto-gen - const download = await client.getCode(codeId); - expect(download).toEqual(wasmCode); + const { data } = await client.getCode(codeId); + expect(fromBase64(data)).toEqual(wasmCode); }); it("can list contracts and get info", async () => { diff --git a/packages/sdk/src/restclient.ts b/packages/sdk/src/restclient.ts index ac5fd3cb..f08d2b26 100644 --- a/packages/sdk/src/restclient.ts +++ b/packages/sdk/src/restclient.ts @@ -137,12 +137,17 @@ export interface CodeInfo { /** Bech32 account address */ readonly creator: string; /** Hex-encoded sha256 hash of the code stored here */ - readonly code_hash: string; + readonly data_hash: string; // TODO: these are not supported in current wasmd readonly source?: string; readonly builder?: string; } +export interface CodeDetails extends CodeInfo { + /** Base64 encoded raw wasm data */ + readonly data: string; +} + // This is list view, without contract info export interface ContractInfo { readonly address: string; @@ -157,11 +162,6 @@ export interface ContractDetails extends ContractInfo { readonly init_msg: object; } -interface GetCodeResult { - // base64 encoded wasm - readonly code: string; -} - interface SmartQueryResponse { // base64 encoded response readonly smart: string; @@ -177,9 +177,9 @@ type RestClientResponse = | EncodeTxResponse | WasmResponse | WasmResponse + | WasmResponse | WasmResponse - | WasmResponse - | WasmResponse; + | WasmResponse; /** * The mode used to send transaction @@ -355,11 +355,10 @@ export class RestClient { // this will download the original wasm bytecode by code id // throws error if no code with this id - public async getCode(id: number): Promise { + public async getCode(id: number): Promise { const path = `/wasm/code/${id}`; - const responseData = (await this.get(path)) as WasmResponse; - const { code } = unwrapWasmResponse(responseData); - return fromBase64(code); + const responseData = (await this.get(path)) as WasmResponse; + return unwrapWasmResponse(responseData); } public async listContractsByCodeId(id: number): Promise { diff --git a/packages/sdk/types/restclient.d.ts b/packages/sdk/types/restclient.d.ts index 3e8a00d1..e1dd8191 100644 --- a/packages/sdk/types/restclient.d.ts +++ b/packages/sdk/types/restclient.d.ts @@ -106,10 +106,14 @@ export interface CodeInfo { /** Bech32 account address */ readonly creator: string; /** Hex-encoded sha256 hash of the code stored here */ - readonly code_hash: string; + readonly data_hash: string; readonly source?: string; readonly builder?: string; } +export interface CodeDetails extends CodeInfo { + /** Base64 encoded raw wasm data */ + readonly data: string; +} export interface ContractInfo { readonly address: string; readonly code_id: number; @@ -121,9 +125,6 @@ export interface ContractDetails extends ContractInfo { /** Argument passed on initialization of the contract */ readonly init_msg: object; } -interface GetCodeResult { - readonly code: string; -} declare type RestClientResponse = | NodeInfoResponse | BlockResponse @@ -134,9 +135,9 @@ declare type RestClientResponse = | EncodeTxResponse | WasmResponse | WasmResponse + | WasmResponse | WasmResponse - | WasmResponse - | WasmResponse; + | WasmResponse; /** * The mode used to send transaction * @@ -173,7 +174,7 @@ export declare class RestClient { */ postTx(tx: StdTx): Promise; listCodeInfo(): Promise; - getCode(id: number): Promise; + getCode(id: number): Promise; listContractsByCodeId(id: number): Promise; /** * Returns null when contract was not found at this address. diff --git a/scripts/wasmd/env b/scripts/wasmd/env index 44e57464..3ea3d1cb 100644 --- a/scripts/wasmd/env +++ b/scripts/wasmd/env @@ -1,5 +1,5 @@ # Choose from https://hub.docker.com/r/cosmwasm/wasmd-demo/tags REPOSITORY="cosmwasm/wasmd-demo" -VERSION="v0.7.0-rc2" +VERSION="v0.7.0-rc3" CONTAINER_NAME="wasmd"