diff --git a/CHANGELOG.md b/CHANGELOG.md index 3cb8302cdc..8f538b1a1a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,9 +40,13 @@ and this project adheres to - all: Upgrade cosmjs-types to 0.5 ([#1131]). - @cosmjs/stargate: Change `packetCommitment` parameter `sequence` type from `Long` to `number` ([#1168]). +- @cosmjs/tendermint-rpc: The type of `votingPower` fields was changed from + `number` to `bigint` as those values can exceed the safe integer range + ([#1133]). [#1131]: https://github.com/cosmos/cosmjs/pull/1131 [#1168]: https://github.com/cosmos/cosmjs/pull/1168 +[#1133]: https://github.com/cosmos/cosmjs/issues/1133 ## [0.28.9] - 2022-06-21 diff --git a/packages/tendermint-rpc/src/tendermint34/adaptor/responses.spec.ts b/packages/tendermint-rpc/src/tendermint34/adaptor/responses.spec.ts index 0ad26490ab..7de09654d0 100644 --- a/packages/tendermint-rpc/src/tendermint34/adaptor/responses.spec.ts +++ b/packages/tendermint-rpc/src/tendermint34/adaptor/responses.spec.ts @@ -44,7 +44,7 @@ describe("Adaptor Responses", () => { }); expect(validator).toEqual({ address: fromHex("A03DC128D38DB0BC5F18AE1872F1CB2E1FD41157"), - votingPower: 169980, + votingPower: BigInt(169980), pubkey: { algorithm: "ed25519", data: fromBase64("2BX6Zuj8RmdJAkD1BAg6KB0v04liyM7jBdwOGIb9F9Q="), @@ -72,7 +72,7 @@ describe("Adaptor Responses", () => { algorithm: "ed25519", data: fromBase64("0kNlxBMpm+5WtfHIG1xsWatOXTKPLtmSqn3EiEIDZeI="), }, - votingPower: 11418237, + votingPower: BigInt(11418237), }); }); @@ -93,7 +93,7 @@ describe("Adaptor Responses", () => { algorithm: "ed25519", data: fromBase64("HjSC7VkhKih6xMhudlqfaFE8ZZnP8RKJPv4iqR7RhcE="), }, - votingPower: 0, + votingPower: BigInt(0), }); }); }); @@ -116,7 +116,7 @@ describe("Adaptor Responses", () => { algorithm: "ed25519", data: fromBase64("0kNlxBMpm+5WtfHIG1xsWatOXTKPLtmSqn3EiEIDZeI="), }, - votingPower: 11228980, + votingPower: BigInt(11228980), proposerPriority: 62870960, }); }); diff --git a/packages/tendermint-rpc/src/tendermint34/adaptor/responses.ts b/packages/tendermint-rpc/src/tendermint34/adaptor/responses.ts index 3457bdd235..e522294442 100644 --- a/packages/tendermint-rpc/src/tendermint34/adaptor/responses.ts +++ b/packages/tendermint-rpc/src/tendermint34/adaptor/responses.ts @@ -4,7 +4,7 @@ import { JsonRpcSuccessResponse } from "@cosmjs/json-rpc"; import { assert } from "@cosmjs/utils"; import { DateWithNanoseconds, fromRfc3339WithNanoseconds } from "../../dates"; -import { apiToSmallInt } from "../../inthelpers"; +import { apiToBigInt, apiToSmallInt } from "../../inthelpers"; import { SubscriptionEvent } from "../../rpcclients"; import { BlockIdFlag, CommitSignature, ValidatorPubkey } from "../../types"; import { @@ -279,7 +279,7 @@ interface RpcValidatorUpdate { export function decodeValidatorUpdate(data: RpcValidatorUpdate): responses.ValidatorUpdate { return { pubkey: decodePubkey(assertObject(data.pub_key)), - votingPower: apiToSmallInt(data.power ?? 0), + votingPower: apiToBigInt(data.power ?? "0"), }; } @@ -528,7 +528,7 @@ export function decodeValidatorGenesis(data: RpcValidatorGenesis): responses.Val return { address: fromHex(assertNotEmpty(data.address)), pubkey: decodePubkey(assertObject(data.pub_key)), - votingPower: apiToSmallInt(assertNotEmpty(data.power)), + votingPower: apiToBigInt(assertNotEmpty(data.power)), }; } @@ -571,7 +571,7 @@ interface RpcValidatorInfo { export function decodeValidatorInfo(data: RpcValidatorInfo): responses.Validator { return { pubkey: decodePubkey(assertObject(data.pub_key)), - votingPower: apiToSmallInt(assertNotEmpty(data.voting_power)), + votingPower: apiToBigInt(assertNotEmpty(data.voting_power)), address: fromHex(assertNotEmpty(data.address)), proposerPriority: data.proposer_priority ? apiToSmallInt(data.proposer_priority) : undefined, }; diff --git a/packages/tendermint-rpc/src/tendermint34/responses.ts b/packages/tendermint-rpc/src/tendermint34/responses.ts index 0e82dcb3db..70a3516fb3 100644 --- a/packages/tendermint-rpc/src/tendermint34/responses.ts +++ b/packages/tendermint-rpc/src/tendermint34/responses.ts @@ -352,13 +352,13 @@ export interface SyncInfo { export interface Validator { readonly address: Uint8Array; readonly pubkey?: ValidatorPubkey; - readonly votingPower: number; + readonly votingPower: bigint; readonly proposerPriority?: number; } export interface ValidatorUpdate { readonly pubkey: ValidatorPubkey; - readonly votingPower: number; + readonly votingPower: bigint; } export interface ConsensusParams { diff --git a/packages/tendermint-rpc/src/tendermint35/adaptor/responses.spec.ts b/packages/tendermint-rpc/src/tendermint35/adaptor/responses.spec.ts index 35e86679ea..c85b753328 100644 --- a/packages/tendermint-rpc/src/tendermint35/adaptor/responses.spec.ts +++ b/packages/tendermint-rpc/src/tendermint35/adaptor/responses.spec.ts @@ -44,7 +44,7 @@ describe("Adaptor Responses", () => { }); expect(validator).toEqual({ address: fromHex("A03DC128D38DB0BC5F18AE1872F1CB2E1FD41157"), - votingPower: 169980, + votingPower: BigInt(169980), pubkey: { algorithm: "ed25519", data: fromBase64("2BX6Zuj8RmdJAkD1BAg6KB0v04liyM7jBdwOGIb9F9Q="), @@ -72,7 +72,7 @@ describe("Adaptor Responses", () => { algorithm: "ed25519", data: fromBase64("0kNlxBMpm+5WtfHIG1xsWatOXTKPLtmSqn3EiEIDZeI="), }, - votingPower: 11418237, + votingPower: BigInt(11418237), }); }); @@ -93,7 +93,7 @@ describe("Adaptor Responses", () => { algorithm: "ed25519", data: fromBase64("HjSC7VkhKih6xMhudlqfaFE8ZZnP8RKJPv4iqR7RhcE="), }, - votingPower: 0, + votingPower: BigInt(0), }); }); }); @@ -116,7 +116,7 @@ describe("Adaptor Responses", () => { algorithm: "ed25519", data: fromBase64("0kNlxBMpm+5WtfHIG1xsWatOXTKPLtmSqn3EiEIDZeI="), }, - votingPower: 11228980, + votingPower: BigInt(11228980), proposerPriority: 62870960, }); }); diff --git a/packages/tendermint-rpc/src/tendermint35/adaptor/responses.ts b/packages/tendermint-rpc/src/tendermint35/adaptor/responses.ts index b6a76fc45a..30aad6efba 100644 --- a/packages/tendermint-rpc/src/tendermint35/adaptor/responses.ts +++ b/packages/tendermint-rpc/src/tendermint35/adaptor/responses.ts @@ -4,7 +4,7 @@ import { JsonRpcSuccessResponse } from "@cosmjs/json-rpc"; import { assert } from "@cosmjs/utils"; import { DateWithNanoseconds, fromRfc3339WithNanoseconds } from "../../dates"; -import { apiToSmallInt } from "../../inthelpers"; +import { apiToBigInt, apiToSmallInt } from "../../inthelpers"; import { SubscriptionEvent } from "../../rpcclients"; import { BlockIdFlag, CommitSignature, ValidatorPubkey } from "../../types"; import { @@ -280,7 +280,7 @@ interface RpcValidatorUpdate { export function decodeValidatorUpdate(data: RpcValidatorUpdate): responses.ValidatorUpdate { return { pubkey: decodePubkey(assertObject(data.pub_key)), - votingPower: apiToSmallInt(data.power ?? 0), + votingPower: apiToBigInt(data.power ?? "0"), }; } @@ -529,7 +529,7 @@ export function decodeValidatorGenesis(data: RpcValidatorGenesis): responses.Val return { address: fromHex(assertNotEmpty(data.address)), pubkey: decodePubkey(assertObject(data.pub_key)), - votingPower: apiToSmallInt(assertNotEmpty(data.power)), + votingPower: apiToBigInt(assertNotEmpty(data.power)), }; } @@ -572,7 +572,7 @@ interface RpcValidatorInfo { export function decodeValidatorInfo(data: RpcValidatorInfo): responses.Validator { return { pubkey: decodePubkey(assertObject(data.pub_key)), - votingPower: apiToSmallInt(assertNotEmpty(data.voting_power)), + votingPower: apiToBigInt(assertNotEmpty(data.voting_power)), address: fromHex(assertNotEmpty(data.address)), proposerPriority: data.proposer_priority ? apiToSmallInt(data.proposer_priority) : undefined, }; diff --git a/packages/tendermint-rpc/src/tendermint35/responses.ts b/packages/tendermint-rpc/src/tendermint35/responses.ts index f03cabcac8..7440d8d927 100644 --- a/packages/tendermint-rpc/src/tendermint35/responses.ts +++ b/packages/tendermint-rpc/src/tendermint35/responses.ts @@ -357,13 +357,13 @@ export interface SyncInfo { export interface Validator { readonly address: Uint8Array; readonly pubkey?: ValidatorPubkey; - readonly votingPower: number; + readonly votingPower: bigint; readonly proposerPriority?: number; } export interface ValidatorUpdate { readonly pubkey: ValidatorPubkey; - readonly votingPower: number; + readonly votingPower: bigint; } export interface ConsensusParams {