Skip to content

Commit

Permalink
default to RPC client commitment in token client
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinheavey committed Feb 11, 2022
1 parent dd2105a commit 4918012
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
10 changes: 6 additions & 4 deletions src/spl/token/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down
10 changes: 6 additions & 4 deletions src/spl/token/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down
10 changes: 6 additions & 4 deletions src/spl/token/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 4918012

Please sign in to comment.