proto-signing: Remove TxBody and Any from registry
This commit is contained in:
parent
16e4b2906e
commit
15fdb34d91
@ -3,8 +3,12 @@ import { assert } from "@cosmjs/utils";
|
||||
import { Message } from "protobufjs";
|
||||
|
||||
import { cosmosField, cosmosMessage } from "./decorator";
|
||||
import { cosmos_sdk as cosmosSdk, google } from "./generated/codecimpl";
|
||||
import { Registry } from "./registry";
|
||||
|
||||
const { TxBody } = cosmosSdk.tx.v1;
|
||||
const { Any } = google.protobuf;
|
||||
|
||||
describe("decorator demo", () => {
|
||||
it("works with a custom msg", () => {
|
||||
const nestedTypeUrl = "/demo.MsgNestedDemo";
|
||||
@ -44,8 +48,6 @@ describe("decorator demo", () => {
|
||||
|
||||
const MsgNestedDemoT = myRegistry.lookupType(nestedTypeUrl)!;
|
||||
const MsgDemoT = myRegistry.lookupType(typeUrl)!;
|
||||
const TxBody = myRegistry.lookupType("/cosmos.tx.TxBody")!;
|
||||
const Any = myRegistry.lookupType("/google.protobuf.Any")!;
|
||||
|
||||
const msgNestedDemoFields = {
|
||||
foo: "bar",
|
||||
|
||||
@ -2,20 +2,17 @@
|
||||
import { assert } from "@cosmjs/utils";
|
||||
|
||||
import { MsgDemo as MsgDemoType } from "./demo";
|
||||
import { cosmos_sdk as cosmosSdk } from "./generated/codecimpl";
|
||||
import { cosmos_sdk as cosmosSdk, google } from "./generated/codecimpl";
|
||||
import { Registry } from "./registry";
|
||||
|
||||
type MsgDemo = {
|
||||
readonly example: string;
|
||||
};
|
||||
const { TxBody } = cosmosSdk.tx.v1;
|
||||
const { Any } = google.protobuf;
|
||||
|
||||
describe("registry demo", () => {
|
||||
it("works with a default msg", () => {
|
||||
const registry = new Registry();
|
||||
const Coin = registry.lookupType("/cosmos.Coin")!;
|
||||
const MsgSend = registry.lookupType("/cosmos.bank.MsgSend")!;
|
||||
const TxBody = registry.lookupType("/cosmos.tx.TxBody")!;
|
||||
const Any = registry.lookupType("/google.protobuf.Any")!;
|
||||
|
||||
const coin = Coin.create({
|
||||
denom: "ucosm",
|
||||
@ -57,8 +54,6 @@ describe("registry demo", () => {
|
||||
const typeUrl = "/demo.MsgDemo";
|
||||
const registry = new Registry([[typeUrl, MsgDemoType]]);
|
||||
const MsgDemo = registry.lookupType(typeUrl)!;
|
||||
const TxBody = registry.lookupType("/cosmos.tx.TxBody")!;
|
||||
const Any = registry.lookupType("/google.protobuf.Any")!;
|
||||
|
||||
const msgDemo = MsgDemo.create({
|
||||
example: "Some example text",
|
||||
|
||||
@ -23,8 +23,8 @@ export type TxBodyValue = {
|
||||
readonly messages: readonly EncodeObject[];
|
||||
readonly memo?: string;
|
||||
readonly timeoutHeight?: number;
|
||||
readonly extensionOptions?: readonly any[];
|
||||
readonly nonCriticalExtensionOptions?: readonly any[];
|
||||
readonly extensionOptions?: google.protobuf.IAny[];
|
||||
readonly nonCriticalExtensionOptions?: google.protobuf.IAny[];
|
||||
};
|
||||
|
||||
const defaultTypeUrls = {
|
||||
@ -38,12 +38,10 @@ export class Registry {
|
||||
private readonly types: Map<string, GeneratedType>;
|
||||
|
||||
constructor(customTypes: Iterable<[string, GeneratedType]> = []) {
|
||||
const { cosmosCoin, cosmosMsgSend, cosmosTxBody, googleAny } = defaultTypeUrls;
|
||||
const { cosmosCoin, cosmosMsgSend } = defaultTypeUrls;
|
||||
this.types = new Map<string, GeneratedType>([
|
||||
[cosmosCoin, cosmosSdk.v1.Coin],
|
||||
[cosmosMsgSend, cosmosSdk.x.bank.v1.MsgSend],
|
||||
[cosmosTxBody, cosmosSdk.tx.v1.TxBody],
|
||||
[googleAny, google.protobuf.Any],
|
||||
...customTypes,
|
||||
]);
|
||||
}
|
||||
@ -74,8 +72,8 @@ export class Registry {
|
||||
}
|
||||
|
||||
public encodeTxBody(txBodyFields: TxBodyValue): Uint8Array {
|
||||
const TxBody = this.lookupTypeWithError(defaultTypeUrls.cosmosTxBody);
|
||||
const Any = this.lookupTypeWithError(defaultTypeUrls.googleAny);
|
||||
const { TxBody } = cosmosSdk.tx.v1;
|
||||
const { Any } = google.protobuf;
|
||||
|
||||
const wrappedMessages = txBodyFields.messages.map((message) => {
|
||||
const messageBytes = this.encode(message);
|
||||
@ -100,7 +98,7 @@ export class Registry {
|
||||
}
|
||||
|
||||
public decodeTxBody(txBody: Uint8Array): cosmosSdk.tx.v1.TxBody {
|
||||
const TxBody = this.lookupTypeWithError(defaultTypeUrls.cosmosTxBody);
|
||||
const { TxBody } = cosmosSdk.tx.v1;
|
||||
const decodedTxBody = TxBody.decode(txBody);
|
||||
|
||||
return {
|
||||
|
||||
6
packages/proto-signing/types/registry.d.ts
vendored
6
packages/proto-signing/types/registry.d.ts
vendored
@ -1,5 +1,5 @@
|
||||
import protobuf from "protobufjs";
|
||||
import { cosmos_sdk as cosmosSdk } from "./generated/codecimpl";
|
||||
import { cosmos_sdk as cosmosSdk, google } from "./generated/codecimpl";
|
||||
export interface GeneratedType {
|
||||
readonly create: (properties?: { [k: string]: any }) => any;
|
||||
readonly encode: (
|
||||
@ -24,8 +24,8 @@ export declare type TxBodyValue = {
|
||||
readonly messages: readonly EncodeObject[];
|
||||
readonly memo?: string;
|
||||
readonly timeoutHeight?: number;
|
||||
readonly extensionOptions?: readonly any[];
|
||||
readonly nonCriticalExtensionOptions?: readonly any[];
|
||||
readonly extensionOptions?: google.protobuf.IAny[];
|
||||
readonly nonCriticalExtensionOptions?: google.protobuf.IAny[];
|
||||
};
|
||||
export declare class Registry {
|
||||
private readonly types;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user