Simplify memo handling

This commit is contained in:
Simon Warta 2020-02-11 09:43:12 +01:00
parent e7df090ea7
commit b4b36c3a34
2 changed files with 10 additions and 12 deletions

View File

@ -142,7 +142,7 @@ describe("CosmWasmClient", () => {
); );
// execute // execute
const result = await client.execute(contractAddress, {}); const result = await client.execute(contractAddress, {}, undefined);
const [firstLog] = result.logs; const [firstLog] = result.logs;
expect(firstLog.log).toEqual(`released funds to ${beneficiaryAddress}`); expect(firstLog.log).toEqual(`released funds to ${beneficiaryAddress}`);

View File

@ -61,7 +61,7 @@ export class CosmWasmClient {
} }
/** Uploads code and returns a code ID */ /** Uploads code and returns a code ID */
public async upload(wasmCode: Uint8Array, memo?: string): Promise<number> { public async upload(wasmCode: Uint8Array, memo = ""): Promise<number> {
const storeCodeMsg: MsgStoreCode = { const storeCodeMsg: MsgStoreCode = {
type: "wasm/store-code", type: "wasm/store-code",
value: { value: {
@ -84,12 +84,12 @@ export class CosmWasmClient {
const account = (await this.restClient.authAccounts(this.senderAddress)).result.value; const account = (await this.restClient.authAccounts(this.senderAddress)).result.value;
const chainId = await this.chainId(); 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 signature = await this.signCallback(signBytes);
const signedTx = { const signedTx = {
msg: [storeCodeMsg], msg: [storeCodeMsg],
fee: fee, fee: fee,
memo: memo || "", memo: memo,
signatures: [signature], signatures: [signature],
}; };
@ -106,10 +106,9 @@ export class CosmWasmClient {
public async instantiate( public async instantiate(
codeId: number, codeId: number,
initMsg: object, initMsg: object,
memo?: string, memo = "",
transferAmount?: readonly Coin[], transferAmount?: readonly Coin[],
): Promise<string> { ): Promise<string> {
const normalizedMemo = memo || "";
const instantiateMsg: MsgInstantiateContract = { const instantiateMsg: MsgInstantiateContract = {
type: "wasm/instantiate", type: "wasm/instantiate",
value: { value: {
@ -134,13 +133,13 @@ export class CosmWasmClient {
const account = (await this.restClient.authAccounts(this.senderAddress)).result.value; const account = (await this.restClient.authAccounts(this.senderAddress)).result.value;
const chainId = await this.chainId(); 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 signature = await this.signCallback(signBytes);
const signedTx = { const signedTx = {
msg: [instantiateMsg], msg: [instantiateMsg],
fee: fee, fee: fee,
memo: normalizedMemo, memo: memo,
signatures: [signature], signatures: [signature],
}; };
const result = await this.restClient.postTx(marshalTx(signedTx)); const result = await this.restClient.postTx(marshalTx(signedTx));
@ -155,10 +154,9 @@ export class CosmWasmClient {
public async execute( public async execute(
contractAddress: string, contractAddress: string,
handleMsg: object, handleMsg: object,
memo?: string, memo = "",
transferAmount?: readonly Coin[], transferAmount?: readonly Coin[],
): Promise<{ readonly logs: readonly Log[] }> { ): Promise<{ readonly logs: readonly Log[] }> {
const normalizedMemo = memo || "";
const executeMsg: MsgExecuteContract = { const executeMsg: MsgExecuteContract = {
type: "wasm/execute", type: "wasm/execute",
value: { value: {
@ -181,12 +179,12 @@ export class CosmWasmClient {
const account = (await this.restClient.authAccounts(this.senderAddress)).result.value; const account = (await this.restClient.authAccounts(this.senderAddress)).result.value;
const chainId = await this.chainId(); 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 signature = await this.signCallback(signBytes);
const signedTx = { const signedTx = {
msg: [executeMsg], msg: [executeMsg],
fee: fee, fee: fee,
memo: normalizedMemo, memo: memo,
signatures: [signature], signatures: [signature],
}; };
const result = await this.restClient.postTx(marshalTx(signedTx)); const result = await this.restClient.postTx(marshalTx(signedTx));