diff --git a/src/solana/rpc/api.py b/src/solana/rpc/api.py index cea07dfa..5a130d0b 100644 --- a/src/solana/rpc/api.py +++ b/src/solana/rpc/api.py @@ -26,6 +26,7 @@ GetIdentityResp, GetInflationGovernorResp, GetInflationRateResp, + GetInflationRewardResp, GetLargestAccountsResp, GetLatestBlockhashResp, GetLeaderScheduleResp, @@ -476,6 +477,24 @@ def get_inflation_rate(self) -> GetInflationRateResp: """ return self._provider.make_request(self._get_inflation_rate, GetInflationRateResp) + def get_inflation_reward( + self, pubkeys: List[Pubkey], epoch: Optional[int] = None, commitment: Optional[Commitment] = None + ) -> GetInflationRewardResp: + """Returns the inflation / staking reward for a list of addresses for an epoch. + + Args: + pubkeys: An array of addresses to query, as base-58 encoded strings + epoch: (optional) An epoch for which the reward occurs. If omitted, the previous epoch will be used + commitment: Bank state to query. It can be either "finalized" or "confirmed". + + Example: + >>> solana_client = Client("http://localhost:8899") + >>> solana_client.get_inflation_reward().value.amount # doctest: +SKIP + 2500 + """ + body = self._get_inflation_reward_body(pubkeys, epoch, commitment) + return self._provider.make_request(body, GetInflationRewardResp) + def get_largest_accounts( self, filter_opt: Optional[str] = None, commitment: Optional[Commitment] = None ) -> GetLargestAccountsResp: diff --git a/src/solana/rpc/async_api.py b/src/solana/rpc/async_api.py index a09b265c..62ad9c49 100644 --- a/src/solana/rpc/async_api.py +++ b/src/solana/rpc/async_api.py @@ -25,6 +25,7 @@ GetIdentityResp, GetInflationGovernorResp, GetInflationRateResp, + GetInflationRewardResp, GetLargestAccountsResp, GetLatestBlockhashResp, GetLeaderScheduleResp, @@ -488,6 +489,24 @@ async def get_inflation_rate(self) -> GetInflationRateResp: """ return await self._provider.make_request(self._get_inflation_rate, GetInflationRateResp) + async def get_inflation_reward( + self, pubkeys: List[Pubkey], epoch: Optional[int] = None, commitment: Optional[Commitment] = None + ) -> GetInflationRewardResp: + """Returns the inflation / staking reward for a list of addresses for an epoch. + + Args: + pubkeys: An array of addresses to query, as base-58 encoded strings + epoch: (optional) An epoch for which the reward occurs. If omitted, the previous epoch will be used + commitment: Bank state to query. It can be either "finalized" or "confirmed". + + Example: + >>> solana_client = AsyncClient("http://localhost:8899") + >>> (await solana_client.get_inflation_reward()).value.amount # doctest: +SKIP + 2500 + """ + body = self._get_inflation_reward_body(pubkeys, epoch, commitment) + return await self._provider.make_request(body, GetInflationRewardResp) + async def get_largest_accounts( self, filter_opt: Optional[str] = None, commitment: Optional[Commitment] = None ) -> GetLargestAccountsResp: diff --git a/src/solana/rpc/core.py b/src/solana/rpc/core.py index e4aa37f3..1f42d795 100644 --- a/src/solana/rpc/core.py +++ b/src/solana/rpc/core.py @@ -45,6 +45,7 @@ GetIdentity, GetInflationGovernor, GetInflationRate, + GetInflationReward, GetLargestAccounts, GetLatestBlockhash, GetLeaderSchedule, @@ -347,6 +348,15 @@ def _get_stake_activation_body( commitment_to_use = _COMMITMENT_TO_SOLDERS[commitment or self._commitment] return GetStakeActivation(pubkey, RpcEpochConfig(epoch, commitment_to_use)) + def _get_inflation_reward_body( + self, + pubkeys: List[Pubkey], + epoch: Optional[int], + commitment: Optional[Commitment], + ) -> GetInflationReward: + commitment_to_use = _COMMITMENT_TO_SOLDERS[commitment or self._commitment] + return GetInflationReward(pubkeys, RpcEpochConfig(epoch, commitment_to_use)) + def _get_supply_body(self, commitment: Optional[Commitment]) -> GetSupply: commitment_to_use = _COMMITMENT_TO_SOLDERS[commitment or self._commitment] return GetSupply( diff --git a/tests/integration/test_async_http_client.py b/tests/integration/test_async_http_client.py index 58f1919c..babd7bc7 100644 --- a/tests/integration/test_async_http_client.py +++ b/tests/integration/test_async_http_client.py @@ -431,6 +431,15 @@ async def test_get_inflation_rate(test_http_client_async): assert_valid_response(resp) +# XXX: Block not available for slot on local cluster +@pytest.mark.skip +@pytest.mark.integration +async def test_get_inflation_reward(stubbed_sender, test_http_client_async): + """Test get inflation reward.""" + resp = await test_http_client_async.get_inflation_reward([stubbed_sender.pubkey()], commitment=Confirmed) + assert_valid_response(resp) + + @pytest.mark.integration async def test_get_largest_accounts(test_http_client_async): """Test get largest accounts.""" diff --git a/tests/integration/test_http_client.py b/tests/integration/test_http_client.py index 99e042a5..d947281b 100644 --- a/tests/integration/test_http_client.py +++ b/tests/integration/test_http_client.py @@ -415,6 +415,15 @@ def test_get_inflation_rate(test_http_client: Client): assert_valid_response(resp) +# XXX: Block not available for slot on local cluster +@pytest.mark.skip +@pytest.mark.integration +def test_get_inflation_reward(stubbed_sender, test_http_client: Client): + """Test get inflation reward.""" + resp = test_http_client.get_inflation_reward([stubbed_sender.pubkey()], commitment=Confirmed) + assert_valid_response(resp) + + @pytest.mark.integration def test_get_largest_accounts(test_http_client: Client): """Test get largest accounts."""