Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added implementations for get_token_largest_accounts() and get_token_supply() #104

Merged
merged 6 commits into from
Sep 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions solana/rpc/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -874,13 +874,19 @@ def __get_token_accounts(
args = self._get_token_accounts_args(method, pubkey, opts, commitment)
return self._provider.make_request(*args)

def get_token_largest_accounts(self, pubkey: Union[PublicKey, str]) -> types.RPCResponse:
"""Returns the 20 largest accounts of a particular SPL Token type (UNSTABLE)."""
raise NotImplementedError("get_token_largbest_accounts not implemented")
def get_token_largest_accounts(
self, pubkey: Union[PublicKey, str], commitment: Optional[Commitment] = None
) -> types.RPCResponse:
"""Returns the 20 largest accounts of a particular SPL Token type."""
args = self._get_token_largest_account_args(pubkey, commitment)
return self._provider.make_request(*args)

def get_token_supply(self, pubkey: Union[PublicKey, str]) -> types.RPCResponse:
"""Returns the total supply of an SPL Token type(UNSTABLE)."""
raise NotImplementedError("get_token_supply not implemented")
def get_token_supply(
self, pubkey: Union[PublicKey, str], commitment: Optional[Commitment] = None
) -> types.RPCResponse:
"""Returns the total supply of an SPL Token type."""
args = self._get_token_supply_args(pubkey, commitment)
return self._provider.make_request(*args)

def get_transaction_count(self, commitment: Optional[Commitment] = None) -> types.RPCResponse:
"""Returns the current Transaction count from the ledger.
Expand Down
18 changes: 12 additions & 6 deletions solana/rpc/async_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -870,13 +870,19 @@ async def __get_token_accounts(
args = self._get_token_accounts_args(method, pubkey, opts, commitment)
return await self._provider.make_request(*args)

async def get_token_largest_accounts(self, pubkey: Union[PublicKey, str]) -> types.RPCResponse:
"""Returns the 20 largest accounts of a particular SPL Token type (UNSTABLE)."""
raise NotImplementedError("get_token_largbest_accounts not implemented")
async def get_token_largest_accounts(
self, pubkey: Union[PublicKey, str], commitment: Optional[Commitment] = None
) -> types.RPCResponse:
"""Returns the 20 largest accounts of a particular SPL Token type."""
args = self._get_token_largest_account_args(pubkey, commitment)
return await self._provider.make_request(*args)

async def get_token_supply(self, pubkey: Union[PublicKey, str]) -> types.RPCResponse:
"""Returns the total supply of an SPL Token type(UNSTABLE)."""
raise NotImplementedError("get_token_supply not implemented")
async def get_token_supply(
self, pubkey: Union[PublicKey, str], commitment: Optional[Commitment] = None
) -> types.RPCResponse:
"""Returns the total supply of an SPL Token type."""
args = self._get_token_supply_args(pubkey, commitment)
return await self._provider.make_request(*args)

async def get_transaction_count(self, commitment: Optional[Commitment] = None) -> types.RPCResponse:
"""Returns the current Transaction count from the ledger.
Expand Down
10 changes: 10 additions & 0 deletions solana/rpc/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,16 @@ def _get_token_accounts_args(

return method, pubkey, acc_opts, rpc_opts

def _get_token_largest_account_args(
self, pubkey: Union[str, PublicKey], commitment: Optional[Commitment]
) -> Tuple[types.RPCMethod, str, Dict[str, Commitment]]:
return types.RPCMethod("getTokenLargestAccounts"), str(pubkey), {self._comm_key: commitment or self._commitment}

def _get_token_supply_args(
self, pubkey: Union[str, PublicKey], commitment: Optional[Commitment]
) -> Tuple[types.RPCMethod, str, Dict[str, Commitment]]:
return types.RPCMethod("getTokenSupply"), str(pubkey), {self._comm_key: commitment or self._commitment}

def _get_transaction_count_args(
self, commitment: Optional[Commitment]
) -> Tuple[types.RPCMethod, Dict[str, Commitment]]:
Expand Down
17 changes: 17 additions & 0 deletions tests/integration/test_async_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import solana.system_program as sp
from solana.rpc.api import DataSliceOpt
from solana.transaction import Transaction
from spl.token.constants import WRAPPED_SOL_MINT

from .utils import AIRDROP_AMOUNT, aconfirm_transaction, assert_valid_response, generate_expected_meta_after_airdrop

Expand Down Expand Up @@ -500,6 +501,22 @@ async def test_get_supply(test_http_client_async):
assert_valid_response(resp)


@pytest.mark.integration
whdev1 marked this conversation as resolved.
Show resolved Hide resolved
@pytest.mark.asyncio
async def test_get_token_largest_accounts(test_http_client_async):
"""Test get token largest accounts."""
resp = await test_http_client_async.get_token_largest_accounts(WRAPPED_SOL_MINT)
assert_valid_response(resp)


@pytest.mark.integration
@pytest.mark.asyncio
async def test_get_token_supply(test_http_client_async):
"""Test get token supply."""
resp = await test_http_client_async.get_token_supply(WRAPPED_SOL_MINT)
assert_valid_response(resp)


@pytest.mark.integration
@pytest.mark.asyncio
async def test_get_transaction_count(test_http_client_async):
Expand Down
15 changes: 15 additions & 0 deletions tests/integration/test_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import solana.system_program as sp
from solana.rpc.api import DataSliceOpt
from solana.transaction import Transaction
from spl.token.constants import WRAPPED_SOL_MINT

from .utils import AIRDROP_AMOUNT, assert_valid_response, confirm_transaction, generate_expected_meta_after_airdrop

Expand Down Expand Up @@ -490,6 +491,20 @@ def test_get_multiple_accounts(stubbed_sender, test_http_client):
assert_valid_response(resp)


@pytest.mark.integration
def test_get_token_largest_accounts(test_http_client):
"""Test get token largest accounts."""
resp = test_http_client.get_token_largest_accounts(WRAPPED_SOL_MINT)
assert_valid_response(resp)


@pytest.mark.integration
def test_get_token_supply(test_http_client):
"""Test get token supply."""
resp = test_http_client.get_token_supply(WRAPPED_SOL_MINT)
assert_valid_response(resp)


@pytest.mark.integration
def test_get_vote_accounts(test_http_client):
"""Test get vote accounts."""
Expand Down