proto-signing: Update for new proto definition structure

This commit is contained in:
willclarktech 2020-07-16 15:13:13 +02:00
parent 363790d00f
commit e59beb01ac
No known key found for this signature in database
GPG Key ID: 551A86E2E398ADF7
7 changed files with 1539 additions and 1432 deletions

View File

@ -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", () => {

View File

@ -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 {

View File

@ -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",
}),

View File

@ -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",

View File

@ -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 {

File diff suppressed because it is too large Load Diff

View File

@ -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;
}