From 49180122df581d21aac4b6c52c185d8af60c354b Mon Sep 17 00:00:00 2001 From: Kevin Heavey Date: Fri, 11 Feb 2022 21:52:01 +0000 Subject: [PATCH] default to RPC client commitment in token client --- src/spl/token/async_client.py | 10 ++++++---- src/spl/token/client.py | 10 ++++++---- src/spl/token/core.py | 10 ++++++---- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/spl/token/async_client.py b/src/spl/token/async_client.py index 5eda3cb3..9d3229f6 100644 --- a/src/spl/token/async_client.py +++ b/src/spl/token/async_client.py @@ -9,7 +9,7 @@ from solana.keypair import Keypair from solana.publickey import PublicKey from solana.rpc.async_api import AsyncClient -from solana.rpc.commitment import Commitment, Confirmed +from solana.rpc.commitment import Commitment from solana.rpc.types import RPCResponse, TxOpts from spl.token._layouts import ACCOUNT_LAYOUT, MINT_LAYOUT, MULTISIG_LAYOUT from spl.token.core import AccountInfo, MintInfo, _TokenCore @@ -57,7 +57,7 @@ async def get_accounts( self, owner: PublicKey, is_delegate: bool = False, - commitment: Commitment = Confirmed, + commitment: Optional[Commitment] = None, encoding: str = "jsonParsed", ) -> RPCResponse: """Get token accounts of the provided owner by the token's mint. @@ -72,14 +72,16 @@ async def get_accounts( valid mint cannot be found for a particular account, that account will be filtered out from results. jsonParsed encoding is UNSTABLE. """ - args = self._get_accounts_args(owner, commitment, encoding) + args = self._get_accounts_args( + owner, commitment, encoding, self._conn._commitment # pylint: disable=protected-access + ) return ( await self._conn.get_token_accounts_by_delegate(*args) if is_delegate else await self._conn.get_token_accounts_by_owner(*args) ) - async def get_balance(self, pubkey: PublicKey, commitment: Commitment = Confirmed) -> RPCResponse: + async def get_balance(self, pubkey: PublicKey, commitment: Optional[Commitment] = None) -> RPCResponse: """Get the balance of the provided token account. :param pubkey: Public Key of the token account. diff --git a/src/spl/token/client.py b/src/spl/token/client.py index 5fdeade8..bed4ed19 100644 --- a/src/spl/token/client.py +++ b/src/spl/token/client.py @@ -9,7 +9,7 @@ from solana.keypair import Keypair from solana.publickey import PublicKey from solana.rpc.api import Client -from solana.rpc.commitment import Commitment, Confirmed +from solana.rpc.commitment import Commitment from solana.rpc.types import RPCResponse, TxOpts from spl.token._layouts import ACCOUNT_LAYOUT, MINT_LAYOUT, MULTISIG_LAYOUT from spl.token.core import AccountInfo, MintInfo, _TokenCore @@ -57,7 +57,7 @@ def get_accounts( self, owner: PublicKey, is_delegate: bool = False, - commitment: Commitment = Confirmed, + commitment: Optional[Commitment] = None, encoding: str = "jsonParsed", ) -> RPCResponse: """Get token accounts of the provided owner by the token's mint. @@ -72,14 +72,16 @@ def get_accounts( valid mint cannot be found for a particular account, that account will be filtered out from results. jsonParsed encoding is UNSTABLE. """ - args = self._get_accounts_args(owner, commitment, encoding) + args = self._get_accounts_args( + owner, commitment, encoding, self._conn._commitment # pylint: disable=protected-access + ) return ( self._conn.get_token_accounts_by_delegate(*args) if is_delegate else self._conn.get_token_accounts_by_owner(*args) ) - def get_balance(self, pubkey: PublicKey, commitment: Commitment = Confirmed) -> RPCResponse: + def get_balance(self, pubkey: PublicKey, commitment: Optional[Commitment] = None) -> RPCResponse: """Get the balance of the provided token account. :param pubkey: Public Key of the token account. diff --git a/src/spl/token/core.py b/src/spl/token/core.py index 6d90a309..48c42623 100644 --- a/src/spl/token/core.py +++ b/src/spl/token/core.py @@ -10,7 +10,7 @@ from solana.publickey import PublicKey from solana.rpc.api import Client from solana.rpc.async_api import AsyncClient -from solana.rpc.commitment import Commitment, Confirmed +from solana.rpc.commitment import Commitment from solana.rpc.types import RPCResponse, TokenAccountOpts, TxOpts from solana.transaction import Transaction from solana.utils.helpers import decode_byte_string @@ -89,10 +89,12 @@ def __init__(self, pubkey: PublicKey, program_id: PublicKey, payer: Keypair) -> def _get_accounts_args( self, owner: PublicKey, - commitment: Commitment = Confirmed, - encoding: str = "jsonParsed", + commitment: Optional[Commitment], + encoding, + default_commitment: Commitment, ) -> Tuple[PublicKey, TokenAccountOpts, Commitment]: - return owner, TokenAccountOpts(mint=self.pubkey, encoding=encoding), commitment + commitment_to_use = default_commitment if commitment is None else commitment + return owner, TokenAccountOpts(mint=self.pubkey, encoding=encoding), commitment_to_use @staticmethod def _create_mint_args(