diff --git a/CHANGELOG.md b/CHANGELOG.md index 46a3ff87..6268a8f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,8 +13,14 @@ 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]) +- @cosmjs/tendermint-rpc: The property `evidence` in the interface `Block` is now + non-optional. ([#1011]) [#989]: https://github.com/cosmos/cosmjs/issues/989 +[#994]: https://github.com/cosmos/cosmjs/issues/994 +[#1011]: https://github.com/cosmos/cosmjs/issues/1011 ### Removed diff --git a/packages/proto-signing/src/registry.ts b/packages/proto-signing/src/registry.ts index 90dbf127..13b72f77 100644 --- a/packages/proto-signing/src/registry.ts +++ b/packages/proto-signing/src/registry.ts @@ -81,27 +81,21 @@ 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]> = []) { + public constructor(customTypes?: Iterable<[string, GeneratedType]>) { const { cosmosCoin, cosmosMsgSend } = defaultTypeUrls; - this.types = new Map([ - [cosmosCoin, Coin], - [cosmosMsgSend, MsgSend], - ...customTypes, - ]); + this.types = customTypes + ? new Map([...customTypes]) + : new Map([ + [cosmosCoin, Coin], + [cosmosMsgSend, MsgSend], + ]); } public register(typeUrl: string, type: GeneratedType): void { diff --git a/packages/stargate/src/signingstargateclient.ts b/packages/stargate/src/signingstargateclient.ts index e86834c6..9a9d457a 100644 --- a/packages/stargate/src/signingstargateclient.ts +++ b/packages/stargate/src/signingstargateclient.ts @@ -15,7 +15,7 @@ import { import { Tendermint34Client } from "@cosmjs/tendermint-rpc"; import { assert, assertDefined } from "@cosmjs/utils"; import { MsgExec, MsgGrant, MsgRevoke } from "cosmjs-types/cosmos/authz/v1beta1/tx"; -import { 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, @@ -74,6 +74,8 @@ import { calculateFee, GasPrice } from "./fee"; 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], diff --git a/packages/tendermint-rpc/src/tendermint34/adaptor/responses.ts b/packages/tendermint-rpc/src/tendermint34/adaptor/responses.ts index b8784188..b2255d99 100644 --- a/packages/tendermint-rpc/src/tendermint34/adaptor/responses.ts +++ b/packages/tendermint-rpc/src/tendermint34/adaptor/responses.ts @@ -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 ?? [], }; } diff --git a/packages/tendermint-rpc/src/tendermint34/responses.ts b/packages/tendermint-rpc/src/tendermint34/responses.ts index c7648f69..fbbb058d 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[]; } /**