cosmwasm-stargate: Update for review comments

This commit is contained in:
willclarktech 2021-01-13 16:09:59 +00:00
parent c613186cbe
commit 9e2f2d3168
No known key found for this signature in database
GPG Key ID: 551A86E2E398ADF7
4 changed files with 31 additions and 32 deletions

View File

@ -7,12 +7,12 @@ import {
MsgStoreCode,
MsgUpdateAdmin,
} from "@cosmjs/cosmwasm-launchpad";
import { fromBase64, toAscii } from "@cosmjs/encoding";
import { fromBase64, toUtf8 } from "@cosmjs/encoding";
import { coins } from "@cosmjs/launchpad";
import { AminoTypes } from "@cosmjs/stargate";
import Long from "long";
import { defaultTypes } from "./aminotypes";
import { cosmWasmTypes } from "./aminotypes";
import { cosmwasm } from "./codec";
type IMsgStoreCode = cosmwasm.wasm.v1beta1.IMsgStoreCode;
@ -31,7 +31,7 @@ describe("AminoTypes", () => {
source: "Arrabiata",
builder: "Bob",
};
const aminoMsg = new AminoTypes({ additions: defaultTypes }).toAmino({
const aminoMsg = new AminoTypes({ additions: cosmWasmTypes }).toAmino({
typeUrl: "/cosmwasm.wasm.v1beta1.MsgStoreCode",
value: msg,
});
@ -52,7 +52,7 @@ describe("AminoTypes", () => {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
codeId: Long.fromString("12345"),
label: "sticky",
initMsg: toAscii(
initMsg: toUtf8(
JSON.stringify({
foo: "bar",
}),
@ -60,7 +60,7 @@ describe("AminoTypes", () => {
initFunds: coins(1234, "ucosm"),
admin: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
};
const aminoMsg = new AminoTypes({ additions: defaultTypes }).toAmino({
const aminoMsg = new AminoTypes({ additions: cosmWasmTypes }).toAmino({
typeUrl: "/cosmwasm.wasm.v1beta1.MsgInstantiateContract",
value: msg,
});
@ -86,7 +86,7 @@ describe("AminoTypes", () => {
newAdmin: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
};
const aminoMsg = new AminoTypes({ additions: defaultTypes }).toAmino({
const aminoMsg = new AminoTypes({ additions: cosmWasmTypes }).toAmino({
typeUrl: "/cosmwasm.wasm.v1beta1.MsgUpdateAdmin",
value: msg,
});
@ -106,7 +106,7 @@ describe("AminoTypes", () => {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
};
const aminoMsg = new AminoTypes({ additions: defaultTypes }).toAmino({
const aminoMsg = new AminoTypes({ additions: cosmWasmTypes }).toAmino({
typeUrl: "/cosmwasm.wasm.v1beta1.MsgClearAdmin",
value: msg,
});
@ -124,14 +124,14 @@ describe("AminoTypes", () => {
const msg: IMsgExecuteContract = {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
msg: toAscii(
msg: toUtf8(
JSON.stringify({
foo: "bar",
}),
),
sentFunds: coins(1234, "ucosm"),
};
const aminoMsg = new AminoTypes({ additions: defaultTypes }).toAmino({
const aminoMsg = new AminoTypes({ additions: cosmWasmTypes }).toAmino({
typeUrl: "/cosmwasm.wasm.v1beta1.MsgExecuteContract",
value: msg,
});
@ -154,13 +154,13 @@ describe("AminoTypes", () => {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
codeId: Long.fromString("98765"),
migrateMsg: toAscii(
migrateMsg: toUtf8(
JSON.stringify({
foo: "bar",
}),
),
};
const aminoMsg = new AminoTypes({ additions: defaultTypes }).toAmino({
const aminoMsg = new AminoTypes({ additions: cosmWasmTypes }).toAmino({
typeUrl: "/cosmwasm.wasm.v1beta1.MsgMigrateContract",
value: msg,
});
@ -190,7 +190,7 @@ describe("AminoTypes", () => {
builder: "Bob",
},
};
const msg = new AminoTypes({ additions: defaultTypes }).fromAmino(aminoMsg);
const msg = new AminoTypes({ additions: cosmWasmTypes }).fromAmino(aminoMsg);
const expectedValue: IMsgStoreCode = {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
wasmByteCode: fromBase64("WUVMTE9XIFNVQk1BUklORQ=="),
@ -217,12 +217,12 @@ describe("AminoTypes", () => {
admin: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
},
};
const msg = new AminoTypes({ additions: defaultTypes }).fromAmino(aminoMsg);
const msg = new AminoTypes({ additions: cosmWasmTypes }).fromAmino(aminoMsg);
const expectedValue: IMsgInstantiateContract = {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
codeId: Long.fromString("12345"),
label: "sticky",
initMsg: toAscii(
initMsg: toUtf8(
JSON.stringify({
foo: "bar",
}),
@ -245,7 +245,7 @@ describe("AminoTypes", () => {
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
},
};
const msg = new AminoTypes({ additions: defaultTypes }).fromAmino(aminoMsg);
const msg = new AminoTypes({ additions: cosmWasmTypes }).fromAmino(aminoMsg);
const expectedValue: IMsgUpdateAdmin = {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
newAdmin: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
@ -265,7 +265,7 @@ describe("AminoTypes", () => {
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
},
};
const msg = new AminoTypes({ additions: defaultTypes }).fromAmino(aminoMsg);
const msg = new AminoTypes({ additions: cosmWasmTypes }).fromAmino(aminoMsg);
const expectedValue: IMsgClearAdmin = {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
@ -288,11 +288,11 @@ describe("AminoTypes", () => {
sent_funds: coins(1234, "ucosm"),
},
};
const msg = new AminoTypes({ additions: defaultTypes }).fromAmino(aminoMsg);
const msg = new AminoTypes({ additions: cosmWasmTypes }).fromAmino(aminoMsg);
const expectedValue: IMsgExecuteContract = {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
msg: toAscii(
msg: toUtf8(
JSON.stringify({
foo: "bar",
}),
@ -317,12 +317,12 @@ describe("AminoTypes", () => {
},
},
};
const msg = new AminoTypes({ additions: defaultTypes }).fromAmino(aminoMsg);
const msg = new AminoTypes({ additions: cosmWasmTypes }).fromAmino(aminoMsg);
const expectedValue: IMsgMigrateContract = {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
codeId: Long.fromString("98765"),
migrateMsg: toAscii(
migrateMsg: toUtf8(
JSON.stringify({
foo: "bar",
}),

View File

@ -7,7 +7,7 @@ import {
MsgStoreCode,
MsgUpdateAdmin,
} from "@cosmjs/cosmwasm-launchpad";
import { fromAscii, fromBase64, toAscii, toBase64 } from "@cosmjs/encoding";
import { fromBase64, fromUtf8, toBase64, toUtf8 } from "@cosmjs/encoding";
import { Coin } from "@cosmjs/launchpad";
import { AminoConverter, codec } from "@cosmjs/stargate";
import { assert } from "@cosmjs/utils";
@ -35,7 +35,7 @@ function checkAmount(amount: readonly ICoin[] | undefined | null): readonly Coin
});
}
export const defaultTypes: Record<string, AminoConverter> = {
export const cosmWasmTypes: Record<string, AminoConverter> = {
"/cosmwasm.wasm.v1beta1.MsgStoreCode": {
aminoType: "wasm/MsgStoreCode",
toAmino: ({ sender, wasmByteCode, source, builder }: IMsgStoreCode): MsgStoreCode["value"] => {
@ -75,7 +75,7 @@ export const defaultTypes: Record<string, AminoConverter> = {
sender: sender,
code_id: codeId.toString(),
label: label,
init_msg: JSON.parse(fromAscii(initMsg)),
init_msg: JSON.parse(fromUtf8(initMsg)),
init_funds: checkAmount(initFunds),
admin: admin ?? undefined,
};
@ -91,7 +91,7 @@ export const defaultTypes: Record<string, AminoConverter> = {
sender: sender,
codeId: Long.fromString(code_id),
label: label,
initMsg: toAscii(JSON.stringify(init_msg)),
initMsg: toUtf8(JSON.stringify(init_msg)),
initFunds: [...init_funds],
admin: admin,
}),
@ -138,14 +138,14 @@ export const defaultTypes: Record<string, AminoConverter> = {
return {
sender: sender,
contract: contract,
msg: JSON.parse(fromAscii(msg)),
msg: JSON.parse(fromUtf8(msg)),
sent_funds: checkAmount(sentFunds),
};
},
fromAmino: ({ sender, contract, msg, sent_funds }: MsgExecuteContract["value"]): IMsgExecuteContract => ({
sender: sender,
contract: contract,
msg: toAscii(JSON.stringify(msg)),
msg: toUtf8(JSON.stringify(msg)),
sentFunds: [...sent_funds],
}),
},
@ -160,14 +160,14 @@ export const defaultTypes: Record<string, AminoConverter> = {
sender: sender,
contract: contract,
code_id: codeId.toString(),
msg: JSON.parse(fromAscii(migrateMsg)),
msg: JSON.parse(fromUtf8(migrateMsg)),
};
},
fromAmino: ({ sender, contract, code_id, msg }: MsgMigrateContract["value"]): IMsgMigrateContract => ({
sender: sender,
contract: contract,
codeId: Long.fromString(code_id),
migrateMsg: toAscii(JSON.stringify(msg)),
migrateMsg: toUtf8(JSON.stringify(msg)),
}),
},
};

View File

@ -46,7 +46,7 @@ import { adaptor34, Client as TendermintClient } from "@cosmjs/tendermint-rpc";
import Long from "long";
import pako from "pako";
import { defaultTypes } from "./aminotypes";
import { cosmWasmTypes } from "./aminotypes";
import { cosmwasm } from "./codec";
import { CosmWasmClient } from "./cosmwasmclient";
@ -146,7 +146,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
super(tmClient);
const {
registry = createDefaultRegistry(),
aminoTypes = new AminoTypes({ additions: defaultTypes, prefix: options.prefix }),
aminoTypes = new AminoTypes({ additions: cosmWasmTypes, prefix: options.prefix }),
gasPrice = defaultGasPrice,
gasLimits = defaultGasLimits,
} = options;
@ -392,7 +392,6 @@ export class SigningCosmWasmClient extends CosmWasmClient {
const signedTx = Uint8Array.from(TxRaw.encode(txRaw).finish());
return this.broadcastTx(signedTx);
}
// Amino signer
// Amino signer
const signMode = SignMode.SIGN_MODE_LEGACY_AMINO_JSON;

View File

@ -1,2 +1,2 @@
import { AminoConverter } from "@cosmjs/stargate";
export declare const defaultTypes: Record<string, AminoConverter>;
export declare const cosmWasmTypes: Record<string, AminoConverter>;