mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-10 21:49:15 +00:00
Merge pull request #296 from CosmWasm/289-upgrade-protobufjs
Upgrade protobufjs to 6.10.0
This commit is contained in:
commit
0f571a2429
1
packages/proto-signing/.gitignore
vendored
1
packages/proto-signing/.gitignore
vendored
@ -2,3 +2,4 @@ build/
|
||||
dist/
|
||||
docs/
|
||||
proto/
|
||||
tmp/
|
||||
|
@ -37,13 +37,14 @@
|
||||
"test": "yarn build-or-skip && yarn test-node",
|
||||
"coverage": "nyc --reporter=text --reporter=lcov yarn test --quiet",
|
||||
"pack-web": "yarn build-or-skip && webpack --mode development --config webpack.web.config.js",
|
||||
"preget-proto": "rm -rf proto",
|
||||
"get-proto": "REF=master ./scripts/get-proto.sh",
|
||||
"predefine-proto": "mkdir -p src/generated && pbjs -t static-module -w commonjs -o src/generated/codecimpl.tmp.js --sparse --no-beautify --no-delimited --no-verify --no-convert ./proto/cosmos/cosmos-sdk/{x/bank/types/types.proto,types/types.proto,types/tx/types.proto,types/tx/signing/types.proto,third_party/proto/tendermint/**/*.proto,crypto/types/types.proto}",
|
||||
"define-proto": "pbts src/generated/codecimpl.tmp.js -o src/generated/codecimpl.d.ts && tsc --removeComments --outFile src/generated/codecimpl.js --allowJs src/generated/codecimpl.tmp.js && rm src/generated/codecimpl.tmp.js",
|
||||
"predefine-proto": "./scripts/predefine-proto.sh",
|
||||
"define-proto": "./scripts/define-proto.sh",
|
||||
"postdefine-proto": "prettier --write \"src/generated/codecimpl.*\""
|
||||
},
|
||||
"dependencies": {
|
||||
"protobufjs": "~6.9.0"
|
||||
"protobufjs": "~6.10.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@cosmjs/encoding": "^0.21.1",
|
||||
|
14
packages/proto-signing/scripts/define-proto.sh
Executable file
14
packages/proto-signing/scripts/define-proto.sh
Executable file
@ -0,0 +1,14 @@
|
||||
#!/bin/bash
|
||||
set -o errexit -o nounset -o pipefail
|
||||
command -v shellcheck > /dev/null && shellcheck "$0"
|
||||
|
||||
TMP_DIR="./tmp"
|
||||
JS_SOURCE_FILE="$TMP_DIR/codecimpl.js"
|
||||
DEFINITIONS_FILE="$TMP_DIR/codecimpl.d.ts"
|
||||
OUTPUT_DIR="./src/generated/"
|
||||
|
||||
|
||||
pbts "$JS_SOURCE_FILE" -o "$DEFINITIONS_FILE"
|
||||
tsc --removeComments --outDir "$OUTPUT_DIR" --allowJs "$JS_SOURCE_FILE"
|
||||
cp "$DEFINITIONS_FILE" "$OUTPUT_DIR"
|
||||
rm "$DEFINITIONS_FILE" "$JS_SOURCE_FILE"
|
30
packages/proto-signing/scripts/predefine-proto.sh
Executable file
30
packages/proto-signing/scripts/predefine-proto.sh
Executable file
@ -0,0 +1,30 @@
|
||||
#!/bin/bash
|
||||
set -o errexit -o nounset -o pipefail
|
||||
command -v shellcheck > /dev/null && shellcheck "$0"
|
||||
|
||||
GENERATED_DIR="./tmp"
|
||||
ROOT_PROTO_DIR="./proto/cosmos/cosmos-sdk"
|
||||
COSMOS_PROTO_DIR="$ROOT_PROTO_DIR/proto/cosmos"
|
||||
TENDERMINT_PROTO_DIR="$ROOT_PROTO_DIR/third_party/proto/tendermint"
|
||||
GOOGLE_PROTO_DIR="$ROOT_PROTO_DIR/third_party/proto/google"
|
||||
|
||||
mkdir -p "$GENERATED_DIR"
|
||||
pbjs \
|
||||
-t static-module \
|
||||
--es6 \
|
||||
-w commonjs \
|
||||
-o "$GENERATED_DIR/codecimpl.js" \
|
||||
--sparse \
|
||||
--no-beautify \
|
||||
--no-delimited \
|
||||
--no-verify \
|
||||
--no-convert \
|
||||
"$COSMOS_PROTO_DIR/cosmos.proto" \
|
||||
"$COSMOS_PROTO_DIR/bank/bank.proto" \
|
||||
"$COSMOS_PROTO_DIR/crypto/crypto.proto" \
|
||||
"$COSMOS_PROTO_DIR/tx/tx.proto" \
|
||||
"$COSMOS_PROTO_DIR/tx/signing/signing.proto" \
|
||||
"$TENDERMINT_PROTO_DIR/abci/types/types.proto" \
|
||||
"$TENDERMINT_PROTO_DIR/crypto/merkle/merkle.proto" \
|
||||
"$TENDERMINT_PROTO_DIR/libs/kv/types.proto" \
|
||||
"$GOOGLE_PROTO_DIR/protobuf/any.proto"
|
@ -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 {
|
||||
|
2927
packages/proto-signing/src/generated/codecimpl.d.ts
vendored
2927
packages/proto-signing/src/generated/codecimpl.d.ts
vendored
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -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;
|
||||
}
|
||||
|
@ -6708,10 +6708,10 @@ proto-list@~1.2.1:
|
||||
resolved "https://registry.yarnpkg.com/proto-list/-/proto-list-1.2.4.tgz#212d5bfe1318306a420f6402b8e26ff39647a849"
|
||||
integrity sha1-IS1b/hMYMGpCD2QCuOJv85ZHqEk=
|
||||
|
||||
protobufjs@~6.9.0:
|
||||
version "6.9.0"
|
||||
resolved "https://registry.yarnpkg.com/protobufjs/-/protobufjs-6.9.0.tgz#c08b2bf636682598e6fabbf0edb0b1256ff090bd"
|
||||
integrity sha512-LlGVfEWDXoI/STstRDdZZKb/qusoAWUnmLg9R8OLSO473mBLWHowx8clbX5/+mKDEI+v7GzjoK9tRPZMMcoTrg==
|
||||
protobufjs@~6.10.0:
|
||||
version "6.10.0"
|
||||
resolved "https://registry.yarnpkg.com/protobufjs/-/protobufjs-6.10.0.tgz#b0698a2a91fc597e2dc625dcf3539ece9675c8fd"
|
||||
integrity sha512-Hdz1+CXkrlmGDKkP6DczxysdnUyUuhM1mjeaydnBxOcjxQPbJldLZ8eGE1gX0UTsgv+0QkFfn6dioo5yt9XORw==
|
||||
dependencies:
|
||||
"@protobufjs/aspromise" "^1.1.2"
|
||||
"@protobufjs/base64" "^1.1.2"
|
||||
|
Loading…
x
Reference in New Issue
Block a user