Merge pull request #1484 from cosmos/new-cosmjs-types

Upgrade to new cosmjs-types (Telescope 1.0, big int 🔥)
This commit is contained in:
Simon Warta 2023-10-25 11:54:24 +02:00 committed by GitHub
commit 08200aeb22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
50 changed files with 328 additions and 303 deletions

23
.pnp.cjs generated
View File

@ -1056,7 +1056,7 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
],\
[\
"cosmjs-types",\
"npm:0.8.0"\
"npm:0.9.0"\
],\
[\
"cross-spawn",\
@ -3291,7 +3291,7 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
["axios", "npm:0.21.4"],\
["babylon", "npm:6.18.0"],\
["chalk", "npm:4.1.2"],\
["cosmjs-types", "npm:0.8.0"],\
["cosmjs-types", "npm:0.9.0"],\
["diff", "npm:4.0.2"],\
["eslint", "npm:7.26.0"],\
["eslint-config-prettier", "virtual:4f1584ad4aba8733a24be7c8aebbffafef25607f2d00f4b314cf96717145c692763628a31c2b85d4686fbb091ff21ebffa3cc337399c042c19a32b9bdb786464#npm:8.3.0"],\
@ -3337,7 +3337,7 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
["@types/pako", "npm:1.0.1"],\
["@typescript-eslint/eslint-plugin", "virtual:4f1584ad4aba8733a24be7c8aebbffafef25607f2d00f4b314cf96717145c692763628a31c2b85d4686fbb091ff21ebffa3cc337399c042c19a32b9bdb786464#npm:5.54.0"],\
["@typescript-eslint/parser", "virtual:4f1584ad4aba8733a24be7c8aebbffafef25607f2d00f4b314cf96717145c692763628a31c2b85d4686fbb091ff21ebffa3cc337399c042c19a32b9bdb786464#npm:5.54.0"],\
["cosmjs-types", "npm:0.8.0"],\
["cosmjs-types", "npm:0.9.0"],\
["eslint", "npm:7.26.0"],\
["eslint-config-prettier", "virtual:4f1584ad4aba8733a24be7c8aebbffafef25607f2d00f4b314cf96717145c692763628a31c2b85d4686fbb091ff21ebffa3cc337399c042c19a32b9bdb786464#npm:8.3.0"],\
["eslint-import-resolver-node", "npm:0.3.4"],\
@ -3353,11 +3353,9 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
["karma-firefox-launcher", "npm:2.1.0"],\
["karma-jasmine", "virtual:4f1584ad4aba8733a24be7c8aebbffafef25607f2d00f4b314cf96717145c692763628a31c2b85d4686fbb091ff21ebffa3cc337399c042c19a32b9bdb786464#npm:5.1.0"],\
["karma-jasmine-html-reporter", "virtual:4f1584ad4aba8733a24be7c8aebbffafef25607f2d00f4b314cf96717145c692763628a31c2b85d4686fbb091ff21ebffa3cc337399c042c19a32b9bdb786464#npm:1.6.0"],\
["long", "npm:4.0.0"],\
["nyc", "npm:15.1.0"],\
["pako", "npm:2.0.3"],\
["prettier", "npm:2.8.8"],\
["protobufjs", "npm:6.11.4"],\
["readonly-date", "npm:1.0.0"],\
["ses", "npm:0.11.1"],\
["source-map-support", "npm:0.5.21"],\
@ -3710,7 +3708,7 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
["@types/node", "npm:18.15.11"],\
["@typescript-eslint/eslint-plugin", "virtual:4f1584ad4aba8733a24be7c8aebbffafef25607f2d00f4b314cf96717145c692763628a31c2b85d4686fbb091ff21ebffa3cc337399c042c19a32b9bdb786464#npm:5.54.0"],\
["@typescript-eslint/parser", "virtual:4f1584ad4aba8733a24be7c8aebbffafef25607f2d00f4b314cf96717145c692763628a31c2b85d4686fbb091ff21ebffa3cc337399c042c19a32b9bdb786464#npm:5.54.0"],\
["cosmjs-types", "npm:0.8.0"],\
["cosmjs-types", "npm:0.9.0"],\
["eslint", "npm:7.26.0"],\
["eslint-config-prettier", "virtual:4f1584ad4aba8733a24be7c8aebbffafef25607f2d00f4b314cf96717145c692763628a31c2b85d4686fbb091ff21ebffa3cc337399c042c19a32b9bdb786464#npm:8.3.0"],\
["eslint-import-resolver-node", "npm:0.3.4"],\
@ -3726,7 +3724,6 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
["karma-firefox-launcher", "npm:2.1.0"],\
["karma-jasmine", "virtual:4f1584ad4aba8733a24be7c8aebbffafef25607f2d00f4b314cf96717145c692763628a31c2b85d4686fbb091ff21ebffa3cc337399c042c19a32b9bdb786464#npm:5.1.0"],\
["karma-jasmine-html-reporter", "virtual:4f1584ad4aba8733a24be7c8aebbffafef25607f2d00f4b314cf96717145c692763628a31c2b85d4686fbb091ff21ebffa3cc337399c042c19a32b9bdb786464#npm:1.6.0"],\
["long", "npm:4.0.0"],\
["nyc", "npm:15.1.0"],\
["prettier", "npm:2.8.8"],\
["protobufjs", "npm:6.11.4"],\
@ -3811,7 +3808,7 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
["@types/node", "npm:18.15.11"],\
["@typescript-eslint/eslint-plugin", "virtual:4f1584ad4aba8733a24be7c8aebbffafef25607f2d00f4b314cf96717145c692763628a31c2b85d4686fbb091ff21ebffa3cc337399c042c19a32b9bdb786464#npm:5.54.0"],\
["@typescript-eslint/parser", "virtual:4f1584ad4aba8733a24be7c8aebbffafef25607f2d00f4b314cf96717145c692763628a31c2b85d4686fbb091ff21ebffa3cc337399c042c19a32b9bdb786464#npm:5.54.0"],\
["cosmjs-types", "npm:0.8.0"],\
["cosmjs-types", "npm:0.9.0"],\
["eslint", "npm:7.26.0"],\
["eslint-config-prettier", "virtual:4f1584ad4aba8733a24be7c8aebbffafef25607f2d00f4b314cf96717145c692763628a31c2b85d4686fbb091ff21ebffa3cc337399c042c19a32b9bdb786464#npm:8.3.0"],\
["eslint-import-resolver-node", "npm:0.3.4"],\
@ -3827,10 +3824,8 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
["karma-firefox-launcher", "npm:2.1.0"],\
["karma-jasmine", "virtual:4f1584ad4aba8733a24be7c8aebbffafef25607f2d00f4b314cf96717145c692763628a31c2b85d4686fbb091ff21ebffa3cc337399c042c19a32b9bdb786464#npm:5.1.0"],\
["karma-jasmine-html-reporter", "virtual:4f1584ad4aba8733a24be7c8aebbffafef25607f2d00f4b314cf96717145c692763628a31c2b85d4686fbb091ff21ebffa3cc337399c042c19a32b9bdb786464#npm:1.6.0"],\
["long", "npm:4.0.0"],\
["nyc", "npm:15.1.0"],\
["prettier", "npm:2.8.8"],\
["protobufjs", "npm:6.11.4"],\
["readonly-date", "npm:1.0.0"],\
["ses", "npm:0.11.1"],\
["source-map-support", "npm:0.5.21"],\
@ -7152,12 +7147,10 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
}]\
]],\
["cosmjs-types", [\
["npm:0.8.0", {\
"packageLocation": "./.yarn/cache/cosmjs-types-npm-0.8.0-4c175fd383-99714ec956.zip/node_modules/cosmjs-types/",\
["npm:0.9.0", {\
"packageLocation": "./.yarn/cache/cosmjs-types-npm-0.9.0-e5d36a4ae5-9b00d169ec.zip/node_modules/cosmjs-types/",\
"packageDependencies": [\
["cosmjs-types", "npm:0.8.0"],\
["long", "npm:4.0.0"],\
["protobufjs", "npm:6.11.4"]\
["cosmjs-types", "npm:0.9.0"]\
],\
"linkType": "HARD"\
}]\

Binary file not shown.

BIN
.yarn/cache/cosmjs-types-npm-0.9.0-e5d36a4ae5-9b00d169ec.zip (Stored with Git LFS) vendored Normal file

Binary file not shown.

View File

@ -8,6 +8,10 @@ and this project adheres to
### Changed
- all: Upgrade cosmjs-types to 0.9.0. This makes a few fields non-optional. It
changes all 64 bit int fields from type `long` to `bigint`. As part of the
upgrade, the types do not require the `long` and `protobufjs` anymore.
([#1484])
- Drop support for Node.js 14 and add support for Node.js 20. ([#1421])
- @cosmjs/tendermint-rpc: Remove `Adaptor` abstractions which are not needed
anymore by haing a dedicated client for each backend.
@ -16,6 +20,7 @@ and this project adheres to
`connectComet` for auto-detecting the right client for a provided endpoint.
[#1421]: https://github.com/cosmos/cosmjs/issues/1421
[#1484]: https://github.com/cosmos/cosmjs/pull/1484
### Deprecated

View File

@ -54,7 +54,7 @@
"axios": "^0.21.2",
"babylon": "^6.18.0",
"chalk": "^4",
"cosmjs-types": "^0.8.0",
"cosmjs-types": "^0.9.0",
"diff": "^4",
"recast": "^0.20",
"ts-node": "^8",

View File

@ -46,8 +46,7 @@
"@cosmjs/stargate": "workspace:^",
"@cosmjs/tendermint-rpc": "workspace:^",
"@cosmjs/utils": "workspace:^",
"cosmjs-types": "^0.8.0",
"long": "^4.0.0",
"cosmjs-types": "^0.9.0",
"pako": "^2.0.2"
},
"devDependencies": {
@ -79,7 +78,6 @@
"karma-jasmine-html-reporter": "^1.5.4",
"nyc": "^15.1.0",
"prettier": "^2.8.1",
"protobufjs": "~6.11.4",
"readonly-date": "^1.0.0",
"ses": "^0.11.0",
"source-map-support": "^0.5.19",

View File

@ -339,7 +339,7 @@ export class CosmWasmClient {
return allCodes.map((entry: CodeInfoResponse): Code => {
assert(entry.creator && entry.codeId && entry.dataHash, "entry incomplete");
return {
id: entry.codeId.toNumber(),
id: Number(entry.codeId),
creator: entry.creator,
checksum: toHex(entry.dataHash),
};
@ -356,7 +356,7 @@ export class CosmWasmClient {
"codeInfo missing or incomplete",
);
const codeDetails: CodeDetails = {
id: codeInfo.codeId.toNumber(),
id: Number(codeInfo.codeId),
creator: codeInfo.creator,
checksum: toHex(codeInfo.dataHash),
data: data,
@ -413,7 +413,7 @@ export class CosmWasmClient {
assert(contractInfo.codeId && contractInfo.creator && contractInfo.label, "contractInfo incomplete");
return {
address: retrievedAddress,
codeId: contractInfo.codeId.toNumber(),
codeId: Number(contractInfo.codeId),
creator: contractInfo.creator,
admin: contractInfo.admin || undefined,
label: contractInfo.label,
@ -436,7 +436,7 @@ export class CosmWasmClient {
assert(entry.operation && entry.codeId && entry.msg);
return {
operation: operations[entry.operation],
codeId: entry.codeId.toNumber(),
codeId: Number(entry.codeId),
msg: JSON.parse(fromUtf8(entry.msg)),
};
});

View File

@ -11,7 +11,6 @@ import {
MsgUpdateAdmin,
} from "cosmjs-types/cosmwasm/wasm/v1/tx";
import { AccessType } from "cosmjs-types/cosmwasm/wasm/v1/types";
import Long from "long";
import {
AminoMsgClearAdmin,
@ -27,11 +26,10 @@ import {
describe("AminoTypes", () => {
describe("toAmino", () => {
it("works for MsgStoreCode", () => {
const msg: MsgStoreCode = {
const msg = MsgStoreCode.fromPartial({
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
wasmByteCode: fromBase64("WUVMTE9XIFNVQk1BUklORQ=="),
instantiatePermission: undefined,
};
});
const aminoMsg = new AminoTypes(createWasmAminoConverters()).toAmino({
typeUrl: "/cosmwasm.wasm.v1.MsgStoreCode",
value: msg,
@ -81,7 +79,7 @@ describe("AminoTypes", () => {
{
const msg: MsgInstantiateContract = {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
codeId: Long.fromString("12345"),
codeId: BigInt("12345"),
label: "sticky",
msg: toUtf8(`{"foo":"bar"}`),
funds: coins(1234, "ucosm"),
@ -109,7 +107,7 @@ describe("AminoTypes", () => {
{
const msg: MsgInstantiateContract = {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
codeId: Long.fromString("12345"),
codeId: BigInt("12345"),
label: "sticky",
msg: toUtf8(`{"foo":"bar"}`),
funds: coins(1234, "ucosm"),
@ -139,7 +137,7 @@ describe("AminoTypes", () => {
{
const msg: MsgInstantiateContract2 = {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
codeId: Long.fromString("12345"),
codeId: BigInt("12345"),
label: "sticky",
msg: toUtf8(`{"foo":"bar"}`),
funds: coins(1234, "ucosm"),
@ -171,7 +169,7 @@ describe("AminoTypes", () => {
{
const msg: MsgInstantiateContract2 = {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
codeId: Long.fromString("12345"),
codeId: BigInt("12345"),
label: "sticky",
msg: toUtf8(`{"foo":"bar"}`),
funds: coins(1234, "ucosm"),
@ -267,7 +265,7 @@ describe("AminoTypes", () => {
const msg: MsgMigrateContract = {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
codeId: Long.fromString("98765"),
codeId: BigInt("98765"),
msg: toUtf8(`{"foo":"bar"}`),
};
const aminoMsg = new AminoTypes(createWasmAminoConverters()).toAmino({
@ -297,11 +295,10 @@ describe("AminoTypes", () => {
},
};
const msg = new AminoTypes(createWasmAminoConverters()).fromAmino(aminoMsg);
const expectedValue: MsgStoreCode = {
const expectedValue = MsgStoreCode.fromPartial({
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
wasmByteCode: fromBase64("WUVMTE9XIFNVQk1BUklORQ=="),
instantiatePermission: undefined,
};
});
expect(msg).toEqual({
typeUrl: "/cosmwasm.wasm.v1.MsgStoreCode",
value: expectedValue,
@ -354,7 +351,7 @@ describe("AminoTypes", () => {
const msg = new AminoTypes(createWasmAminoConverters()).fromAmino(aminoMsg);
const expectedValue: MsgInstantiateContract = {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
codeId: Long.fromString("12345"),
codeId: BigInt("12345"),
label: "sticky",
msg: toUtf8(`{"foo":"bar"}`),
funds: coins(1234, "ucosm"),
@ -381,7 +378,7 @@ describe("AminoTypes", () => {
const msg = new AminoTypes(createWasmAminoConverters()).fromAmino(aminoMsg);
const expectedValue: MsgInstantiateContract = {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
codeId: Long.fromString("12345"),
codeId: BigInt("12345"),
label: "sticky",
msg: toUtf8(`{"foo":"bar"}`),
funds: coins(1234, "ucosm"),
@ -471,7 +468,7 @@ describe("AminoTypes", () => {
const expectedValue: MsgMigrateContract = {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
codeId: Long.fromString("98765"),
codeId: BigInt("98765"),
msg: toUtf8(`{"foo":"bar"}`),
};
expect(msg).toEqual({

View File

@ -10,8 +10,7 @@ import {
MsgStoreCode,
MsgUpdateAdmin,
} from "cosmjs-types/cosmwasm/wasm/v1/tx";
import { AccessType } from "cosmjs-types/cosmwasm/wasm/v1/types";
import Long from "long";
import { AccessConfig, AccessType } from "cosmjs-types/cosmwasm/wasm/v1/types";
export function accessTypeFromString(str: string): AccessType {
switch (str) {
@ -51,7 +50,7 @@ export function accessTypeToString(object: any): string {
/**
* @see https://github.com/CosmWasm/wasmd/blob/v0.18.0-rc1/proto/cosmwasm/wasm/v1/types.proto#L36-L41
*/
export interface AccessConfig {
export interface AminoAccessConfig {
/**
* Permission should be one kind of string 'Nobody', 'OnlyAddress', 'Everybody', 'AnyOfAddresses', 'Unspecified'
* @see https://github.com/CosmWasm/wasmd/blob/v0.31.0/x/wasm/types/params.go#L54
@ -77,7 +76,7 @@ export interface AminoMsgStoreCode {
readonly sender: string;
/** Base64 encoded Wasm */
readonly wasm_byte_code: string;
readonly instantiate_permission?: AccessConfig;
readonly instantiate_permission?: AminoAccessConfig;
};
}
@ -226,11 +225,11 @@ export function createWasmAminoConverters(): AminoConverters {
sender: sender,
wasmByteCode: fromBase64(wasm_byte_code),
instantiatePermission: instantiate_permission
? {
? AccessConfig.fromPartial({
permission: accessTypeFromString(instantiate_permission.permission),
address: instantiate_permission.address ?? "",
addresses: instantiate_permission.addresses ?? [],
}
})
: undefined,
}),
},
@ -260,7 +259,7 @@ export function createWasmAminoConverters(): AminoConverters {
admin,
}: AminoMsgInstantiateContract["value"]): MsgInstantiateContract => ({
sender: sender,
codeId: Long.fromString(code_id),
codeId: BigInt(code_id),
label: label,
msg: toUtf8(JSON.stringify(msg)),
funds: [...funds],
@ -299,7 +298,7 @@ export function createWasmAminoConverters(): AminoConverters {
fix_msg,
}: AminoMsgInstantiateContract2["value"]): MsgInstantiateContract2 => ({
sender: sender,
codeId: Long.fromString(code_id),
codeId: BigInt(code_id),
label: label,
msg: toUtf8(JSON.stringify(msg)),
funds: [...funds],
@ -368,7 +367,7 @@ export function createWasmAminoConverters(): AminoConverters {
}: AminoMsgMigrateContract["value"]): MsgMigrateContract => ({
sender: sender,
contract: contract,
codeId: Long.fromString(code_id),
codeId: BigInt(code_id),
msg: toUtf8(JSON.stringify(msg)),
}),
},

View File

@ -14,7 +14,6 @@ import {
import { assert, assertDefined } from "@cosmjs/utils";
import { MsgExecuteContract, MsgInstantiateContract, MsgStoreCode } from "cosmjs-types/cosmwasm/wasm/v1/tx";
import { AbsoluteTxPosition, ContractCodeHistoryOperationType } from "cosmjs-types/cosmwasm/wasm/v1/types";
import Long from "long";
import { SigningCosmWasmClient } from "../../signingcosmwasmclient";
import {
@ -74,7 +73,7 @@ async function instantiateContract(
typeUrl: "/cosmwasm.wasm.v1.MsgInstantiateContract",
value: MsgInstantiateContract.fromPartial({
sender: alice.address0,
codeId: Long.fromNumber(codeId),
codeId: BigInt(codeId),
label: "my escrow",
msg: toUtf8(
JSON.stringify({
@ -161,7 +160,7 @@ describe("WasmExtension", () => {
const { codeInfos } = await client.wasm.listCodeInfo();
assert(codeInfos);
const lastCode = codeInfos[codeInfos.length - 1];
expect(lastCode.codeId.toNumber()).toEqual(hackatomCodeId);
expect(Number(lastCode.codeId)).toEqual(hackatomCodeId);
expect(lastCode.creator).toEqual(alice.address0);
expect(toHex(lastCode.dataHash)).toEqual(toHex(sha256(hackatom.data)));
});
@ -174,7 +173,7 @@ describe("WasmExtension", () => {
const client = await makeWasmClient(wasmd.endpoint);
const { codeInfo, data } = await client.wasm.getCode(hackatomCodeId);
assert(codeInfo);
expect(codeInfo.codeId.toNumber()).toEqual(hackatomCodeId);
expect(Number(codeInfo.codeId)).toEqual(hackatomCodeId);
expect(codeInfo.creator).toEqual(alice.address0);
expect(toHex(codeInfo.dataHash)).toEqual(toHex(sha256(hackatom.data)));
expect(data).toEqual(hackatom.data);
@ -213,18 +212,20 @@ describe("WasmExtension", () => {
const { contractInfo } = await client.wasm.getContractInfo(myAddress);
assert(contractInfo);
expect(contractInfo).toEqual({
codeId: Long.fromNumber(hackatomCodeId, true),
expect(contractInfo).toEqual(
jasmine.objectContaining({
codeId: BigInt(hackatomCodeId),
creator: alice.address0,
label: "my escrow",
admin: "",
ibcPortId: "",
created: AbsoluteTxPosition.fromPartial({
blockHeight: Long.fromNumber(instantiateResult.height, true),
txIndex: Long.UZERO,
blockHeight: BigInt(instantiateResult.height),
txIndex: BigInt(0),
}),
extension: undefined,
});
}),
);
expect(contractInfo.admin).toEqual("");
});
@ -261,7 +262,7 @@ describe("WasmExtension", () => {
assert(history.entries);
expect(history.entries).toContain(
jasmine.objectContaining({
codeId: Long.fromNumber(hackatomCodeId, true),
codeId: BigInt(hackatomCodeId),
operation: ContractCodeHistoryOperationType.CONTRACT_CODE_HISTORY_OPERATION_TYPE_INIT,
msg: toUtf8(
JSON.stringify({

View File

@ -3,15 +3,16 @@ import { createPagination, createProtobufRpcClient, QueryClient } from "@cosmjs/
import {
QueryAllContractStateResponse,
QueryClientImpl,
QueryCodeRequest,
QueryCodeResponse,
QueryCodesResponse,
QueryContractHistoryResponse,
QueryContractInfoResponse,
QueryContractsByCodeRequest,
QueryContractsByCodeResponse,
QueryContractsByCreatorResponse,
QueryRawContractStateResponse,
} from "cosmjs-types/cosmwasm/wasm/v1/query";
import Long from "long";
/**
* An object containing a parsed JSON document. The result of JSON.parse().
@ -88,14 +89,14 @@ export function setupWasmExtension(base: QueryClient): WasmExtension {
return queryService.Codes(request);
},
getCode: async (id: number) => {
const request = { codeId: Long.fromNumber(id) };
const request = QueryCodeRequest.fromPartial({ codeId: BigInt(id) });
return queryService.Code(request);
},
listContractsByCodeId: async (id: number, paginationKey?: Uint8Array) => {
const request = {
codeId: Long.fromNumber(id),
const request = QueryContractsByCodeRequest.fromPartial({
codeId: BigInt(id),
pagination: createPagination(paginationKey),
};
});
return queryService.ContractsByCode(request);
},
listContractsByCreator: async (creator: string, paginationKey?: Uint8Array) => {

View File

@ -15,15 +15,14 @@ import {
} from "@cosmjs/stargate";
import { assert, sleep } from "@cosmjs/utils";
import { DeepPartial } from "cosmjs-types";
import { BinaryWriter } from "cosmjs-types/binary";
import { MsgSend } from "cosmjs-types/cosmos/bank/v1beta1/tx";
import { Coin } from "cosmjs-types/cosmos/base/v1beta1/coin";
import { MsgDelegate } from "cosmjs-types/cosmos/staking/v1beta1/tx";
import { AuthInfo, TxBody, TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
import { MsgExecuteContract, MsgStoreCode } from "cosmjs-types/cosmwasm/wasm/v1/tx";
import { AccessConfig, AccessType } from "cosmjs-types/cosmwasm/wasm/v1/types";
import Long from "long";
import pako from "pako";
import protobuf from "protobufjs/minimal";
import { instantiate2Address } from "./instantiate2";
import { MsgExecuteContractEncodeObject, MsgStoreCodeEncodeObject } from "./modules";
@ -481,7 +480,7 @@ describe("SigningCosmWasmClient", () => {
assert(contractInfo2);
expect({ ...contractInfo2 }).toEqual({
...contractInfo1,
codeId: Long.fromNumber(codeId2, true),
codeId: BigInt(codeId2),
});
client.disconnect();
@ -526,7 +525,7 @@ describe("SigningCosmWasmClient", () => {
assert(contractInfo2);
expect({ ...contractInfo2 }).toEqual({
...contractInfo1,
codeId: Long.fromNumber(codeId2, true),
codeId: BigInt(codeId2),
});
client.disconnect();
@ -879,7 +878,7 @@ describe("SigningCosmWasmClient", () => {
// From ModifyingDirectSecp256k1HdWallet
expect(tx.body.memo).toEqual("This was modified");
expect({ ...tx.authInfo.fee!.amount[0] }).toEqual(coin(3000, "ucosm"));
expect(tx.authInfo.fee!.gasLimit.toNumber()).toEqual(333333);
expect(Number(tx.authInfo.fee!.gasLimit)).toEqual(333333);
client.disconnect();
});
@ -949,11 +948,10 @@ describe("SigningCosmWasmClient", () => {
});
const { data } = getHackatom();
const msgStoreCode: MsgStoreCode = {
const msgStoreCode = MsgStoreCode.fromPartial({
sender: alice.address0,
wasmByteCode: pako.gzip(data),
instantiatePermission: undefined,
};
});
const msgAny: MsgStoreCodeEncodeObject = {
typeUrl: "/cosmwasm.wasm.v1.MsgStoreCode",
value: msgStoreCode,
@ -985,11 +983,9 @@ describe("SigningCosmWasmClient", () => {
customValidatorAddress: "",
};
const CustomMsgDelegate = {
typeUrl: "foobar",
// Adapted from autogenerated MsgDelegate implementation
encode(
message: CustomMsgDelegate,
writer: protobuf.Writer = protobuf.Writer.create(),
): protobuf.Writer {
encode(message: CustomMsgDelegate, writer: BinaryWriter = BinaryWriter.create()): BinaryWriter {
writer.uint32(10).string(message.customDelegatorAddress ?? "");
writer.uint32(18).string(message.customValidatorAddress ?? "");
if (message.customAmount !== undefined) {
@ -1118,7 +1114,7 @@ describe("SigningCosmWasmClient", () => {
// From ModifyingSecp256k1HdWallet
expect(tx.body.memo).toEqual("This was modified");
expect({ ...tx.authInfo.fee!.amount[0] }).toEqual(coin(3000, "ucosm"));
expect(tx.authInfo.fee!.gasLimit.toNumber()).toEqual(333333);
expect(Number(tx.authInfo.fee!.gasLimit)).toEqual(333333);
client.disconnect();
});
@ -1187,7 +1183,7 @@ describe("SigningCosmWasmClient", () => {
// From ModifyingDirectSecp256k1HdWallet
expect(body.memo).toEqual("This was modified");
expect({ ...authInfo.fee!.amount[0] }).toEqual(coin(3000, "ucosm"));
expect(authInfo.fee!.gasLimit.toNumber()).toEqual(333333);
expect(Number(authInfo.fee!.gasLimit)).toEqual(333333);
// ensure signature is valid
const result = await client.broadcastTx(Uint8Array.from(TxRaw.encode(signed).finish()));
@ -1275,11 +1271,9 @@ describe("SigningCosmWasmClient", () => {
customValidatorAddress: "",
};
const CustomMsgDelegate = {
typeUrl: "foobar",
// Adapted from autogenerated MsgDelegate implementation
encode(
message: CustomMsgDelegate,
writer: protobuf.Writer = protobuf.Writer.create(),
): protobuf.Writer {
encode(message: CustomMsgDelegate, writer: BinaryWriter = BinaryWriter.create()): BinaryWriter {
writer.uint32(10).string(message.customDelegatorAddress ?? "");
writer.uint32(18).string(message.customValidatorAddress ?? "");
if (message.customAmount !== undefined && message.customAmount !== undefined) {
@ -1405,7 +1399,7 @@ describe("SigningCosmWasmClient", () => {
// From ModifyingSecp256k1HdWallet
expect(body.memo).toEqual("This was modified");
expect({ ...authInfo.fee!.amount[0] }).toEqual(coin(3000, "ucosm"));
expect(authInfo.fee!.gasLimit.toNumber()).toEqual(333333);
expect(Number(authInfo.fee!.gasLimit)).toEqual(333333);
// ensure signature is valid
const result = await client.broadcastTx(Uint8Array.from(TxRaw.encode(signed).finish()));

View File

@ -47,7 +47,6 @@ import {
MsgUpdateAdmin,
} from "cosmjs-types/cosmwasm/wasm/v1/tx";
import { AccessConfig } from "cosmjs-types/cosmwasm/wasm/v1/types";
import Long from "long";
import pako from "pako";
import { CosmWasmClient } from "./cosmwasmclient";
@ -317,7 +316,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
typeUrl: "/cosmwasm.wasm.v1.MsgInstantiateContract",
value: MsgInstantiateContract.fromPartial({
sender: senderAddress,
codeId: Long.fromString(new Uint53(codeId).toString()),
codeId: BigInt(new Uint53(codeId).toString()),
label: label,
msg: toUtf8(JSON.stringify(msg)),
funds: [...(options.funds || [])],
@ -354,7 +353,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
typeUrl: "/cosmwasm.wasm.v1.MsgInstantiateContract2",
value: MsgInstantiateContract2.fromPartial({
sender: senderAddress,
codeId: Long.fromString(new Uint53(codeId).toString()),
codeId: BigInt(new Uint53(codeId).toString()),
label: label,
msg: toUtf8(JSON.stringify(msg)),
funds: [...(options.funds || [])],
@ -449,7 +448,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
value: MsgMigrateContract.fromPartial({
sender: senderAddress,
contract: contractAddress,
codeId: Long.fromString(new Uint53(codeId).toString()),
codeId: BigInt(new Uint53(codeId).toString()),
msg: toUtf8(JSON.stringify(migrateMsg)),
}),
};

View File

@ -19,6 +19,7 @@ import {
setupBankExtension,
} from "@cosmjs/stargate";
import { Tendermint34Client } from "@cosmjs/tendermint-rpc";
import { assertDefinedAndNotNull } from "@cosmjs/utils";
import { SignMode } from "cosmjs-types/cosmos/tx/signing/v1beta1/signing";
import { AuthInfo, SignDoc, TxBody } from "cosmjs-types/cosmos/tx/v1beta1/tx";
@ -219,10 +220,13 @@ export class ModifyingDirectSecp256k1HdWallet extends DirectSecp256k1HdWallet {
memo: "This was modified",
});
const authInfo = AuthInfo.decode(signDoc.authInfoBytes);
const signers = authInfo.signerInfos.map((signerInfo) => ({
pubkey: signerInfo.publicKey!,
sequence: signerInfo.sequence.toNumber(),
}));
const signers = authInfo.signerInfos.map((signerInfo) => {
assertDefinedAndNotNull(signerInfo.publicKey);
return {
pubkey: signerInfo.publicKey,
sequence: Number(signerInfo.sequence),
};
});
const modifiedFeeAmount = coins(3000, "ucosm");
const modifiedGasLimit = 333333;
const modifiedFeeGranter = undefined;

View File

@ -44,8 +44,7 @@
"@cosmjs/encoding": "workspace:^",
"@cosmjs/math": "workspace:^",
"@cosmjs/utils": "workspace:^",
"cosmjs-types": "^0.8.0",
"long": "^4.0.0"
"cosmjs-types": "^0.9.0"
},
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "^1.0.1",

View File

@ -3,7 +3,6 @@ import { MsgSend } from "cosmjs-types/cosmos/bank/v1beta1/tx";
import { PubKey } from "cosmjs-types/cosmos/crypto/secp256k1/keys";
import { SignMode } from "cosmjs-types/cosmos/tx/signing/v1beta1/signing";
import { Any } from "cosmjs-types/google/protobuf/any";
import Long from "long";
import { decodeTxRaw } from "./decode";
import { faucet, testVectors } from "./testutils.spec";
@ -46,11 +45,11 @@ describe("decode", () => {
},
multi: undefined,
},
sequence: Long.UZERO,
sequence: BigInt(0),
},
],
fee: {
gasLimit: Long.fromNumber(200000, true),
gasLimit: BigInt(200000),
payer: "",
granter: "",
amount: [{ amount: "2000", denom: "ucosm" }],
@ -58,7 +57,7 @@ describe("decode", () => {
}),
body: {
memo: "",
timeoutHeight: Long.UZERO,
timeoutHeight: BigInt(0),
messages: [expectedMsg],
extensionOptions: [],
nonCriticalExtensionOptions: [],

View File

@ -8,7 +8,7 @@ export {
} from "./directsecp256k1hdwallet";
export { DirectSecp256k1Wallet } from "./directsecp256k1wallet";
export { makeCosmoshubPath } from "./paths";
export { anyToSinglePubkey, decodePubkey, encodePubkey } from "./pubkey";
export { anyToSinglePubkey, decodeOptionalPubkey, decodePubkey, encodePubkey } from "./pubkey";
export {
DecodeObject,
EncodeObject,

View File

@ -97,6 +97,30 @@ export function decodePubkey(pubkey: Any): Pubkey {
return out;
}
default:
throw new Error(`Pubkey type_url ${pubkey.typeUrl} not recognized`);
throw new Error(`Pubkey type URL '${pubkey.typeUrl}' not recognized`);
}
}
/**
* Decodes an optional pubkey from a protobuf `Any` into `Pubkey | null`.
* This supports single pubkeys such as Cosmos ed25519 and secp256k1 keys
* as well as multisig threshold pubkeys.
*/
export function decodeOptionalPubkey(pubkey: Any | null | undefined): Pubkey | null {
if (!pubkey) return null;
if (pubkey.typeUrl) {
if (pubkey.value.length) {
// both set
return decodePubkey(pubkey);
} else {
throw new Error(`Pubkey is an Any with type URL '${pubkey.typeUrl}' but an empty value`);
}
} else {
if (pubkey.value.length) {
throw new Error(`Pubkey is an Any with an empty type URL but a value set`);
} else {
// both unset, assuming this empty instance means null
return null;
}
}
}

View File

@ -4,7 +4,6 @@ import { assert } from "@cosmjs/utils";
import { MsgSend as IMsgSend } from "cosmjs-types/cosmos/bank/v1beta1/tx";
import { TxBody } from "cosmjs-types/cosmos/tx/v1beta1/tx";
import { Any } from "cosmjs-types/google/protobuf/any";
import Long from "long";
import { Field, Type } from "protobufjs";
import { isPbjsGeneratedType, isTsProtoGeneratedType, Registry } from "./registry";
@ -36,7 +35,7 @@ describe("registry demo", () => {
const txBody = TxBody.fromPartial({
messages: [msgSendWrapped],
memo: "Some memo",
timeoutHeight: Long.fromNumber(9999),
timeoutHeight: BigInt(9999),
extensionOptions: [],
});
const txBodyBytes = TxBody.encode(txBody).finish();
@ -84,7 +83,7 @@ describe("registry demo", () => {
const txBody = TxBody.fromPartial({
messages: [msgDemoWrapped],
memo: "Some memo",
timeoutHeight: Long.fromNumber(9999),
timeoutHeight: BigInt(9999),
extensionOptions: [],
});
const txBodyBytes = TxBody.encode(txBody).finish();

View File

@ -1,11 +1,29 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { BinaryWriter } from "cosmjs-types/binary";
import { MsgSend } from "cosmjs-types/cosmos/bank/v1beta1/tx";
import { Coin } from "cosmjs-types/cosmos/base/v1beta1/coin";
import { TxBody } from "cosmjs-types/cosmos/tx/v1beta1/tx";
import { Any } from "cosmjs-types/google/protobuf/any";
import Long from "long";
import type protobuf from "protobufjs";
/**
* A type generated by Telescope 1.0.
*/
export interface TelescopeGeneratedType {
/** This may or may not exist depending on the code generator settings. Don't rely on it. */
readonly typeUrl?: string;
readonly encode: (
message:
| any
| {
[k: string]: any;
},
writer?: BinaryWriter,
) => BinaryWriter;
readonly decode: (input: Uint8Array, length?: number) => any;
readonly fromPartial: (object: any) => any;
}
/**
* A type generated by [ts-proto](https://github.com/stephenh/ts-proto).
*/
@ -30,7 +48,12 @@ export interface PbjsGeneratedType {
readonly decode: (reader: protobuf.Reader | Uint8Array, length?: number) => any;
}
export type GeneratedType = TsProtoGeneratedType | PbjsGeneratedType;
export type GeneratedType = TelescopeGeneratedType | TsProtoGeneratedType | PbjsGeneratedType;
export function isTelescopeGeneratedType(type: GeneratedType): type is TelescopeGeneratedType {
const casted = type as TelescopeGeneratedType;
return typeof casted.fromPartial === "function" && typeof casted.typeUrl == "string";
}
export function isTsProtoGeneratedType(type: GeneratedType): type is TsProtoGeneratedType {
return typeof (type as TsProtoGeneratedType).fromPartial === "function";
@ -60,7 +83,7 @@ export interface EncodeObject {
interface TxBodyValue {
readonly messages: readonly EncodeObject[];
readonly memo?: string;
readonly timeoutHeight?: Long;
readonly timeoutHeight?: bigint;
readonly extensionOptions?: Any[];
readonly nonCriticalExtensionOptions?: Any[];
}
@ -144,7 +167,10 @@ export class Registry {
return this.encodeTxBody(value);
}
const type = this.lookupTypeWithError(typeUrl);
const instance = isTsProtoGeneratedType(type) ? type.fromPartial(value) : type.create(value);
const instance =
isTelescopeGeneratedType(type) || isTsProtoGeneratedType(type)
? type.fromPartial(value)
: type.create(value);
return type.encode(instance).finish();
}
@ -164,6 +190,7 @@ export class Registry {
const wrappedMessages = txBodyFields.messages.map((message) => this.encodeAsAny(message));
const txBody = TxBody.fromPartial({
...txBodyFields,
timeoutHeight: BigInt(txBodyFields.timeoutHeight?.toString() ?? "0"),
messages: wrappedMessages,
});
return TxBody.encode(txBody).finish();

View File

@ -4,7 +4,6 @@ import { Coin } from "cosmjs-types/cosmos/base/v1beta1/coin";
import { SignMode } from "cosmjs-types/cosmos/tx/signing/v1beta1/signing";
import { AuthInfo, SignDoc, SignerInfo } from "cosmjs-types/cosmos/tx/v1beta1/tx";
import { Any } from "cosmjs-types/google/protobuf/any";
import Long from "long";
/**
* Create signer infos from the provided signers.
@ -12,7 +11,7 @@ import Long from "long";
* This implementation does not support different signing modes for the different signers.
*/
function makeSignerInfos(
signers: ReadonlyArray<{ readonly pubkey: Any; readonly sequence: number }>,
signers: ReadonlyArray<{ readonly pubkey: Any; readonly sequence: number | bigint }>,
signMode: SignMode,
): SignerInfo[] {
return signers.map(
@ -21,7 +20,7 @@ function makeSignerInfos(
modeInfo: {
single: { mode: signMode },
},
sequence: Long.fromNumber(sequence),
sequence: BigInt(sequence),
}),
);
}
@ -32,7 +31,7 @@ function makeSignerInfos(
* This implementation does not support different signing modes for the different signers.
*/
export function makeAuthInfoBytes(
signers: ReadonlyArray<{ readonly pubkey: Any; readonly sequence: number }>,
signers: ReadonlyArray<{ readonly pubkey: Any; readonly sequence: bigint | number }>,
feeAmount: readonly Coin[],
gasLimit: number,
feeGranter: string | undefined,
@ -50,7 +49,7 @@ export function makeAuthInfoBytes(
signerInfos: makeSignerInfos(signers, signMode),
fee: {
amount: [...feeAmount],
gasLimit: Long.fromNumber(gasLimit),
gasLimit: BigInt(gasLimit),
granter: feeGranter,
payer: feePayer,
},
@ -68,7 +67,7 @@ export function makeSignDoc(
bodyBytes: bodyBytes,
authInfoBytes: authInfoBytes,
chainId: chainId,
accountNumber: Long.fromNumber(accountNumber),
accountNumber: BigInt(accountNumber),
};
}

View File

@ -46,9 +46,7 @@
"@cosmjs/stream": "workspace:^",
"@cosmjs/tendermint-rpc": "workspace:^",
"@cosmjs/utils": "workspace:^",
"cosmjs-types": "^0.8.0",
"long": "^4.0.0",
"protobufjs": "~6.11.4",
"cosmjs-types": "^0.9.0",
"xstream": "^11.14.0"
},
"devDependencies": {

View File

@ -1,6 +1,6 @@
import { Pubkey } from "@cosmjs/amino";
import { Uint64 } from "@cosmjs/math";
import { decodePubkey } from "@cosmjs/proto-signing";
import { decodeOptionalPubkey } from "@cosmjs/proto-signing";
import { assert } from "@cosmjs/utils";
import { BaseAccount, ModuleAccount } from "cosmjs-types/cosmos/auth/v1beta1/auth";
import {
@ -10,7 +10,6 @@ import {
PeriodicVestingAccount,
} from "cosmjs-types/cosmos/vesting/v1beta1/vesting";
import { Any } from "cosmjs-types/google/protobuf/any";
import Long from "long";
export interface Account {
/** Bech32 account address */
@ -20,13 +19,13 @@ export interface Account {
readonly sequence: number;
}
function uint64FromProto(input: number | Long): Uint64 {
function uint64FromProto(input: number | bigint): Uint64 {
return Uint64.fromString(input.toString());
}
function accountFromBaseAccount(input: BaseAccount): Account {
const { address, pubKey, accountNumber, sequence } = input;
const pubkey = pubKey ? decodePubkey(pubKey) : null;
const pubkey = decodeOptionalPubkey(pubKey);
return {
address: address,
pubkey: pubkey,

View File

@ -4,7 +4,6 @@ import { Tendermint34Client } from "@cosmjs/tendermint-rpc";
import { assert } from "@cosmjs/utils";
import { BaseAccount } from "cosmjs-types/cosmos/auth/v1beta1/auth";
import { Any } from "cosmjs-types/google/protobuf/any";
import Long from "long";
import { QueryClient } from "../../queryclient";
import { nonExistentAddress, pendingWithoutSimapp, simapp, unused, validator } from "../../testutils.spec";
@ -26,12 +25,13 @@ describe("AuthExtension", () => {
assert(account);
expect(account.typeUrl).toEqual("/cosmos.auth.v1beta1.BaseAccount");
expect(BaseAccount.decode(account.value)).toEqual({
expect(BaseAccount.decode(account.value)).toEqual(
jasmine.objectContaining({
address: unused.address,
pubKey: undefined,
accountNumber: Long.fromNumber(unused.accountNumber, true),
sequence: Long.UZERO,
});
accountNumber: BigInt(unused.accountNumber),
sequence: BigInt(0),
}),
);
tmClient.disconnect();
});
@ -46,8 +46,8 @@ describe("AuthExtension", () => {
expect(BaseAccount.decode(account.value)).toEqual({
address: validator.delegatorAddress,
pubKey: Any.fromPartial(encodePubkey(validator.pubkey)),
accountNumber: Long.UZERO,
sequence: Long.fromNumber(validator.sequence, true),
accountNumber: BigInt(0),
sequence: BigInt(validator.sequence),
});
tmClient.disconnect();

View File

@ -1,7 +1,12 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { assert } from "@cosmjs/utils";
import { Metadata } from "cosmjs-types/cosmos/bank/v1beta1/bank";
import { QueryClientImpl, QueryTotalSupplyResponse } from "cosmjs-types/cosmos/bank/v1beta1/query";
import {
QueryAllBalancesRequest,
QueryClientImpl,
QueryDenomsMetadataRequest,
QueryTotalSupplyResponse,
} from "cosmjs-types/cosmos/bank/v1beta1/query";
import { Coin } from "cosmjs-types/cosmos/base/v1beta1/coin";
import { createPagination, createProtobufRpcClient, QueryClient } from "../../queryclient";
@ -31,7 +36,9 @@ export function setupBankExtension(base: QueryClient): BankExtension {
return balance;
},
allBalances: async (address: string) => {
const { balances } = await queryService.AllBalances({ address: address });
const { balances } = await queryService.AllBalances(
QueryAllBalancesRequest.fromPartial({ address: address }),
);
return balances;
},
totalSupply: async (paginationKey?: Uint8Array) => {
@ -51,9 +58,11 @@ export function setupBankExtension(base: QueryClient): BankExtension {
return metadata;
},
denomsMetadata: async () => {
const { metadatas } = await queryService.DenomsMetadata({
const { metadatas } = await queryService.DenomsMetadata(
QueryDenomsMetadataRequest.fromPartial({
pagination: undefined, // Not implemented
});
}),
);
return metadatas;
},
},

View File

@ -11,7 +11,6 @@ import {
QueryValidatorOutstandingRewardsResponse,
QueryValidatorSlashesResponse,
} from "cosmjs-types/cosmos/distribution/v1beta1/query";
import Long from "long";
import { createPagination, createProtobufRpcClient, QueryClient } from "../../queryclient";
@ -100,8 +99,8 @@ export function setupDistributionExtension(base: QueryClient): DistributionExten
) => {
const response = await queryService.ValidatorSlashes({
validatorAddress: validatorAddress,
startingHeight: Long.fromNumber(startingHeight, true),
endingHeight: Long.fromNumber(endingHeight, true),
startingHeight: BigInt(startingHeight),
endingHeight: BigInt(endingHeight),
pagination: createPagination(paginationKey),
});
return response;

View File

@ -1,7 +1,6 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { TextProposal, VoteOption } from "cosmjs-types/cosmos/gov/v1beta1/gov";
import { MsgDeposit, MsgSubmitProposal, MsgVote, MsgVoteWeighted } from "cosmjs-types/cosmos/gov/v1beta1/tx";
import Long from "long";
import { AminoTypes } from "../../aminotypes";
import {
@ -18,7 +17,7 @@ describe("AminoTypes", () => {
const msg: MsgDeposit = {
amount: [{ amount: "12300000", denom: "ustake" }],
depositor: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
proposalId: Long.fromNumber(5),
proposalId: BigInt(5),
};
const aminoTypes = new AminoTypes(createGovAminoConverters());
const aminoMsg = aminoTypes.toAmino({
@ -73,7 +72,7 @@ describe("AminoTypes", () => {
it("works for MsgVote", () => {
const msg: MsgVote = {
option: VoteOption.VOTE_OPTION_NO_WITH_VETO,
proposalId: Long.fromNumber(5),
proposalId: BigInt(5),
voter: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
};
const aminoTypes = new AminoTypes(createGovAminoConverters());
@ -94,7 +93,7 @@ describe("AminoTypes", () => {
it("works for MsgVoteWeighted", () => {
const msg: MsgVoteWeighted = {
proposalId: Long.fromNumber(5),
proposalId: BigInt(5),
voter: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
options: [
{ option: VoteOption.VOTE_OPTION_NO_WITH_VETO, weight: "700000000000000000" /* 0.7 */ },
@ -135,7 +134,7 @@ describe("AminoTypes", () => {
const expectedValue: MsgDeposit = {
amount: [{ amount: "12300000", denom: "ustake" }],
depositor: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
proposalId: Long.fromNumber(5),
proposalId: BigInt(5),
};
expect(msg).toEqual({
typeUrl: "/cosmos.gov.v1beta1.MsgDeposit",
@ -188,7 +187,7 @@ describe("AminoTypes", () => {
const msg = new AminoTypes(createGovAminoConverters()).fromAmino(aminoMsg);
const expectedValue: MsgVote = {
option: VoteOption.VOTE_OPTION_NO_WITH_VETO,
proposalId: Long.fromNumber(5),
proposalId: BigInt(5),
voter: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
};
expect(msg).toEqual({
@ -211,7 +210,7 @@ describe("AminoTypes", () => {
};
const msg = new AminoTypes(createGovAminoConverters()).fromAmino(aminoMsg);
const expectedValue: MsgVoteWeighted = {
proposalId: Long.fromNumber(5),
proposalId: BigInt(5),
voter: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
options: [
{ option: VoteOption.VOTE_OPTION_NO_WITH_VETO, weight: "750000000000000000" },

View File

@ -5,7 +5,6 @@ import { assert, assertDefinedAndNotNull, isNonNullObject } from "@cosmjs/utils"
import { TextProposal, voteOptionFromJSON } from "cosmjs-types/cosmos/gov/v1beta1/gov";
import { MsgDeposit, MsgSubmitProposal, MsgVote, MsgVoteWeighted } from "cosmjs-types/cosmos/gov/v1beta1/tx";
import { Any } from "cosmjs-types/google/protobuf/any";
import Long from "long";
import { AminoConverters } from "../../aminotypes";
import { decodeCosmosSdkDecFromProto } from "../../queryclient";
@ -120,7 +119,7 @@ export function createGovAminoConverters(): AminoConverters {
return {
amount: Array.from(amount),
depositor,
proposalId: Long.fromString(proposal_id),
proposalId: BigInt(proposal_id),
};
},
},
@ -136,7 +135,7 @@ export function createGovAminoConverters(): AminoConverters {
fromAmino: ({ option, proposal_id, voter }: AminoMsgVote["value"]): MsgVote => {
return {
option: voteOptionFromJSON(option),
proposalId: Long.fromString(proposal_id),
proposalId: BigInt(proposal_id),
voter: voter,
};
},
@ -157,7 +156,7 @@ export function createGovAminoConverters(): AminoConverters {
},
fromAmino: ({ options, proposal_id, voter }: AminoMsgVoteWeighted["value"]): MsgVoteWeighted => {
return {
proposalId: Long.fromString(proposal_id),
proposalId: BigInt(proposal_id),
voter: voter,
options: options.map((o) => ({
option: voteOptionFromJSON(o.option),

View File

@ -11,7 +11,6 @@ import {
WeightedVoteOption,
} from "cosmjs-types/cosmos/gov/v1beta1/gov";
import { Any } from "cosmjs-types/google/protobuf/any";
import Long from "long";
import { longify, QueryClient } from "../../queryclient";
import { SigningStargateClient } from "../../signingstargateclient";
@ -161,7 +160,7 @@ describe("GovExtension", () => {
depositParams: {
minDeposit: simapp.govMinDeposit,
maxDepositPeriod: {
seconds: Long.fromNumber(172800, false),
seconds: BigInt(172800),
nanos: 0,
},
},
@ -199,7 +198,7 @@ describe("GovExtension", () => {
jasmine.objectContaining({
votingParams: {
votingPeriod: {
seconds: Long.fromNumber(172800, false),
seconds: BigInt(172800),
nanos: 0,
},
},
@ -230,11 +229,11 @@ describe("GovExtension", () => {
proposalId: longify(proposalId),
status: ProposalStatus.PROPOSAL_STATUS_VOTING_PERIOD,
finalTallyResult: { yes: "0", abstain: "0", no: "0", noWithVeto: "0" },
submitTime: { seconds: jasmine.any(Long), nanos: jasmine.any(Number) },
depositEndTime: { seconds: jasmine.any(Long), nanos: jasmine.any(Number) },
submitTime: { seconds: jasmine.anything(), nanos: jasmine.any(Number) },
depositEndTime: { seconds: jasmine.anything(), nanos: jasmine.any(Number) },
totalDeposit: initialDeposit,
votingStartTime: { seconds: jasmine.any(Long), nanos: jasmine.any(Number) },
votingEndTime: { seconds: jasmine.any(Long), nanos: jasmine.any(Number) },
votingStartTime: { seconds: jasmine.anything(), nanos: jasmine.any(Number) },
votingEndTime: { seconds: jasmine.anything(), nanos: jasmine.any(Number) },
});
tmClient.disconnect();
@ -256,11 +255,12 @@ describe("GovExtension", () => {
proposalId: longify(proposalId),
status: ProposalStatus.PROPOSAL_STATUS_VOTING_PERIOD,
finalTallyResult: { yes: "0", abstain: "0", no: "0", noWithVeto: "0" },
submitTime: { seconds: jasmine.any(Long), nanos: jasmine.any(Number) },
depositEndTime: { seconds: jasmine.any(Long), nanos: jasmine.any(Number) },
// Note: jasmine.any(Bigint) does not seem to work as expected in Jasmine 4.6
submitTime: { seconds: jasmine.anything(), nanos: jasmine.any(Number) },
depositEndTime: { seconds: jasmine.anything(), nanos: jasmine.any(Number) },
totalDeposit: initialDeposit,
votingStartTime: { seconds: jasmine.any(Long), nanos: jasmine.any(Number) },
votingEndTime: { seconds: jasmine.any(Long), nanos: jasmine.any(Number) },
votingStartTime: { seconds: jasmine.anything(), nanos: jasmine.any(Number) },
votingEndTime: { seconds: jasmine.anything(), nanos: jasmine.any(Number) },
});
tmClient.disconnect();

View File

@ -11,13 +11,12 @@ import {
QueryVoteResponse,
QueryVotesResponse,
} from "cosmjs-types/cosmos/gov/v1beta1/query";
import Long from "long";
import { createPagination, createProtobufRpcClient, longify, QueryClient } from "../../queryclient";
export type GovParamsType = "deposit" | "tallying" | "voting";
export type GovProposalId = string | number | Long | Uint64;
export type GovProposalId = string | number | Uint64;
export interface GovExtension {
readonly gov: {

View File

@ -1,7 +1,6 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { coin } from "@cosmjs/proto-signing";
import { MsgTransfer } from "cosmjs-types/ibc/applications/transfer/v1/tx";
import Long from "long";
import { AminoTypes } from "../../aminotypes";
import { AminoMsgTransfer, createIbcAminoConverters } from "./aminomessages";
@ -16,10 +15,10 @@ describe("AminoTypes", () => {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
receiver: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
timeoutHeight: {
revisionHeight: Long.fromString("123", true),
revisionNumber: Long.fromString("456", true),
revisionHeight: BigInt("123"),
revisionNumber: BigInt("456"),
},
timeoutTimestamp: Long.fromString("789", true),
timeoutTimestamp: BigInt("789"),
memo: "",
};
const aminoTypes = new AminoTypes(createIbcAminoConverters());
@ -54,10 +53,10 @@ describe("AminoTypes", () => {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
receiver: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
timeoutHeight: {
revisionHeight: Long.UZERO,
revisionNumber: Long.UZERO,
revisionHeight: BigInt(0),
revisionNumber: BigInt(0),
},
timeoutTimestamp: Long.UZERO,
timeoutTimestamp: BigInt(0),
memo: "",
};
const aminoTypes = new AminoTypes(createIbcAminoConverters());
@ -85,16 +84,16 @@ describe("AminoTypes", () => {
});
it("works for MsgTransfer with no height timeout", () => {
const msg: MsgTransfer = {
const msg = MsgTransfer.fromPartial({
sourcePort: "testport",
sourceChannel: "testchannel",
token: coin(1234, "utest"),
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
receiver: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
timeoutHeight: undefined,
timeoutTimestamp: Long.UZERO,
timeoutTimestamp: BigInt(0),
memo: "",
};
});
const aminoMsg = new AminoTypes(createIbcAminoConverters()).toAmino({
typeUrl: "/ibc.applications.transfer.v1.MsgTransfer",
value: msg,
@ -107,7 +106,10 @@ describe("AminoTypes", () => {
token: coin(1234, "utest"),
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
receiver: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
timeout_height: {},
timeout_height: {
revision_number: undefined,
revision_height: undefined,
},
timeout_timestamp: undefined,
memo: undefined,
},
@ -141,10 +143,10 @@ describe("AminoTypes", () => {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
receiver: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
timeoutHeight: {
revisionHeight: Long.fromString("123", true),
revisionNumber: Long.fromString("456", true),
revisionHeight: BigInt("123"),
revisionNumber: BigInt("456"),
},
timeoutTimestamp: Long.fromString("789", true),
timeoutTimestamp: BigInt("789"),
memo: "",
};
expect(msg).toEqual({
@ -177,10 +179,10 @@ describe("AminoTypes", () => {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
receiver: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
timeoutHeight: {
revisionHeight: Long.UZERO,
revisionNumber: Long.UZERO,
revisionHeight: BigInt(0),
revisionNumber: BigInt(0),
},
timeoutTimestamp: Long.UZERO,
timeoutTimestamp: BigInt(0),
memo: "",
};
expect(msg).toEqual({

View File

@ -1,7 +1,6 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { AminoMsg, Coin } from "@cosmjs/amino";
import { MsgTransfer } from "cosmjs-types/ibc/applications/transfer/v1/tx";
import Long from "long";
import { AminoConverters } from "../../aminotypes";
@ -46,7 +45,7 @@ export function isAminoMsgTransfer(msg: AminoMsg): msg is AminoMsgTransfer {
return msg.type === "cosmos-sdk/MsgTransfer";
}
function omitDefault<T extends string | number | Long>(input: T): T | undefined {
function omitDefault<T extends string | number | bigint>(input: T): T | undefined {
if (typeof input === "string") {
return input === "" ? undefined : input;
}
@ -55,8 +54,8 @@ function omitDefault<T extends string | number | Long>(input: T): T | undefined
return input === 0 ? undefined : input;
}
if (Long.isLong(input)) {
return input.isZero() ? undefined : input;
if (typeof input === "bigint") {
return input === BigInt(0) ? undefined : input;
}
throw new Error(`Got unsupported type '${typeof input}'`);
@ -107,11 +106,11 @@ export function createIbcAminoConverters(): AminoConverters {
receiver: receiver,
timeoutHeight: timeout_height
? {
revisionHeight: Long.fromString(timeout_height.revision_height || "0", true),
revisionNumber: Long.fromString(timeout_height.revision_number || "0", true),
revisionHeight: BigInt(timeout_height.revision_height || "0"),
revisionNumber: BigInt(timeout_height.revision_number || "0"),
}
: undefined,
timeoutTimestamp: Long.fromString(timeout_timestamp || "0", true),
timeoutTimestamp: BigInt(timeout_timestamp || "0"),
}),
},
};

View File

@ -15,7 +15,6 @@ import {
State as ConnectionState,
Version,
} from "cosmjs-types/ibc/core/connection/v1/connection";
import Long from "long";
// From scripts/simapp42/genesis-ibc.json
@ -61,7 +60,7 @@ export const commitment = {
export const packetState = PacketState.fromPartial({
portId: portId,
channelId: channelId,
sequence: Long.fromInt(commitment.sequence, true),
sequence: BigInt(commitment.sequence),
data: commitment.data,
});

View File

@ -1,5 +1,4 @@
import { Tendermint34Client } from "@cosmjs/tendermint-rpc";
import Long from "long";
import { QueryClient } from "../../queryclient";
import { simapp } from "../../testutils.spec";
@ -233,7 +232,7 @@ describe("IbcExtension", () => {
ibcTest.channelId,
[1, 2, 3],
);
expect(response.sequences).toEqual([1, 2, 3].map((n) => Long.fromInt(n, true)));
expect(response.sequences).toEqual([1, 2, 3].map((n) => BigInt(n)));
expect(response.height).toBeDefined();
tmClient.disconnect();
@ -250,7 +249,7 @@ describe("IbcExtension", () => {
ibcTest.channelId,
[1, 2, 3, 4, 5, 6, 7],
);
expect(response.sequences).toEqual([Long.fromInt(ibcTest.commitment.sequence, true)]);
expect(response.sequences).toEqual([BigInt(ibcTest.commitment.sequence)]);
expect(response.height).toBeDefined();
tmClient.disconnect();
@ -263,7 +262,7 @@ describe("IbcExtension", () => {
const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl);
const response = await client.ibc.channel.nextSequenceReceive(ibcTest.portId, ibcTest.channelId);
expect(response.nextSequenceReceive).toEqual(Long.fromInt(1, true));
expect(response.nextSequenceReceive).toEqual(BigInt(1));
expect(response.proofHeight).toBeDefined();
expect(response.proofHeight).not.toBeNull();

View File

@ -49,9 +49,8 @@ import {
ClientState as TendermintClientState,
ConsensusState as TendermintConsensusState,
} from "cosmjs-types/ibc/lightclients/tendermint/v1/tendermint";
import Long from "long";
import { createPagination, createProtobufRpcClient, QueryClient } from "../../queryclient";
import { createPagination, createProtobufRpcClient, longify, QueryClient } from "../../queryclient";
function decodeTendermintClientStateAny(clientState: Any | undefined): TendermintClientState {
if (clientState?.typeUrl !== "/ibc.lightclients.tendermint.v1.ClientState") {
@ -218,10 +217,10 @@ export function setupIbcExtension(base: QueryClient): IbcExtension {
channels.push(...response.channels);
key = response.pagination?.nextKey;
} while (key && key.length);
return {
return QueryChannelsResponse.fromPartial({
channels: channels,
height: response.height,
};
});
},
connectionChannels: async (connection: string, paginationKey?: Uint8Array) =>
channelQueryService.ConnectionChannels({
@ -240,10 +239,10 @@ export function setupIbcExtension(base: QueryClient): IbcExtension {
channels.push(...response.channels);
key = response.pagination?.nextKey;
} while (key && key.length);
return {
return QueryConnectionChannelsResponse.fromPartial({
channels: channels,
height: response.height,
};
});
},
clientState: async (portId: string, channelId: string) =>
channelQueryService.ChannelClientState({
@ -259,14 +258,14 @@ export function setupIbcExtension(base: QueryClient): IbcExtension {
channelQueryService.ChannelConsensusState({
portId: portId,
channelId: channelId,
revisionNumber: Long.fromNumber(revisionNumber, true),
revisionHeight: Long.fromNumber(revisionHeight, true),
revisionNumber: BigInt(revisionNumber),
revisionHeight: BigInt(revisionHeight),
}),
packetCommitment: async (portId: string, channelId: string, sequence: number) =>
channelQueryService.PacketCommitment({
portId: portId,
channelId: channelId,
sequence: Long.fromNumber(sequence, true),
sequence: longify(sequence),
}),
packetCommitments: async (portId: string, channelId: string, paginationKey?: Uint8Array) =>
channelQueryService.PacketCommitments({
@ -287,22 +286,22 @@ export function setupIbcExtension(base: QueryClient): IbcExtension {
commitments.push(...response.commitments);
key = response.pagination?.nextKey;
} while (key && key.length);
return {
return QueryPacketCommitmentsResponse.fromPartial({
commitments: commitments,
height: response.height,
};
});
},
packetReceipt: async (portId: string, channelId: string, sequence: number) =>
channelQueryService.PacketReceipt({
portId: portId,
channelId: channelId,
sequence: Long.fromNumber(sequence, true),
sequence: longify(sequence),
}),
packetAcknowledgement: async (portId: string, channelId: string, sequence: number) =>
channelQueryService.PacketAcknowledgement({
portId: portId,
channelId: channelId,
sequence: Long.fromNumber(sequence, true),
sequence: longify(sequence),
}),
packetAcknowledgements: async (portId: string, channelId: string, paginationKey?: Uint8Array) => {
const request = QueryPacketAcknowledgementsRequest.fromPartial({
@ -326,10 +325,10 @@ export function setupIbcExtension(base: QueryClient): IbcExtension {
acknowledgements.push(...response.acknowledgements);
key = response.pagination?.nextKey;
} while (key && key.length);
return {
return QueryPacketAcknowledgementsResponse.fromPartial({
acknowledgements: acknowledgements,
height: response.height,
};
});
},
unreceivedPackets: async (
portId: string,
@ -339,13 +338,13 @@ export function setupIbcExtension(base: QueryClient): IbcExtension {
channelQueryService.UnreceivedPackets({
portId: portId,
channelId: channelId,
packetCommitmentSequences: packetCommitmentSequences.map((s) => Long.fromNumber(s, true)),
packetCommitmentSequences: packetCommitmentSequences.map((s) => BigInt(s)),
}),
unreceivedAcks: async (portId: string, channelId: string, packetAckSequences: readonly number[]) =>
channelQueryService.UnreceivedAcks({
portId: portId,
channelId: channelId,
packetAckSequences: packetAckSequences.map((s) => Long.fromNumber(s, true)),
packetAckSequences: packetAckSequences.map((s) => BigInt(s)),
}),
nextSequenceReceive: async (portId: string, channelId: string) =>
channelQueryService.NextSequenceReceive({
@ -370,16 +369,15 @@ export function setupIbcExtension(base: QueryClient): IbcExtension {
clientStates.push(...response.clientStates);
key = response.pagination?.nextKey;
} while (key && key.length);
return {
return QueryClientStatesResponse.fromPartial({
clientStates: clientStates,
};
});
},
consensusState: async (clientId: string, consensusHeight?: number) =>
clientQueryService.ConsensusState(
QueryConsensusStateRequest.fromPartial({
clientId: clientId,
revisionHeight:
consensusHeight !== undefined ? Long.fromNumber(consensusHeight, true) : undefined,
revisionHeight: consensusHeight !== undefined ? BigInt(consensusHeight) : undefined,
latestHeight: consensusHeight === undefined,
}),
),
@ -400,9 +398,9 @@ export function setupIbcExtension(base: QueryClient): IbcExtension {
consensusStates.push(...response.consensusStates);
key = response.pagination?.nextKey;
} while (key && key.length);
return {
return QueryConsensusStatesResponse.fromPartial({
consensusStates: consensusStates,
};
});
},
params: async () => clientQueryService.ClientParams({}),
stateTm: async (clientId: string) => {
@ -460,10 +458,10 @@ export function setupIbcExtension(base: QueryClient): IbcExtension {
connections.push(...response.connections);
key = response.pagination?.nextKey;
} while (key && key.length);
return {
return QueryConnectionsResponse.fromPartial({
connections: connections,
height: response.height,
};
});
},
clientConnections: async (clientId: string) =>
connectionQueryService.ClientConnections({
@ -477,7 +475,7 @@ export function setupIbcExtension(base: QueryClient): IbcExtension {
connectionQueryService.ConnectionConsensusState(
QueryConnectionConsensusStateRequest.fromPartial({
connectionId: connectionId,
revisionHeight: Long.fromNumber(revisionHeight, true),
revisionHeight: BigInt(revisionHeight),
}),
),
},
@ -498,9 +496,9 @@ export function setupIbcExtension(base: QueryClient): IbcExtension {
denomTraces.push(...response.denomTraces);
key = response.pagination?.nextKey;
} while (key && key.length);
return {
return QueryDenomTracesResponse.fromPartial({
denomTraces: denomTraces,
};
});
},
params: async () => transferQueryService.Params({}),
},

View File

@ -18,8 +18,8 @@ describe("MintExtension", () => {
const [client, tmClient] = await makeClientWithMint(simapp.tendermintUrl);
const params = await client.mint.params();
expect(params.blocksPerYear.toNumber()).toBeGreaterThan(100_000);
expect(params.blocksPerYear.toNumber()).toBeLessThan(100_000_000);
expect(Number(params.blocksPerYear)).toBeGreaterThan(100_000);
expect(Number(params.blocksPerYear)).toBeLessThan(100_000_000);
expect(params.goalBonded.toString()).toEqual("0.67");
expect(params.inflationMin.toString()).toEqual("0.07");
expect(params.inflationMax.toString()).toEqual("0.2");

View File

@ -233,7 +233,7 @@ describe("StakingExtension", () => {
},
balance: { denom: "ustake", amount: "3000000" },
});
expect(response.pagination?.total.toNumber()).toBeGreaterThanOrEqual(2);
expect(Number(response.pagination!.total)).toBeGreaterThanOrEqual(2);
tmClient.disconnect();
});

View File

@ -17,7 +17,6 @@ import {
QueryValidatorUnbondingDelegationsResponse,
} from "cosmjs-types/cosmos/staking/v1beta1/query";
import { BondStatus } from "cosmjs-types/cosmos/staking/v1beta1/staking";
import Long from "long";
import { createPagination, createProtobufRpcClient, QueryClient } from "../../queryclient";
@ -118,9 +117,9 @@ export function setupStakingExtension(base: QueryClient): StakingExtension {
});
return response;
},
historicalInfo: async (height: number) => {
historicalInfo: async (height: number | bigint) => {
const response = await queryService.HistoricalInfo({
height: Long.fromNumber(height, true),
height: BigInt(height),
});
return response;
},

View File

@ -2,7 +2,6 @@ import { coin, coins, DirectSecp256k1HdWallet, Registry } from "@cosmjs/proto-si
import { Tendermint34Client } from "@cosmjs/tendermint-rpc";
import { assertDefined, sleep } from "@cosmjs/utils";
import { MsgDelegate } from "cosmjs-types/cosmos/staking/v1beta1/tx";
import Long from "long";
import { QueryClient } from "../../queryclient";
import { defaultRegistryTypes, SigningStargateClient } from "../../signingstargateclient";
@ -94,11 +93,11 @@ describe("TxExtension", () => {
const { sequence } = await sequenceClient.getSequence(faucet.address0);
const response = await client.tx.simulate([msgAny], "foo", faucet.pubkey0, sequence);
expect(response.gasInfo?.gasUsed.toNumber()).toBeGreaterThanOrEqual(101_000);
expect(response.gasInfo?.gasUsed.toNumber()).toBeLessThanOrEqual(200_000);
expect(response.gasInfo?.gasUsed).toBeGreaterThanOrEqual(101_000);
expect(response.gasInfo?.gasUsed).toBeLessThanOrEqual(200_000);
expect(response.gasInfo?.gasWanted).toEqual(
// Some dummy value. Value does not matter for regular users.
simapp44Enabled() ? Long.UZERO : Long.MAX_UNSIGNED_VALUE,
simapp44Enabled() ? BigInt(0) : BigInt("0xffffffffffffffff"),
);
tmClient.disconnect();

View File

@ -10,7 +10,6 @@ import {
} from "cosmjs-types/cosmos/tx/v1beta1/service";
import { AuthInfo, Fee, Tx, TxBody } from "cosmjs-types/cosmos/tx/v1beta1/tx";
import { Any } from "cosmjs-types/google/protobuf/any";
import Long from "long";
import { createProtobufRpcClient, QueryClient } from "../../queryclient";
@ -56,7 +55,7 @@ export function setupTxExtension(base: QueryClient): TxExtension {
signerInfos: [
{
publicKey: encodePubkey(signer),
sequence: Long.fromNumber(sequence, true),
sequence: BigInt(sequence),
modeInfo: { single: { mode: SignMode.SIGN_MODE_UNSPECIFIED } },
},
],

View File

@ -1,7 +1,6 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { coins } from "@cosmjs/amino";
import { MsgCreateVestingAccount } from "cosmjs-types/cosmos/vesting/v1beta1/tx";
import Long from "long";
import { AminoTypes } from "../../aminotypes";
import { AminoMsgCreateVestingAccount, createVestingAminoConverters } from "./aminomessages";
@ -13,7 +12,7 @@ describe("vesting Amino messages", () => {
fromAddress: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
toAddress: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
amount: coins(1234, "ucosm"),
endTime: Long.fromString("1838718434"),
endTime: BigInt("1838718434"),
delayed: true,
});
const aminoTypes = new AminoTypes(createVestingAminoConverters());
@ -52,7 +51,7 @@ describe("vesting Amino messages", () => {
fromAddress: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
toAddress: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
amount: coins(1234, "ucosm"),
endTime: Long.fromString("1838718434"),
endTime: BigInt("1838718434"),
delayed: true,
};
expect(msg).toEqual({

View File

@ -1,7 +1,6 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { AminoMsg, Coin } from "@cosmjs/amino";
import { MsgCreateVestingAccount } from "cosmjs-types/cosmos/vesting/v1beta1/tx";
import Long from "long";
import { AminoConverters } from "../../aminotypes";
@ -49,7 +48,7 @@ export function createVestingAminoConverters(): AminoConverters {
fromAddress: from_address,
toAddress: to_address,
amount: [...amount],
endTime: Long.fromString(end_time),
endTime: BigInt(end_time),
delayed: delayed,
}),
},

View File

@ -1,7 +1,6 @@
import { coin, coins, Secp256k1HdWallet } from "@cosmjs/amino";
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
import { MsgCreateVestingAccount } from "cosmjs-types/cosmos/vesting/v1beta1/tx";
import Long from "long";
import { SigningStargateClient } from "../../signingstargateclient";
import { assertIsDeliverTxSuccess } from "../../stargateclient";
@ -33,7 +32,7 @@ describe("vesting messages", () => {
fromAddress: faucet.address0,
toAddress: recipient,
amount: coins(1234, "ucosm"),
endTime: Long.fromString("1838718434"),
endTime: BigInt("1838718434"),
delayed: true,
}),
};
@ -63,7 +62,7 @@ describe("vesting messages", () => {
fromAddress: faucet.address0,
toAddress: recipient,
amount: coins(1234, "ucosm"),
endTime: Long.fromString("1838718434"),
endTime: BigInt("1838718434"),
delayed: true,
}),
};

View File

@ -5,7 +5,6 @@ import { CompactBitArray, MultiSignature } from "cosmjs-types/cosmos/crypto/mult
import { SignMode } from "cosmjs-types/cosmos/tx/signing/v1beta1/signing";
import { AuthInfo, SignerInfo } from "cosmjs-types/cosmos/tx/v1beta1/tx";
import { TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
import Long from "long";
export function makeCompactBitArray(bits: readonly boolean[]): CompactBitArray {
const byteCount = Math.ceil(bits.length / 8);
@ -58,14 +57,14 @@ export function makeMultisignedTx(
modeInfos: signaturesList.map((_) => ({ single: { mode: SignMode.SIGN_MODE_LEGACY_AMINO_JSON } })),
},
},
sequence: Long.fromNumber(sequence),
sequence: BigInt(sequence),
};
const authInfo = AuthInfo.fromPartial({
signerInfos: [signerInfo],
fee: {
amount: [...fee.amount],
gasLimit: Long.fromString(fee.gas),
gasLimit: BigInt(fee.gas),
},
});

View File

@ -98,7 +98,9 @@ describe("QueryClient", () => {
const [client, tmClient] = await makeClient(simapp.tendermintUrlWs);
const requestData = Uint8Array.from(
QueryAllBalancesRequest.encode({ address: unused.address }).finish(),
QueryAllBalancesRequest.encode(
QueryAllBalancesRequest.fromPartial({ address: unused.address }),
).finish(),
);
const { value } = await client.queryAbci(`/cosmos.bank.v1beta1.Query/AllBalances`, requestData);
const response = QueryAllBalancesResponse.decode(value);
@ -112,7 +114,9 @@ describe("QueryClient", () => {
const [client, tmClient] = await makeClient(simapp.tendermintUrlHttp);
const requestData = Uint8Array.from(
QueryAllBalancesRequest.encode({ address: unused.address }).finish(),
QueryAllBalancesRequest.encode(
QueryAllBalancesRequest.fromPartial({ address: unused.address }),
).finish(),
);
const { value } = await client.queryAbci(`/cosmos.bank.v1beta1.Query/AllBalances`, requestData);
const response = QueryAllBalancesResponse.decode(value);

View File

@ -1,7 +1,6 @@
import { fromAscii, fromBech32 } from "@cosmjs/encoding";
import { Decimal, Uint64 } from "@cosmjs/math";
import { PageRequest } from "cosmjs-types/cosmos/base/query/v1beta1/pagination";
import Long from "long";
import { QueryClient } from "./queryclient";
@ -21,8 +20,8 @@ export function toAccAddress(address: string): Uint8Array {
* Use this with a query response's pagination next key to
* request the next page.
*/
export function createPagination(paginationKey?: Uint8Array): PageRequest | undefined {
return paginationKey ? PageRequest.fromPartial({ key: paginationKey }) : undefined;
export function createPagination(paginationKey?: Uint8Array): PageRequest {
return paginationKey ? PageRequest.fromPartial({ key: paginationKey }) : PageRequest.fromPartial({});
}
export interface ProtobufRpcClient {
@ -40,12 +39,12 @@ export function createProtobufRpcClient(base: QueryClient): ProtobufRpcClient {
}
/**
* Takes a uint64 value as string, number, Long or Uint64 and returns an unsigned Long instance
* Takes a uint64 value as string, number, BigInt or Uint64 and returns a BigInt
* of it.
*/
export function longify(value: string | number | Long | Uint64): Long {
export function longify(value: string | number | Uint64): bigint {
const checkedValue = Uint64.fromString(value.toString());
return Long.fromBytesBE([...checkedValue.toBytesBigEndian()], true);
return BigInt(checkedValue.toString());
}
/**

View File

@ -11,6 +11,7 @@ import {
import { Tendermint34Client } from "@cosmjs/tendermint-rpc";
import { assert, sleep } from "@cosmjs/utils";
import { DeepPartial } from "cosmjs-types";
import { BinaryWriter } from "cosmjs-types/binary";
import { MsgSend } from "cosmjs-types/cosmos/bank/v1beta1/tx";
import { Coin } from "cosmjs-types/cosmos/base/v1beta1/coin";
import { BasicAllowance } from "cosmjs-types/cosmos/feegrant/v1beta1/feegrant";
@ -18,8 +19,6 @@ import { MsgGrantAllowance } from "cosmjs-types/cosmos/feegrant/v1beta1/tx";
import { MsgDelegate } from "cosmjs-types/cosmos/staking/v1beta1/tx";
import { AuthInfo, TxBody, TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
import { Any } from "cosmjs-types/google/protobuf/any";
import Long from "long";
import protobuf from "protobufjs/minimal";
import { AminoTypes } from "./aminotypes";
import {
@ -190,14 +189,16 @@ describe("SigningStargateClient", () => {
const allowance: Any = {
typeUrl: "/cosmos.feegrant.v1beta1.BasicAllowance",
value: Uint8Array.from(
BasicAllowance.encode({
BasicAllowance.encode(
BasicAllowance.fromPartial({
spendLimit: [
{
denom: "ucosm",
amount: "1234567",
},
],
}).finish(),
}),
).finish(),
),
};
const grantMsg = {
@ -260,7 +261,7 @@ describe("SigningStargateClient", () => {
coin(1234, "ucosm"),
"fooPort",
"fooChannel",
{ revisionHeight: Long.fromNumber(123), revisionNumber: Long.fromNumber(456) },
{ revisionHeight: BigInt(123), revisionNumber: BigInt(456) },
Math.floor(Date.now() / 1000) + 60,
fee,
memo,
@ -309,7 +310,7 @@ describe("SigningStargateClient", () => {
coin(1234, "ucosm"),
"fooPort",
"fooChannel",
{ revisionHeight: Long.fromNumber(123), revisionNumber: Long.fromNumber(456) },
{ revisionHeight: BigInt(123), revisionNumber: BigInt(456) },
Math.floor(Date.now() / 1000) + 60,
fee,
memo,
@ -455,7 +456,7 @@ describe("SigningStargateClient", () => {
// From ModifyingDirectSecp256k1HdWallet
expect(tx.body.memo).toEqual("This was modified");
expect({ ...tx.authInfo.fee!.amount[0] }).toEqual(coin(3000, "ucosm"));
expect(tx.authInfo.fee!.gasLimit.toNumber()).toEqual(333333);
expect(tx.authInfo.fee!.gasLimit).toEqual(BigInt(333333));
});
});
@ -558,10 +559,8 @@ describe("SigningStargateClient", () => {
};
const CustomMsgDelegate = {
// Adapted from autogenerated MsgDelegate implementation
encode(
message: CustomMsgDelegate,
writer: protobuf.Writer = protobuf.Writer.create(),
): protobuf.Writer {
typeUrl: "foobar",
encode(message: CustomMsgDelegate, writer: BinaryWriter = BinaryWriter.create()): BinaryWriter {
writer.uint32(10).string(message.customDelegatorAddress ?? "");
writer.uint32(18).string(message.customValidatorAddress ?? "");
if (message.customAmount !== undefined) {
@ -685,7 +684,7 @@ describe("SigningStargateClient", () => {
// From ModifyingSecp256k1HdWallet
expect(tx.body.memo).toEqual("This was modified");
expect({ ...tx.authInfo.fee!.amount[0] }).toEqual(coin(3000, "ucosm"));
expect(tx.authInfo.fee!.gasLimit.toNumber()).toEqual(333333);
expect(tx.authInfo.fee!.gasLimit).toEqual(BigInt(333333));
});
});
});
@ -906,7 +905,7 @@ describe("SigningStargateClient", () => {
// From ModifyingDirectSecp256k1HdWallet
expect(body.memo).toEqual("This was modified");
expect({ ...authInfo.fee!.amount[0] }).toEqual(coin(3000, "ucosm"));
expect(authInfo.fee!.gasLimit.toNumber()).toEqual(333333);
expect(authInfo.fee!.gasLimit).toEqual(BigInt(333333));
// ensure signature is valid
const result = await client.broadcastTx(Uint8Array.from(TxRaw.encode(signed).finish()));
@ -991,11 +990,9 @@ describe("SigningStargateClient", () => {
customValidatorAddress: "",
};
const CustomMsgDelegate = {
typeUrl: "foobar",
// Adapted from autogenerated MsgDelegate implementation
encode(
message: CustomMsgDelegate,
writer: protobuf.Writer = protobuf.Writer.create(),
): protobuf.Writer {
encode(message: CustomMsgDelegate, writer: BinaryWriter = BinaryWriter.create()): BinaryWriter {
writer.uint32(10).string(message.customDelegatorAddress ?? "");
writer.uint32(18).string(message.customValidatorAddress ?? "");
if (message.customAmount !== undefined && message.customAmount !== undefined) {
@ -1118,7 +1115,7 @@ describe("SigningStargateClient", () => {
// From ModifyingSecp256k1HdWallet
expect(body.memo).toEqual("This was modified");
expect({ ...authInfo.fee!.amount[0] }).toEqual(coin(3000, "ucosm"));
expect(authInfo.fee!.gasLimit.toNumber()).toEqual(333333);
expect(authInfo.fee!.gasLimit).toEqual(BigInt(333333));
// ensure signature is valid
const result = await client.broadcastTx(Uint8Array.from(TxRaw.encode(signed).finish()));

View File

@ -26,7 +26,6 @@ import { SignMode } from "cosmjs-types/cosmos/tx/signing/v1beta1/signing";
import { TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
import { MsgTransfer } from "cosmjs-types/ibc/applications/transfer/v1/tx";
import { Height } from "cosmjs-types/ibc/core/client/v1/client";
import Long from "long";
import { AminoConverters, AminoTypes } from "./aminotypes";
import { calculateFee, GasPrice } from "./fee";
@ -291,7 +290,7 @@ export class SigningStargateClient extends StargateClient {
memo = "",
): Promise<DeliverTxResponse> {
const timeoutTimestampNanoseconds = timeoutTimestamp
? Long.fromNumber(timeoutTimestamp).multiply(1_000_000_000)
? BigInt(timeoutTimestamp) * BigInt(1_000_000_000)
: undefined;
const transferMsg: MsgTransferEncodeObject = {
typeUrl: "/ibc.applications.transfer.v1.MsgTransfer",

View File

@ -9,6 +9,7 @@ import {
DirectSignResponse,
makeAuthInfoBytes,
} from "@cosmjs/proto-signing";
import { assertDefinedAndNotNull } from "@cosmjs/utils";
import { SignMode } from "cosmjs-types/cosmos/tx/signing/v1beta1/signing";
import { AuthInfo, SignDoc, TxBody } from "cosmjs-types/cosmos/tx/v1beta1/tx";
@ -230,10 +231,13 @@ export class ModifyingDirectSecp256k1HdWallet extends DirectSecp256k1HdWallet {
memo: "This was modified",
});
const authInfo = AuthInfo.decode(signDoc.authInfoBytes);
const signers = authInfo.signerInfos.map((signerInfo) => ({
pubkey: signerInfo.publicKey!,
sequence: signerInfo.sequence.toNumber(),
}));
const signers = authInfo.signerInfos.map((signerInfo) => {
assertDefinedAndNotNull(signerInfo.publicKey);
return {
pubkey: signerInfo.publicKey,
sequence: signerInfo.sequence,
};
});
const modifiedFeeAmount = coins(3000, "ucosm");
const modifiedGasLimit = 333333;
const modifiedFeeGranter = undefined;

View File

@ -358,7 +358,7 @@ __metadata:
axios: ^0.21.2
babylon: ^6.18.0
chalk: ^4
cosmjs-types: ^0.8.0
cosmjs-types: ^0.9.0
diff: ^4
eslint: ^7.5
eslint-config-prettier: ^8.3.0
@ -404,7 +404,7 @@ __metadata:
"@types/pako": ^1.0.1
"@typescript-eslint/eslint-plugin": ^5.54.0
"@typescript-eslint/parser": ^5.54.0
cosmjs-types: ^0.8.0
cosmjs-types: ^0.9.0
eslint: ^7.5
eslint-config-prettier: ^8.3.0
eslint-import-resolver-node: ^0.3.4
@ -420,11 +420,9 @@ __metadata:
karma-firefox-launcher: ^2.1.0
karma-jasmine: ^5
karma-jasmine-html-reporter: ^1.5.4
long: ^4.0.0
nyc: ^15.1.0
pako: ^2.0.2
prettier: ^2.8.1
protobufjs: ~6.11.4
readonly-date: ^1.0.0
ses: ^0.11.0
source-map-support: ^0.5.19
@ -763,7 +761,7 @@ __metadata:
"@types/node": ^18
"@typescript-eslint/eslint-plugin": ^5.54.0
"@typescript-eslint/parser": ^5.54.0
cosmjs-types: ^0.8.0
cosmjs-types: ^0.9.0
eslint: ^7.5
eslint-config-prettier: ^8.3.0
eslint-import-resolver-node: ^0.3.4
@ -779,7 +777,6 @@ __metadata:
karma-firefox-launcher: ^2.1.0
karma-jasmine: ^5
karma-jasmine-html-reporter: ^1.5.4
long: ^4.0.0
nyc: ^15.1.0
prettier: ^2.8.1
protobufjs: ~6.11.4
@ -860,7 +857,7 @@ __metadata:
"@types/node": ^18
"@typescript-eslint/eslint-plugin": ^5.54.0
"@typescript-eslint/parser": ^5.54.0
cosmjs-types: ^0.8.0
cosmjs-types: ^0.9.0
eslint: ^7.5
eslint-config-prettier: ^8.3.0
eslint-import-resolver-node: ^0.3.4
@ -876,10 +873,8 @@ __metadata:
karma-firefox-launcher: ^2.1.0
karma-jasmine: ^5
karma-jasmine-html-reporter: ^1.5.4
long: ^4.0.0
nyc: ^15.1.0
prettier: ^2.8.1
protobufjs: ~6.11.4
readonly-date: ^1.0.0
ses: ^0.11.0
source-map-support: ^0.5.19
@ -3079,13 +3074,10 @@ __metadata:
languageName: unknown
linkType: soft
"cosmjs-types@npm:^0.8.0":
version: 0.8.0
resolution: "cosmjs-types@npm:0.8.0"
dependencies:
long: ^4.0.0
protobufjs: ~6.11.2
checksum: 99714ec956d2cb2e521d39896c9c9a24cf9df0d370265c203646ea015b51e86472efc0cb11f67a80f0649d178b0bcff77ac659e67fdfc8b2437cd7a42018577f
"cosmjs-types@npm:^0.9.0":
version: 0.9.0
resolution: "cosmjs-types@npm:0.9.0"
checksum: 9b00d169eca334f27418bb80b39e0cff0196af40b0079e1f85536246059279207b853bdb6ec224ead0a02d15d4b7f6bf16bc096d41c436426aa5f8976ed2b430
languageName: node
linkType: hard
@ -6368,7 +6360,7 @@ __metadata:
languageName: node
linkType: hard
"protobufjs@npm:^6.8.8, protobufjs@npm:~6.11.2, protobufjs@npm:~6.11.4":
"protobufjs@npm:^6.8.8, protobufjs@npm:~6.11.4":
version: 6.11.4
resolution: "protobufjs@npm:6.11.4"
dependencies: