Skip to content

Commit

Permalink
Change votingPower field to bigint type
Browse files Browse the repository at this point in the history
  • Loading branch information
webmaster128 committed Jun 29, 2022
1 parent 2d3604a commit baa11e2
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 20 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe("Adaptor Responses", () => {
});
expect(validator).toEqual({
address: fromHex("A03DC128D38DB0BC5F18AE1872F1CB2E1FD41157"),
votingPower: 169980,
votingPower: BigInt(169980),
pubkey: {
algorithm: "ed25519",
data: fromBase64("2BX6Zuj8RmdJAkD1BAg6KB0v04liyM7jBdwOGIb9F9Q="),
Expand Down Expand Up @@ -72,7 +72,7 @@ describe("Adaptor Responses", () => {
algorithm: "ed25519",
data: fromBase64("0kNlxBMpm+5WtfHIG1xsWatOXTKPLtmSqn3EiEIDZeI="),
},
votingPower: 11418237,
votingPower: BigInt(11418237),
});
});

Expand All @@ -93,7 +93,7 @@ describe("Adaptor Responses", () => {
algorithm: "ed25519",
data: fromBase64("HjSC7VkhKih6xMhudlqfaFE8ZZnP8RKJPv4iqR7RhcE="),
},
votingPower: 0,
votingPower: BigInt(0),
});
});
});
Expand All @@ -116,7 +116,7 @@ describe("Adaptor Responses", () => {
algorithm: "ed25519",
data: fromBase64("0kNlxBMpm+5WtfHIG1xsWatOXTKPLtmSqn3EiEIDZeI="),
},
votingPower: 11228980,
votingPower: BigInt(11228980),
proposerPriority: 62870960,
});
});
Expand Down
8 changes: 4 additions & 4 deletions packages/tendermint-rpc/src/tendermint34/adaptor/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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"),
};
}

Expand Down Expand Up @@ -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)),
};
}

Expand Down Expand Up @@ -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,
};
Expand Down
4 changes: 2 additions & 2 deletions packages/tendermint-rpc/src/tendermint34/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe("Adaptor Responses", () => {
});
expect(validator).toEqual({
address: fromHex("A03DC128D38DB0BC5F18AE1872F1CB2E1FD41157"),
votingPower: 169980,
votingPower: BigInt(169980),
pubkey: {
algorithm: "ed25519",
data: fromBase64("2BX6Zuj8RmdJAkD1BAg6KB0v04liyM7jBdwOGIb9F9Q="),
Expand Down Expand Up @@ -72,7 +72,7 @@ describe("Adaptor Responses", () => {
algorithm: "ed25519",
data: fromBase64("0kNlxBMpm+5WtfHIG1xsWatOXTKPLtmSqn3EiEIDZeI="),
},
votingPower: 11418237,
votingPower: BigInt(11418237),
});
});

Expand All @@ -93,7 +93,7 @@ describe("Adaptor Responses", () => {
algorithm: "ed25519",
data: fromBase64("HjSC7VkhKih6xMhudlqfaFE8ZZnP8RKJPv4iqR7RhcE="),
},
votingPower: 0,
votingPower: BigInt(0),
});
});
});
Expand All @@ -116,7 +116,7 @@ describe("Adaptor Responses", () => {
algorithm: "ed25519",
data: fromBase64("0kNlxBMpm+5WtfHIG1xsWatOXTKPLtmSqn3EiEIDZeI="),
},
votingPower: 11228980,
votingPower: BigInt(11228980),
proposerPriority: 62870960,
});
});
Expand Down
8 changes: 4 additions & 4 deletions packages/tendermint-rpc/src/tendermint35/adaptor/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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"),
};
}

Expand Down Expand Up @@ -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)),
};
}

Expand Down Expand Up @@ -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,
};
Expand Down
4 changes: 2 additions & 2 deletions packages/tendermint-rpc/src/tendermint35/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit baa11e2

Please sign in to comment.