cosmwasm-stargate: Add proto scripts

This commit is contained in:
willclarktech 2020-12-03 12:25:47 +00:00
parent 97fe2d1e2d
commit 4207e8e373
No known key found for this signature in database
GPG Key ID: 551A86E2E398ADF7
3 changed files with 76 additions and 0 deletions

View File

@ -0,0 +1,16 @@
#!/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/codec/generated/"
yarn pbts "$JS_SOURCE_FILE" -o "$DEFINITIONS_FILE"
# Remove comments after using them for the .d.ts
# Note "When input files are specified on the command line, tsconfig.json files are ignored." (https://www.typescriptlang.org/docs/handbook/tsconfig-json.html)
yarn tsc --removeComments --target es2017 --module commonjs --outDir "$OUTPUT_DIR" --allowJs "$JS_SOURCE_FILE"
cp "$DEFINITIONS_FILE" "$OUTPUT_DIR"
rm "$DEFINITIONS_FILE" "$JS_SOURCE_FILE"

View File

@ -0,0 +1,31 @@
#!/bin/bash
set -o errexit -o nounset -o pipefail
command -v shellcheck >/dev/null && shellcheck "$0"
PROTO_DIR="./proto"
COSMOS_DIR="$PROTO_DIR/cosmos"
COSMOS_SDK_DIR="$COSMOS_DIR/cosmos-sdk"
COSMOS_SDK_ZIP_FILE="$COSMOS_DIR/tmp.zip"
COSMOS_REF=${COSMOS_REF:-"master"}
COSMOS_SUFFIX=${COSMOS_REF}
[[ $COSMOS_SUFFIX =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-.+)?$ ]] && COSMOS_SUFFIX=${COSMOS_SUFFIX#v}
COSMWASM_DIR="$PROTO_DIR/cosmwasm"
WASMD_DIR="$COSMWASM_DIR/wasmd"
WASMD_ZIP_FILE="$COSMWASM_DIR/tmp.zip"
WASM_REF=${WASM_REF:-"master"}
WASM_SUFFIX=${WASM_REF}
[[ $WASM_SUFFIX =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-.+)?$ ]] && WASM_SUFFIX=${WASM_SUFFIX#v}
mkdir -p "$COSMOS_DIR"
wget -qO "$COSMOS_SDK_ZIP_FILE" "https://github.com/cosmos/cosmos-sdk/archive/$COSMOS_REF.zip"
unzip "$COSMOS_SDK_ZIP_FILE" "*.proto" -d "$COSMOS_DIR"
mv "$COSMOS_SDK_DIR-$COSMOS_SUFFIX" "$COSMOS_SDK_DIR"
rm "$COSMOS_SDK_ZIP_FILE"
mkdir -p "$COSMWASM_DIR"
wget -qO "$WASMD_ZIP_FILE" "https://github.com/cosmwasm/wasmd/archive/$WASM_REF.zip"
unzip "$WASMD_ZIP_FILE" "*.proto" -d "$COSMWASM_DIR"
mv "$WASMD_DIR-$WASM_SUFFIX" "$WASMD_DIR"
rm "$WASMD_ZIP_FILE"

View File

@ -0,0 +1,29 @@
#!/bin/bash
set -o errexit -o nounset -o pipefail
command -v shellcheck >/dev/null && shellcheck "$0"
GENERATED_DIR="./tmp"
ROOT_PROTO_DIR="./proto/cosmwasm/wasmd"
WASM_PROTO_DIR="$ROOT_PROTO_DIR/x/wasm"
mkdir -p "$GENERATED_DIR"
# Can't use --sparse for some reason. Seems related to https://github.com/protobufjs/protobuf.js/issues/1165
yarn pbjs \
-t static-module \
--es6 \
-w commonjs \
-o "$GENERATED_DIR/codecimpl.js" \
--no-beautify \
--no-delimited \
--no-verify \
--no-convert \
--force-long \
"$WASM_PROTO_DIR/internal/types/msg.proto" \
"$WASM_PROTO_DIR/internal/types/query.proto" \
"$WASM_PROTO_DIR/internal/types/types.proto" \
"./proto/cosmos/cosmos-sdk/proto/cosmos/base/v1beta1/coin.proto" \
"./proto/cosmos/cosmos-sdk/proto/cosmos/base/query/v1beta1/pagination.proto"
# Work around https://github.com/protobufjs/protobuf.js/issues/1477
# shellcheck disable=SC2016
sed -i "" -e 's/^const \$root =.*$/const \$root = {};/' "$GENERATED_DIR/codecimpl.js"