From 01758aadb293e6fec8442bed4e622519ea235d00 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Mon, 2 Mar 2020 13:24:28 +0100 Subject: [PATCH] Standardize ExecuteResult, InstantiateResult, UploadResult --- packages/sdk/src/cosmwasmclient.spec.ts | 4 +-- packages/sdk/src/index.ts | 5 ++-- .../sdk/src/signingcosmwasmclient.spec.ts | 4 +-- packages/sdk/src/signingcosmwasmclient.ts | 25 ++++++++++++++++--- packages/sdk/types/index.d.ts | 5 ++-- packages/sdk/types/signingcosmwasmclient.d.ts | 16 +++++++++--- scripts/wasmd/deploy_erc20.js | 2 +- scripts/wasmd/deploy_nameservice.js | 2 +- 8 files changed, 46 insertions(+), 17 deletions(-) diff --git a/packages/sdk/src/cosmwasmclient.spec.ts b/packages/sdk/src/cosmwasmclient.spec.ts index 773816a3..1953b3c2 100644 --- a/packages/sdk/src/cosmwasmclient.spec.ts +++ b/packages/sdk/src/cosmwasmclient.spec.ts @@ -313,7 +313,7 @@ describe("CosmWasmClient", () => { ); const { codeId } = await client.upload(getRandomizedHackatom()); const initMsg = { verifier: makeRandomAddress(), beneficiary: makeRandomAddress() }; - const contractAddress = await client.instantiate(codeId, initMsg, "random hackatom"); + const { contractAddress } = await client.instantiate(codeId, initMsg, "random hackatom"); contract = { initMsg: initMsg, address: contractAddress }; } }); @@ -366,7 +366,7 @@ describe("CosmWasmClient", () => { ); const { codeId } = await client.upload(getRandomizedHackatom()); const initMsg = { verifier: makeRandomAddress(), beneficiary: makeRandomAddress() }; - const contractAddress = await client.instantiate(codeId, initMsg, "a different hackatom"); + const { contractAddress } = await client.instantiate(codeId, initMsg, "a different hackatom"); contract = { initMsg: initMsg, address: contractAddress }; } }); diff --git a/packages/sdk/src/index.ts b/packages/sdk/src/index.ts index 425cad66..d6d5d2ef 100644 --- a/packages/sdk/src/index.ts +++ b/packages/sdk/src/index.ts @@ -29,9 +29,10 @@ export { export { findSequenceForSignedTx } from "./sequence"; export { encodeSecp256k1Signature, decodeSignature } from "./signature"; export { + ExecuteResult, + InstantiateResult, SigningCallback, SigningCosmWasmClient, - ExecuteResult, UploadMeta, - UploadReceipt, + UploadResult, } from "./signingcosmwasmclient"; diff --git a/packages/sdk/src/signingcosmwasmclient.spec.ts b/packages/sdk/src/signingcosmwasmclient.spec.ts index 56cb6171..096008d0 100644 --- a/packages/sdk/src/signingcosmwasmclient.spec.ts +++ b/packages/sdk/src/signingcosmwasmclient.spec.ts @@ -87,7 +87,7 @@ describe("SigningCosmWasmClient", () => { }, ]; const beneficiaryAddress = makeRandomAddress(); - const contractAddress = await client.instantiate( + const { contractAddress } = await client.instantiate( codeId, { verifier: faucet.address, @@ -148,7 +148,7 @@ describe("SigningCosmWasmClient", () => { }, ]; const beneficiaryAddress = makeRandomAddress(); - const contractAddress = await client.instantiate( + const { contractAddress } = await client.instantiate( codeId, { verifier: faucet.address, diff --git a/packages/sdk/src/signingcosmwasmclient.ts b/packages/sdk/src/signingcosmwasmclient.ts index 8a2616a5..67d38752 100644 --- a/packages/sdk/src/signingcosmwasmclient.ts +++ b/packages/sdk/src/signingcosmwasmclient.ts @@ -68,7 +68,7 @@ export interface UploadMeta { readonly builder?: string; } -export interface UploadReceipt { +export interface UploadResult { /** Size of the original wasm code in bytes */ readonly originalSize: number; /** A hex encoded sha256 checksum of the original wasm code (that is stored on chain) */ @@ -79,6 +79,17 @@ export interface UploadReceipt { readonly compressedChecksum: string; /** The ID of the code asigned by the chain */ readonly codeId: number; + readonly logs: readonly Log[]; + /** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */ + readonly transactionHash: string; +} + +export interface InstantiateResult { + /** The address of the newly instantiated contract */ + readonly contractAddress: string; + readonly logs: readonly Log[]; + /** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */ + readonly transactionHash: string; } export interface ExecuteResult { @@ -115,7 +126,7 @@ export class SigningCosmWasmClient extends CosmWasmClient { } /** Uploads code and returns a receipt, including the code ID */ - public async upload(wasmCode: Uint8Array, meta: UploadMeta = {}, memo = ""): Promise { + public async upload(wasmCode: Uint8Array, meta: UploadMeta = {}, memo = ""): Promise { const source = meta.source || ""; const builder = prepareBuilder(meta.builder); @@ -150,6 +161,8 @@ export class SigningCosmWasmClient extends CosmWasmClient { compressedSize: compressed.length, compressedChecksum: Encoding.toHex(new Sha256(compressed).digest()), codeId: Number.parseInt(codeIdAttr.value, 10), + logs: result.logs, + transactionHash: result.transactionHash, }; } @@ -159,7 +172,7 @@ export class SigningCosmWasmClient extends CosmWasmClient { label: string, memo = "", transferAmount?: readonly Coin[], - ): Promise { + ): Promise { const instantiateMsg: MsgInstantiateContract = { type: "wasm/instantiate", value: { @@ -188,7 +201,11 @@ export class SigningCosmWasmClient extends CosmWasmClient { const result = await this.postTx(signedTx); const contractAddressAttr = findAttribute(result.logs, "message", "contract_address"); - return contractAddressAttr.value; + return { + contractAddress: contractAddressAttr.value, + logs: result.logs, + transactionHash: result.transactionHash, + }; } public async execute( diff --git a/packages/sdk/types/index.d.ts b/packages/sdk/types/index.d.ts index b1cd5985..a96ec335 100644 --- a/packages/sdk/types/index.d.ts +++ b/packages/sdk/types/index.d.ts @@ -28,9 +28,10 @@ export { export { findSequenceForSignedTx } from "./sequence"; export { encodeSecp256k1Signature, decodeSignature } from "./signature"; export { + ExecuteResult, + InstantiateResult, SigningCallback, SigningCosmWasmClient, - ExecuteResult, UploadMeta, - UploadReceipt, + UploadResult, } from "./signingcosmwasmclient"; diff --git a/packages/sdk/types/signingcosmwasmclient.d.ts b/packages/sdk/types/signingcosmwasmclient.d.ts index 318a387a..8b169172 100644 --- a/packages/sdk/types/signingcosmwasmclient.d.ts +++ b/packages/sdk/types/signingcosmwasmclient.d.ts @@ -17,7 +17,7 @@ export interface UploadMeta { /** The builder tag */ readonly builder?: string; } -export interface UploadReceipt { +export interface UploadResult { /** Size of the original wasm code in bytes */ readonly originalSize: number; /** A hex encoded sha256 checksum of the original wasm code (that is stored on chain) */ @@ -28,6 +28,16 @@ export interface UploadReceipt { readonly compressedChecksum: string; /** The ID of the code asigned by the chain */ readonly codeId: number; + readonly logs: readonly Log[]; + /** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */ + readonly transactionHash: string; +} +export interface InstantiateResult { + /** The address of the newly instantiated contract */ + readonly contractAddress: string; + readonly logs: readonly Log[]; + /** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */ + readonly transactionHash: string; } export interface ExecuteResult { readonly logs: readonly Log[]; @@ -48,14 +58,14 @@ 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, meta?: UploadMeta, memo?: string): Promise; + upload(wasmCode: Uint8Array, meta?: UploadMeta, memo?: string): Promise; instantiate( codeId: number, initMsg: object, label: string, memo?: string, transferAmount?: readonly Coin[], - ): Promise; + ): Promise; execute( contractAddress: string, handleMsg: object, diff --git a/scripts/wasmd/deploy_erc20.js b/scripts/wasmd/deploy_erc20.js index 63af5032..0e513945 100755 --- a/scripts/wasmd/deploy_erc20.js +++ b/scripts/wasmd/deploy_erc20.js @@ -82,7 +82,7 @@ async function main() { for (const initMsg of [initMsgHash, initMsgIsa, initMsgJade]) { const memo = `Create an ERC20 instance for ${initMsg.symbol}`; - const contractAddress = await client.instantiate(uploadReceipt.codeId, initMsg, initMsg.symbol, memo); + const { contractAddress } = await client.instantiate(uploadReceipt.codeId, initMsg, initMsg.symbol, memo); console.info(`Contract instantiated for ${initMsg.symbol} at ${contractAddress}`); } } diff --git a/scripts/wasmd/deploy_nameservice.js b/scripts/wasmd/deploy_nameservice.js index 9b689420..e835d4e4 100755 --- a/scripts/wasmd/deploy_nameservice.js +++ b/scripts/wasmd/deploy_nameservice.js @@ -45,7 +45,7 @@ async function main() { for (const { label, initMsg } of [free, luxury]) { const memo = `Create an nameservice instance "${label}"`; - const contractAddress = await client.instantiate(uploadReceipt.codeId, initMsg, label, memo); + const { contractAddress } = await client.instantiate(uploadReceipt.codeId, initMsg, label, memo); console.info(`Contract "${label}" instantiated at ${contractAddress}`); } }