Skip to content

Commit 53c5235

Browse files
authored
Merge pull request #1014 from cosmos/improve-AminoTypes-constructor
Make prefix required in AminoTypes constructor
2 parents f4342bb + 353f2da commit 53c5235

File tree

9 files changed

+80
-54
lines changed

9 files changed

+80
-54
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ and this project adheres to
66

77
## [Unreleased]
88

9+
### Changed
10+
11+
- @cosmjs/stargate: The `AminoTypes` now always requires an argument of type
12+
`AminoTypesOptions`. This is an object with a required `prefix` field. Before
13+
the prefix defaulted to "cosmos" but this is almost never the right choice for
14+
CosmJS users that need to add Amino types manually. ([#989])
15+
16+
[#989]: https://github.com/cosmos/cosmjs/issues/989
17+
918
### Removed
1019

1120
- @cosmjs/crypto: Remove the SHA1 implementation (`Sha1` and `sha1`) as it is

packages/cosmwasm-stargate/src/aminotypes.spec.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe("AminoTypes", () => {
2929
wasmByteCode: fromBase64("WUVMTE9XIFNVQk1BUklORQ=="),
3030
instantiatePermission: undefined,
3131
};
32-
const aminoMsg = new AminoTypes({ additions: cosmWasmTypes }).toAmino({
32+
const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).toAmino({
3333
typeUrl: "/cosmwasm.wasm.v1.MsgStoreCode",
3434
value: msg,
3535
});
@@ -54,7 +54,7 @@ describe("AminoTypes", () => {
5454
funds: coins(1234, "ucosm"),
5555
admin: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
5656
};
57-
const aminoMsg = new AminoTypes({ additions: cosmWasmTypes }).toAmino({
57+
const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).toAmino({
5858
typeUrl: "/cosmwasm.wasm.v1.MsgInstantiateContract",
5959
value: msg,
6060
});
@@ -82,7 +82,7 @@ describe("AminoTypes", () => {
8282
funds: coins(1234, "ucosm"),
8383
admin: "",
8484
};
85-
const aminoMsg = new AminoTypes({ additions: cosmWasmTypes }).toAmino({
85+
const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).toAmino({
8686
typeUrl: "/cosmwasm.wasm.v1.MsgInstantiateContract",
8787
value: msg,
8888
});
@@ -107,7 +107,7 @@ describe("AminoTypes", () => {
107107
newAdmin: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
108108
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
109109
};
110-
const aminoMsg = new AminoTypes({ additions: cosmWasmTypes }).toAmino({
110+
const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).toAmino({
111111
typeUrl: "/cosmwasm.wasm.v1.MsgUpdateAdmin",
112112
value: msg,
113113
});
@@ -127,7 +127,7 @@ describe("AminoTypes", () => {
127127
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
128128
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
129129
};
130-
const aminoMsg = new AminoTypes({ additions: cosmWasmTypes }).toAmino({
130+
const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).toAmino({
131131
typeUrl: "/cosmwasm.wasm.v1.MsgClearAdmin",
132132
value: msg,
133133
});
@@ -148,7 +148,7 @@ describe("AminoTypes", () => {
148148
msg: toUtf8(`{"foo":"bar"}`),
149149
funds: coins(1234, "ucosm"),
150150
};
151-
const aminoMsg = new AminoTypes({ additions: cosmWasmTypes }).toAmino({
151+
const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).toAmino({
152152
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
153153
value: msg,
154154
});
@@ -171,7 +171,7 @@ describe("AminoTypes", () => {
171171
codeId: Long.fromString("98765"),
172172
msg: toUtf8(`{"foo":"bar"}`),
173173
};
174-
const aminoMsg = new AminoTypes({ additions: cosmWasmTypes }).toAmino({
174+
const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).toAmino({
175175
typeUrl: "/cosmwasm.wasm.v1.MsgMigrateContract",
176176
value: msg,
177177
});
@@ -197,7 +197,7 @@ describe("AminoTypes", () => {
197197
wasm_byte_code: "WUVMTE9XIFNVQk1BUklORQ==",
198198
},
199199
};
200-
const msg = new AminoTypes({ additions: cosmWasmTypes }).fromAmino(aminoMsg);
200+
const msg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).fromAmino(aminoMsg);
201201
const expectedValue: MsgStoreCode = {
202202
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
203203
wasmByteCode: fromBase64("WUVMTE9XIFNVQk1BUklORQ=="),
@@ -223,7 +223,7 @@ describe("AminoTypes", () => {
223223
admin: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
224224
},
225225
};
226-
const msg = new AminoTypes({ additions: cosmWasmTypes }).fromAmino(aminoMsg);
226+
const msg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).fromAmino(aminoMsg);
227227
const expectedValue: MsgInstantiateContract = {
228228
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
229229
codeId: Long.fromString("12345"),
@@ -250,7 +250,7 @@ describe("AminoTypes", () => {
250250
funds: coins(1234, "ucosm"),
251251
},
252252
};
253-
const msg = new AminoTypes({ additions: cosmWasmTypes }).fromAmino(aminoMsg);
253+
const msg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).fromAmino(aminoMsg);
254254
const expectedValue: MsgInstantiateContract = {
255255
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
256256
codeId: Long.fromString("12345"),
@@ -275,7 +275,7 @@ describe("AminoTypes", () => {
275275
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
276276
},
277277
};
278-
const msg = new AminoTypes({ additions: cosmWasmTypes }).fromAmino(aminoMsg);
278+
const msg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).fromAmino(aminoMsg);
279279
const expectedValue: MsgUpdateAdmin = {
280280
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
281281
newAdmin: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
@@ -295,7 +295,7 @@ describe("AminoTypes", () => {
295295
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
296296
},
297297
};
298-
const msg = new AminoTypes({ additions: cosmWasmTypes }).fromAmino(aminoMsg);
298+
const msg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).fromAmino(aminoMsg);
299299
const expectedValue: MsgClearAdmin = {
300300
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
301301
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
@@ -316,7 +316,7 @@ describe("AminoTypes", () => {
316316
funds: coins(1234, "ucosm"),
317317
},
318318
};
319-
const msg = new AminoTypes({ additions: cosmWasmTypes }).fromAmino(aminoMsg);
319+
const msg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).fromAmino(aminoMsg);
320320
const expectedValue: MsgExecuteContract = {
321321
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
322322
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
@@ -339,7 +339,7 @@ describe("AminoTypes", () => {
339339
msg: { foo: "bar" },
340340
},
341341
};
342-
const msg = new AminoTypes({ additions: cosmWasmTypes }).fromAmino(aminoMsg);
342+
const msg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).fromAmino(aminoMsg);
343343
const expectedValue: MsgMigrateContract = {
344344
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
345345
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",

packages/cosmwasm-stargate/src/signingcosmwasmclient.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,7 @@ describe("SigningCosmWasmClient", () => {
818818
};
819819
customRegistry.register(msgDelegateTypeUrl, CustomMsgDelegate);
820820
const customAminoTypes = new AminoTypes({
821+
prefix: "cosmos",
821822
additions: {
822823
"/cosmos.staking.v1beta1.MsgDelegate": {
823824
aminoType: "cosmos-sdk/MsgDelegate",
@@ -1122,6 +1123,7 @@ describe("SigningCosmWasmClient", () => {
11221123
};
11231124
customRegistry.register(msgDelegateTypeUrl, CustomMsgDelegate);
11241125
const customAminoTypes = new AminoTypes({
1126+
prefix: "cosmos",
11251127
additions: {
11261128
"/cosmos.staking.v1beta1.MsgDelegate": {
11271129
aminoType: "cosmos-sdk/MsgDelegate",

packages/cosmwasm-stargate/src/signingcosmwasmclient.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,11 @@ export class SigningCosmWasmClient extends CosmWasmClient {
187187
options: SigningCosmWasmClientOptions,
188188
) {
189189
super(tmClient);
190+
// TODO: do we really want to set a default here? Ideally we could get it from the signer such that users only have to set it once.
191+
const prefix = options.prefix ?? "cosmos";
190192
const {
191193
registry = createDefaultRegistry(),
192-
aminoTypes = new AminoTypes({ additions: cosmWasmTypes, prefix: options.prefix }),
194+
aminoTypes = new AminoTypes({ prefix, additions: cosmWasmTypes }),
193195
} = options;
194196
this.registry = registry;
195197
this.aminoTypes = aminoTypes;

0 commit comments

Comments
 (0)