mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-10 21:49:15 +00:00
demo-protobuf: Add GeneratedType interface
This commit is contained in:
parent
78a96cf06c
commit
21e29d1f25
@ -2,24 +2,21 @@ import protobuf from "protobufjs";
|
||||
|
||||
import { cosmos_sdk as cosmosSdk, google } from "./generated/codecimpl";
|
||||
|
||||
export type GeneratedType = {
|
||||
readonly create: (properties?: { [k: string]: any }) => protobuf.Message<{}>;
|
||||
readonly encode: (
|
||||
message: protobuf.Message<{}> | { [k: string]: any },
|
||||
writer?: protobuf.Writer,
|
||||
) => protobuf.Writer;
|
||||
readonly decode: (reader: protobuf.Reader | Uint8Array, length?: number) => protobuf.Message<{}>;
|
||||
};
|
||||
interface GeneratedType {
|
||||
readonly create: (properties?: { [k: string]: any }) => any;
|
||||
readonly encode: (message: any | { [k: string]: any }, writer?: protobuf.Writer) => protobuf.Writer;
|
||||
readonly decode: (reader: protobuf.Reader | Uint8Array, length?: number) => any;
|
||||
}
|
||||
|
||||
export class Registry {
|
||||
private readonly types: Map<string, GeneratedType>;
|
||||
|
||||
constructor(customTypes: Iterable<[string, GeneratedType]> = []) {
|
||||
this.types = new Map<string, GeneratedType>([
|
||||
["/cosmos.Coin", (cosmosSdk.v1.Coin as unknown) as GeneratedType],
|
||||
["/cosmos.bank.MsgSend", (cosmosSdk.x.bank.v1.MsgSend as unknown) as GeneratedType],
|
||||
["/cosmos.tx.TxBody", (cosmosSdk.tx.v1.TxBody as unknown) as GeneratedType],
|
||||
["/google.protobuf.Any", (google.protobuf.Any as unknown) as GeneratedType],
|
||||
["/cosmos.Coin", cosmosSdk.v1.Coin],
|
||||
["/cosmos.bank.MsgSend", cosmosSdk.x.bank.v1.MsgSend],
|
||||
["/cosmos.tx.TxBody", cosmosSdk.tx.v1.TxBody],
|
||||
["/google.protobuf.Any", google.protobuf.Any],
|
||||
...customTypes,
|
||||
]);
|
||||
}
|
||||
|
11
packages/demo-protobuf/types/registry.d.ts
vendored
11
packages/demo-protobuf/types/registry.d.ts
vendored
@ -1,18 +1,19 @@
|
||||
import protobuf from "protobufjs";
|
||||
export declare type GeneratedType = {
|
||||
readonly create: (properties?: { [k: string]: any }) => protobuf.Message<{}>;
|
||||
interface GeneratedType {
|
||||
readonly create: (properties?: { [k: string]: any }) => any;
|
||||
readonly encode: (
|
||||
message:
|
||||
| protobuf.Message<{}>
|
||||
| any
|
||||
| {
|
||||
[k: string]: any;
|
||||
},
|
||||
writer?: protobuf.Writer,
|
||||
) => protobuf.Writer;
|
||||
readonly decode: (reader: protobuf.Reader | Uint8Array, length?: number) => protobuf.Message<{}>;
|
||||
};
|
||||
readonly decode: (reader: protobuf.Reader | Uint8Array, length?: number) => any;
|
||||
}
|
||||
export declare class Registry {
|
||||
private readonly types;
|
||||
constructor(customTypes?: Iterable<[string, GeneratedType]>);
|
||||
lookupType(name: string): GeneratedType | undefined;
|
||||
}
|
||||
export {};
|
||||
|
Loading…
x
Reference in New Issue
Block a user