proto-signing: Update for new proto definition structure
This commit is contained in:
parent
363790d00f
commit
e59beb01ac
@ -3,10 +3,10 @@ import { assert } from "@cosmjs/utils";
|
||||
import { Message } from "protobufjs";
|
||||
|
||||
import { cosmosField, cosmosMessage } from "./decorator";
|
||||
import { cosmos_sdk as cosmosSdk, google } from "./generated/codecimpl";
|
||||
import { cosmos, google } from "./generated/codecimpl";
|
||||
import { Registry } from "./registry";
|
||||
|
||||
const { TxBody } = cosmosSdk.tx.v1;
|
||||
const { TxBody } = cosmos.tx;
|
||||
const { Any } = google.protobuf;
|
||||
|
||||
describe("decorator demo", () => {
|
||||
|
||||
@ -5,15 +5,15 @@ import protobuf from "protobufjs";
|
||||
import reflectionRoot from "./demo";
|
||||
import demoJson from "./demo.json";
|
||||
import demoProto from "./demo.proto";
|
||||
import { cosmos_sdk as cosmosSdk, google } from "./generated/codecimpl";
|
||||
import { cosmos, google } from "./generated/codecimpl";
|
||||
|
||||
type MsgDemo = {
|
||||
readonly example: string;
|
||||
};
|
||||
|
||||
const { Coin } = cosmosSdk.v1;
|
||||
const { TxBody } = cosmosSdk.tx.v1;
|
||||
const { MsgSend } = cosmosSdk.x.bank.v1;
|
||||
const { Coin } = cosmos;
|
||||
const { TxBody } = cosmos.tx;
|
||||
const { MsgSend } = cosmos.bank;
|
||||
const { Any } = google.protobuf;
|
||||
|
||||
function getTypeName(typeUrl: string): string {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { fromHex } from "@cosmjs/encoding";
|
||||
|
||||
import { cosmos_sdk as cosmosSdk } from "./generated/codecimpl";
|
||||
import { cosmos } from "./generated/codecimpl";
|
||||
import { Coin, MsgSend } from "./msgs";
|
||||
|
||||
describe("msgs", () => {
|
||||
@ -14,16 +14,16 @@ describe("msgs", () => {
|
||||
];
|
||||
const donation = new MsgSend({ from_address: alice, to_address: bob, amount });
|
||||
|
||||
const expected = cosmosSdk.x.bank.v1.MsgSend.encode(
|
||||
cosmosSdk.x.bank.v1.MsgSend.create({
|
||||
const expected = cosmos.bank.MsgSend.encode(
|
||||
cosmos.bank.MsgSend.create({
|
||||
fromAddress: alice,
|
||||
toAddress: bob,
|
||||
amount: [
|
||||
cosmosSdk.v1.Coin.create({
|
||||
cosmos.Coin.create({
|
||||
denom: "utoken",
|
||||
amount: "123",
|
||||
}),
|
||||
cosmosSdk.v1.Coin.create({
|
||||
cosmos.Coin.create({
|
||||
denom: "ustake",
|
||||
amount: "654",
|
||||
}),
|
||||
|
||||
@ -2,10 +2,10 @@
|
||||
import { assert } from "@cosmjs/utils";
|
||||
|
||||
import { MsgDemo as MsgDemoType } from "./demo";
|
||||
import { cosmos_sdk as cosmosSdk, google } from "./generated/codecimpl";
|
||||
import { cosmos, google } from "./generated/codecimpl";
|
||||
import { Registry } from "./registry";
|
||||
|
||||
const { TxBody } = cosmosSdk.tx.v1;
|
||||
const { TxBody } = cosmos.tx;
|
||||
const { Any } = google.protobuf;
|
||||
|
||||
describe("registry demo", () => {
|
||||
@ -22,7 +22,7 @@ describe("registry demo", () => {
|
||||
fromAddress: Uint8Array.from(Array.from({ length: 20 }, () => 1)),
|
||||
toAddress: Uint8Array.from(Array.from({ length: 20 }, () => 2)),
|
||||
amount: [coin],
|
||||
}) as unknown) as cosmosSdk.x.bank.v1.MsgSend;
|
||||
}) as unknown) as cosmos.bank.MsgSend;
|
||||
const msgSendBytes = MsgSend.encode(msgSend).finish();
|
||||
const msgSendWrapped = Any.create({
|
||||
type_url: "/cosmos.bank.MsgSend",
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import protobuf from "protobufjs";
|
||||
|
||||
import { cosmos_sdk as cosmosSdk, google } from "./generated/codecimpl";
|
||||
import { cosmos, google } from "./generated/codecimpl";
|
||||
|
||||
export interface GeneratedType {
|
||||
readonly create: (properties?: { [k: string]: any }) => any;
|
||||
@ -40,8 +40,8 @@ export class Registry {
|
||||
constructor(customTypes: Iterable<[string, GeneratedType]> = []) {
|
||||
const { cosmosCoin, cosmosMsgSend } = defaultTypeUrls;
|
||||
this.types = new Map<string, GeneratedType>([
|
||||
[cosmosCoin, cosmosSdk.v1.Coin],
|
||||
[cosmosMsgSend, cosmosSdk.x.bank.v1.MsgSend],
|
||||
[cosmosCoin, cosmos.Coin],
|
||||
[cosmosMsgSend, cosmos.bank.MsgSend],
|
||||
...customTypes,
|
||||
]);
|
||||
}
|
||||
@ -72,7 +72,7 @@ export class Registry {
|
||||
}
|
||||
|
||||
public encodeTxBody(txBodyFields: TxBodyValue): Uint8Array {
|
||||
const { TxBody } = cosmosSdk.tx.v1;
|
||||
const { TxBody } = cosmos.tx;
|
||||
const { Any } = google.protobuf;
|
||||
|
||||
const wrappedMessages = txBodyFields.messages.map((message) => {
|
||||
@ -103,8 +103,8 @@ export class Registry {
|
||||
return decoded;
|
||||
}
|
||||
|
||||
public decodeTxBody(txBody: Uint8Array): cosmosSdk.tx.v1.TxBody {
|
||||
const { TxBody } = cosmosSdk.tx.v1;
|
||||
public decodeTxBody(txBody: Uint8Array): cosmos.tx.TxBody {
|
||||
const { TxBody } = cosmos.tx;
|
||||
const decodedTxBody = TxBody.decode(txBody);
|
||||
|
||||
return {
|
||||
|
||||
2927
packages/proto-signing/types/generated/codecimpl.d.ts
vendored
2927
packages/proto-signing/types/generated/codecimpl.d.ts
vendored
File diff suppressed because it is too large
Load Diff
4
packages/proto-signing/types/registry.d.ts
vendored
4
packages/proto-signing/types/registry.d.ts
vendored
@ -1,5 +1,5 @@
|
||||
import protobuf from "protobufjs";
|
||||
import { cosmos_sdk as cosmosSdk, google } from "./generated/codecimpl";
|
||||
import { cosmos, google } from "./generated/codecimpl";
|
||||
export interface GeneratedType {
|
||||
readonly create: (properties?: { [k: string]: any }) => any;
|
||||
readonly encode: (
|
||||
@ -36,5 +36,5 @@ export declare class Registry {
|
||||
encode({ typeUrl, value }: EncodeObject): Uint8Array;
|
||||
encodeTxBody(txBodyFields: TxBodyValue): Uint8Array;
|
||||
decode({ typeUrl, value }: DecodeObject): any;
|
||||
decodeTxBody(txBody: Uint8Array): cosmosSdk.tx.v1.TxBody;
|
||||
decodeTxBody(txBody: Uint8Array): cosmos.tx.TxBody;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user