Merge pull request #1024 from cosmos/Registry-constructor-arguments
Let Registry constructor argument override default types
This commit is contained in:
commit
79b147b644
@ -13,10 +13,13 @@ 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
|
||||
|
||||
@ -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<string, GeneratedType>([
|
||||
[cosmosCoin, Coin],
|
||||
[cosmosMsgSend, MsgSend],
|
||||
...customTypes,
|
||||
]);
|
||||
this.types = customTypes
|
||||
? new Map<string, GeneratedType>([...customTypes])
|
||||
: new Map<string, GeneratedType>([
|
||||
[cosmosCoin, Coin],
|
||||
[cosmosMsgSend, MsgSend],
|
||||
]);
|
||||
}
|
||||
|
||||
public register(typeUrl: string, type: GeneratedType): void {
|
||||
|
||||
@ -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 { MsgMultiSend, MsgSend } from "cosmjs-types/cosmos/bank/v1beta1/tx";
|
||||
import { Coin } from "cosmjs-types/cosmos/base/v1beta1/coin";
|
||||
import {
|
||||
MsgFundCommunityPool,
|
||||
@ -72,6 +72,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],
|
||||
|
||||
Loading…
Reference in New Issue
Block a user