Skip to content
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
17 changes: 17 additions & 0 deletions docs/supra_sdk.clients.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,20 @@ Api Client
:members:
:show-inheritance:
:undoc-members:


Supra Token
-------------------------------------

.. automodule:: supra_sdk.clients.supra_token
:members:
:show-inheritance:
:undoc-members:

Supra Token Object
-------------------------------------

.. automodule:: supra_sdk.clients.supra_token_object
:members:
:show-inheritance:
:undoc-members:
16 changes: 0 additions & 16 deletions docs/supra_sdk.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,6 @@ Metadata
:show-inheritance:
:undoc-members:

Supra Token Client
--------------------------------------

.. automodule:: supra_sdk.supra_token_client
:members:
:show-inheritance:
:undoc-members:

Supra TokenV1 Client
----------------------------------------

.. automodule:: supra_sdk.supra_tokenv1_client
:members:
:show-inheritance:
:undoc-members:

Transactions
------------------------------

Expand Down
6 changes: 3 additions & 3 deletions examples/simple_nft.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

from examples.common import RPC_NODE_URL
from supra_sdk.account import Account
from supra_sdk.clients import SupraTokenClient
from supra_sdk.clients.rest import SupraClient
from supra_sdk.supra_tokenv1_client import SupraTokenV1Client


async def main():
supra_client = SupraClient(RPC_NODE_URL)
token_client = SupraTokenV1Client(supra_client)
token_client = SupraTokenClient(supra_client)

alice = Account.generate()
bob = Account.generate()
Expand Down Expand Up @@ -54,7 +54,7 @@ async def main():
)
print(f"Alice's token balance: {balance}")
token_data = await token_client.get_token_data(
alice.address(), collection_name, token_name, property_version
alice.address(), collection_name, token_name
)
print(f"Alice's token data: {json.dumps(token_data, indent=4, sort_keys=True)}")

Expand Down
10 changes: 5 additions & 5 deletions examples/simple_supra_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
from supra_sdk.account import Account
from supra_sdk.account_address import AccountAddress
from supra_sdk.clients.rest import SupraClient
from supra_sdk.supra_token_client import (
from supra_sdk.clients.supra_token_object import (
Collection,
Object,
PropertyMap,
ReadObject,
SupraTokenClient,
SupraTokenObjectClient,
Token,
)

Expand All @@ -24,7 +24,7 @@ def get_owner(obj: ReadObject) -> AccountAddress:


async def get_collection_data(
token_client: SupraTokenClient, collection_addr: AccountAddress
token_client: SupraTokenObjectClient, collection_addr: AccountAddress
) -> dict[str, str]:
collection = (await token_client.read_object(collection_addr)).resources[Collection]
return {
Expand All @@ -36,7 +36,7 @@ async def get_collection_data(


async def get_token_data(
token_client: SupraTokenClient, token_addr: AccountAddress
token_client: SupraTokenObjectClient, token_addr: AccountAddress
) -> dict[str, str]:
token = (await token_client.read_object(token_addr)).resources[Token]
return {
Expand All @@ -50,7 +50,7 @@ async def get_token_data(

async def main():
supra_client = SupraClient(RPC_NODE_URL)
token_client = SupraTokenClient(supra_client)
token_client = SupraTokenObjectClient(supra_client)

alice = Account.generate()
bob = Account.generate()
Expand Down
9 changes: 7 additions & 2 deletions examples/supra_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@
from supra_sdk.account import Account
from supra_sdk.account_address import AccountAddress
from supra_sdk.clients.rest import SupraClient
from supra_sdk.supra_token_client import Object, Property, PropertyMap, SupraTokenClient
from supra_sdk.clients.supra_token_object import (
Object,
Property,
PropertyMap,
SupraTokenObjectClient,
)


async def main():
supra_client = SupraClient(RPC_NODE_URL)
token_client = SupraTokenClient(supra_client)
token_client = SupraTokenObjectClient(supra_client)

alice = Account.generate()
bob = Account.generate()
Expand Down
4 changes: 3 additions & 1 deletion supra_sdk/clients/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
# SPDX-License-Identifier: Apache-2.0

from supra_sdk.clients.api_client import ApiClient, ApiClientConfig
from supra_sdk.clients.supra_token import SupraTokenClient
from supra_sdk.clients.supra_token_object import SupraTokenObjectClient

__all__ = ["ApiClient", "ApiClientConfig"]
__all__ = ["ApiClient", "ApiClientConfig", "SupraTokenClient", "SupraTokenObjectClient"]
2 changes: 1 addition & 1 deletion supra_sdk/clients/rest/rest_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class RestClient:
api_client: ApiClient

def __init__(self, api_client: ApiClient):
"""Initialize a `RestClient` instance.
"""Initializes a `RestClient` instance.

Args:
api_client (supra_sdk.clients.api_client.ApiClient): An instance of `ApiClient` responsible for managing HTTP requests.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,21 @@
U64_MAX = 18446744073709551615


class SupraTokenV1Client:
"""A wrapper around reading and mutating SupraTokens also known as Token Objects"""
class SupraTokenClient:
"""A class that provides convenient methods to interact with the `aptos-token` package.

Args:
client (SupraClient): Instance of the `SupraClient` class used for interacting with rpc-node.
"""

client: SupraClient

def __init__(self, client: SupraClient):
"""Initializes a `SupraTokenClient` instance.

Args:
client (SupraClient): Instance of the `SupraClient` class.
"""
self.client = client

async def create_collection(
Expand Down Expand Up @@ -185,10 +194,6 @@ async def direct_transfer_token(
)
return await self.client.submit_transaction(signed_transaction)

"""
Token accessors
"""

async def get_token(
self,
owner: AccountAddress,
Expand Down Expand Up @@ -241,7 +246,6 @@ async def get_token_data(
creator: AccountAddress,
collection_name: str,
token_name: str,
_property_version: int,
) -> Any:
resource = await self.client.account_resource(
creator, "0x3::token::Collections"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,14 +335,23 @@ def __str__(self) -> str:
return response


class SupraTokenClient:
"""A wrapper around reading and mutating Digital Assets also known as Token Objects"""
class SupraTokenObjectClient:
"""A class that provides convenient methods to interact with the `aptos-token-package` package.

Args:
client (SupraClient): Instance of the `SupraClient` class used for interacting with rpc-node.
"""

client: SupraClient

PAGINATION_COUNT: int = 100

def __init__(self, client: SupraClient):
"""Initializes a `SupraTokenObjectClient` instance.

Args:
client (SupraClient): Instance of the `SupraClient` class.
"""
self.client = client

async def read_object(self, address: AccountAddress) -> ReadObject:
Expand Down Expand Up @@ -425,7 +434,7 @@ async def create_collection(
royalty_numerator: int,
royalty_denominator: int,
) -> str:
payload = SupraTokenClient.create_collection_payload(
payload = SupraTokenObjectClient.create_collection_payload(
description,
max_supply,
name,
Expand Down Expand Up @@ -490,7 +499,7 @@ async def mint_token(
uri: str,
properties: PropertyMap,
) -> str: # <:!:mint_token
payload = SupraTokenClient.mint_token_payload(
payload = SupraTokenObjectClient.mint_token_payload(
collection, description, name, uri, properties
)
signed_transaction = await self.client.create_signed_transaction(
Expand Down