From b4b36c3a34273bb77cb86b043471ccf7bfcf8b7d Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Tue, 11 Feb 2020 09:43:12 +0100 Subject: [PATCH] Simplify memo handling --- packages/sdk/src/cosmwasmclient.spec.ts | 2 +- packages/sdk/src/cosmwasmclient.ts | 20 +++++++++----------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/packages/sdk/src/cosmwasmclient.spec.ts b/packages/sdk/src/cosmwasmclient.spec.ts index 10aadfe1fe..30a3686b5d 100644 --- a/packages/sdk/src/cosmwasmclient.spec.ts +++ b/packages/sdk/src/cosmwasmclient.spec.ts @@ -142,7 +142,7 @@ describe("CosmWasmClient", () => { ); // execute - const result = await client.execute(contractAddress, {}); + const result = await client.execute(contractAddress, {}, undefined); const [firstLog] = result.logs; expect(firstLog.log).toEqual(`released funds to ${beneficiaryAddress}`); diff --git a/packages/sdk/src/cosmwasmclient.ts b/packages/sdk/src/cosmwasmclient.ts index bbdc63e396..20e2429c7e 100644 --- a/packages/sdk/src/cosmwasmclient.ts +++ b/packages/sdk/src/cosmwasmclient.ts @@ -61,7 +61,7 @@ export class CosmWasmClient { } /** Uploads code and returns a code ID */ - public async upload(wasmCode: Uint8Array, memo?: string): Promise { + public async upload(wasmCode: Uint8Array, memo = ""): Promise { const storeCodeMsg: MsgStoreCode = { type: "wasm/store-code", value: { @@ -84,12 +84,12 @@ export class CosmWasmClient { const account = (await this.restClient.authAccounts(this.senderAddress)).result.value; const chainId = await this.chainId(); - const signBytes = makeSignBytes([storeCodeMsg], fee, chainId, memo || "", account); + const signBytes = makeSignBytes([storeCodeMsg], fee, chainId, memo, account); const signature = await this.signCallback(signBytes); const signedTx = { msg: [storeCodeMsg], fee: fee, - memo: memo || "", + memo: memo, signatures: [signature], }; @@ -106,10 +106,9 @@ export class CosmWasmClient { public async instantiate( codeId: number, initMsg: object, - memo?: string, + memo = "", transferAmount?: readonly Coin[], ): Promise { - const normalizedMemo = memo || ""; const instantiateMsg: MsgInstantiateContract = { type: "wasm/instantiate", value: { @@ -134,13 +133,13 @@ export class CosmWasmClient { const account = (await this.restClient.authAccounts(this.senderAddress)).result.value; const chainId = await this.chainId(); - const signBytes = makeSignBytes([instantiateMsg], fee, chainId, normalizedMemo, account); + const signBytes = makeSignBytes([instantiateMsg], fee, chainId, memo, account); const signature = await this.signCallback(signBytes); const signedTx = { msg: [instantiateMsg], fee: fee, - memo: normalizedMemo, + memo: memo, signatures: [signature], }; const result = await this.restClient.postTx(marshalTx(signedTx)); @@ -155,10 +154,9 @@ export class CosmWasmClient { public async execute( contractAddress: string, handleMsg: object, - memo?: string, + memo = "", transferAmount?: readonly Coin[], ): Promise<{ readonly logs: readonly Log[] }> { - const normalizedMemo = memo || ""; const executeMsg: MsgExecuteContract = { type: "wasm/execute", value: { @@ -181,12 +179,12 @@ export class CosmWasmClient { const account = (await this.restClient.authAccounts(this.senderAddress)).result.value; const chainId = await this.chainId(); - const signBytes = makeSignBytes([executeMsg], fee, chainId, normalizedMemo, account); + const signBytes = makeSignBytes([executeMsg], fee, chainId, memo, account); const signature = await this.signCallback(signBytes); const signedTx = { msg: [executeMsg], fee: fee, - memo: normalizedMemo, + memo: memo, signatures: [signature], }; const result = await this.restClient.postTx(marshalTx(signedTx));