Remove unnecessary address prefix from createStakingAminoConverters

This commit is contained in:
Simon Warta 2022-12-08 15:21:28 +01:00
parent e8eefe85af
commit 6dd634afda
7 changed files with 24 additions and 39 deletions

View File

@ -18,10 +18,15 @@ and this project adheres to
unnecessary problems around importing Node.js modules. ([#1341])
- @cosmjs/proto-signing: Make input and output of `decodePubkey` non-optional
([#1289]).
- @cosmjs/stargate: Remove unnecessary address prefix argument from
`createStakingAminoConverters`. This made `prefix` in
`SigningCosmWasmClientOptions` and `SigningStargateClientOptions` obsolete, so
this was also deleted. ([#1291])
[#1002]: https://github.com/cosmos/cosmjs/issues/1002
[#1240]: https://github.com/cosmos/cosmjs/pull/1240
[#1289]: https://github.com/cosmos/cosmjs/issues/1289
[#1291]: https://github.com/cosmos/cosmjs/issues/1291
[#1341]: https://github.com/cosmos/cosmjs/issues/1341
## [0.29.5] - 2022-12-07

View File

@ -55,7 +55,6 @@ describe("SigningCosmWasmClient", () => {
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(alice.mnemonic, { prefix: wasmd.prefix });
const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet, {
...defaultSigningClientOptions,
prefix: wasmd.prefix,
});
expect(client).toBeTruthy();
client.disconnect();
@ -673,7 +672,6 @@ describe("SigningCosmWasmClient", () => {
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(alice.mnemonic, { prefix: wasmd.prefix });
const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet, {
...defaultSigningClientOptions,
prefix: wasmd.prefix,
});
const msgDelegateTypeUrl = "/cosmos.staking.v1beta1.MsgDelegate";
@ -702,7 +700,6 @@ describe("SigningCosmWasmClient", () => {
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(alice.mnemonic, { prefix: wasmd.prefix });
const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet, {
...defaultSigningClientOptions,
prefix: wasmd.prefix,
gasPrice: defaultGasPrice,
});
const msgDelegateTypeUrl = "/cosmos.staking.v1beta1.MsgDelegate";
@ -730,7 +727,6 @@ describe("SigningCosmWasmClient", () => {
});
const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet, {
...defaultSigningClientOptions,
prefix: wasmd.prefix,
});
const msgDelegateTypeUrl = "/cosmos.staking.v1beta1.MsgDelegate";
@ -771,7 +767,6 @@ describe("SigningCosmWasmClient", () => {
const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic, { prefix: wasmd.prefix });
const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet, {
...defaultSigningClientOptions,
prefix: wasmd.prefix,
});
const msgSend: MsgSend = {
@ -799,8 +794,7 @@ describe("SigningCosmWasmClient", () => {
const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic, { prefix: wasmd.prefix });
const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet, {
...defaultSigningClientOptions,
aminoTypes: new AminoTypes(createStakingAminoConverters(wasmd.prefix)),
prefix: wasmd.prefix,
aminoTypes: new AminoTypes(createStakingAminoConverters()),
});
const msgDelegate: MsgDelegate = {
@ -828,7 +822,6 @@ describe("SigningCosmWasmClient", () => {
const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic, { prefix: wasmd.prefix });
const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet, {
...defaultSigningClientOptions,
prefix: wasmd.prefix,
});
const { data } = getHackatom();
@ -982,8 +975,7 @@ describe("SigningCosmWasmClient", () => {
});
const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet, {
...defaultSigningClientOptions,
aminoTypes: new AminoTypes(createStakingAminoConverters(wasmd.prefix)),
prefix: wasmd.prefix,
aminoTypes: new AminoTypes(createStakingAminoConverters()),
});
const msg = {
@ -1025,7 +1017,6 @@ describe("SigningCosmWasmClient", () => {
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(alice.mnemonic, { prefix: wasmd.prefix });
const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet, {
...defaultSigningClientOptions,
prefix: wasmd.prefix,
});
const msg = MsgDelegate.fromPartial({
@ -1058,7 +1049,6 @@ describe("SigningCosmWasmClient", () => {
});
const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet, {
...defaultSigningClientOptions,
prefix: wasmd.prefix,
});
const msg = MsgDelegate.fromPartial({
@ -1098,7 +1088,6 @@ describe("SigningCosmWasmClient", () => {
const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic, { prefix: wasmd.prefix });
const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet, {
...defaultSigningClientOptions,
prefix: wasmd.prefix,
});
const msgSend: MsgSend = {
@ -1129,8 +1118,7 @@ describe("SigningCosmWasmClient", () => {
const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic, { prefix: wasmd.prefix });
const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet, {
...defaultSigningClientOptions,
aminoTypes: new AminoTypes(createStakingAminoConverters(wasmd.prefix)),
prefix: wasmd.prefix,
aminoTypes: new AminoTypes(createStakingAminoConverters()),
});
const msgDelegate: MsgDelegate = {
@ -1286,8 +1274,7 @@ describe("SigningCosmWasmClient", () => {
});
const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet, {
...defaultSigningClientOptions,
aminoTypes: new AminoTypes(createStakingAminoConverters(wasmd.prefix)),
prefix: wasmd.prefix,
aminoTypes: new AminoTypes(createStakingAminoConverters()),
});
const msg: MsgDelegate = {

View File

@ -169,7 +169,6 @@ function createDefaultRegistry(): Registry {
export interface SigningCosmWasmClientOptions {
readonly registry?: Registry;
readonly aminoTypes?: AminoTypes;
readonly prefix?: string;
readonly broadcastTimeoutMs?: number;
readonly broadcastPollIntervalMs?: number;
readonly gasPrice?: GasPrice;

View File

@ -45,7 +45,7 @@ describe("AminoTypes", () => {
it("can override type with Amino type collision", () => {
const types = new AminoTypes({
...createStakingAminoConverters("cosmos"),
...createStakingAminoConverters(),
"/cosmos.staking.otherVersion456.MsgDelegate": {
aminoType: "cosmos-sdk/MsgDelegate",
toAmino: (m: MsgDelegate): { readonly foo: string } => ({

View File

@ -41,7 +41,7 @@ describe("AminoTypes", () => {
validatorDstAddress: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
amount: coin(1234, "ucosm"),
};
const aminoTypes = new AminoTypes(createStakingAminoConverters("cosmos"));
const aminoTypes = new AminoTypes(createStakingAminoConverters());
const aminoMsg = aminoTypes.toAmino({
typeUrl: "/cosmos.staking.v1beta1.MsgBeginRedelegate",
value: msg,
@ -87,7 +87,7 @@ describe("AminoTypes", () => {
},
value: coin(1234, "ucosm"),
};
const aminoTypes = new AminoTypes(createStakingAminoConverters("cosmos"));
const aminoTypes = new AminoTypes(createStakingAminoConverters());
const aminoMsg = aminoTypes.toAmino({
typeUrl: "/cosmos.staking.v1beta1.MsgCreateValidator",
value: msg,
@ -126,7 +126,7 @@ describe("AminoTypes", () => {
validatorAddress: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
amount: coin(1234, "ucosm"),
};
const aminoTypes = new AminoTypes(createStakingAminoConverters("cosmos"));
const aminoTypes = new AminoTypes(createStakingAminoConverters());
const aminoMsg = aminoTypes.toAmino({
typeUrl: "/cosmos.staking.v1beta1.MsgDelegate",
value: msg,
@ -155,7 +155,7 @@ describe("AminoTypes", () => {
minSelfDelegation: "123",
validatorAddress: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
};
const aminoTypes = new AminoTypes(createStakingAminoConverters("cosmos"));
const aminoTypes = new AminoTypes(createStakingAminoConverters());
const aminoMsg = aminoTypes.toAmino({
typeUrl: "/cosmos.staking.v1beta1.MsgEditValidator",
value: msg,
@ -184,7 +184,7 @@ describe("AminoTypes", () => {
validatorAddress: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
amount: coin(1234, "ucosm"),
};
const aminoTypes = new AminoTypes(createStakingAminoConverters("cosmos"));
const aminoTypes = new AminoTypes(createStakingAminoConverters());
const aminoMsg = aminoTypes.toAmino({
typeUrl: "/cosmos.staking.v1beta1.MsgUndelegate",
value: msg,
@ -212,7 +212,7 @@ describe("AminoTypes", () => {
amount: coin(1234, "ucosm"),
},
};
const msg = new AminoTypes(createStakingAminoConverters("cosmos")).fromAmino(aminoMsg);
const msg = new AminoTypes(createStakingAminoConverters()).fromAmino(aminoMsg);
const expectedValue: MsgBeginRedelegate = {
delegatorAddress: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
validatorSrcAddress: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
@ -251,7 +251,7 @@ describe("AminoTypes", () => {
value: coin(1234, "ucosm"),
},
};
const msg = new AminoTypes(createStakingAminoConverters("cosmos")).fromAmino(aminoMsg);
const msg = new AminoTypes(createStakingAminoConverters()).fromAmino(aminoMsg);
const expectedValue: MsgCreateValidator = {
description: {
moniker: "validator",
@ -295,7 +295,7 @@ describe("AminoTypes", () => {
amount: coin(1234, "ucosm"),
},
};
const msg = new AminoTypes(createStakingAminoConverters("cosmos")).fromAmino(aminoMsg);
const msg = new AminoTypes(createStakingAminoConverters()).fromAmino(aminoMsg);
const expectedValue: MsgDelegate = {
delegatorAddress: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
validatorAddress: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
@ -323,7 +323,7 @@ describe("AminoTypes", () => {
validator_address: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
},
};
const msg = new AminoTypes(createStakingAminoConverters("cosmos")).fromAmino(aminoMsg);
const msg = new AminoTypes(createStakingAminoConverters()).fromAmino(aminoMsg);
const expectedValue: MsgEditValidator = {
description: {
moniker: "validator",
@ -351,7 +351,7 @@ describe("AminoTypes", () => {
amount: coin(1234, "ucosm"),
},
};
const msg = new AminoTypes(createStakingAminoConverters("cosmos")).fromAmino(aminoMsg);
const msg = new AminoTypes(createStakingAminoConverters()).fromAmino(aminoMsg);
const expectedValue: MsgUndelegate = {
delegatorAddress: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
validatorAddress: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",

View File

@ -143,9 +143,7 @@ export function isAminoMsgUndelegate(msg: AminoMsg): msg is AminoMsgUndelegate {
return msg.type === "cosmos-sdk/MsgUndelegate";
}
export function createStakingAminoConverters(
_prefix: string,
): Record<string, AminoConverter | "not_supported_by_chain"> {
export function createStakingAminoConverters(): Record<string, AminoConverter | "not_supported_by_chain"> {
return {
"/cosmos.staking.v1beta1.MsgBeginRedelegate": {
aminoType: "cosmos-sdk/MsgBeginRedelegate",

View File

@ -87,19 +87,18 @@ export interface PrivateSigningStargateClient {
export interface SigningStargateClientOptions extends StargateClientOptions {
readonly registry?: Registry;
readonly aminoTypes?: AminoTypes;
readonly prefix?: string;
readonly broadcastTimeoutMs?: number;
readonly broadcastPollIntervalMs?: number;
readonly gasPrice?: GasPrice;
}
function createDefaultTypes(prefix: string): AminoConverters {
function createDefaultTypes(): AminoConverters {
return {
...createAuthzAminoConverters(),
...createBankAminoConverters(),
...createDistributionAminoConverters(),
...createGovAminoConverters(),
...createStakingAminoConverters(prefix),
...createStakingAminoConverters(),
...createIbcAminoConverters(),
...createFeegrantAminoConverters(),
...createVestingAminoConverters(),
@ -146,10 +145,7 @@ export class SigningStargateClient extends StargateClient {
options: SigningStargateClientOptions,
) {
super(tmClient, options);
// 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.
const prefix = options.prefix ?? "cosmos";
const { registry = createDefaultRegistry(), aminoTypes = new AminoTypes(createDefaultTypes(prefix)) } =
options;
const { registry = createDefaultRegistry(), aminoTypes = new AminoTypes(createDefaultTypes()) } = options;
this.registry = registry;
this.aminoTypes = aminoTypes;
this.signer = signer;