From b9e9615d8b71c19b800a47b21e5082942fb9b98c Mon Sep 17 00:00:00 2001 From: Kollan House Date: Fri, 30 Dec 2022 00:06:14 +0800 Subject: [PATCH 1/2] fix: adds commission field matching RPC spec --- web3.js/src/connection.ts | 11 +++++++++++ web3.js/test/connection.test.ts | 1 + 2 files changed, 12 insertions(+) diff --git a/web3.js/src/connection.ts b/web3.js/src/connection.ts index fd7d9b7edda12c..254d00d9d2e04f 100644 --- a/web3.js/src/connection.ts +++ b/web3.js/src/connection.ts @@ -767,6 +767,8 @@ export type InflationReward = { amount: number; /** post balance of the account in lamports */ postBalance: number; + /** vote account commission when the reward was credited */ + commission: number | null; }; /** @@ -780,6 +782,7 @@ const GetInflationRewardResult = jsonRpcResult( effectiveSlot: number(), amount: number(), postBalance: number(), + commission: optional(nullable(number())), }), ), ), @@ -1232,6 +1235,8 @@ export type BlockResponse = { postBalance: number | null; /** Type of reward received */ rewardType: string | null; + /** Vote account commission when the reward was credited, only present for voting and staking rewards */ + commission: number | null; }>; /** The unix timestamp of when the block was processed */ blockTime: number | null; @@ -1276,6 +1281,8 @@ export type ParsedBlockResponse = { postBalance: number | null; /** Type of reward received */ rewardType: string | null; + /** Vote account commission when the reward was credited, only present for voting and staking rewards */ + commission: number | null; }>; /** The unix timestamp of when the block was processed */ blockTime: number | null; @@ -1344,6 +1351,8 @@ export type VersionedBlockResponse = { postBalance: number | null; /** Type of reward received */ rewardType: string | null; + /** Vote account commission when the reward was credited, only present for voting and staking rewards */ + commission: number | null; }>; /** The unix timestamp of when the block was processed */ blockTime: number | null; @@ -1399,6 +1408,7 @@ export type ConfirmedBlock = { lamports: number; postBalance: number | null; rewardType: string | null; + commission: number | null; }>; /** The unix timestamp of when the block was processed */ blockTime: number | null; @@ -2297,6 +2307,7 @@ const RewardsResult = pick({ lamports: number(), postBalance: nullable(number()), rewardType: nullable(string()), + commission: optional(nullable(number())), }); /** diff --git a/web3.js/test/connection.test.ts b/web3.js/test/connection.test.ts index 08e0383114f7c9..c530748620d798 100644 --- a/web3.js/test/connection.test.ts +++ b/web3.js/test/connection.test.ts @@ -808,6 +808,7 @@ describe('Connection', function () { effectiveSlot: 432000, epoch: 0, postBalance: 30504783, + commission: 0, }, null, ], From e24e84c25cfd5323a01ea9b46517b7467c1dba43 Mon Sep 17 00:00:00 2001 From: Kollan House Date: Fri, 30 Dec 2022 08:38:24 +0800 Subject: [PATCH 2/2] fix: update optional to follow type pattern --- web3.js/src/connection.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/web3.js/src/connection.ts b/web3.js/src/connection.ts index 254d00d9d2e04f..3ad11570d5925f 100644 --- a/web3.js/src/connection.ts +++ b/web3.js/src/connection.ts @@ -768,7 +768,7 @@ export type InflationReward = { /** post balance of the account in lamports */ postBalance: number; /** vote account commission when the reward was credited */ - commission: number | null; + commission?: number | null; }; /** @@ -1236,7 +1236,7 @@ export type BlockResponse = { /** Type of reward received */ rewardType: string | null; /** Vote account commission when the reward was credited, only present for voting and staking rewards */ - commission: number | null; + commission?: number | null; }>; /** The unix timestamp of when the block was processed */ blockTime: number | null; @@ -1282,7 +1282,7 @@ export type ParsedBlockResponse = { /** Type of reward received */ rewardType: string | null; /** Vote account commission when the reward was credited, only present for voting and staking rewards */ - commission: number | null; + commission?: number | null; }>; /** The unix timestamp of when the block was processed */ blockTime: number | null; @@ -1352,7 +1352,7 @@ export type VersionedBlockResponse = { /** Type of reward received */ rewardType: string | null; /** Vote account commission when the reward was credited, only present for voting and staking rewards */ - commission: number | null; + commission?: number | null; }>; /** The unix timestamp of when the block was processed */ blockTime: number | null; @@ -1408,7 +1408,7 @@ export type ConfirmedBlock = { lamports: number; postBalance: number | null; rewardType: string | null; - commission: number | null; + commission?: number | null; }>; /** The unix timestamp of when the block was processed */ blockTime: number | null;