diff --git a/packages/cli/package.json b/packages/cli/package.json index 1976419c..4a398b2b 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -19,6 +19,7 @@ "format-text": "prettier --write --prose-wrap always --print-width 80 \"./*.md\"", "lint": "eslint --max-warnings 0 \"**/*.{js,ts}\"", "lint-fix": "eslint --max-warnings 0 \"**/*.{js,ts}\" --fix", + "prebuild": "shx rm -rf ./build", "build": "tsc", "build-or-skip": "[ -n \"$SKIP_BUILD\" ] || yarn build", "start": "yarn build-or-skip && ./bin/cosmwasm-cli", diff --git a/packages/cosmwasm/package.json b/packages/cosmwasm/package.json index ad633fe9..5c0596ea 100644 --- a/packages/cosmwasm/package.json +++ b/packages/cosmwasm/package.json @@ -28,7 +28,9 @@ "lint-fix": "eslint --max-warnings 0 \"**/*.{js,ts}\" --fix", "move-types": "shx rm -rf ./types/* && shx mv build/types/* ./types && rm -rf ./types/testdata && shx rm -f ./types/*.spec.d.ts && shx rm ./types/**/*.spec.d.ts", "format-types": "prettier --write --loglevel warn \"./types/**/*.d.ts\"", - "build": "shx rm -rf ./build && tsc && yarn move-types && yarn format-types", + "prebuild": "shx rm -rf ./build", + "build": "tsc", + "postbuild": "yarn move-types && yarn format-types", "build-or-skip": "[ -n \"$SKIP_BUILD\" ] || yarn build", "test-node": "node jasmine-testrunner.js", "test-firefox": "yarn pack-web && karma start --single-run --browsers Firefox", diff --git a/packages/crypto/package.json b/packages/crypto/package.json index 4ac5120a..93addc23 100644 --- a/packages/crypto/package.json +++ b/packages/crypto/package.json @@ -38,7 +38,9 @@ "coverage": "nyc --reporter=text --reporter=lcov yarn test --quiet", "move-types": "shx rm -r ./types/* && shx mv build/types/* ./types && rm -rf ./types/testdata && shx rm -f ./types/*.spec.d.ts", "format-types": "prettier --write --loglevel warn \"./types/**/*.d.ts\"", - "build": "shx rm -rf ./build && tsc && yarn move-types && yarn format-types", + "prebuild": "shx rm -rf ./build", + "build": "tsc", + "postbuild": "yarn move-types && yarn format-types", "build-or-skip": "[ -n \"$SKIP_BUILD\" ] || yarn build", "pack-web": "yarn build-or-skip && webpack --mode development --config webpack.web.config.js" }, diff --git a/packages/encoding/package.json b/packages/encoding/package.json index 151c4ff6..75f4eaa5 100644 --- a/packages/encoding/package.json +++ b/packages/encoding/package.json @@ -37,7 +37,9 @@ "coverage": "nyc --reporter=text --reporter=lcov yarn test --quiet", "move-types": "shx rm -r ./types/* && shx mv build/types/* ./types && rm -rf ./types/testdata && shx rm -f ./types/*.spec.d.ts", "format-types": "prettier --write --loglevel warn \"./types/**/*.d.ts\"", - "build": "shx rm -rf ./build && tsc && yarn move-types && yarn format-types", + "prebuild": "shx rm -rf ./build", + "build": "tsc", + "postbuild": "yarn move-types && yarn format-types", "build-or-skip": "[ -n \"$SKIP_BUILD\" ] || yarn build", "pack-web": "yarn build-or-skip && webpack --mode development --config webpack.web.config.js" }, diff --git a/packages/faucet/package.json b/packages/faucet/package.json index 72d0fea2..80e33c1b 100644 --- a/packages/faucet/package.json +++ b/packages/faucet/package.json @@ -27,7 +27,8 @@ "format-text": "prettier --write --prose-wrap always --print-width 80 \"./*.md\"", "lint": "eslint --max-warnings 0 \"**/*.{js,ts}\"", "lint-fix": "eslint --max-warnings 0 \"**/*.{js,ts}\" --fix", - "build": "shx rm -rf ./build && tsc", + "prebuild": "shx rm -rf ./build", + "build": "tsc", "build-or-skip": "[ -n \"$SKIP_BUILD\" ] || yarn build", "test-node": "node jasmine-testrunner.js", "test": "yarn build-or-skip && yarn test-node", diff --git a/packages/json-rpc/package.json b/packages/json-rpc/package.json index 99ea16b0..dde78942 100644 --- a/packages/json-rpc/package.json +++ b/packages/json-rpc/package.json @@ -39,7 +39,9 @@ "coverage": "nyc --reporter=text --reporter=lcov yarn test --quiet", "move-types": "shx rm -r ./types/* && shx mv build/types/* ./types && rm -rf ./types/testdata && shx rm -f ./types/*.spec.d.ts", "format-types": "prettier --write --loglevel warn \"./types/**/*.d.ts\"", - "build": "shx rm -rf ./build && tsc && tsc -p tsconfig.workers.json && yarn move-types && yarn format-types", + "prebuild": "shx rm -rf ./build", + "build": "tsc && tsc -p tsconfig.workers.json", + "postbuild": "yarn move-types && yarn format-types", "build-or-skip": "[ -n \"$SKIP_BUILD\" ] || yarn build", "pack-web": "yarn build-or-skip && webpack --mode development --config webpack.web.config.js" }, diff --git a/packages/launchpad/package.json b/packages/launchpad/package.json index a89e7411..0e02e3a7 100644 --- a/packages/launchpad/package.json +++ b/packages/launchpad/package.json @@ -31,7 +31,9 @@ "lint-fix": "eslint --max-warnings 0 \"**/*.{js,ts}\" --fix", "move-types": "shx rm -rf ./types/* && shx mv build/types/* ./types && rm -rf ./types/testdata && shx rm -f ./types/*.spec.d.ts && shx rm ./types/**/*.spec.d.ts", "format-types": "prettier --write --loglevel warn \"./types/**/*.d.ts\"", - "build": "shx rm -rf ./build && tsc && yarn move-types && yarn format-types", + "prebuild": "shx rm -rf ./build", + "build": "tsc", + "postbuild": "yarn move-types && yarn format-types", "build-or-skip": "[ -n \"$SKIP_BUILD\" ] || yarn build", "test-node": "node jasmine-testrunner.js", "test-firefox": "yarn pack-web && karma start --single-run --browsers Firefox", diff --git a/packages/math/package.json b/packages/math/package.json index 77bf6de9..24f14e51 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -37,7 +37,9 @@ "coverage": "nyc --reporter=text --reporter=lcov yarn test --quiet", "move-types": "shx rm -r ./types/* && shx mv build/types/* ./types && rm -rf ./types/testdata && shx rm -f ./types/*.spec.d.ts", "format-types": "prettier --write --loglevel warn \"./types/**/*.d.ts\"", - "build": "shx rm -rf ./build && tsc && yarn move-types && yarn format-types", + "prebuild": "shx rm -rf ./build", + "build": "tsc", + "postbuild": "yarn move-types && yarn format-types", "build-or-skip": "[ -n \"$SKIP_BUILD\" ] || yarn build", "pack-web": "yarn build-or-skip && webpack --mode development --config webpack.web.config.js" }, diff --git a/packages/proto-signing/package.json b/packages/proto-signing/package.json index 0c0c20af..fb9d40f2 100644 --- a/packages/proto-signing/package.json +++ b/packages/proto-signing/package.json @@ -29,7 +29,9 @@ "lint-fix": "eslint --max-warnings 0 \"**/*.{js,ts}\" --fix", "move-types": "shx rm -rf ./types/* && shx mv build/types/* ./types && rm -rf ./types/testdata && shx rm -f ./types/*.spec.d.ts", "format-types": "prettier --write --loglevel warn \"./types/**/*.d.ts\"", - "build": "shx rm -rf ./build && tsc && shx mkdir -p build/generated && shx cp ./src/generated/*.js ./build/generated && shx mkdir -p ./build/types/generated && shx cp ./src/generated/*.d.ts ./build/types/generated && yarn move-types && yarn format-types", + "prebuild": "shx rm -rf ./build", + "build": "tsc && shx mkdir -p build/generated && shx cp ./src/generated/*.js ./build/generated && shx mkdir -p ./build/types/generated && shx cp ./src/generated/*.d.ts ./build/types/generated", + "postbuild": "yarn move-types && yarn format-types", "build-or-skip": "[ -n \"$SKIP_BUILD\" ] || yarn build", "test-node": "node jasmine-testrunner.js", "test-firefox": "yarn pack-web && karma start --single-run --browsers Firefox", diff --git a/packages/proto-signing/src/any.ts b/packages/proto-signing/src/any.ts deleted file mode 100644 index 27a49698..00000000 --- a/packages/proto-signing/src/any.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { google } from "./generated/codecimpl"; - -/** - * Decodes a serialized [google.protobuf.Any](https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/any.proto) - * and returns the components. - */ -export function decodeAny(serialized: Uint8Array): { readonly typeUrl: string; readonly value: Uint8Array } { - const envelope = google.protobuf.Any.decode(serialized); - return { - typeUrl: envelope.type_url, - value: envelope.value, - }; -} diff --git a/packages/proto-signing/src/index.ts b/packages/proto-signing/src/index.ts index ce95215d..114a1bd7 100644 --- a/packages/proto-signing/src/index.ts +++ b/packages/proto-signing/src/index.ts @@ -1,5 +1,4 @@ export { omitDefaults } from "./adr27"; -export { decodeAny } from "./any"; export { Coin } from "./msgs"; export { cosmosField } from "./decorator"; export { Registry } from "./registry"; diff --git a/packages/proto-signing/types/any.d.ts b/packages/proto-signing/types/any.d.ts deleted file mode 100644 index c76a6b15..00000000 --- a/packages/proto-signing/types/any.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -/** - * Decodes a serialized [google.protobuf.Any](https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/any.proto) - * and returns the components. - */ -export declare function decodeAny( - serialized: Uint8Array, -): { - readonly typeUrl: string; - readonly value: Uint8Array; -}; diff --git a/packages/proto-signing/types/index.d.ts b/packages/proto-signing/types/index.d.ts index ce95215d..114a1bd7 100644 --- a/packages/proto-signing/types/index.d.ts +++ b/packages/proto-signing/types/index.d.ts @@ -1,5 +1,4 @@ export { omitDefaults } from "./adr27"; -export { decodeAny } from "./any"; export { Coin } from "./msgs"; export { cosmosField } from "./decorator"; export { Registry } from "./registry"; diff --git a/packages/socket/package.json b/packages/socket/package.json index 87b793e4..ff2e8799 100644 --- a/packages/socket/package.json +++ b/packages/socket/package.json @@ -39,7 +39,9 @@ "coverage": "nyc --reporter=text --reporter=lcov yarn test --quiet", "move-types": "shx rm -r ./types/* && shx mv build/types/* ./types && rm -rf ./types/testdata && shx rm -f ./types/*.spec.d.ts", "format-types": "prettier --write --loglevel warn \"./types/**/*.d.ts\"", - "build": "shx rm -rf ./build && tsc && yarn move-types && yarn format-types", + "prebuild": "shx rm -rf ./build", + "build": "tsc", + "postbuild": "yarn move-types && yarn format-types", "build-or-skip": "[ -n \"$SKIP_BUILD\" ] || yarn build", "pack-web": "yarn build-or-skip && webpack --mode development --config webpack.web.config.js" }, diff --git a/packages/stargate/package.json b/packages/stargate/package.json index 9353b1b5..d5ae9cf2 100644 --- a/packages/stargate/package.json +++ b/packages/stargate/package.json @@ -26,9 +26,11 @@ "format-text": "prettier --write --prose-wrap always --print-width 80 \"./*.md\"", "lint": "eslint --max-warnings 0 \"**/*.{js,ts}\"", "lint-fix": "eslint --max-warnings 0 \"**/*.{js,ts}\" --fix", - "move-types": "shx rm -rf ./types/* && shx mv build/types/* ./types && rm -rf ./types/testdata && shx rm -f ./types/*.spec.d.ts", + "move-types": "shx rm -rf ./types/* && shx mv build/types/* ./types && rm -rf ./types/testdata && shx rm -f ./types/*.spec.d.ts && shx rm ./types/**/*.spec.d.ts", "format-types": "prettier --write --loglevel warn \"./types/**/*.d.ts\"", - "build": "shx rm -rf ./build && tsc && shx mkdir -p build/generated && shx cp ./src/generated/*.js ./build/generated && shx mkdir -p ./build/types/generated && shx cp ./src/generated/*.d.ts ./build/types/generated && yarn move-types && yarn format-types", + "prebuild": "shx rm -rf ./build", + "build": "tsc && shx mkdir -p build/codec/generated && shx cp ./src/codec/generated/*.js ./build/codec/generated", + "postbuild": "shx mkdir -p ./build/types/codec/generated && shx cp ./src/codec/generated/*.d.ts ./build/types/codec/generated && yarn move-types && yarn format-types", "build-or-skip": "[ -n \"$SKIP_BUILD\" ] || yarn build", "test-node": "node jasmine-testrunner.js", "test-firefox": "yarn pack-web && karma start --single-run --browsers Firefox", diff --git a/packages/stargate/scripts/predefine-proto.sh b/packages/stargate/scripts/predefine-proto.sh index 86a1a8de..3bc39794 100755 --- a/packages/stargate/scripts/predefine-proto.sh +++ b/packages/stargate/scripts/predefine-proto.sh @@ -19,6 +19,7 @@ yarn pbjs \ --no-delimited \ --no-verify \ --no-convert \ + --force-long \ "$COSMOS_PROTO_DIR/cosmos.proto" \ "$COSMOS_PROTO_DIR/auth/{auth,query}.proto" \ "$COSMOS_PROTO_DIR/bank/{bank,query}.proto" \ diff --git a/packages/stargate/src/generated/codecimpl.d.ts b/packages/stargate/src/codec/generated/codecimpl.d.ts similarity index 98% rename from packages/stargate/src/generated/codecimpl.d.ts rename to packages/stargate/src/codec/generated/codecimpl.d.ts index 627c179e..43c0b29b 100644 --- a/packages/stargate/src/generated/codecimpl.d.ts +++ b/packages/stargate/src/codec/generated/codecimpl.d.ts @@ -231,10 +231,10 @@ export namespace cosmos { /** Properties of a GasInfo. */ interface IGasInfo { /** GasInfo gasWanted */ - gasWanted?: number | Long | null; + gasWanted?: Long | null; /** GasInfo gasUsed */ - gasUsed?: number | Long | null; + gasUsed?: Long | null; } /** Represents a GasInfo. */ @@ -246,10 +246,10 @@ export namespace cosmos { constructor(p?: cosmos.IGasInfo); /** GasInfo gasWanted. */ - public gasWanted: number | Long; + public gasWanted: Long; /** GasInfo gasUsed. */ - public gasUsed: number | Long; + public gasUsed: Long; /** * Creates a new GasInfo instance using the specified properties. @@ -476,7 +476,7 @@ export namespace cosmos { /** Properties of a TxResponse. */ interface ITxResponse { /** TxResponse height */ - height?: number | Long | null; + height?: Long | null; /** TxResponse txhash */ txhash?: string | null; @@ -500,10 +500,10 @@ export namespace cosmos { info?: string | null; /** TxResponse gasWanted */ - gasWanted?: number | Long | null; + gasWanted?: Long | null; /** TxResponse gasUsed */ - gasUsed?: number | Long | null; + gasUsed?: Long | null; /** TxResponse tx */ tx?: google.protobuf.IAny | null; @@ -521,7 +521,7 @@ export namespace cosmos { constructor(p?: cosmos.ITxResponse); /** TxResponse height. */ - public height: number | Long; + public height: Long; /** TxResponse txhash. */ public txhash: string; @@ -545,10 +545,10 @@ export namespace cosmos { public info: string; /** TxResponse gasWanted. */ - public gasWanted: number | Long; + public gasWanted: Long; /** TxResponse gasUsed. */ - public gasUsed: number | Long; + public gasUsed: Long; /** TxResponse tx. */ public tx?: google.protobuf.IAny | null; @@ -746,10 +746,10 @@ export namespace cosmos { pubKey?: Uint8Array | null; /** BaseAccount accountNumber */ - accountNumber?: number | Long | null; + accountNumber?: Long | null; /** BaseAccount sequence */ - sequence?: number | Long | null; + sequence?: Long | null; } /** Represents a BaseAccount. */ @@ -767,10 +767,10 @@ export namespace cosmos { public pubKey: Uint8Array; /** BaseAccount accountNumber. */ - public accountNumber: number | Long; + public accountNumber: Long; /** BaseAccount sequence. */ - public sequence: number | Long; + public sequence: Long; /** * Creates a new BaseAccount instance using the specified properties. @@ -856,19 +856,19 @@ export namespace cosmos { /** Properties of a Params. */ interface IParams { /** Params maxMemoCharacters */ - maxMemoCharacters?: number | Long | null; + maxMemoCharacters?: Long | null; /** Params txSigLimit */ - txSigLimit?: number | Long | null; + txSigLimit?: Long | null; /** Params txSizeCostPerByte */ - txSizeCostPerByte?: number | Long | null; + txSizeCostPerByte?: Long | null; /** Params sigVerifyCostEd25519 */ - sigVerifyCostEd25519?: number | Long | null; + sigVerifyCostEd25519?: Long | null; /** Params sigVerifyCostSecp256k1 */ - sigVerifyCostSecp256k1?: number | Long | null; + sigVerifyCostSecp256k1?: Long | null; } /** Represents a Params. */ @@ -880,19 +880,19 @@ export namespace cosmos { constructor(p?: cosmos.auth.IParams); /** Params maxMemoCharacters. */ - public maxMemoCharacters: number | Long; + public maxMemoCharacters: Long; /** Params txSigLimit. */ - public txSigLimit: number | Long; + public txSigLimit: Long; /** Params txSizeCostPerByte. */ - public txSizeCostPerByte: number | Long; + public txSizeCostPerByte: Long; /** Params sigVerifyCostEd25519. */ - public sigVerifyCostEd25519: number | Long; + public sigVerifyCostEd25519: Long; /** Params sigVerifyCostSecp256k1. */ - public sigVerifyCostSecp256k1: number | Long; + public sigVerifyCostSecp256k1: Long; /** * Creates a new Params instance using the specified properties. @@ -2360,10 +2360,10 @@ export namespace cosmos { key?: Uint8Array | null; /** PageRequest offset */ - offset?: number | Long | null; + offset?: Long | null; /** PageRequest limit */ - limit?: number | Long | null; + limit?: Long | null; /** PageRequest countTotal */ countTotal?: boolean | null; @@ -2381,10 +2381,10 @@ export namespace cosmos { public key: Uint8Array; /** PageRequest offset. */ - public offset: number | Long; + public offset: Long; /** PageRequest limit. */ - public limit: number | Long; + public limit: Long; /** PageRequest countTotal. */ public countTotal: boolean; @@ -2421,7 +2421,7 @@ export namespace cosmos { nextKey?: Uint8Array | null; /** PageResponse total */ - total?: number | Long | null; + total?: Long | null; } /** Represents a PageResponse. */ @@ -2436,7 +2436,7 @@ export namespace cosmos { public nextKey: Uint8Array; /** PageResponse total. */ - public total: number | Long; + public total: Long; /** * Creates a new PageResponse instance using the specified properties. @@ -2589,10 +2589,10 @@ export namespace cosmos { chainId?: string | null; /** SignDoc accountNumber */ - accountNumber?: number | Long | null; + accountNumber?: Long | null; /** SignDoc accountSequence */ - accountSequence?: number | Long | null; + accountSequence?: Long | null; } /** Represents a SignDoc. */ @@ -2613,10 +2613,10 @@ export namespace cosmos { public chainId: string; /** SignDoc accountNumber. */ - public accountNumber: number | Long; + public accountNumber: Long; /** SignDoc accountSequence. */ - public accountSequence: number | Long; + public accountSequence: Long; /** * Creates a new SignDoc instance using the specified properties. @@ -2653,7 +2653,7 @@ export namespace cosmos { memo?: string | null; /** TxBody timeoutHeight */ - timeoutHeight?: number | Long | null; + timeoutHeight?: Long | null; /** TxBody extensionOptions */ extensionOptions?: google.protobuf.IAny[] | null; @@ -2677,7 +2677,7 @@ export namespace cosmos { public memo: string; /** TxBody timeoutHeight. */ - public timeoutHeight: number | Long; + public timeoutHeight: Long; /** TxBody extensionOptions. */ public extensionOptions: google.protobuf.IAny[]; @@ -2961,7 +2961,7 @@ export namespace cosmos { amount?: cosmos.ICoin[] | null; /** Fee gasLimit */ - gasLimit?: number | Long | null; + gasLimit?: Long | null; } /** Represents a Fee. */ @@ -2976,7 +2976,7 @@ export namespace cosmos { public amount: cosmos.ICoin[]; /** Fee gasLimit. */ - public gasLimit: number | Long; + public gasLimit: Long; /** * Creates a new Fee instance using the specified properties. @@ -3519,10 +3519,10 @@ export namespace tendermint { version?: string | null; /** RequestInfo blockVersion */ - blockVersion?: number | Long | null; + blockVersion?: Long | null; /** RequestInfo p2pVersion */ - p2pVersion?: number | Long | null; + p2pVersion?: Long | null; } /** Represents a RequestInfo. */ @@ -3537,10 +3537,10 @@ export namespace tendermint { public version: string; /** RequestInfo blockVersion. */ - public blockVersion: number | Long; + public blockVersion: Long; /** RequestInfo p2pVersion. */ - public p2pVersion: number | Long; + public p2pVersion: Long; /** * Creates a new RequestInfo instance using the specified properties. @@ -3711,7 +3711,7 @@ export namespace tendermint { path?: string | null; /** RequestQuery height */ - height?: number | Long | null; + height?: Long | null; /** RequestQuery prove */ prove?: boolean | null; @@ -3732,7 +3732,7 @@ export namespace tendermint { public path: string; /** RequestQuery height. */ - public height: number | Long; + public height: Long; /** RequestQuery prove. */ public prove: boolean; @@ -3954,7 +3954,7 @@ export namespace tendermint { /** Properties of a RequestEndBlock. */ interface IRequestEndBlock { /** RequestEndBlock height */ - height?: number | Long | null; + height?: Long | null; } /** Represents a RequestEndBlock. */ @@ -3966,7 +3966,7 @@ export namespace tendermint { constructor(p?: tendermint.abci.types.IRequestEndBlock); /** RequestEndBlock height. */ - public height: number | Long; + public height: Long; /** * Creates a new RequestEndBlock instance using the specified properties. @@ -4318,10 +4318,10 @@ export namespace tendermint { version?: string | null; /** ResponseInfo appVersion */ - appVersion?: number | Long | null; + appVersion?: Long | null; /** ResponseInfo lastBlockHeight */ - lastBlockHeight?: number | Long | null; + lastBlockHeight?: Long | null; /** ResponseInfo lastBlockAppHash */ lastBlockAppHash?: Uint8Array | null; @@ -4342,10 +4342,10 @@ export namespace tendermint { public version: string; /** ResponseInfo appVersion. */ - public appVersion: number | Long; + public appVersion: Long; /** ResponseInfo lastBlockHeight. */ - public lastBlockHeight: number | Long; + public lastBlockHeight: Long; /** ResponseInfo lastBlockAppHash. */ public lastBlockAppHash: Uint8Array; @@ -4513,7 +4513,7 @@ export namespace tendermint { info?: string | null; /** ResponseQuery index */ - index?: number | Long | null; + index?: Long | null; /** ResponseQuery key */ key?: Uint8Array | null; @@ -4525,7 +4525,7 @@ export namespace tendermint { proof?: tendermint.crypto.merkle.IProof | null; /** ResponseQuery height */ - height?: number | Long | null; + height?: Long | null; /** ResponseQuery codespace */ codespace?: string | null; @@ -4549,7 +4549,7 @@ export namespace tendermint { public info: string; /** ResponseQuery index. */ - public index: number | Long; + public index: Long; /** ResponseQuery key. */ public key: Uint8Array; @@ -4561,7 +4561,7 @@ export namespace tendermint { public proof?: tendermint.crypto.merkle.IProof | null; /** ResponseQuery height. */ - public height: number | Long; + public height: Long; /** ResponseQuery codespace. */ public codespace: string; @@ -4663,10 +4663,10 @@ export namespace tendermint { info?: string | null; /** ResponseCheckTx gasWanted */ - gasWanted?: number | Long | null; + gasWanted?: Long | null; /** ResponseCheckTx gasUsed */ - gasUsed?: number | Long | null; + gasUsed?: Long | null; /** ResponseCheckTx events */ events?: tendermint.abci.types.IEvent[] | null; @@ -4696,10 +4696,10 @@ export namespace tendermint { public info: string; /** ResponseCheckTx gasWanted. */ - public gasWanted: number | Long; + public gasWanted: Long; /** ResponseCheckTx gasUsed. */ - public gasUsed: number | Long; + public gasUsed: Long; /** ResponseCheckTx events. */ public events: tendermint.abci.types.IEvent[]; @@ -4756,10 +4756,10 @@ export namespace tendermint { info?: string | null; /** ResponseDeliverTx gasWanted */ - gasWanted?: number | Long | null; + gasWanted?: Long | null; /** ResponseDeliverTx gasUsed */ - gasUsed?: number | Long | null; + gasUsed?: Long | null; /** ResponseDeliverTx events */ events?: tendermint.abci.types.IEvent[] | null; @@ -4789,10 +4789,10 @@ export namespace tendermint { public info: string; /** ResponseDeliverTx gasWanted. */ - public gasWanted: number | Long; + public gasWanted: Long; /** ResponseDeliverTx gasUsed. */ - public gasUsed: number | Long; + public gasUsed: Long; /** ResponseDeliverTx events. */ public events: tendermint.abci.types.IEvent[]; @@ -5014,10 +5014,10 @@ export namespace tendermint { /** Properties of a BlockParams. */ interface IBlockParams { /** BlockParams maxBytes */ - maxBytes?: number | Long | null; + maxBytes?: Long | null; /** BlockParams maxGas */ - maxGas?: number | Long | null; + maxGas?: Long | null; } /** Represents a BlockParams. */ @@ -5029,10 +5029,10 @@ export namespace tendermint { constructor(p?: tendermint.abci.types.IBlockParams); /** BlockParams maxBytes. */ - public maxBytes: number | Long; + public maxBytes: Long; /** BlockParams maxGas. */ - public maxGas: number | Long; + public maxGas: Long; /** * Creates a new BlockParams instance using the specified properties. @@ -5065,7 +5065,7 @@ export namespace tendermint { /** Properties of an EvidenceParams. */ interface IEvidenceParams { /** EvidenceParams maxAgeNumBlocks */ - maxAgeNumBlocks?: number | Long | null; + maxAgeNumBlocks?: Long | null; /** EvidenceParams maxAgeDuration */ maxAgeDuration?: google.protobuf.IDuration | null; @@ -5080,7 +5080,7 @@ export namespace tendermint { constructor(p?: tendermint.abci.types.IEvidenceParams); /** EvidenceParams maxAgeNumBlocks. */ - public maxAgeNumBlocks: number | Long; + public maxAgeNumBlocks: Long; /** EvidenceParams maxAgeDuration. */ public maxAgeDuration?: google.protobuf.IDuration | null; @@ -5285,7 +5285,7 @@ export namespace tendermint { chainId?: string | null; /** Header height */ - height?: number | Long | null; + height?: Long | null; /** Header time */ time?: google.protobuf.ITimestamp | null; @@ -5336,7 +5336,7 @@ export namespace tendermint { public chainId: string; /** Header height. */ - public height: number | Long; + public height: Long; /** Header time. */ public time?: google.protobuf.ITimestamp | null; @@ -5400,10 +5400,10 @@ export namespace tendermint { /** Properties of a Version. */ interface IVersion { /** Version Block */ - Block?: number | Long | null; + Block?: Long | null; /** Version App */ - App?: number | Long | null; + App?: Long | null; } /** Represents a Version. */ @@ -5415,10 +5415,10 @@ export namespace tendermint { constructor(p?: tendermint.abci.types.IVersion); /** Version Block. */ - public Block: number | Long; + public Block: Long; /** Version App. */ - public App: number | Long; + public App: Long; /** * Creates a new Version instance using the specified properties. @@ -5555,7 +5555,7 @@ export namespace tendermint { address?: Uint8Array | null; /** Validator power */ - power?: number | Long | null; + power?: Long | null; } /** Represents a Validator. */ @@ -5570,7 +5570,7 @@ export namespace tendermint { public address: Uint8Array; /** Validator power. */ - public power: number | Long; + public power: Long; /** * Creates a new Validator instance using the specified properties. @@ -5604,7 +5604,7 @@ export namespace tendermint { pubKey?: tendermint.abci.types.IPubKey | null; /** ValidatorUpdate power */ - power?: number | Long | null; + power?: Long | null; } /** Represents a ValidatorUpdate. */ @@ -5619,7 +5619,7 @@ export namespace tendermint { public pubKey?: tendermint.abci.types.IPubKey | null; /** ValidatorUpdate power. */ - public power: number | Long; + public power: Long; /** * Creates a new ValidatorUpdate instance using the specified properties. @@ -5762,13 +5762,13 @@ export namespace tendermint { validator?: tendermint.abci.types.IValidator | null; /** Evidence height */ - height?: number | Long | null; + height?: Long | null; /** Evidence time */ time?: google.protobuf.ITimestamp | null; /** Evidence totalVotingPower */ - totalVotingPower?: number | Long | null; + totalVotingPower?: Long | null; } /** Represents an Evidence. */ @@ -5786,13 +5786,13 @@ export namespace tendermint { public validator?: tendermint.abci.types.IValidator | null; /** Evidence height. */ - public height: number | Long; + public height: Long; /** Evidence time. */ public time?: google.protobuf.ITimestamp | null; /** Evidence totalVotingPower. */ - public totalVotingPower: number | Long; + public totalVotingPower: Long; /** * Creates a new Evidence instance using the specified properties. @@ -6313,7 +6313,7 @@ export namespace tendermint { key?: Uint8Array | null; /** KI64Pair value */ - value?: number | Long | null; + value?: Long | null; } /** Represents a KI64Pair. */ @@ -6328,7 +6328,7 @@ export namespace tendermint { public key: Uint8Array; /** KI64Pair value. */ - public value: number | Long; + public value: Long; /** * Creates a new KI64Pair instance using the specified properties. @@ -6415,7 +6415,7 @@ export namespace google { /** Properties of a Timestamp. */ interface ITimestamp { /** Timestamp seconds */ - seconds?: number | Long | null; + seconds?: Long | null; /** Timestamp nanos */ nanos?: number | null; @@ -6430,7 +6430,7 @@ export namespace google { constructor(p?: google.protobuf.ITimestamp); /** Timestamp seconds. */ - public seconds: number | Long; + public seconds: Long; /** Timestamp nanos. */ public nanos: number; @@ -6464,7 +6464,7 @@ export namespace google { /** Properties of a Duration. */ interface IDuration { /** Duration seconds */ - seconds?: number | Long | null; + seconds?: Long | null; /** Duration nanos */ nanos?: number | null; @@ -6479,7 +6479,7 @@ export namespace google { constructor(p?: google.protobuf.IDuration); /** Duration seconds. */ - public seconds: number | Long; + public seconds: Long; /** Duration nanos. */ public nanos: number; diff --git a/packages/stargate/src/generated/codecimpl.js b/packages/stargate/src/codec/generated/codecimpl.js similarity index 100% rename from packages/stargate/src/generated/codecimpl.js rename to packages/stargate/src/codec/generated/codecimpl.js diff --git a/packages/stargate/src/codec/index.ts b/packages/stargate/src/codec/index.ts new file mode 100644 index 00000000..e27bfc7e --- /dev/null +++ b/packages/stargate/src/codec/index.ts @@ -0,0 +1,9 @@ +import Long from "long"; +import protobuf from "protobufjs/minimal"; + +// Ensure the protobuf module has a Long implementation, which otherwise only works +// in Node.js (see https://github.com/protobufjs/protobuf.js/issues/921#issuecomment-334925145) +protobuf.util.Long = Long; +protobuf.configure(); + +export * from "./generated/codecimpl"; diff --git a/packages/stargate/src/queries/auth.spec.ts b/packages/stargate/src/queries/auth.spec.ts new file mode 100644 index 00000000..14225043 --- /dev/null +++ b/packages/stargate/src/queries/auth.spec.ts @@ -0,0 +1,108 @@ +import { encodeAminoPubkey } from "@cosmjs/launchpad"; +import { Client as TendermintClient } from "@cosmjs/tendermint-rpc"; +import { assert } from "@cosmjs/utils"; +import Long from "long"; + +import { nonExistentAddress, pendingWithoutSimapp, simapp, unused, validator } from "../testutils.spec"; +import { AuthExtension, setupAuthExtension } from "./auth"; +import { QueryClient } from "./queryclient"; +import { toAccAddress } from "./utils"; + +async function makeAuthClient(rpcUrl: string): Promise<[QueryClient & AuthExtension, TendermintClient]> { + const tmClient = await TendermintClient.connect(rpcUrl); + return [QueryClient.withExtensions(tmClient, setupAuthExtension), tmClient]; +} + +describe("AuthExtension", () => { + describe("account", () => { + it("works for unused account", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeAuthClient(simapp.tendermintUrl); + + const account = await client.auth.account(unused.address); + assert(account); + + expect(account).toEqual({ + address: toAccAddress(unused.address), + // pubKey not set + accountNumber: Long.fromNumber(unused.accountNumber, true), + // sequence not set + }); + + tmClient.disconnect(); + }); + + it("works for account with pubkey and non-zero sequence", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeAuthClient(simapp.tendermintUrl); + + const account = await client.auth.account(validator.address); + assert(account); + expect(account).toEqual({ + address: toAccAddress(validator.address), + pubKey: encodeAminoPubkey(validator.pubkey), + // accountNumber not set + sequence: Long.fromNumber(validator.sequence, true), + }); + + tmClient.disconnect(); + }); + + it("returns null for non-existent address", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeAuthClient(simapp.tendermintUrl); + + const account = await client.auth.account(nonExistentAddress); + expect(account).toBeNull(); + + tmClient.disconnect(); + }); + }); + + describe("unverified", () => { + describe("account", () => { + it("works for unused account", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeAuthClient(simapp.tendermintUrl); + + const account = await client.auth.unverified.account(unused.address); + assert(account); + expect(account).toEqual({ + address: toAccAddress(unused.address), + // pubKey not set + accountNumber: Long.fromNumber(unused.accountNumber, true), + // sequence not set + }); + + tmClient.disconnect(); + }); + + it("works for account with pubkey and non-zero sequence", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeAuthClient(simapp.tendermintUrl); + + const account = await client.auth.unverified.account(validator.address); + assert(account); + expect(account).toEqual({ + address: toAccAddress(validator.address), + pubKey: encodeAminoPubkey(validator.pubkey), + // accountNumber not set + sequence: Long.fromNumber(validator.sequence, true), + }); + + tmClient.disconnect(); + }); + + it("returns null for non-existent address", async () => { + pending("This fails with Error: Query failed with (1): internal"); + pendingWithoutSimapp(); + const [client, tmClient] = await makeAuthClient(simapp.tendermintUrl); + + const account = await client.auth.unverified.account(nonExistentAddress); + expect(account).toBeNull(); + + tmClient.disconnect(); + }); + }); + }); +}); diff --git a/packages/stargate/src/queries/auth.ts b/packages/stargate/src/queries/auth.ts new file mode 100644 index 00000000..aeffb54c --- /dev/null +++ b/packages/stargate/src/queries/auth.ts @@ -0,0 +1,60 @@ +import { assert } from "@cosmjs/utils"; + +import { cosmos, google } from "../codec"; +import { QueryClient } from "./queryclient"; +import { toAccAddress, toObject } from "./utils"; + +export interface AuthExtension { + readonly auth: { + readonly account: (address: string) => Promise; + readonly unverified: { + readonly account: (address: string) => Promise; + }; + }; +} + +export function setupAuthExtension(base: QueryClient): AuthExtension { + // Use this service to get easy typed access to query methods + // This cannot be used to for proof verification + const queryService = cosmos.auth.Query.create((method: any, requestData, callback) => { + // Parts of the path are unavailable, so we hardcode them here. See https://github.com/protobufjs/protobuf.js/issues/1229 + const path = `/cosmos.auth.Query/${method.name}`; + base + .queryUnverified(path, requestData) + .then((response) => callback(null, response)) + .catch((error) => callback(error)); + }); + + return { + auth: { + account: async (address: string) => { + // https://github.com/cosmos/cosmos-sdk/blob/8cab43c8120fec5200c3459cbf4a92017bb6f287/x/auth/types/keys.go#L29-L32 + const key = Uint8Array.from([0x01, ...toAccAddress(address)]); + const responseData = await base.queryVerified("acc", key); + if (responseData.length === 0) return null; + const account = google.protobuf.Any.decode(responseData); + switch (account.type_url) { + case "/cosmos.auth.BaseAccount": { + return toObject(cosmos.auth.BaseAccount.decode(account.value)); + } + default: + throw new Error(`Unsupported type: '${account.type_url}'`); + } + }, + unverified: { + account: async (address: string) => { + const { account } = await queryService.account({ address: toAccAddress(address) }); + if (!account) return null; + switch (account.type_url) { + case "/cosmos.auth.BaseAccount": { + assert(account.value); + return toObject(cosmos.auth.BaseAccount.decode(account.value)); + } + default: + throw new Error(`Unsupported type: '${account.type_url}'`); + } + }, + }, + }, + }; +} diff --git a/packages/stargate/src/queries/bank.spec.ts b/packages/stargate/src/queries/bank.spec.ts new file mode 100644 index 00000000..9d73e4b1 --- /dev/null +++ b/packages/stargate/src/queries/bank.spec.ts @@ -0,0 +1,186 @@ +import { Client as TendermintClient } from "@cosmjs/tendermint-rpc"; + +import { + nonExistentAddress, + nonNegativeIntegerMatcher, + pendingWithoutSimapp, + simapp, + unused, +} from "../testutils.spec"; +import { BankExtension, setupBankExtension } from "./bank"; +import { QueryClient } from "./queryclient"; + +async function makeBankClient(rpcUrl: string): Promise<[QueryClient & BankExtension, TendermintClient]> { + const tmClient = await TendermintClient.connect(rpcUrl); + return [QueryClient.withExtensions(tmClient, setupBankExtension), tmClient]; +} + +describe("BankExtension", () => { + describe("balance", () => { + it("works for different existing balances", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeBankClient(simapp.tendermintUrl); + + const response1 = await client.bank.balance(unused.address, simapp.denomFee); + expect(response1).toEqual({ + amount: unused.balanceFee, + denom: simapp.denomFee, + }); + const response2 = await client.bank.balance(unused.address, simapp.denomStaking); + expect(response2).toEqual({ + amount: unused.balanceStaking, + denom: simapp.denomStaking, + }); + + tmClient.disconnect(); + }); + + it("returns null for non-existent balance", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeBankClient(simapp.tendermintUrl); + + const response = await client.bank.balance(unused.address, "gintonic"); + expect(response).toBeNull(); + + tmClient.disconnect(); + }); + + it("returns null for non-existent address", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeBankClient(simapp.tendermintUrl); + + const response = await client.bank.balance(nonExistentAddress, simapp.denomFee); + expect(response).toBeNull(); + + tmClient.disconnect(); + }); + }); + + describe("unverified", () => { + describe("balance", () => { + it("works for different existing balances", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeBankClient(simapp.tendermintUrl); + + const response1 = await client.bank.unverified.balance(unused.address, simapp.denomFee); + expect(response1).toEqual({ + amount: unused.balanceFee, + denom: simapp.denomFee, + }); + const response2 = await client.bank.unverified.balance(unused.address, simapp.denomStaking); + expect(response2).toEqual({ + amount: unused.balanceStaking, + denom: simapp.denomStaking, + }); + + tmClient.disconnect(); + }); + + it("returns zero for non-existent balance", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeBankClient(simapp.tendermintUrl); + + const response = await client.bank.unverified.balance(unused.address, "gintonic"); + expect(response).toEqual({ + amount: "0", + denom: "gintonic", + }); + + tmClient.disconnect(); + }); + + it("returns zero for non-existent address", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeBankClient(simapp.tendermintUrl); + + const response = await client.bank.unverified.balance(nonExistentAddress, simapp.denomFee); + expect(response).toEqual({ + amount: "0", + denom: simapp.denomFee, + }); + + tmClient.disconnect(); + }); + }); + + describe("allBalances", () => { + it("returns all balances for unused account", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeBankClient(simapp.tendermintUrl); + + const balances = await client.bank.unverified.allBalances(unused.address); + expect(balances).toEqual([ + { + amount: unused.balanceFee, + denom: simapp.denomFee, + }, + { + amount: unused.balanceStaking, + denom: simapp.denomStaking, + }, + ]); + + tmClient.disconnect(); + }); + + it("returns an empty list for non-existent account", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeBankClient(simapp.tendermintUrl); + + const balances = await client.bank.unverified.allBalances(nonExistentAddress); + expect(balances).toEqual([]); + + tmClient.disconnect(); + }); + }); + + describe("totalSupply", () => { + it("works", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeBankClient(simapp.tendermintUrl); + + const response = await client.bank.unverified.totalSupply(); + expect(response).toEqual([ + { + amount: "18000000000", + denom: simapp.denomFee, + }, + { + amount: jasmine.stringMatching(nonNegativeIntegerMatcher), + denom: simapp.denomStaking, + }, + ]); + + tmClient.disconnect(); + }); + }); + + describe("supplyOf", () => { + it("works for existing denom", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeBankClient(simapp.tendermintUrl); + + const response = await client.bank.unverified.supplyOf(simapp.denomFee); + expect(response).toEqual({ + amount: "18000000000", + denom: simapp.denomFee, + }); + + tmClient.disconnect(); + }); + + it("returns zero for non-existent denom", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeBankClient(simapp.tendermintUrl); + + const response = await client.bank.unverified.supplyOf("gintonic"); + expect(response).toEqual({ + amount: "0", + denom: "gintonic", + }); + + tmClient.disconnect(); + }); + }); + }); +}); diff --git a/packages/stargate/src/queries/bank.ts b/packages/stargate/src/queries/bank.ts new file mode 100644 index 00000000..6b85cb8f --- /dev/null +++ b/packages/stargate/src/queries/bank.ts @@ -0,0 +1,67 @@ +import { toAscii } from "@cosmjs/encoding"; +import { assert } from "@cosmjs/utils"; + +import { cosmos } from "../codec"; +import { QueryClient } from "./queryclient"; +import { toAccAddress, toObject } from "./utils"; + +export interface BankExtension { + readonly bank: { + readonly balance: (address: string, denom: string) => Promise; + readonly unverified: { + readonly balance: (address: string, denom: string) => Promise; + readonly allBalances: (address: string) => Promise; + readonly totalSupply: () => Promise; + readonly supplyOf: (denom: string) => Promise; + }; + }; +} + +export function setupBankExtension(base: QueryClient): BankExtension { + // Use this service to get easy typed access to query methods + // This cannot be used to for proof verification + const queryService = cosmos.bank.Query.create((method: any, requestData, callback) => { + // Parts of the path are unavailable, so we hardcode them here. See https://github.com/protobufjs/protobuf.js/issues/1229 + const path = `/cosmos.bank.Query/${method.name}`; + base + .queryUnverified(path, requestData) + .then((response) => callback(null, response)) + .catch((error) => callback(error)); + }); + + return { + bank: { + balance: async (address: string, denom: string) => { + // balance key is a bit tricker, using some prefix stores + // https://github.com/cosmwasm/cosmos-sdk/blob/80f7ff62f79777a487d0c7a53c64b0f7e43c47b9/x/bank/keeper/view.go#L74-L77 + // ("balances", binAddress, denom) + // it seem like prefix stores just do a dumb concat with the keys (no tricks to avoid overlap) + // https://github.com/cosmos/cosmos-sdk/blob/2879c0702c87dc9dd828a8c42b9224dc054e28ad/store/prefix/store.go#L61-L64 + // https://github.com/cosmos/cosmos-sdk/blob/2879c0702c87dc9dd828a8c42b9224dc054e28ad/store/prefix/store.go#L37-L43 + const key = Uint8Array.from([...toAscii("balances"), ...toAccAddress(address), ...toAscii(denom)]); + const responseData = await base.queryVerified("bank", key); + return responseData.length ? toObject(cosmos.Coin.decode(responseData)) : null; + }, + unverified: { + balance: async (address: string, denom: string) => { + const { balance } = await queryService.balance({ address: toAccAddress(address), denom: denom }); + assert(balance); + return toObject(balance); + }, + allBalances: async (address: string) => { + const { balances } = await queryService.allBalances({ address: toAccAddress(address) }); + return balances.map(toObject); + }, + totalSupply: async () => { + const { supply } = await queryService.totalSupply({}); + return supply.map(toObject); + }, + supplyOf: async (denom: string) => { + const { amount } = await queryService.supplyOf({ denom: denom }); + assert(amount); + return toObject(amount); + }, + }, + }, + }; +} diff --git a/packages/stargate/src/queries/index.ts b/packages/stargate/src/queries/index.ts new file mode 100644 index 00000000..afcfb022 --- /dev/null +++ b/packages/stargate/src/queries/index.ts @@ -0,0 +1,8 @@ +// Base symbols + +export { QueryClient } from "./queryclient"; + +// Extensions + +export { AuthExtension, setupAuthExtension } from "./auth"; +export { BankExtension, setupBankExtension } from "./bank"; diff --git a/packages/stargate/src/queries/queryclient.ts b/packages/stargate/src/queries/queryclient.ts new file mode 100644 index 00000000..fedc9a0f --- /dev/null +++ b/packages/stargate/src/queries/queryclient.ts @@ -0,0 +1,183 @@ +/* eslint-disable no-dupe-class-members, @typescript-eslint/ban-types, @typescript-eslint/naming-convention */ +import { toHex } from "@cosmjs/encoding"; +import { Client as TendermintClient } from "@cosmjs/tendermint-rpc"; +import { arrayContentEquals, assert, isNonNullObject } from "@cosmjs/utils"; + +type QueryExtensionSetup

= (base: QueryClient) => P; + +export class QueryClient { + /** Constructs a QueryClient with 0 extensions */ + public static withExtensions(tmClient: TendermintClient): QueryClient; + + /** Constructs a QueryClient with 1 extension */ + public static withExtensions( + tmClient: TendermintClient, + setupExtensionA: QueryExtensionSetup, + ): QueryClient & A; + + /** Constructs a QueryClient with 2 extensions */ + public static withExtensions( + tmClient: TendermintClient, + setupExtensionA: QueryExtensionSetup, + setupExtensionB: QueryExtensionSetup, + ): QueryClient & A & B; + + /** Constructs a QueryClient with 3 extensions */ + public static withExtensions( + tmClient: TendermintClient, + setupExtensionA: QueryExtensionSetup, + setupExtensionB: QueryExtensionSetup, + setupExtensionC: QueryExtensionSetup, + ): QueryClient & A & B & C; + + /** Constructs a QueryClient with 4 extensions */ + public static withExtensions( + tmClient: TendermintClient, + setupExtensionA: QueryExtensionSetup, + setupExtensionB: QueryExtensionSetup, + setupExtensionC: QueryExtensionSetup, + setupExtensionD: QueryExtensionSetup, + ): QueryClient & A & B & C & D; + + /** Constructs a QueryClient with 5 extensions */ + public static withExtensions< + A extends object, + B extends object, + C extends object, + D extends object, + E extends object + >( + tmClient: TendermintClient, + setupExtensionA: QueryExtensionSetup, + setupExtensionB: QueryExtensionSetup, + setupExtensionC: QueryExtensionSetup, + setupExtensionD: QueryExtensionSetup, + setupExtensionE: QueryExtensionSetup, + ): QueryClient & A & B & C & D & E; + + /** Constructs a QueryClient with 6 extensions */ + public static withExtensions< + A extends object, + B extends object, + C extends object, + D extends object, + E extends object, + F extends object + >( + tmClient: TendermintClient, + setupExtensionA: QueryExtensionSetup, + setupExtensionB: QueryExtensionSetup, + setupExtensionC: QueryExtensionSetup, + setupExtensionD: QueryExtensionSetup, + setupExtensionE: QueryExtensionSetup, + setupExtensionF: QueryExtensionSetup, + ): QueryClient & A & B & C & D & E & F; + + /** Constructs a QueryClient with 7 extensions */ + public static withExtensions< + A extends object, + B extends object, + C extends object, + D extends object, + E extends object, + F extends object, + G extends object + >( + tmClient: TendermintClient, + setupExtensionA: QueryExtensionSetup, + setupExtensionB: QueryExtensionSetup, + setupExtensionC: QueryExtensionSetup, + setupExtensionD: QueryExtensionSetup, + setupExtensionE: QueryExtensionSetup, + setupExtensionF: QueryExtensionSetup, + setupExtensionG: QueryExtensionSetup, + ): QueryClient & A & B & C & D & E & F & G; + + /** Constructs a QueryClient with 8 extensions */ + public static withExtensions< + A extends object, + B extends object, + C extends object, + D extends object, + E extends object, + F extends object, + G extends object, + H extends object + >( + tmClient: TendermintClient, + setupExtensionA: QueryExtensionSetup, + setupExtensionB: QueryExtensionSetup, + setupExtensionC: QueryExtensionSetup, + setupExtensionD: QueryExtensionSetup, + setupExtensionE: QueryExtensionSetup, + setupExtensionF: QueryExtensionSetup, + setupExtensionG: QueryExtensionSetup, + setupExtensionH: QueryExtensionSetup, + ): QueryClient & A & B & C & D & E & F & G & H; + + public static withExtensions( + tmClient: TendermintClient, + ...extensionSetups: Array> + ): any { + const client = new QueryClient(tmClient); + const extensions = extensionSetups.map((setupExtension) => setupExtension(client)); + for (const extension of extensions) { + assert(isNonNullObject(extension), `Extension must be a non-null object`); + for (const [moduleKey, moduleValue] of Object.entries(extension)) { + assert( + isNonNullObject(moduleValue), + `Module must be a non-null object. Found type ${typeof moduleValue} for module "${moduleKey}".`, + ); + const current = (client as any)[moduleKey] || {}; + (client as any)[moduleKey] = { + ...current, + ...moduleValue, + }; + } + } + return client; + } + + private readonly tmClient: TendermintClient; + + public constructor(tmClient: TendermintClient) { + this.tmClient = tmClient; + } + + public async queryVerified(store: string, key: Uint8Array): Promise { + const response = await this.tmClient.abciQuery({ + // we need the StoreKey for the module, not the module name + // https://github.com/cosmos/cosmos-sdk/blob/8cab43c8120fec5200c3459cbf4a92017bb6f287/x/auth/types/keys.go#L12 + path: `/store/${store}/key`, + data: key, + prove: true, + }); + + if (response.code) { + throw new Error(`Query failed with (${response.code}): ${response.log}`); + } + + if (!arrayContentEquals(response.key, key)) { + throw new Error(`Response key ${toHex(response.key)} doesn't match query key ${toHex(key)}`); + } + + // TODO: implement proof verification + // https://github.com/CosmWasm/cosmjs/issues/347 + + return response.value; + } + + public async queryUnverified(path: string, request: Uint8Array): Promise { + const response = await this.tmClient.abciQuery({ + path: path, + data: request, + prove: false, + }); + + if (response.code) { + throw new Error(`Query failed with (${response.code}): ${response.log}`); + } + + return response.value; + } +} diff --git a/packages/stargate/src/queries/utils.ts b/packages/stargate/src/queries/utils.ts new file mode 100644 index 00000000..0466765e --- /dev/null +++ b/packages/stargate/src/queries/utils.ts @@ -0,0 +1,19 @@ +import { Bech32 } from "@cosmjs/encoding"; + +/** + * Takes a bech32 encoded address and returns the data part. The prefix is ignored and discarded. + * This is called AccAddress in Cosmos SDK, which is basically an alias for raw binary data. + * The result is typically 20 bytes long but not restricted to that. + */ +export function toAccAddress(address: string): Uint8Array { + return Bech32.decode(address).data; +} + +/** + * Use this to convert a protobuf.js class to the interface (e.g. Coin to ICoin) + * in a ways that makes Jasmine's toEqual happy. + */ +// eslint-disable-next-line @typescript-eslint/ban-types +export function toObject(thing: I): Omit { + return { ...thing }; +} diff --git a/packages/stargate/src/stargateclient.searchtx.spec.ts b/packages/stargate/src/stargateclient.searchtx.spec.ts index 1f10a41b..855fcf73 100644 --- a/packages/stargate/src/stargateclient.searchtx.spec.ts +++ b/packages/stargate/src/stargateclient.searchtx.spec.ts @@ -3,8 +3,9 @@ import { Bech32, fromBase64 } from "@cosmjs/encoding"; import { Coin, coins, Secp256k1Wallet } from "@cosmjs/launchpad"; import { makeSignBytes, omitDefaults, Registry } from "@cosmjs/proto-signing"; import { assert } from "@cosmjs/utils"; +import Long from "long"; -import { cosmos } from "./generated/codecimpl"; +import { cosmos } from "./codec"; import { BroadcastTxResponse, isBroadcastTxFailure, @@ -68,7 +69,7 @@ async function sendTokens( }, ], fee: { - gasLimit: 200000, + gasLimit: Long.fromNumber(200000), }, }; const authInfoBytes = Uint8Array.from(AuthInfo.encode(authInfo).finish()); diff --git a/packages/stargate/src/stargateclient.spec.ts b/packages/stargate/src/stargateclient.spec.ts index a4bf8c4b..130edc2f 100644 --- a/packages/stargate/src/stargateclient.spec.ts +++ b/packages/stargate/src/stargateclient.spec.ts @@ -3,9 +3,10 @@ import { Bech32, fromBase64 } from "@cosmjs/encoding"; import { Secp256k1Wallet } from "@cosmjs/launchpad"; import { makeSignBytes, omitDefaults, Registry } from "@cosmjs/proto-signing"; import { assert, sleep } from "@cosmjs/utils"; +import Long from "long"; import { ReadonlyDate } from "readonly-date"; -import { cosmos } from "./generated/codecimpl"; +import { cosmos } from "./codec"; import { assertIsBroadcastTxSuccess, PrivateStargateClient, StargateClient } from "./stargateclient"; import { faucet, @@ -290,7 +291,7 @@ describe("StargateClient", () => { }, ], fee: { - gasLimit: 200000, + gasLimit: Long.fromNumber(200000), }, }; const authInfoBytes = Uint8Array.from(AuthInfo.encode(authInfo).finish()); diff --git a/packages/stargate/src/stargateclient.ts b/packages/stargate/src/stargateclient.ts index 75b18ec9..447a87bf 100644 --- a/packages/stargate/src/stargateclient.ts +++ b/packages/stargate/src/stargateclient.ts @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import { Bech32, toAscii, toHex } from "@cosmjs/encoding"; +import { Bech32, toHex } from "@cosmjs/encoding"; import { Block, Coin, @@ -11,12 +11,12 @@ import { SearchTxQuery, } from "@cosmjs/launchpad"; import { Uint53, Uint64 } from "@cosmjs/math"; -import { decodeAny } from "@cosmjs/proto-signing"; import { broadcastTxCommitSuccess, Client as TendermintClient, QueryString } from "@cosmjs/tendermint-rpc"; -import { arrayContentEquals, assert, assertDefined } from "@cosmjs/utils"; +import { assert, assertDefined } from "@cosmjs/utils"; import Long from "long"; -import { cosmos } from "./generated/codecimpl"; +import { cosmos } from "./codec"; +import { AuthExtension, BankExtension, QueryClient, setupAuthExtension, setupBankExtension } from "./queries"; /** A transaction that is indexed as part of the transaction history */ export interface IndexedTx { @@ -80,14 +80,16 @@ export function assertIsBroadcastTxSuccess( } } -function uint64FromProto(input: number | Long): Uint64 { +function uint64FromProto(input: number | Long | null | undefined): Uint64 { + if (!input) return Uint64.fromNumber(0); return Uint64.fromString(input.toString()); } -function decodeBaseAccount(data: Uint8Array, prefix: string): Account { - const { address, pubKey, accountNumber, sequence } = cosmos.auth.BaseAccount.decode(data); +function accountFromProto(input: cosmos.auth.IBaseAccount, prefix: string): Account { + const { address, pubKey, accountNumber, sequence } = input; // Pubkey is still Amino-encoded in BaseAccount (https://github.com/cosmos/cosmos-sdk/issues/6886) - const pubkey = pubKey.length ? decodeAminoPubkey(pubKey) : null; + const pubkey = pubKey && pubKey.length ? decodeAminoPubkey(pubKey) : null; + assert(address); return { address: Bech32.encode(prefix, address), pubkey: pubkey, @@ -114,6 +116,7 @@ export interface PrivateStargateClient { export class StargateClient { private readonly tmClient: TendermintClient; + private readonly queryClient: QueryClient & AuthExtension & BankExtension; private chainId: string | undefined; public static async connect(endpoint: string): Promise { @@ -123,6 +126,7 @@ export class StargateClient { private constructor(tmClient: TendermintClient) { this.tmClient = tmClient; + this.queryClient = QueryClient.withExtensions(tmClient, setupAuthExtension, setupBankExtension); } public async getChainId(): Promise { @@ -142,21 +146,10 @@ export class StargateClient { } public async getAccount(searchAddress: string): Promise { - const { prefix, data: binAddress } = Bech32.decode(searchAddress); - // https://github.com/cosmos/cosmos-sdk/blob/8cab43c8120fec5200c3459cbf4a92017bb6f287/x/auth/types/keys.go#L29-L32 - const accountKey = Uint8Array.from([0x01, ...binAddress]); - const responseData = await this.queryVerified("acc", accountKey); + const { prefix } = Bech32.decode(searchAddress); - if (responseData.length === 0) return null; - - const { typeUrl, value } = decodeAny(responseData); - switch (typeUrl) { - case "/cosmos.auth.BaseAccount": { - return decodeBaseAccount(value, prefix); - } - default: - throw new Error(`Unsupported type: '${typeUrl}'`); - } + const account = await this.queryClient.auth.account(searchAddress); + return account ? accountFromProto(account, prefix) : null; } public async getSequence(address: string): Promise { @@ -189,25 +182,8 @@ export class StargateClient { } public async getBalance(address: string, searchDenom: string): Promise { - // balance key is a bit tricker, using some prefix stores - // https://github.com/cosmwasm/cosmos-sdk/blob/80f7ff62f79777a487d0c7a53c64b0f7e43c47b9/x/bank/keeper/view.go#L74-L77 - // ("balances", binAddress, denom) - // it seem like prefix stores just do a dumb concat with the keys (no tricks to avoid overlap) - // https://github.com/cosmos/cosmos-sdk/blob/2879c0702c87dc9dd828a8c42b9224dc054e28ad/store/prefix/store.go#L61-L64 - // https://github.com/cosmos/cosmos-sdk/blob/2879c0702c87dc9dd828a8c42b9224dc054e28ad/store/prefix/store.go#L37-L43 - const binAddress = Bech32.decode(address).data; - const bankKey = Uint8Array.from([...toAscii("balances"), ...binAddress, ...toAscii(searchDenom)]); - - const responseData = await this.queryVerified("bank", bankKey); - const { amount, denom } = cosmos.Coin.decode(responseData); - if (denom === "") { - return null; - } else { - return { - amount: amount, - denom: denom, - }; - } + const balance = await this.queryClient.bank.balance(address, searchDenom); + return balance ? coinFromProto(balance) : null; } /** @@ -217,13 +193,8 @@ export class StargateClient { * proofs from such a method. */ public async getAllBalancesUnverified(address: string): Promise { - const path = "/cosmos.bank.Query/AllBalances"; - const request = cosmos.bank.QueryAllBalancesRequest.encode({ - address: Bech32.decode(address).data, - }).finish(); - const responseData = await this.queryUnverified(path, request); - const response = cosmos.bank.QueryAllBalancesResponse.decode(responseData); - return response.balances.map(coinFromProto); + const balances = await this.queryClient.bank.unverified.allBalances(address); + return balances.map(coinFromProto); } public async searchTx(query: SearchTxQuery, filter: SearchTxFilter = {}): Promise { @@ -280,43 +251,6 @@ export class StargateClient { }; } - private async queryVerified(store: string, key: Uint8Array): Promise { - const response = await this.tmClient.abciQuery({ - // we need the StoreKey for the module, not the module name - // https://github.com/cosmos/cosmos-sdk/blob/8cab43c8120fec5200c3459cbf4a92017bb6f287/x/auth/types/keys.go#L12 - path: `/store/${store}/key`, - data: key, - prove: true, - }); - - if (response.code) { - throw new Error(`Query failed with (${response.code}): ${response.log}`); - } - - if (!arrayContentEquals(response.key, key)) { - throw new Error(`Response key ${toHex(response.key)} doesn't match query key ${toHex(key)}`); - } - - // TODO: implement proof verification - // https://github.com/CosmWasm/cosmjs/issues/347 - - return response.value; - } - - private async queryUnverified(path: string, request: Uint8Array): Promise { - const response = await this.tmClient.abciQuery({ - path: path, - data: request, - prove: false, - }); - - if (response.code) { - throw new Error(`Query failed with (${response.code}): ${response.log}`); - } - - return response.value; - } - private async txsQuery(query: string): Promise { const params = { query: query as QueryString, diff --git a/packages/stargate/src/testutils.spec.ts b/packages/stargate/src/testutils.spec.ts index 25d985b9..4bfbfafa 100644 --- a/packages/stargate/src/testutils.spec.ts +++ b/packages/stargate/src/testutils.spec.ts @@ -64,4 +64,5 @@ export const validator = { export const nonExistentAddress = "cosmos1p79apjaufyphcmsn4g07cynqf0wyjuezqu84hd"; +export const nonNegativeIntegerMatcher = /^[0-9]+$/; export const tendermintIdMatcher = /^[0-9A-F]{64}$/; diff --git a/packages/stargate/types/generated/codecimpl.d.ts b/packages/stargate/types/codec/generated/codecimpl.d.ts similarity index 98% rename from packages/stargate/types/generated/codecimpl.d.ts rename to packages/stargate/types/codec/generated/codecimpl.d.ts index 627c179e..43c0b29b 100644 --- a/packages/stargate/types/generated/codecimpl.d.ts +++ b/packages/stargate/types/codec/generated/codecimpl.d.ts @@ -231,10 +231,10 @@ export namespace cosmos { /** Properties of a GasInfo. */ interface IGasInfo { /** GasInfo gasWanted */ - gasWanted?: number | Long | null; + gasWanted?: Long | null; /** GasInfo gasUsed */ - gasUsed?: number | Long | null; + gasUsed?: Long | null; } /** Represents a GasInfo. */ @@ -246,10 +246,10 @@ export namespace cosmos { constructor(p?: cosmos.IGasInfo); /** GasInfo gasWanted. */ - public gasWanted: number | Long; + public gasWanted: Long; /** GasInfo gasUsed. */ - public gasUsed: number | Long; + public gasUsed: Long; /** * Creates a new GasInfo instance using the specified properties. @@ -476,7 +476,7 @@ export namespace cosmos { /** Properties of a TxResponse. */ interface ITxResponse { /** TxResponse height */ - height?: number | Long | null; + height?: Long | null; /** TxResponse txhash */ txhash?: string | null; @@ -500,10 +500,10 @@ export namespace cosmos { info?: string | null; /** TxResponse gasWanted */ - gasWanted?: number | Long | null; + gasWanted?: Long | null; /** TxResponse gasUsed */ - gasUsed?: number | Long | null; + gasUsed?: Long | null; /** TxResponse tx */ tx?: google.protobuf.IAny | null; @@ -521,7 +521,7 @@ export namespace cosmos { constructor(p?: cosmos.ITxResponse); /** TxResponse height. */ - public height: number | Long; + public height: Long; /** TxResponse txhash. */ public txhash: string; @@ -545,10 +545,10 @@ export namespace cosmos { public info: string; /** TxResponse gasWanted. */ - public gasWanted: number | Long; + public gasWanted: Long; /** TxResponse gasUsed. */ - public gasUsed: number | Long; + public gasUsed: Long; /** TxResponse tx. */ public tx?: google.protobuf.IAny | null; @@ -746,10 +746,10 @@ export namespace cosmos { pubKey?: Uint8Array | null; /** BaseAccount accountNumber */ - accountNumber?: number | Long | null; + accountNumber?: Long | null; /** BaseAccount sequence */ - sequence?: number | Long | null; + sequence?: Long | null; } /** Represents a BaseAccount. */ @@ -767,10 +767,10 @@ export namespace cosmos { public pubKey: Uint8Array; /** BaseAccount accountNumber. */ - public accountNumber: number | Long; + public accountNumber: Long; /** BaseAccount sequence. */ - public sequence: number | Long; + public sequence: Long; /** * Creates a new BaseAccount instance using the specified properties. @@ -856,19 +856,19 @@ export namespace cosmos { /** Properties of a Params. */ interface IParams { /** Params maxMemoCharacters */ - maxMemoCharacters?: number | Long | null; + maxMemoCharacters?: Long | null; /** Params txSigLimit */ - txSigLimit?: number | Long | null; + txSigLimit?: Long | null; /** Params txSizeCostPerByte */ - txSizeCostPerByte?: number | Long | null; + txSizeCostPerByte?: Long | null; /** Params sigVerifyCostEd25519 */ - sigVerifyCostEd25519?: number | Long | null; + sigVerifyCostEd25519?: Long | null; /** Params sigVerifyCostSecp256k1 */ - sigVerifyCostSecp256k1?: number | Long | null; + sigVerifyCostSecp256k1?: Long | null; } /** Represents a Params. */ @@ -880,19 +880,19 @@ export namespace cosmos { constructor(p?: cosmos.auth.IParams); /** Params maxMemoCharacters. */ - public maxMemoCharacters: number | Long; + public maxMemoCharacters: Long; /** Params txSigLimit. */ - public txSigLimit: number | Long; + public txSigLimit: Long; /** Params txSizeCostPerByte. */ - public txSizeCostPerByte: number | Long; + public txSizeCostPerByte: Long; /** Params sigVerifyCostEd25519. */ - public sigVerifyCostEd25519: number | Long; + public sigVerifyCostEd25519: Long; /** Params sigVerifyCostSecp256k1. */ - public sigVerifyCostSecp256k1: number | Long; + public sigVerifyCostSecp256k1: Long; /** * Creates a new Params instance using the specified properties. @@ -2360,10 +2360,10 @@ export namespace cosmos { key?: Uint8Array | null; /** PageRequest offset */ - offset?: number | Long | null; + offset?: Long | null; /** PageRequest limit */ - limit?: number | Long | null; + limit?: Long | null; /** PageRequest countTotal */ countTotal?: boolean | null; @@ -2381,10 +2381,10 @@ export namespace cosmos { public key: Uint8Array; /** PageRequest offset. */ - public offset: number | Long; + public offset: Long; /** PageRequest limit. */ - public limit: number | Long; + public limit: Long; /** PageRequest countTotal. */ public countTotal: boolean; @@ -2421,7 +2421,7 @@ export namespace cosmos { nextKey?: Uint8Array | null; /** PageResponse total */ - total?: number | Long | null; + total?: Long | null; } /** Represents a PageResponse. */ @@ -2436,7 +2436,7 @@ export namespace cosmos { public nextKey: Uint8Array; /** PageResponse total. */ - public total: number | Long; + public total: Long; /** * Creates a new PageResponse instance using the specified properties. @@ -2589,10 +2589,10 @@ export namespace cosmos { chainId?: string | null; /** SignDoc accountNumber */ - accountNumber?: number | Long | null; + accountNumber?: Long | null; /** SignDoc accountSequence */ - accountSequence?: number | Long | null; + accountSequence?: Long | null; } /** Represents a SignDoc. */ @@ -2613,10 +2613,10 @@ export namespace cosmos { public chainId: string; /** SignDoc accountNumber. */ - public accountNumber: number | Long; + public accountNumber: Long; /** SignDoc accountSequence. */ - public accountSequence: number | Long; + public accountSequence: Long; /** * Creates a new SignDoc instance using the specified properties. @@ -2653,7 +2653,7 @@ export namespace cosmos { memo?: string | null; /** TxBody timeoutHeight */ - timeoutHeight?: number | Long | null; + timeoutHeight?: Long | null; /** TxBody extensionOptions */ extensionOptions?: google.protobuf.IAny[] | null; @@ -2677,7 +2677,7 @@ export namespace cosmos { public memo: string; /** TxBody timeoutHeight. */ - public timeoutHeight: number | Long; + public timeoutHeight: Long; /** TxBody extensionOptions. */ public extensionOptions: google.protobuf.IAny[]; @@ -2961,7 +2961,7 @@ export namespace cosmos { amount?: cosmos.ICoin[] | null; /** Fee gasLimit */ - gasLimit?: number | Long | null; + gasLimit?: Long | null; } /** Represents a Fee. */ @@ -2976,7 +2976,7 @@ export namespace cosmos { public amount: cosmos.ICoin[]; /** Fee gasLimit. */ - public gasLimit: number | Long; + public gasLimit: Long; /** * Creates a new Fee instance using the specified properties. @@ -3519,10 +3519,10 @@ export namespace tendermint { version?: string | null; /** RequestInfo blockVersion */ - blockVersion?: number | Long | null; + blockVersion?: Long | null; /** RequestInfo p2pVersion */ - p2pVersion?: number | Long | null; + p2pVersion?: Long | null; } /** Represents a RequestInfo. */ @@ -3537,10 +3537,10 @@ export namespace tendermint { public version: string; /** RequestInfo blockVersion. */ - public blockVersion: number | Long; + public blockVersion: Long; /** RequestInfo p2pVersion. */ - public p2pVersion: number | Long; + public p2pVersion: Long; /** * Creates a new RequestInfo instance using the specified properties. @@ -3711,7 +3711,7 @@ export namespace tendermint { path?: string | null; /** RequestQuery height */ - height?: number | Long | null; + height?: Long | null; /** RequestQuery prove */ prove?: boolean | null; @@ -3732,7 +3732,7 @@ export namespace tendermint { public path: string; /** RequestQuery height. */ - public height: number | Long; + public height: Long; /** RequestQuery prove. */ public prove: boolean; @@ -3954,7 +3954,7 @@ export namespace tendermint { /** Properties of a RequestEndBlock. */ interface IRequestEndBlock { /** RequestEndBlock height */ - height?: number | Long | null; + height?: Long | null; } /** Represents a RequestEndBlock. */ @@ -3966,7 +3966,7 @@ export namespace tendermint { constructor(p?: tendermint.abci.types.IRequestEndBlock); /** RequestEndBlock height. */ - public height: number | Long; + public height: Long; /** * Creates a new RequestEndBlock instance using the specified properties. @@ -4318,10 +4318,10 @@ export namespace tendermint { version?: string | null; /** ResponseInfo appVersion */ - appVersion?: number | Long | null; + appVersion?: Long | null; /** ResponseInfo lastBlockHeight */ - lastBlockHeight?: number | Long | null; + lastBlockHeight?: Long | null; /** ResponseInfo lastBlockAppHash */ lastBlockAppHash?: Uint8Array | null; @@ -4342,10 +4342,10 @@ export namespace tendermint { public version: string; /** ResponseInfo appVersion. */ - public appVersion: number | Long; + public appVersion: Long; /** ResponseInfo lastBlockHeight. */ - public lastBlockHeight: number | Long; + public lastBlockHeight: Long; /** ResponseInfo lastBlockAppHash. */ public lastBlockAppHash: Uint8Array; @@ -4513,7 +4513,7 @@ export namespace tendermint { info?: string | null; /** ResponseQuery index */ - index?: number | Long | null; + index?: Long | null; /** ResponseQuery key */ key?: Uint8Array | null; @@ -4525,7 +4525,7 @@ export namespace tendermint { proof?: tendermint.crypto.merkle.IProof | null; /** ResponseQuery height */ - height?: number | Long | null; + height?: Long | null; /** ResponseQuery codespace */ codespace?: string | null; @@ -4549,7 +4549,7 @@ export namespace tendermint { public info: string; /** ResponseQuery index. */ - public index: number | Long; + public index: Long; /** ResponseQuery key. */ public key: Uint8Array; @@ -4561,7 +4561,7 @@ export namespace tendermint { public proof?: tendermint.crypto.merkle.IProof | null; /** ResponseQuery height. */ - public height: number | Long; + public height: Long; /** ResponseQuery codespace. */ public codespace: string; @@ -4663,10 +4663,10 @@ export namespace tendermint { info?: string | null; /** ResponseCheckTx gasWanted */ - gasWanted?: number | Long | null; + gasWanted?: Long | null; /** ResponseCheckTx gasUsed */ - gasUsed?: number | Long | null; + gasUsed?: Long | null; /** ResponseCheckTx events */ events?: tendermint.abci.types.IEvent[] | null; @@ -4696,10 +4696,10 @@ export namespace tendermint { public info: string; /** ResponseCheckTx gasWanted. */ - public gasWanted: number | Long; + public gasWanted: Long; /** ResponseCheckTx gasUsed. */ - public gasUsed: number | Long; + public gasUsed: Long; /** ResponseCheckTx events. */ public events: tendermint.abci.types.IEvent[]; @@ -4756,10 +4756,10 @@ export namespace tendermint { info?: string | null; /** ResponseDeliverTx gasWanted */ - gasWanted?: number | Long | null; + gasWanted?: Long | null; /** ResponseDeliverTx gasUsed */ - gasUsed?: number | Long | null; + gasUsed?: Long | null; /** ResponseDeliverTx events */ events?: tendermint.abci.types.IEvent[] | null; @@ -4789,10 +4789,10 @@ export namespace tendermint { public info: string; /** ResponseDeliverTx gasWanted. */ - public gasWanted: number | Long; + public gasWanted: Long; /** ResponseDeliverTx gasUsed. */ - public gasUsed: number | Long; + public gasUsed: Long; /** ResponseDeliverTx events. */ public events: tendermint.abci.types.IEvent[]; @@ -5014,10 +5014,10 @@ export namespace tendermint { /** Properties of a BlockParams. */ interface IBlockParams { /** BlockParams maxBytes */ - maxBytes?: number | Long | null; + maxBytes?: Long | null; /** BlockParams maxGas */ - maxGas?: number | Long | null; + maxGas?: Long | null; } /** Represents a BlockParams. */ @@ -5029,10 +5029,10 @@ export namespace tendermint { constructor(p?: tendermint.abci.types.IBlockParams); /** BlockParams maxBytes. */ - public maxBytes: number | Long; + public maxBytes: Long; /** BlockParams maxGas. */ - public maxGas: number | Long; + public maxGas: Long; /** * Creates a new BlockParams instance using the specified properties. @@ -5065,7 +5065,7 @@ export namespace tendermint { /** Properties of an EvidenceParams. */ interface IEvidenceParams { /** EvidenceParams maxAgeNumBlocks */ - maxAgeNumBlocks?: number | Long | null; + maxAgeNumBlocks?: Long | null; /** EvidenceParams maxAgeDuration */ maxAgeDuration?: google.protobuf.IDuration | null; @@ -5080,7 +5080,7 @@ export namespace tendermint { constructor(p?: tendermint.abci.types.IEvidenceParams); /** EvidenceParams maxAgeNumBlocks. */ - public maxAgeNumBlocks: number | Long; + public maxAgeNumBlocks: Long; /** EvidenceParams maxAgeDuration. */ public maxAgeDuration?: google.protobuf.IDuration | null; @@ -5285,7 +5285,7 @@ export namespace tendermint { chainId?: string | null; /** Header height */ - height?: number | Long | null; + height?: Long | null; /** Header time */ time?: google.protobuf.ITimestamp | null; @@ -5336,7 +5336,7 @@ export namespace tendermint { public chainId: string; /** Header height. */ - public height: number | Long; + public height: Long; /** Header time. */ public time?: google.protobuf.ITimestamp | null; @@ -5400,10 +5400,10 @@ export namespace tendermint { /** Properties of a Version. */ interface IVersion { /** Version Block */ - Block?: number | Long | null; + Block?: Long | null; /** Version App */ - App?: number | Long | null; + App?: Long | null; } /** Represents a Version. */ @@ -5415,10 +5415,10 @@ export namespace tendermint { constructor(p?: tendermint.abci.types.IVersion); /** Version Block. */ - public Block: number | Long; + public Block: Long; /** Version App. */ - public App: number | Long; + public App: Long; /** * Creates a new Version instance using the specified properties. @@ -5555,7 +5555,7 @@ export namespace tendermint { address?: Uint8Array | null; /** Validator power */ - power?: number | Long | null; + power?: Long | null; } /** Represents a Validator. */ @@ -5570,7 +5570,7 @@ export namespace tendermint { public address: Uint8Array; /** Validator power. */ - public power: number | Long; + public power: Long; /** * Creates a new Validator instance using the specified properties. @@ -5604,7 +5604,7 @@ export namespace tendermint { pubKey?: tendermint.abci.types.IPubKey | null; /** ValidatorUpdate power */ - power?: number | Long | null; + power?: Long | null; } /** Represents a ValidatorUpdate. */ @@ -5619,7 +5619,7 @@ export namespace tendermint { public pubKey?: tendermint.abci.types.IPubKey | null; /** ValidatorUpdate power. */ - public power: number | Long; + public power: Long; /** * Creates a new ValidatorUpdate instance using the specified properties. @@ -5762,13 +5762,13 @@ export namespace tendermint { validator?: tendermint.abci.types.IValidator | null; /** Evidence height */ - height?: number | Long | null; + height?: Long | null; /** Evidence time */ time?: google.protobuf.ITimestamp | null; /** Evidence totalVotingPower */ - totalVotingPower?: number | Long | null; + totalVotingPower?: Long | null; } /** Represents an Evidence. */ @@ -5786,13 +5786,13 @@ export namespace tendermint { public validator?: tendermint.abci.types.IValidator | null; /** Evidence height. */ - public height: number | Long; + public height: Long; /** Evidence time. */ public time?: google.protobuf.ITimestamp | null; /** Evidence totalVotingPower. */ - public totalVotingPower: number | Long; + public totalVotingPower: Long; /** * Creates a new Evidence instance using the specified properties. @@ -6313,7 +6313,7 @@ export namespace tendermint { key?: Uint8Array | null; /** KI64Pair value */ - value?: number | Long | null; + value?: Long | null; } /** Represents a KI64Pair. */ @@ -6328,7 +6328,7 @@ export namespace tendermint { public key: Uint8Array; /** KI64Pair value. */ - public value: number | Long; + public value: Long; /** * Creates a new KI64Pair instance using the specified properties. @@ -6415,7 +6415,7 @@ export namespace google { /** Properties of a Timestamp. */ interface ITimestamp { /** Timestamp seconds */ - seconds?: number | Long | null; + seconds?: Long | null; /** Timestamp nanos */ nanos?: number | null; @@ -6430,7 +6430,7 @@ export namespace google { constructor(p?: google.protobuf.ITimestamp); /** Timestamp seconds. */ - public seconds: number | Long; + public seconds: Long; /** Timestamp nanos. */ public nanos: number; @@ -6464,7 +6464,7 @@ export namespace google { /** Properties of a Duration. */ interface IDuration { /** Duration seconds */ - seconds?: number | Long | null; + seconds?: Long | null; /** Duration nanos */ nanos?: number | null; @@ -6479,7 +6479,7 @@ export namespace google { constructor(p?: google.protobuf.IDuration); /** Duration seconds. */ - public seconds: number | Long; + public seconds: Long; /** Duration nanos. */ public nanos: number; diff --git a/packages/stargate/types/codec/index.d.ts b/packages/stargate/types/codec/index.d.ts new file mode 100644 index 00000000..7cbb5810 --- /dev/null +++ b/packages/stargate/types/codec/index.d.ts @@ -0,0 +1 @@ +export * from "./generated/codecimpl"; diff --git a/packages/stargate/types/queries/auth.d.ts b/packages/stargate/types/queries/auth.d.ts new file mode 100644 index 00000000..1fd1d65c --- /dev/null +++ b/packages/stargate/types/queries/auth.d.ts @@ -0,0 +1,11 @@ +import { cosmos } from "../codec"; +import { QueryClient } from "./queryclient"; +export interface AuthExtension { + readonly auth: { + readonly account: (address: string) => Promise; + readonly unverified: { + readonly account: (address: string) => Promise; + }; + }; +} +export declare function setupAuthExtension(base: QueryClient): AuthExtension; diff --git a/packages/stargate/types/queries/bank.d.ts b/packages/stargate/types/queries/bank.d.ts new file mode 100644 index 00000000..ad67fe12 --- /dev/null +++ b/packages/stargate/types/queries/bank.d.ts @@ -0,0 +1,14 @@ +import { cosmos } from "../codec"; +import { QueryClient } from "./queryclient"; +export interface BankExtension { + readonly bank: { + readonly balance: (address: string, denom: string) => Promise; + readonly unverified: { + readonly balance: (address: string, denom: string) => Promise; + readonly allBalances: (address: string) => Promise; + readonly totalSupply: () => Promise; + readonly supplyOf: (denom: string) => Promise; + }; + }; +} +export declare function setupBankExtension(base: QueryClient): BankExtension; diff --git a/packages/stargate/types/queries/index.d.ts b/packages/stargate/types/queries/index.d.ts new file mode 100644 index 00000000..3aacc3e3 --- /dev/null +++ b/packages/stargate/types/queries/index.d.ts @@ -0,0 +1,3 @@ +export { QueryClient } from "./queryclient"; +export { AuthExtension, setupAuthExtension } from "./auth"; +export { BankExtension, setupBankExtension } from "./bank"; diff --git a/packages/stargate/types/queries/queryclient.d.ts b/packages/stargate/types/queries/queryclient.d.ts new file mode 100644 index 00000000..c00db57b --- /dev/null +++ b/packages/stargate/types/queries/queryclient.d.ts @@ -0,0 +1,109 @@ +import { Client as TendermintClient } from "@cosmjs/tendermint-rpc"; +declare type QueryExtensionSetup

= (base: QueryClient) => P; +export declare class QueryClient { + /** Constructs a QueryClient with 0 extensions */ + static withExtensions(tmClient: TendermintClient): QueryClient; + /** Constructs a QueryClient with 1 extension */ + static withExtensions( + tmClient: TendermintClient, + setupExtensionA: QueryExtensionSetup, + ): QueryClient & A; + /** Constructs a QueryClient with 2 extensions */ + static withExtensions( + tmClient: TendermintClient, + setupExtensionA: QueryExtensionSetup, + setupExtensionB: QueryExtensionSetup, + ): QueryClient & A & B; + /** Constructs a QueryClient with 3 extensions */ + static withExtensions( + tmClient: TendermintClient, + setupExtensionA: QueryExtensionSetup, + setupExtensionB: QueryExtensionSetup, + setupExtensionC: QueryExtensionSetup, + ): QueryClient & A & B & C; + /** Constructs a QueryClient with 4 extensions */ + static withExtensions( + tmClient: TendermintClient, + setupExtensionA: QueryExtensionSetup, + setupExtensionB: QueryExtensionSetup, + setupExtensionC: QueryExtensionSetup, + setupExtensionD: QueryExtensionSetup, + ): QueryClient & A & B & C & D; + /** Constructs a QueryClient with 5 extensions */ + static withExtensions< + A extends object, + B extends object, + C extends object, + D extends object, + E extends object + >( + tmClient: TendermintClient, + setupExtensionA: QueryExtensionSetup, + setupExtensionB: QueryExtensionSetup, + setupExtensionC: QueryExtensionSetup, + setupExtensionD: QueryExtensionSetup, + setupExtensionE: QueryExtensionSetup, + ): QueryClient & A & B & C & D & E; + /** Constructs a QueryClient with 6 extensions */ + static withExtensions< + A extends object, + B extends object, + C extends object, + D extends object, + E extends object, + F extends object + >( + tmClient: TendermintClient, + setupExtensionA: QueryExtensionSetup, + setupExtensionB: QueryExtensionSetup, + setupExtensionC: QueryExtensionSetup, + setupExtensionD: QueryExtensionSetup, + setupExtensionE: QueryExtensionSetup, + setupExtensionF: QueryExtensionSetup, + ): QueryClient & A & B & C & D & E & F; + /** Constructs a QueryClient with 7 extensions */ + static withExtensions< + A extends object, + B extends object, + C extends object, + D extends object, + E extends object, + F extends object, + G extends object + >( + tmClient: TendermintClient, + setupExtensionA: QueryExtensionSetup, + setupExtensionB: QueryExtensionSetup, + setupExtensionC: QueryExtensionSetup, + setupExtensionD: QueryExtensionSetup, + setupExtensionE: QueryExtensionSetup, + setupExtensionF: QueryExtensionSetup, + setupExtensionG: QueryExtensionSetup, + ): QueryClient & A & B & C & D & E & F & G; + /** Constructs a QueryClient with 8 extensions */ + static withExtensions< + A extends object, + B extends object, + C extends object, + D extends object, + E extends object, + F extends object, + G extends object, + H extends object + >( + tmClient: TendermintClient, + setupExtensionA: QueryExtensionSetup, + setupExtensionB: QueryExtensionSetup, + setupExtensionC: QueryExtensionSetup, + setupExtensionD: QueryExtensionSetup, + setupExtensionE: QueryExtensionSetup, + setupExtensionF: QueryExtensionSetup, + setupExtensionG: QueryExtensionSetup, + setupExtensionH: QueryExtensionSetup, + ): QueryClient & A & B & C & D & E & F & G & H; + private readonly tmClient; + constructor(tmClient: TendermintClient); + queryVerified(store: string, key: Uint8Array): Promise; + queryUnverified(path: string, request: Uint8Array): Promise; +} +export {}; diff --git a/packages/stargate/types/queries/utils.d.ts b/packages/stargate/types/queries/utils.d.ts new file mode 100644 index 00000000..3d99f5c2 --- /dev/null +++ b/packages/stargate/types/queries/utils.d.ts @@ -0,0 +1,11 @@ +/** + * Takes a bech32 encoded address and returns the data part. The prefix is ignored and discarded. + * This is called AccAddress in Cosmos SDK, which is basically an alias for raw binary data. + * The result is typically 20 bytes long but not restricted to that. + */ +export declare function toAccAddress(address: string): Uint8Array; +/** + * Use this to convert a protobuf.js class to the interface (e.g. Coin to ICoin) + * in a ways that makes Jasmine's toEqual happy. + */ +export declare function toObject(thing: I): Omit; diff --git a/packages/stargate/types/stargateclient.d.ts b/packages/stargate/types/stargateclient.d.ts index d641352f..b8c8e460 100644 --- a/packages/stargate/types/stargateclient.d.ts +++ b/packages/stargate/types/stargateclient.d.ts @@ -49,6 +49,7 @@ export interface PrivateStargateClient { } export declare class StargateClient { private readonly tmClient; + private readonly queryClient; private chainId; static connect(endpoint: string): Promise; private constructor(); @@ -68,7 +69,5 @@ export declare class StargateClient { searchTx(query: SearchTxQuery, filter?: SearchTxFilter): Promise; disconnect(): void; broadcastTx(tx: Uint8Array): Promise; - private queryVerified; - private queryUnverified; private txsQuery; } diff --git a/packages/stream/package.json b/packages/stream/package.json index 2fc0b767..679dac1b 100644 --- a/packages/stream/package.json +++ b/packages/stream/package.json @@ -39,7 +39,9 @@ "coverage": "nyc --reporter=text --reporter=lcov yarn test --quiet", "move-types": "shx rm -r ./types/* && shx mv build/types/* ./types && rm -rf ./types/testdata && shx rm -f ./types/*.spec.d.ts", "format-types": "prettier --write --loglevel warn \"./types/**/*.d.ts\"", - "build": "shx rm -rf ./build && tsc && yarn move-types && yarn format-types", + "prebuild": "shx rm -rf ./build", + "build": "tsc", + "postbuild": "yarn move-types && yarn format-types", "build-or-skip": "[ -n \"$SKIP_BUILD\" ] || yarn build", "pack-web": "yarn build-or-skip && webpack --mode development --config webpack.web.config.js" }, diff --git a/packages/tendermint-rpc/package.json b/packages/tendermint-rpc/package.json index be5e4efc..a021075e 100644 --- a/packages/tendermint-rpc/package.json +++ b/packages/tendermint-rpc/package.json @@ -39,7 +39,9 @@ "coverage": "nyc --reporter=text --reporter=lcov yarn test --quiet", "move-types": "shx rm -r ./types/* && shx mv build/types/* ./types && rm -rf ./types/testdata && shx rm -f ./types/*.spec.d.ts && shx rm ./types/**/*.spec.d.ts", "format-types": "prettier --write --loglevel warn \"./types/**/*.d.ts\"", - "build": "shx rm -rf ./build && tsc && yarn move-types && yarn format-types", + "prebuild": "shx rm -rf ./build", + "build": "tsc", + "postbuild": "yarn move-types && yarn format-types", "build-or-skip": "[ -n \"$SKIP_BUILD\" ] || yarn build", "pack-web": "yarn build-or-skip && webpack --mode development --config webpack.web.config.js" }, diff --git a/packages/utils/package.json b/packages/utils/package.json index 4252d9da..9d65b425 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -30,7 +30,9 @@ "lint-fix": "eslint --max-warnings 0 \"**/*.{js,ts}\" --fix", "move-types": "shx rm -r ./types/* && shx mv build/types/* ./types && rm -rf ./types/testdata && shx rm -f ./types/*.spec.d.ts", "format-types": "prettier --write --loglevel warn \"./types/**/*.d.ts\"", - "build": "shx rm -rf ./build && tsc && yarn move-types && yarn format-types", + "prebuild": "shx rm -rf ./build", + "build": "tsc", + "postbuild": "yarn move-types && yarn format-types", "build-or-skip": "[ -n \"$SKIP_BUILD\" ] || yarn build", "test-node": "node jasmine-testrunner.js", "test": "yarn build-or-skip && yarn test-node",