From eca225530fc6d3508e270952775c16b84b572fba Mon Sep 17 00:00:00 2001 From: willclarktech Date: Thu, 10 Jun 2021 10:08:47 +0200 Subject: [PATCH 1/4] cosmwasm-launchpad: Rename InstantiateOptions.transferAmount -> .funds --- .../cosmwasm-launchpad/src/signingcosmwasmclient.spec.ts | 4 ++-- packages/cosmwasm-launchpad/src/signingcosmwasmclient.ts | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/cosmwasm-launchpad/src/signingcosmwasmclient.spec.ts b/packages/cosmwasm-launchpad/src/signingcosmwasmclient.spec.ts index a8e47b2f..3636b204 100644 --- a/packages/cosmwasm-launchpad/src/signingcosmwasmclient.spec.ts +++ b/packages/cosmwasm-launchpad/src/signingcosmwasmclient.spec.ts @@ -311,7 +311,7 @@ describe("SigningCosmWasmClient", () => { "My cool label", { memo: "Let's see if the memo is used", - transferAmount: funds, + funds: funds, }, ); @@ -491,7 +491,7 @@ describe("SigningCosmWasmClient", () => { }, "amazing random contract", { - transferAmount: funds, + funds: funds, }, ); diff --git a/packages/cosmwasm-launchpad/src/signingcosmwasmclient.ts b/packages/cosmwasm-launchpad/src/signingcosmwasmclient.ts index 35998fcf..34d3f579 100644 --- a/packages/cosmwasm-launchpad/src/signingcosmwasmclient.ts +++ b/packages/cosmwasm-launchpad/src/signingcosmwasmclient.ts @@ -108,10 +108,8 @@ export interface InstantiateOptions { * created and before the instantiation message is executed by the contract. * * Only native tokens are supported. - * - * TODO: Rename to `funds` for consistency (https://github.com/cosmos/cosmjs/issues/806) */ - readonly transferAmount?: readonly Coin[]; + readonly funds?: readonly Coin[]; /** * A bech32 encoded address of an admin account. * Caution: an admin has the privilege to upgrade a contract. If this is not desired, do not set this value. @@ -238,7 +236,7 @@ export class SigningCosmWasmClient extends CosmWasmClient { code_id: new Uint53(codeId).toString(), label: label, init_msg: msg, - init_funds: options.transferAmount || [], + init_funds: options.funds || [], admin: options.admin, }, }; From ba0a4411ddd85ea85388e857484e486c529d2a4e Mon Sep 17 00:00:00 2001 From: willclarktech Date: Thu, 10 Jun 2021 10:09:12 +0200 Subject: [PATCH 2/4] cosmwasm-stargate: Update for InstantiateOptions.funds --- packages/cosmwasm-stargate/src/signingcosmwasmclient.spec.ts | 4 ++-- packages/cosmwasm-stargate/src/signingcosmwasmclient.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/cosmwasm-stargate/src/signingcosmwasmclient.spec.ts b/packages/cosmwasm-stargate/src/signingcosmwasmclient.spec.ts index ec3dd984..fc5f123b 100644 --- a/packages/cosmwasm-stargate/src/signingcosmwasmclient.spec.ts +++ b/packages/cosmwasm-stargate/src/signingcosmwasmclient.spec.ts @@ -273,7 +273,7 @@ describe("SigningCosmWasmClient", () => { "My cool label", { memo: "Let's see if the memo is used", - transferAmount: funds, + funds: funds, }, ); const wasmClient = await makeWasmClient(wasmd.endpoint); @@ -454,7 +454,7 @@ describe("SigningCosmWasmClient", () => { }, "amazing random contract", { - transferAmount: funds, + funds: funds, }, ); // execute diff --git a/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts b/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts index 4cb1cfa5..0dc89883 100644 --- a/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts +++ b/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts @@ -245,7 +245,7 @@ export class SigningCosmWasmClient extends CosmWasmClient { codeId: Long.fromString(new Uint53(codeId).toString()), label: label, initMsg: toUtf8(JSON.stringify(msg)), - funds: [...(options.transferAmount || [])], + funds: [...(options.funds || [])], admin: options.admin, }), }; From c5adb2a1916719af9bf000754d83e12bfaf19f39 Mon Sep 17 00:00:00 2001 From: willclarktech Date: Thu, 10 Jun 2021 10:12:11 +0200 Subject: [PATCH 3/4] Update CHANGELOG for InstantiateOptions change --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b504d82..f551668d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,12 @@ and this project adheres to ### Changed +- @cosmjs/cosmwasm-launchpad: The `transferAmount` property on + `InstantiateOptions` (accepted as a parameter to + `SigningCosmWasmClient.instantiate`) has been renamed to `funds`. +- @cosmjs/cosmwasm-stargate: The `transferAmount` property on + `InstantiateOptions` (accepted as a parameter to + `SigningCosmWasmClient.instantiate`) has been renamed to `funds`. - @cosmjs/tendermint-rpc: Make `tendermint34.Header.lastBlockId` and `tendermint34.Block.lastCommit` optional to better handle the case of height 1 where there is no previous block. From c04eef3a396f5990f2ec7d224f9a120c9dd2f06c Mon Sep 17 00:00:00 2001 From: willclarktech Date: Thu, 10 Jun 2021 10:40:23 +0200 Subject: [PATCH 4/4] cosmwasm-stargate: Duplicate signing client interfaces from cosmwasm-launchpad --- .../src/signingcosmwasmclient.spec.ts | 3 +- .../src/signingcosmwasmclient.ts | 105 ++++++++++++++---- 2 files changed, 84 insertions(+), 24 deletions(-) diff --git a/packages/cosmwasm-stargate/src/signingcosmwasmclient.spec.ts b/packages/cosmwasm-stargate/src/signingcosmwasmclient.spec.ts index fc5f123b..65f264a0 100644 --- a/packages/cosmwasm-stargate/src/signingcosmwasmclient.spec.ts +++ b/packages/cosmwasm-stargate/src/signingcosmwasmclient.spec.ts @@ -1,6 +1,5 @@ /* eslint-disable @typescript-eslint/naming-convention */ import { Secp256k1HdWallet } from "@cosmjs/amino"; -import { UploadMeta } from "@cosmjs/cosmwasm-launchpad"; import { sha256 } from "@cosmjs/crypto"; import { toHex } from "@cosmjs/encoding"; import { decodeTxRaw, DirectSecp256k1HdWallet, Registry } from "@cosmjs/proto-signing"; @@ -25,7 +24,7 @@ import pako from "pako"; import protobuf from "protobufjs/minimal"; import { MsgStoreCodeEncodeObject } from "./encodeobjects"; -import { SigningCosmWasmClient } from "./signingcosmwasmclient"; +import { SigningCosmWasmClient, UploadMeta } from "./signingcosmwasmclient"; import { alice, getHackatom, diff --git a/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts b/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts index 0dc89883..95c72e09 100644 --- a/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts +++ b/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts @@ -1,15 +1,6 @@ /* eslint-disable @typescript-eslint/naming-convention */ import { encodeSecp256k1Pubkey, makeSignDoc as makeSignDocAmino } from "@cosmjs/amino"; -import { - ChangeAdminResult, - ExecuteResult, - InstantiateOptions, - InstantiateResult, - isValidBuilder, - MigrateResult, - UploadMeta, - UploadResult, -} from "@cosmjs/cosmwasm-launchpad"; +import { isValidBuilder } from "@cosmjs/cosmwasm-launchpad"; import { sha256 } from "@cosmjs/crypto"; import { fromBase64, toHex, toUtf8 } from "@cosmjs/encoding"; import { Int53, Uint53 } from "@cosmjs/math"; @@ -72,18 +63,6 @@ import { MsgUpdateAdminEncodeObject, } from "./encodeobjects"; -// Those types can be copied over to allow them to evolve independently of @cosmjs/cosmwasm-launchpad. -// For now just re-export them such that they can be imported via @cosmjs/cosmwasm-stargate. -export { - ChangeAdminResult, // returned by SigningCosmWasmClient.updateAdmin/SigningCosmWasmClient.clearAdmin - ExecuteResult, // returned by SigningCosmWasmClient.execute - InstantiateOptions, // argument type of SigningCosmWasmClient.instantiate - InstantiateResult, // returned by SigningCosmWasmClient.instantiate - MigrateResult, // returned by SigningCosmWasmClient.migrate - UploadMeta, // argument type of SigningCosmWasmClient.upload - UploadResult, // returned by SigningCosmWasmClient.upload -}; - /** * These fees are used by the higher level methods of SigningCosmWasmClient */ @@ -114,6 +93,88 @@ export const defaultGasLimits: GasLimits = { changeAdmin: 80_000, }; +export interface UploadMeta { + /** + * An URL to a .tar.gz archive of the source code of the contract, which can be used to reproducibly build the Wasm bytecode. + * + * @see https://github.com/CosmWasm/cosmwasm-verify + */ + readonly source?: string; + /** + * A docker image (including version) to reproducibly build the Wasm bytecode from the source code. + * + * @example ```cosmwasm/rust-optimizer:0.8.0``` + * @see https://github.com/CosmWasm/cosmwasm-verify + */ + readonly builder?: string; +} + +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) */ + readonly originalChecksum: string; + /** Size of the compressed wasm code in bytes */ + readonly compressedSize: number; + /** A hex encoded sha256 checksum of the compressed wasm code (that stored in the transaction) */ + readonly compressedChecksum: string; + /** The ID of the code asigned by the chain */ + readonly codeId: number; + readonly logs: readonly logs.Log[]; + /** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */ + readonly transactionHash: string; +} + +/** + * The options of an .instantiate() call. + * All properties are optional. + */ +export interface InstantiateOptions { + readonly memo?: string; + /** + * The funds that are transferred from the sender to the newly created contract. + * The funds are transferred as part of the message execution after the contract address is + * created and before the instantiation message is executed by the contract. + * + * Only native tokens are supported. + */ + readonly funds?: readonly Coin[]; + /** + * A bech32 encoded address of an admin account. + * Caution: an admin has the privilege to upgrade a contract. If this is not desired, do not set this value. + */ + readonly admin?: string; +} + +export interface InstantiateResult { + /** The address of the newly instantiated contract */ + readonly contractAddress: string; + readonly logs: readonly logs.Log[]; + /** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */ + readonly transactionHash: string; +} + +/** + * Result type of updateAdmin and clearAdmin + */ +export interface ChangeAdminResult { + readonly logs: readonly logs.Log[]; + /** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */ + readonly transactionHash: string; +} + +export interface MigrateResult { + readonly logs: readonly logs.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 logs.Log[]; + /** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */ + readonly transactionHash: string; +} + function createBroadcastTxErrorMessage(result: BroadcastTxFailure): string { return `Error when broadcasting tx ${result.transactionHash} at height ${result.height}. Code: ${result.code}; Raw log: ${result.rawLog}`; }