Rename decorator cosmosMessage -> registered
This commit is contained in:
parent
c2e0efd158
commit
feb33aec3d
@ -1,10 +1,10 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { Message } from "protobufjs";
|
||||
|
||||
import { cosmosField, cosmosMessage } from "./decorator";
|
||||
import { cosmosField, registered } from "./decorator";
|
||||
import { defaultRegistry } from "./msgs";
|
||||
|
||||
@cosmosMessage(defaultRegistry, "/cosmos.auth.BaseAccount")
|
||||
@registered(defaultRegistry, "/cosmos.auth.BaseAccount")
|
||||
export class BaseAccount extends Message {
|
||||
@cosmosField.bytes(1)
|
||||
public readonly address?: Uint8Array;
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
import { assert } from "@cosmjs/utils";
|
||||
import { Message } from "protobufjs";
|
||||
|
||||
import { cosmosField, cosmosMessage } from "./decorator";
|
||||
import { cosmosField, registered } from "./decorator";
|
||||
import { cosmos, google } from "./generated/codecimpl";
|
||||
import { Registry } from "./registry";
|
||||
|
||||
@ -15,13 +15,13 @@ describe("decorator demo", () => {
|
||||
const typeUrl = "/demo.MsgDemo";
|
||||
const myRegistry = new Registry();
|
||||
|
||||
@cosmosMessage(myRegistry, nestedTypeUrl)
|
||||
@registered(myRegistry, nestedTypeUrl)
|
||||
class MsgNestedDemo extends Message {
|
||||
@cosmosField.string(1)
|
||||
public readonly foo?: string;
|
||||
}
|
||||
|
||||
@cosmosMessage(myRegistry, typeUrl)
|
||||
@registered(myRegistry, typeUrl)
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
class MsgDemo extends Message {
|
||||
@cosmosField.boolean(1)
|
||||
|
||||
@ -7,7 +7,11 @@ function getTypeName(typeUrl: string): string {
|
||||
return parts[parts.length - 1];
|
||||
}
|
||||
|
||||
export function cosmosMessage(registry: Registry, typeUrl: string): TypeDecorator<any> {
|
||||
/**
|
||||
* A class decorator to register this type under the given type URL
|
||||
* in the given registry.
|
||||
*/
|
||||
export function registered(registry: Registry, typeUrl: string): TypeDecorator<any> {
|
||||
return (ctor: Constructor<Message<any>>) => {
|
||||
const typeName = getTypeName(typeUrl);
|
||||
const generatedType = util.decorateType(ctor, typeName);
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { Message } from "protobufjs";
|
||||
|
||||
import { cosmosField, cosmosMessage } from "./decorator";
|
||||
import { cosmosField, registered } from "./decorator";
|
||||
import { Registry } from "./registry";
|
||||
|
||||
describe("registry magic demo", () => {
|
||||
@ -10,13 +10,13 @@ describe("registry magic demo", () => {
|
||||
const typeUrl = "/demo.MsgMagic";
|
||||
const myRegistry = new Registry();
|
||||
|
||||
@cosmosMessage(myRegistry, nestedTypeUrl)
|
||||
@registered(myRegistry, nestedTypeUrl)
|
||||
class MsgNestedMagic extends Message {
|
||||
@cosmosField.string(1)
|
||||
public readonly foo?: string;
|
||||
}
|
||||
|
||||
@cosmosMessage(myRegistry, typeUrl)
|
||||
@registered(myRegistry, typeUrl)
|
||||
class MsgMagic extends Message {
|
||||
@cosmosField.boolean(1)
|
||||
public readonly booleanDemo?: boolean;
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { Message } from "protobufjs";
|
||||
|
||||
import { cosmosField, cosmosMessage } from "./decorator";
|
||||
import { cosmosField, registered } from "./decorator";
|
||||
import { Registry } from "./registry";
|
||||
|
||||
export const defaultRegistry = new Registry();
|
||||
|
||||
@cosmosMessage(defaultRegistry, "/cosmos.Coin")
|
||||
@registered(defaultRegistry, "/cosmos.Coin")
|
||||
export class Coin extends Message {
|
||||
@cosmosField.string(1)
|
||||
public readonly denom?: string;
|
||||
@ -15,7 +15,7 @@ export class Coin extends Message {
|
||||
public readonly amount?: string;
|
||||
}
|
||||
|
||||
@cosmosMessage(defaultRegistry, "/cosmos.bank.MsgSend")
|
||||
@registered(defaultRegistry, "/cosmos.bank.MsgSend")
|
||||
export class MsgSend extends Message {
|
||||
@cosmosField.bytes(1)
|
||||
public readonly from_address?: Uint8Array;
|
||||
|
||||
6
packages/proto-signing/types/decorator.d.ts
vendored
6
packages/proto-signing/types/decorator.d.ts
vendored
@ -1,6 +1,10 @@
|
||||
import { Constructor, Message, TypeDecorator } from "protobufjs";
|
||||
import { Registry } from "./registry";
|
||||
export declare function cosmosMessage(registry: Registry, typeUrl: string): TypeDecorator<any>;
|
||||
/**
|
||||
* A class decorator to register this type under the given type URL
|
||||
* in the given registry.
|
||||
*/
|
||||
export declare function registered(registry: Registry, typeUrl: string): TypeDecorator<any>;
|
||||
/**
|
||||
* Like PropertyDecorator from lib.es5.d.ts but without symbol support in propertyKey.
|
||||
*/
|
||||
|
||||
Loading…
Reference in New Issue
Block a user