From ca969f28225652b396228d16b24188ab06930c0a Mon Sep 17 00:00:00 2001 From: Milan Steiner Date: Tue, 1 Feb 2022 14:29:32 +0100 Subject: [PATCH 01/11] Make evidence non optional --- packages/tendermint-rpc/src/tendermint34/responses.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/tendermint-rpc/src/tendermint34/responses.ts b/packages/tendermint-rpc/src/tendermint34/responses.ts index c7648f6907..fbbb058d0d 100644 --- a/packages/tendermint-rpc/src/tendermint34/responses.ts +++ b/packages/tendermint-rpc/src/tendermint34/responses.ts @@ -227,8 +227,7 @@ export interface Block { */ readonly lastCommit: Commit | null; readonly txs: readonly Uint8Array[]; - // This field becomes non-optional in 0.28 (https://github.com/cosmos/cosmjs/issues/1011) - readonly evidence?: readonly Evidence[]; + readonly evidence: readonly Evidence[]; } /** From c0882460b028d8ce77500f0f50832f8ce933f958 Mon Sep 17 00:00:00 2001 From: Milan Steiner Date: Tue, 1 Feb 2022 14:59:30 +0100 Subject: [PATCH 02/11] Fix implementation of evidence so its non optional --- packages/tendermint-rpc/src/tendermint34/adaptor/responses.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/tendermint-rpc/src/tendermint34/adaptor/responses.ts b/packages/tendermint-rpc/src/tendermint34/adaptor/responses.ts index b8784188a0..ff1ecc5f63 100644 --- a/packages/tendermint-rpc/src/tendermint34/adaptor/responses.ts +++ b/packages/tendermint-rpc/src/tendermint34/adaptor/responses.ts @@ -743,8 +743,8 @@ interface RpcBlock { }; // It's currently unclear why the deep nesting is requied. // See https://github.com/tendermint/tendermint/issues/7697. - readonly evidence?: { - readonly evidence?: readonly RpcEvidence[]; + readonly evidence: { + readonly evidence: readonly RpcEvidence[]; }; } From 8c9c7596246e7fc6b090f8f6a26c9d1b5cd53d77 Mon Sep 17 00:00:00 2001 From: Milan Steiner Date: Tue, 1 Feb 2022 15:15:51 +0100 Subject: [PATCH 03/11] Fix implementation of evidence so its non optional --- .../tendermint-rpc/src/tendermint34/adaptor/responses.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/tendermint-rpc/src/tendermint34/adaptor/responses.ts b/packages/tendermint-rpc/src/tendermint34/adaptor/responses.ts index ff1ecc5f63..b2255d99d2 100644 --- a/packages/tendermint-rpc/src/tendermint34/adaptor/responses.ts +++ b/packages/tendermint-rpc/src/tendermint34/adaptor/responses.ts @@ -743,8 +743,8 @@ interface RpcBlock { }; // It's currently unclear why the deep nesting is requied. // See https://github.com/tendermint/tendermint/issues/7697. - readonly evidence: { - readonly evidence: readonly RpcEvidence[]; + readonly evidence?: { + readonly evidence?: readonly RpcEvidence[]; }; } @@ -757,7 +757,7 @@ function decodeBlock(data: RpcBlock): responses.Block { txs: data.data.txs ? assertArray(data.data.txs).map(fromBase64) : [], // Lift up .evidence.evidence to just .evidence // See https://github.com/tendermint/tendermint/issues/7697 - evidence: data.evidence?.evidence, + evidence: data.evidence?.evidence ?? [], }; } From 7af2c64732d028b4a0bc76e2ad1ff413fa024290 Mon Sep 17 00:00:00 2001 From: Milan Steiner Date: Tue, 1 Feb 2022 16:17:27 +0100 Subject: [PATCH 04/11] Let Registry constructor argument override types --- packages/proto-signing/src/registry.ts | 7 ++++--- packages/stargate/src/signingstargateclient.ts | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/proto-signing/src/registry.ts b/packages/proto-signing/src/registry.ts index 90dbf12708..760db18034 100644 --- a/packages/proto-signing/src/registry.ts +++ b/packages/proto-signing/src/registry.ts @@ -95,12 +95,13 @@ export class Registry { * change the `customTypes` argument to override the default types if set. * See https://github.com/cosmos/cosmjs/issues/994 */ - public constructor(customTypes: Iterable<[string, GeneratedType]> = []) { + public constructor(customTypes?: Iterable<[string, GeneratedType]>) { const { cosmosCoin, cosmosMsgSend } = defaultTypeUrls; - this.types = new Map([ + this.types = customTypes ? new Map([ + ...customTypes + ]) : new Map([ [cosmosCoin, Coin], [cosmosMsgSend, MsgSend], - ...customTypes, ]); } diff --git a/packages/stargate/src/signingstargateclient.ts b/packages/stargate/src/signingstargateclient.ts index 0d34e1c758..5b00c2cf36 100644 --- a/packages/stargate/src/signingstargateclient.ts +++ b/packages/stargate/src/signingstargateclient.ts @@ -72,6 +72,7 @@ import { calculateFee, GasPrice } from "./fee"; import { DeliverTxResponse, StargateClient } from "./stargateclient"; export const defaultRegistryTypes: ReadonlyArray<[string, GeneratedType]> = [ + ["/cosmos.base.v1beta1.Coin", Coin], ["/cosmos.bank.v1beta1.MsgMultiSend", MsgMultiSend], ["/cosmos.distribution.v1beta1.MsgFundCommunityPool", MsgFundCommunityPool], ["/cosmos.distribution.v1beta1.MsgSetWithdrawAddress", MsgSetWithdrawAddress], From 697e4d2fecea58fb70a0e9bd2157ad9f5eb03c0c Mon Sep 17 00:00:00 2001 From: Milan Steiner Date: Tue, 1 Feb 2022 16:33:25 +0100 Subject: [PATCH 05/11] Fix linting --- packages/proto-signing/src/registry.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/proto-signing/src/registry.ts b/packages/proto-signing/src/registry.ts index 760db18034..1e979c4fe7 100644 --- a/packages/proto-signing/src/registry.ts +++ b/packages/proto-signing/src/registry.ts @@ -97,12 +97,12 @@ export class Registry { */ public constructor(customTypes?: Iterable<[string, GeneratedType]>) { const { cosmosCoin, cosmosMsgSend } = defaultTypeUrls; - this.types = customTypes ? new Map([ - ...customTypes - ]) : new Map([ - [cosmosCoin, Coin], - [cosmosMsgSend, MsgSend], - ]); + this.types = customTypes + ? new Map([...customTypes]) + : new Map([ + [cosmosCoin, Coin], + [cosmosMsgSend, MsgSend], + ]); } public register(typeUrl: string, type: GeneratedType): void { From 7c439e155c327122aac86b0552cdec54c59219d7 Mon Sep 17 00:00:00 2001 From: Milan Steiner Date: Tue, 1 Feb 2022 17:02:10 +0100 Subject: [PATCH 06/11] Adding MsgSend to defaultRegistryTypes --- packages/stargate/src/signingstargateclient.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/stargate/src/signingstargateclient.ts b/packages/stargate/src/signingstargateclient.ts index 5b00c2cf36..cc3bef1db7 100644 --- a/packages/stargate/src/signingstargateclient.ts +++ b/packages/stargate/src/signingstargateclient.ts @@ -14,7 +14,7 @@ import { } from "@cosmjs/proto-signing"; import { Tendermint34Client } from "@cosmjs/tendermint-rpc"; import { assert, assertDefined } from "@cosmjs/utils"; -import { MsgMultiSend } from "cosmjs-types/cosmos/bank/v1beta1/tx"; +import { MsgSend, MsgMultiSend } from "cosmjs-types/cosmos/bank/v1beta1/tx"; import { Coin } from "cosmjs-types/cosmos/base/v1beta1/coin"; import { MsgFundCommunityPool, @@ -73,6 +73,7 @@ import { DeliverTxResponse, StargateClient } from "./stargateclient"; export const defaultRegistryTypes: ReadonlyArray<[string, GeneratedType]> = [ ["/cosmos.base.v1beta1.Coin", Coin], + ["/cosmos.bank.v1beta1.MsgSend", MsgSend], ["/cosmos.bank.v1beta1.MsgMultiSend", MsgMultiSend], ["/cosmos.distribution.v1beta1.MsgFundCommunityPool", MsgFundCommunityPool], ["/cosmos.distribution.v1beta1.MsgSetWithdrawAddress", MsgSetWithdrawAddress], From 25d9b6cd51dbd7a972ee999389d5f75872900ba6 Mon Sep 17 00:00:00 2001 From: Milan Steiner Date: Wed, 2 Feb 2022 09:29:19 +0100 Subject: [PATCH 07/11] Fix linting errors --- packages/stargate/src/signingstargateclient.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/stargate/src/signingstargateclient.ts b/packages/stargate/src/signingstargateclient.ts index cc3bef1db7..cf29473b3f 100644 --- a/packages/stargate/src/signingstargateclient.ts +++ b/packages/stargate/src/signingstargateclient.ts @@ -14,7 +14,7 @@ import { } from "@cosmjs/proto-signing"; import { Tendermint34Client } from "@cosmjs/tendermint-rpc"; import { assert, assertDefined } from "@cosmjs/utils"; -import { MsgSend, MsgMultiSend } from "cosmjs-types/cosmos/bank/v1beta1/tx"; +import { MsgMultiSend, MsgSend } from "cosmjs-types/cosmos/bank/v1beta1/tx"; import { Coin } from "cosmjs-types/cosmos/base/v1beta1/coin"; import { MsgFundCommunityPool, From 4cbf5fec3482d0ad20a5b1f1e2620e694e458052 Mon Sep 17 00:00:00 2001 From: Milan Steiner Date: Wed, 2 Feb 2022 09:35:12 +0100 Subject: [PATCH 08/11] Add changes to CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 46a3ff87be..499bb91411 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,8 +13,11 @@ and this project adheres to `AminoTypesOptions`. This is an object with a required `prefix` field. Before the prefix defaulted to "cosmos" but this is almost never the right choice for CosmJS users that need to add Amino types manually. ([#989]) +- @cosmjs/stargate: `MsgSend` and `Coin` are now parts of `defaultRegistryTypes`. ([#994]) +- @cosmjs/proto-signing: `Registry`'s constructor can now override default types. ([#994]) [#989]: https://github.com/cosmos/cosmjs/issues/989 +[#994]: https://github.com/cosmos/cosmjs/issues/994 ### Removed From cf6487d874f2b48aec9614d3e8f3096f716c7204 Mon Sep 17 00:00:00 2001 From: Milan Steiner Date: Wed, 2 Feb 2022 09:39:54 +0100 Subject: [PATCH 09/11] Editing Docs --- packages/proto-signing/src/registry.ts | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/packages/proto-signing/src/registry.ts b/packages/proto-signing/src/registry.ts index 1e979c4fe7..0a14d8b37b 100644 --- a/packages/proto-signing/src/registry.ts +++ b/packages/proto-signing/src/registry.ts @@ -81,19 +81,12 @@ export class Registry { * actual implementations. Those implementations are typically generated with ts-proto * but we also support protobuf.js as a type generator. * - * By default, a `new Registry()` constains amost no types. `Coin` and `MsgSend` are in there - * for historic reasons but this does not make a lot of sense. - * + * If there is no parameter given, a `new Registry()` adds the types `Coin` and `MsgSend` + * for historic reasons. Those can be overriden by customTypes. + * * There are currently two methods for adding new types: - * 1. Using the `register()` method - * 2. Passing custom types to the constructor. - * This only creates confusion for users. The reason here is historical. - * Using `register()` is recommended and 2. is deprecated because its behaviour - * will change in https://github.com/cosmos/cosmjs/issues/994. - * - * There is currently no way to unregister/override the default types. We should - * change the `customTypes` argument to override the default types if set. - * See https://github.com/cosmos/cosmjs/issues/994 + * 1. Passing types to the constructor. + * 2. Using the `register()` method */ public constructor(customTypes?: Iterable<[string, GeneratedType]>) { const { cosmosCoin, cosmosMsgSend } = defaultTypeUrls; From 099ba78db080f75284e1cb94c992115d06b3c8a0 Mon Sep 17 00:00:00 2001 From: Milan Steiner Date: Wed, 2 Feb 2022 09:46:34 +0100 Subject: [PATCH 10/11] Adding changes to CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 46a3ff87be..732856651b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,8 +13,11 @@ and this project adheres to `AminoTypesOptions`. This is an object with a required `prefix` field. Before the prefix defaulted to "cosmos" but this is almost never the right choice for CosmJS users that need to add Amino types manually. ([#989]) +- @cosmjs/tendermint-rpc: The property `evidence` in the interface `Block` is now + non-optional. ([#1011]) [#989]: https://github.com/cosmos/cosmjs/issues/989 +[#1011]: https://github.com/cosmos/cosmjs/issues/1011 ### Removed From cda08197d64be2757ed2f3f50306493d2e52015e Mon Sep 17 00:00:00 2001 From: Milan Steiner Date: Wed, 2 Feb 2022 09:47:56 +0100 Subject: [PATCH 11/11] Fix Linting --- packages/proto-signing/src/registry.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/proto-signing/src/registry.ts b/packages/proto-signing/src/registry.ts index 0a14d8b37b..13b72f778a 100644 --- a/packages/proto-signing/src/registry.ts +++ b/packages/proto-signing/src/registry.ts @@ -83,7 +83,7 @@ export class Registry { * * If there is no parameter given, a `new Registry()` adds the types `Coin` and `MsgSend` * for historic reasons. Those can be overriden by customTypes. - * + * * There are currently two methods for adding new types: * 1. Passing types to the constructor. * 2. Using the `register()` method