diff --git a/packages/sdk/src/index.ts b/packages/sdk/src/index.ts index 2f343f2f..425cad66 100644 --- a/packages/sdk/src/index.ts +++ b/packages/sdk/src/index.ts @@ -32,5 +32,6 @@ export { SigningCallback, SigningCosmWasmClient, ExecuteResult, + UploadMeta, UploadReceipt, } from "./signingcosmwasmclient"; diff --git a/packages/sdk/src/signingcosmwasmclient.spec.ts b/packages/sdk/src/signingcosmwasmclient.spec.ts index 6a4208ea..56cb6171 100644 --- a/packages/sdk/src/signingcosmwasmclient.spec.ts +++ b/packages/sdk/src/signingcosmwasmclient.spec.ts @@ -4,7 +4,7 @@ import { assert } from "@iov/utils"; import { Secp256k1Pen } from "./pen"; import { RestClient } from "./restclient"; -import { SigningCosmWasmClient } from "./signingcosmwasmclient"; +import { SigningCosmWasmClient, UploadMeta } from "./signingcosmwasmclient"; import { getRandomizedHackatom, makeRandomAddress, pendingWithoutWasmd } from "./testutils.spec"; import { Coin } from "./types"; @@ -50,6 +50,23 @@ describe("SigningCosmWasmClient", () => { expect(compressedSize).toBeLessThan(wasm.length * 0.5); expect(codeId).toBeGreaterThanOrEqual(1); }); + + it("can set builder and source", async () => { + pendingWithoutWasmd(); + const pen = await Secp256k1Pen.fromMnemonic(faucet.mnemonic); + const client = new SigningCosmWasmClient(httpUrl, faucet.address, signBytes => pen.sign(signBytes)); + const wasm = getRandomizedHackatom(); + + const meta: UploadMeta = { + source: "https://crates.io/api/v1/crates/cw-nameservice/0.1.0/download", + builder: "confio/cosmwasm-opt:0.6.2", + }; + const { codeId } = await client.upload(wasm, meta); + + const codeDetails = await client.getCodeDetails(codeId); + expect(codeDetails.source).toEqual(meta.source); + expect(codeDetails.builder).toEqual(meta.builder); + }); }); describe("instantiate", () => { diff --git a/packages/sdk/src/signingcosmwasmclient.ts b/packages/sdk/src/signingcosmwasmclient.ts index efb76b21..2dc60779 100644 --- a/packages/sdk/src/signingcosmwasmclient.ts +++ b/packages/sdk/src/signingcosmwasmclient.ts @@ -51,6 +51,13 @@ const defaultFees: FeeTable = { }, }; +export interface UploadMeta { + /** The source URL */ + readonly source?: string; + /** The builder tag */ + readonly builder?: string; +} + export interface UploadReceipt { /** Size of the original wasm code in bytes */ readonly originalSize: number; @@ -96,7 +103,10 @@ export class SigningCosmWasmClient extends CosmWasmClient { } /** Uploads code and returns a receipt, including the code ID */ - public async upload(wasmCode: Uint8Array, memo = ""): Promise { + public async upload(wasmCode: Uint8Array, meta: UploadMeta = {}, memo = ""): Promise { + const source = meta.source || ""; + const builder = meta.builder || ""; + const compressed = pako.gzip(wasmCode, { level: 9 }); const storeCodeMsg: MsgStoreCode = { type: "wasm/store-code", @@ -104,8 +114,8 @@ export class SigningCosmWasmClient extends CosmWasmClient { sender: this.senderAddress, // eslint-disable-next-line @typescript-eslint/camelcase wasm_byte_code: Encoding.toBase64(compressed), - source: "", - builder: "", + source: source, + builder: builder, }, }; const fee = this.fees.upload; diff --git a/packages/sdk/types/index.d.ts b/packages/sdk/types/index.d.ts index 6a0b7d20..b1cd5985 100644 --- a/packages/sdk/types/index.d.ts +++ b/packages/sdk/types/index.d.ts @@ -31,5 +31,6 @@ export { SigningCallback, SigningCosmWasmClient, ExecuteResult, + UploadMeta, UploadReceipt, } from "./signingcosmwasmclient"; diff --git a/packages/sdk/types/signingcosmwasmclient.d.ts b/packages/sdk/types/signingcosmwasmclient.d.ts index 51513bd9..9510b2fa 100644 --- a/packages/sdk/types/signingcosmwasmclient.d.ts +++ b/packages/sdk/types/signingcosmwasmclient.d.ts @@ -11,6 +11,12 @@ export interface FeeTable { readonly exec: StdFee; readonly send: StdFee; } +export interface UploadMeta { + /** The source URL */ + readonly source?: string; + /** The builder tag */ + readonly builder?: string; +} export interface UploadReceipt { /** Size of the original wasm code in bytes */ readonly originalSize: number; @@ -40,7 +46,7 @@ export declare class SigningCosmWasmClient extends CosmWasmClient { getNonce(address?: string): Promise; getAccount(address?: string): Promise; /** Uploads code and returns a receipt, including the code ID */ - upload(wasmCode: Uint8Array, memo?: string): Promise; + upload(wasmCode: Uint8Array, meta?: UploadMeta, memo?: string): Promise; instantiate( codeId: number, initMsg: object, diff --git a/scripts/wasmd/contracts/checksums.sha256 b/scripts/wasmd/contracts/checksums.sha256 index d31818e8..a7afcb40 100644 --- a/scripts/wasmd/contracts/checksums.sha256 +++ b/scripts/wasmd/contracts/checksums.sha256 @@ -1,2 +1,2 @@ aff8c8873d79d2153a8b9066a0683fec3c903669267eb806ffa831dcd4b3daae cw-erc20.wasm -8427fcbf9e6c15d0e0dea0afe75640d997a6854d03c3aa1c8bdf1a9787a35681 cw-nameservice.wasm +d5dde423d321f7d3793a9b1667d06ac86c7f57dfbd2534a9c790963e1c2955ed cw-nameservice.wasm diff --git a/scripts/wasmd/contracts/cw-nameservice.wasm b/scripts/wasmd/contracts/cw-nameservice.wasm index 33f14cc8..d202c747 100644 Binary files a/scripts/wasmd/contracts/cw-nameservice.wasm and b/scripts/wasmd/contracts/cw-nameservice.wasm differ diff --git a/scripts/wasmd/deploy_erc20.js b/scripts/wasmd/deploy_erc20.js index 12db4239..4401d53d 100755 --- a/scripts/wasmd/deploy_erc20.js +++ b/scripts/wasmd/deploy_erc20.js @@ -72,7 +72,7 @@ async function main() { const client = new SigningCosmWasmClient(httpUrl, faucet.address, signBytes => pen.sign(signBytes)); const wasm = fs.readFileSync(__dirname + "/contracts/cw-erc20.wasm"); - const uploadReceipt = await client.upload(wasm, "Upload ERC20 contract"); + const uploadReceipt = await client.upload(wasm, {}, "Upload ERC20 contract"); console.info(`Upload succeeded. Receipt: ${JSON.stringify(uploadReceipt)}`); for (const initMsg of [initMsgHash, initMsgIsa, initMsgJade]) { diff --git a/scripts/wasmd/deploy_nameservice.js b/scripts/wasmd/deploy_nameservice.js index 023c8b4b..9b689420 100755 --- a/scripts/wasmd/deploy_nameservice.js +++ b/scripts/wasmd/deploy_nameservice.js @@ -11,18 +11,27 @@ const faucet = { address: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", }; -const initFree = { - name: "Free", +const codeMeta = { + source: "https://crates.io/api/v1/crates/cw-nameservice/0.2.0/download", + builder: "confio/cosmwasm-opt:0.7.0", }; -const initLuxury = { - name: "Luxury", - purchase_price: { - denom: "ucosm", - amount: "2000000", - }, - transfer_price: { - denom: "ucosm", - amount: "1000000", + +const free = { + label: "Free", + initMsg: {}, +}; + +const luxury = { + label: "Luxury", + initMsg: { + purchase_price: { + denom: "ucosm", + amount: "2000000", + }, + transfer_price: { + denom: "ucosm", + amount: "1000000", + }, }, }; @@ -31,13 +40,13 @@ async function main() { const client = new SigningCosmWasmClient(httpUrl, faucet.address, signBytes => pen.sign(signBytes)); const wasm = fs.readFileSync(__dirname + "/contracts/cw-nameservice.wasm"); - const uploadReceipt = await client.upload(wasm, "Upload Name Service contract"); + const uploadReceipt = await client.upload(wasm, codeMeta, "Upload Name Service code"); console.info(`Upload succeeded. Receipt: ${JSON.stringify(uploadReceipt)}`); - for (const initMsg of [initFree, initLuxury]) { - const memo = `Create an nameservice instance for ${initMsg.name}`; - const contractAddress = await client.instantiate(uploadReceipt.codeId, initMsg, initMsg.name, memo); - console.info(`Contract instantiated for ${initMsg.name} at ${contractAddress}`); + for (const { label, initMsg } of [free, luxury]) { + const memo = `Create an nameservice instance "${label}"`; + const contractAddress = await client.instantiate(uploadReceipt.codeId, initMsg, label, memo); + console.info(`Contract "${label}" instantiated at ${contractAddress}`); } }