Update wasmd to v0.7.0-rc3 and adapt code

This commit is contained in:
Simon Warta 2020-03-02 17:24:04 +01:00
parent 792e133b29
commit 8845ee08f5
5 changed files with 33 additions and 33 deletions

View File

@ -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<CodeDetails> {
// 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),
};
}

View File

@ -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 () => {

View File

@ -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<string>
| WasmResponse<CodeInfo[]>
| WasmResponse<CodeDetails>
| WasmResponse<ContractInfo[] | null>
| WasmResponse<ContractDetails | null>
| WasmResponse<GetCodeResult>;
| WasmResponse<ContractDetails | null>;
/**
* 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<Uint8Array> {
public async getCode(id: number): Promise<CodeDetails> {
const path = `/wasm/code/${id}`;
const responseData = (await this.get(path)) as WasmResponse<GetCodeResult>;
const { code } = unwrapWasmResponse(responseData);
return fromBase64(code);
const responseData = (await this.get(path)) as WasmResponse<CodeDetails>;
return unwrapWasmResponse(responseData);
}
public async listContractsByCodeId(id: number): Promise<readonly ContractInfo[]> {

View File

@ -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<string>
| WasmResponse<CodeInfo[]>
| WasmResponse<CodeDetails>
| WasmResponse<ContractInfo[] | null>
| WasmResponse<ContractDetails | null>
| WasmResponse<GetCodeResult>;
| WasmResponse<ContractDetails | null>;
/**
* The mode used to send transaction
*
@ -173,7 +174,7 @@ export declare class RestClient {
*/
postTx(tx: StdTx): Promise<PostTxsResponse>;
listCodeInfo(): Promise<readonly CodeInfo[]>;
getCode(id: number): Promise<Uint8Array>;
getCode(id: number): Promise<CodeDetails>;
listContractsByCodeId(id: number): Promise<readonly ContractInfo[]>;
/**
* Returns null when contract was not found at this address.

View File

@ -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"