From f4ec4fc21346261a3592b426a99c5a9710901ed0 Mon Sep 17 00:00:00 2001 From: Ayush Pathak <62694274+ayshptk@users.noreply.github.com> Date: Thu, 11 Nov 2021 18:48:14 +0530 Subject: [PATCH 01/11] collection -> bundle --- README.md | 2 +- tests/test_constants.py | 2 +- tests/test_import.py | 7 +- tests/test_market.py | 6 +- tests/test_roles.py | 6 +- thirdweb/abi/__init__.py | 1 + thirdweb/modules/__init__.py | 1 + thirdweb/modules/base.py | 4 +- thirdweb/modules/bundle.py | 159 ++++++++++++++++++++++++++ thirdweb/modules/collection.py | 78 +++++++++++++ thirdweb/sdk.py | 22 +++- thirdweb/types/bundle/__init__.py | 31 +++++ thirdweb/types/collection/__init__.py | 9 ++ thirdweb/types/listing.py | 4 +- 14 files changed, 311 insertions(+), 21 deletions(-) create mode 100644 thirdweb/modules/bundle.py create mode 100644 thirdweb/types/bundle/__init__.py diff --git a/README.md b/README.md index 75932498..0691e0fc 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ $ pip install thirdweb-sdk nftlabs ├── abi // contains autogenerated ABI contract wrappers ├── errors // commonly thrown errors -├── modules // NFT, Currency, Marketplace, Pack, Collection, etc modules +├── modules // NFT, Currency, Marketplace, Pack, Bundle, etc modules ├── options // Options classes used throughout the SDK ├── sdk.py // NftlabsSdk class, wrapper for the entire package ├── storage // Distributed file storage helper classes diff --git a/tests/test_constants.py b/tests/test_constants.py index c499b8e7..545c1ce7 100644 --- a/tests/test_constants.py +++ b/tests/test_constants.py @@ -1,7 +1,7 @@ TEST_NFT_CONTRACT_ADDRESS = "0xEeD541b524Ae738c48211Be91EB81E97739A0A29" TEST_PACK_CONTRACT_ADDRESS = "0x54ec360704b2e9E4e6499a732b78094D6d78e37B" TEST_MARKET_CONTRACT_ADDRESS = "0x325a98B6081ef88C6356d63c56f48Fa1d0d2DD0D" -TEST_COLLECTION_CONTRACT_ADDRESS = "0x6Da734b14e4CE604f1e18efb7E7f7ef022e96616" +TEST_BUNDLE_CONTRACT_ADDRESS = "0x6Da734b14e4CE604f1e18efb7E7f7ef022e96616" TEST_CURRENCY_CONTRACT_ADDRESS = "0xF18FEb8b2F58691d67C98dB98B360840df340e74" TEST_COMPANION_WALLET_ADDRESS = "0x4d36d531D9cB40b8694763123D52170FAE5e1195" diff --git a/tests/test_import.py b/tests/test_import.py index 00d9844b..e6803d35 100644 --- a/tests/test_import.py +++ b/tests/test_import.py @@ -24,12 +24,13 @@ def test_init_currency_module(self): sdk = NftlabsSdk(SdkOptions(), "https://rpc-mumbai.maticvigil.com") currency_module = sdk.get_currency_module("0xF18FEb8b2F58691d67C98dB98B360840df340e74") - def test_init_collection_module(self): + + def test_init_bundle_module(self): """ - Test that tries to instantiate the Currency module + Test that tries to instantiate the Bundle module """ sdk = NftlabsSdk(SdkOptions(), "https://rpc-mumbai.maticvigil.com") - collection_module = sdk.get_collection_module("0x6Da734b14e4CE604f1e18efb7E7f7ef022e96616") + bundle_module = sdk.get_bundle_module("0x6Da734b14e4CE604f1e18efb7E7f7ef022e96616") def test_init_pack_module(self): """ diff --git a/tests/test_market.py b/tests/test_market.py index c1432809..4a5936d9 100644 --- a/tests/test_market.py +++ b/tests/test_market.py @@ -2,7 +2,7 @@ from nftlabs import NftlabsSdk, SdkOptions -from test_constants import (TEST_COLLECTION_CONTRACT_ADDRESS, +from test_constants import (TEST_BUNDLE_CONTRACT_ADDRESS, TEST_MARKET_CONTRACT_ADDRESS, TEST_NFT_CONTRACT_ADDRESS) @@ -16,11 +16,11 @@ def test_init_marketplace_module(self): market_module = sdk.get_market_module(TEST_MARKET_CONTRACT_ADDRESS) self.assertFalse(market_module.is_erc721( - TEST_COLLECTION_CONTRACT_ADDRESS), "A collection is not a 721 contract") + TEST_BUNDLE_CONTRACT_ADDRESS), "A bundle is not a 721 contract") self.assertTrue(market_module.is_erc721( TEST_NFT_CONTRACT_ADDRESS), "A nft contract is a 721 contract") self.assertTrue(market_module.is_erc1155( - TEST_COLLECTION_CONTRACT_ADDRESS), "A collection is a 1155 contract") + TEST_BUNDLE_CONTRACT_ADDRESS), "A bundle is a 1155 contract") self.assertFalse(market_module.is_erc1155( TEST_NFT_CONTRACT_ADDRESS), "A nft contract is not a 1155 contract") diff --git a/tests/test_roles.py b/tests/test_roles.py index d03a08c5..5a5b3893 100644 --- a/tests/test_roles.py +++ b/tests/test_roles.py @@ -3,7 +3,7 @@ from nftlabs import NftlabsSdk, SdkOptions from nftlabs.types.role import Role from os import environ -from test_constants import TEST_COLLECTION_CONTRACT_ADDRESS, TEST_CURRENCY_CONTRACT_ADDRESS, TEST_MARKET_CONTRACT_ADDRESS, TEST_NFT_CONTRACT_ADDRESS, TEST_COMPANION_WALLET_ADDRESS, TEST_PACK_CONTRACT_ADDRESS +from test_constants import TEST_BUNDLE_CONTRACT_ADDRESS, TEST_CURRENCY_CONTRACT_ADDRESS, TEST_MARKET_CONTRACT_ADDRESS, TEST_NFT_CONTRACT_ADDRESS, TEST_COMPANION_WALLET_ADDRESS, TEST_PACK_CONTRACT_ADDRESS class TestRoles(unittest.TestCase): @@ -20,8 +20,8 @@ def test_grant_and_revoke_role(self): TEST_NFT_CONTRACT_ADDRESS), sdk.get_market_module( TEST_MARKET_CONTRACT_ADDRESS), - sdk.get_collection_module( - TEST_COLLECTION_CONTRACT_ADDRESS), + sdk.get_bundle_module( + TEST_BUNDLE_CONTRACT_ADDRESS), sdk.get_pack_module( TEST_PACK_CONTRACT_ADDRESS), sdk.get_currency_module( diff --git a/thirdweb/abi/__init__.py b/thirdweb/abi/__init__.py index f0606a2a..685bda45 100644 --- a/thirdweb/abi/__init__.py +++ b/thirdweb/abi/__init__.py @@ -4,3 +4,4 @@ from .pack import * from .nft_collection import * +#todo? diff --git a/thirdweb/modules/__init__.py b/thirdweb/modules/__init__.py index 128a8b66..aaa41b7c 100644 --- a/thirdweb/modules/__init__.py +++ b/thirdweb/modules/__init__.py @@ -6,3 +6,4 @@ from .market import * from .pack import * from .collection import * +from .bundle import * diff --git a/thirdweb/modules/base.py b/thirdweb/modules/base.py index 4207dc38..0ec00367 100644 --- a/thirdweb/modules/base.py +++ b/thirdweb/modules/base.py @@ -12,7 +12,7 @@ from ..abi.erc165 import ERC165 from ..abi.market import Market from ..abi.nft import NFT -from ..abi.nft_collection import NFTCollection +from ..abi.nft_collection import NFTCollection as NFTBundle from ..abi.pack import Pack from ..constants.erc_interfaces import InterfaceIdErc721, InterfaceIdErc1155 from ..errors import NoSignerException @@ -20,7 +20,7 @@ from ..storage import IpfsStorage from ..types.role import Role -ModuleTypes = Union[NFT, Market, Pack, NFTCollection, Coin] +ModuleTypes = Union[NFT, Market, Pack, NFTBundle, Coin] class BaseModule(ABC): diff --git a/thirdweb/modules/bundle.py b/thirdweb/modules/bundle.py new file mode 100644 index 00000000..eccb62a7 --- /dev/null +++ b/thirdweb/modules/bundle.py @@ -0,0 +1,159 @@ +from typing import List + +from thirdweb_web3 import Web3 + +from ..abi.nft_collection import NFTCollection as NFTBundle +# from ..types.collection import (BundleMetadata, CreateBundleArg, +# MintBundleArg) +from ..types.bundle import (BundleMetadata, CreateBundleArg, MintBundleArg) +from ..types.metadata import Metadata +from ..types.nft import NftMetadata +from .base import BaseModule + + +class BundleModule(BaseModule): + address: str + __abi_module: NFTBundle + + def __init__(self, address: str, client: Web3): + super().__init__() + self.address = address + self.__abi_module = NFTBundle(client, address) + + def get(self, token_id: int) -> BundleMetadata: + uri = self.__abi_module.uri.call(token_id) + meta_str = self.get_storage().get(uri) + meta: NftMetadata = NftMetadata.from_json(meta_str) + meta.id = token_id + return BundleMetadata( + metadata=meta, + supply=self.__abi_module.total_supply.call(token_id), + creator=self.__abi_module.creator.call(token_id), + id=token_id + ) + + def get_all(self) -> List[BundleMetadata]: + return [self.get(i) for i in range(self.__abi_module.next_token_id.call())] + + ''' + Returns the balance for a given token at owned by a specific address + ''' + + def balance_of(self, address: str, token_id: int) -> int: + return self.__abi_module.balance_of.call(address, token_id) + + ''' + Returns the balance for a given token id for the current signers address + ''' + + def balance(self, token_id: int) -> int: + return self.__abi_module.balance_of.call( + self.get_signer_address(), + token_id + ) + + def is_approved(self, address: str, operator: str) -> bool: + return self.__abi_module.is_approved_for_all.call( + address, + operator + ) + + def set_approval(self, operator: str, approved: bool = True): + self.execute_tx(self.__abi_module.set_approval_for_all.build_transaction( + operator, approved, self.get_transact_opts() + )) + + def transfer(self, to_address: str, token_id: int, amount: int): + self.execute_tx(self.__abi_module.safe_transfer_from.build_transaction( + self.get_signer_address(), to_address, token_id, amount, "", self.get_transact_opts() + )) + + def create(self, metadata: Metadata) -> BundleMetadata: + return self.create_batch([metadata])[0] + + def create_batch(self, metas: List[Metadata]) -> List[BundleMetadata]: + meta_with_supply = [CreateBundleArg( + metadata=m, supply=0) for m in metas] + return self.create_and_mint_batch(meta_with_supply) + + def create_and_mint(self, meta_with_supply: CreateBundleArg) -> BundleMetadata: + return self.create_and_mint_batch([meta_with_supply])[0] + + def create_and_mint_batch(self, meta_with_supply: List[CreateBundleArg]) -> List[BundleMetadata]: + uris = [self.get_storage().upload(meta.to_json(), self.address, + self.get_signer_address()) for meta in meta_with_supply] + supplies = [a.supply for a in meta_with_supply] + receipt = self.execute_tx(self.__abi_module.create_native_tokens.build_transaction( + self.get_signer_address(), uris, supplies, "", self.get_transact_opts() + )) + result = self.__abi_module.get_native_tokens_event( + tx_hash=receipt.transactionHash.hex()) + token_ids = result[0]['args']['tokenIds'] + return [self.get(i) for i in token_ids] + + def create_with_erc20(self, token_contract: str, token_amount: int, arg: CreateBundleArg): + uri = self.get_storage().upload( + arg.metadata, self.address, self.get_signer_address()) + self.execute_tx(self.__abi_module.wrap_erc20.build_transaction( + token_contract, token_amount, arg.supply, uri, self.get_transact_opts() + )) + + def create_with_erc721(self, token_contract: str, token_id: int, metadata): + uri = self.get_storage().upload( + metadata.metadata, self.address, self.get_signer_address()) + self.execute_tx(self.__abi_module.wrap_erc721.build_transaction( + token_contract, token_id, uri, self.get_transact_opts() + )) + + def mint(self, args: MintBundleArg): + self.mint_to(self.get_signer_address(), args) + + def mint_to(self, to_address: str, arg: MintBundleArg): + self.execute_tx(self.__abi_module.mint.build_transaction( + to_address, arg.token_id, arg.amount, "", self.get_transact_opts() + )) + + def mint_batch(self, args: List[MintBundleArg]): + self.mint_batch_to(self.get_signer_address(), args) + + def mint_batch_to(self, to_address, args: List[MintBundleArg]): + ids = [a.token_id for a in args] + amounts = [a.amount for a in args] + tx = self.__abi_module.mint_batch.build_transaction( + to_address, ids, amounts, self.get_transact_opts()) + self.execute_tx(tx) + + def burn(self, args: MintBundleArg): + self.burn_from(self.get_signer_address(), args) + + def burn_batch(self, args: List[MintBundleArg]): + self.burn_batch_from(self.get_signer_address(), args) + + def burn_from(self, account: str, args: MintBundleArg): + self.execute_tx(self.__abi_module.burn.build_transaction( + account, args.token_id, args.amount, self.get_transact_opts() + )) + + def burn_batch_from(self, account: str, args: List[MintBundleArg]): + self.execute_tx(self.__abi_module.burn_batch.build_transaction( + account, [i.id for i in args], [ + i.amount for i in args], self.get_transact_opts() + )) + + def transfer_from(self, from_address: str, to_address: str, args: MintBundleArg): + self.execute_tx(self.__abi_module.safe_transfer_from.build_transaction( + from_address, to_address, args.token_id, args.amount, "", self.get_transact_opts() + )) + + def transfer_batch_from(self, from_address: str, to_address: str, args): + self.execute_tx(self.__abi_module.safe_batch_transfer_from.build_transaction( + from_address, to_address, args.token_id, args.amount, "", self.get_transact_opts() + )) + + def set_royalty_bps(self, amount: int): + self.execute_tx(self.__abi_module.set_royalty_bps.build_transaction( + amount, self.get_transact_opts() + )) + + def get_abi_module(self) -> NFTBundle: + return self.__abi_module diff --git a/thirdweb/modules/collection.py b/thirdweb/modules/collection.py index 806f2bac..8d0e0738 100644 --- a/thirdweb/modules/collection.py +++ b/thirdweb/modules/collection.py @@ -11,6 +11,9 @@ class CollectionModule(BaseModule): + """ + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + """ address: str __abi_module: NFTCollection @@ -20,6 +23,9 @@ def __init__(self, address: str, client: Web3): self.__abi_module = NFTCollection(client, address) def get(self, token_id: int) -> CollectionMetadata: + """ + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + """ uri = self.__abi_module.uri.call(token_id) meta_str = self.get_storage().get(uri) meta: NftMetadata = NftMetadata.from_json(meta_str) @@ -32,6 +38,9 @@ def get(self, token_id: int) -> CollectionMetadata: ) def get_all(self) -> List[CollectionMetadata]: + """ + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + """ return [self.get(i) for i in range(self.__abi_module.next_token_id.call())] ''' @@ -39,6 +48,9 @@ def get_all(self) -> List[CollectionMetadata]: ''' def balance_of(self, address: str, token_id: int) -> int: + """ + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + """ return self.__abi_module.balance_of.call(address, token_id) ''' @@ -46,39 +58,63 @@ def balance_of(self, address: str, token_id: int) -> int: ''' def balance(self, token_id: int) -> int: + """ + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + """ return self.__abi_module.balance_of.call( self.get_signer_address(), token_id ) def is_approved(self, address: str, operator: str) -> bool: + """ + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + """ return self.__abi_module.is_approved_for_all.call( address, operator ) def set_approval(self, operator: str, approved: bool = True): + """ + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + """ self.execute_tx(self.__abi_module.set_approval_for_all.build_transaction( operator, approved, self.get_transact_opts() )) def transfer(self, to_address: str, token_id: int, amount: int): + """ + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + """ self.execute_tx(self.__abi_module.safe_transfer_from.build_transaction( self.get_signer_address(), to_address, token_id, amount, "", self.get_transact_opts() )) def create(self, metadata: Metadata) -> CollectionMetadata: + """ + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + """ return self.create_batch([metadata])[0] def create_batch(self, metas: List[Metadata]) -> List[CollectionMetadata]: + """ + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + """ meta_with_supply = [CreateCollectionArg( metadata=m, supply=0) for m in metas] return self.create_and_mint_batch(meta_with_supply) def create_and_mint(self, meta_with_supply: CreateCollectionArg) -> CollectionMetadata: + """ + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + """ return self.create_and_mint_batch([meta_with_supply])[0] def create_and_mint_batch(self, meta_with_supply: List[CreateCollectionArg]) -> List[CollectionMetadata]: + """ + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + """ uris = [self.get_storage().upload(meta.to_json(), self.address, self.get_signer_address()) for meta in meta_with_supply] supplies = [a.supply for a in meta_with_supply] @@ -91,6 +127,9 @@ def create_and_mint_batch(self, meta_with_supply: List[CreateCollectionArg]) -> return [self.get(i) for i in token_ids] def create_with_erc20(self, token_contract: str, token_amount: int, arg: CreateCollectionArg): + """ + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + """ uri = self.get_storage().upload( arg.metadata, self.address, self.get_signer_address()) self.execute_tx(self.__abi_module.wrap_erc20.build_transaction( @@ -98,6 +137,9 @@ def create_with_erc20(self, token_contract: str, token_amount: int, arg: CreateC )) def create_with_erc721(self, token_contract: str, token_id: int, metadata): + """ + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + """ uri = self.get_storage().upload( metadata.metadata, self.address, self.get_signer_address()) self.execute_tx(self.__abi_module.wrap_erc721.build_transaction( @@ -105,17 +147,29 @@ def create_with_erc721(self, token_contract: str, token_id: int, metadata): )) def mint(self, args: MintCollectionArg): + """ + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + """ self.mint_to(self.get_signer_address(), args) def mint_to(self, to_address: str, arg: MintCollectionArg): + """ + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + """ self.execute_tx(self.__abi_module.mint.build_transaction( to_address, arg.token_id, arg.amount, "", self.get_transact_opts() )) def mint_batch(self, args: List[MintCollectionArg]): + """ + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + """ self.mint_batch_to(self.get_signer_address(), args) def mint_batch_to(self, to_address, args: List[MintCollectionArg]): + """ + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + """ ids = [a.token_id for a in args] amounts = [a.amount for a in args] tx = self.__abi_module.mint_batch.build_transaction( @@ -123,36 +177,60 @@ def mint_batch_to(self, to_address, args: List[MintCollectionArg]): self.execute_tx(tx) def burn(self, args: MintCollectionArg): + """ + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + """ self.burn_from(self.get_signer_address(), args) def burn_batch(self, args: List[MintCollectionArg]): + """ + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + """ self.burn_batch_from(self.get_signer_address(), args) def burn_from(self, account: str, args: MintCollectionArg): + """ + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + """ self.execute_tx(self.__abi_module.burn.build_transaction( account, args.token_id, args.amount, self.get_transact_opts() )) def burn_batch_from(self, account: str, args: List[MintCollectionArg]): + """ + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + """ self.execute_tx(self.__abi_module.burn_batch.build_transaction( account, [i.id for i in args], [ i.amount for i in args], self.get_transact_opts() )) def transfer_from(self, from_address: str, to_address: str, args: MintCollectionArg): + """ + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + """ self.execute_tx(self.__abi_module.safe_transfer_from.build_transaction( from_address, to_address, args.token_id, args.amount, "", self.get_transact_opts() )) def transfer_batch_from(self, from_address: str, to_address: str, args): + """ + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + """ self.execute_tx(self.__abi_module.safe_batch_transfer_from.build_transaction( from_address, to_address, args.token_id, args.amount, "", self.get_transact_opts() )) def set_royalty_bps(self, amount: int): + """ + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + """ self.execute_tx(self.__abi_module.set_royalty_bps.build_transaction( amount, self.get_transact_opts() )) def get_abi_module(self) -> NFTCollection: + """ + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + """ return self.__abi_module diff --git a/thirdweb/sdk.py b/thirdweb/sdk.py index 4e25015f..2dd60bf7 100644 --- a/thirdweb/sdk.py +++ b/thirdweb/sdk.py @@ -7,6 +7,7 @@ from .modules.nft import NftModule from .modules.pack import PackModule from .modules.collection import CollectionModule +from .modules.bundle import BundleModule from .modules.currency import CurrencyModule from .modules.market import MarketModule from .options import SdkOptions @@ -36,6 +37,7 @@ class ThirdwebSdk(object): __nft_module: Optional[NftModule] __pack_module: Optional[PackModule] __collection_module: Optional[CollectionModule] + __bundle_module = Optional[BundleModule] __market_module: Optional[MarketModule] """ @@ -47,6 +49,7 @@ def __init__(self, options: SdkOptions, url: str): self.__nft_module = None self.__pack_module = None self.__collection_module = None + self.__bundle_module = None self.__current_account = None self.__market_module = None @@ -129,17 +132,24 @@ def get_market_module(self, address: str) -> MarketModule: return self.__market_module """ - Returns an instance of the collection module + Returns an instance of the bundle module """ @set_default_account def get_collection_module(self, address: str) -> CollectionModule: - if self.__collection_module is not None: - return self.__collection_module + """ + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + """ + get_bundle_module(self, address) - module = CollectionModule(address, self.__get_client()) + def get_bundle_module(self, address: str) -> BundleModule: + + if self.__bundle_module is not None: + return self.__bundle_module + + module = BundleModule(address, self.__get_client()) self.__init_module(module) - self.__collection_module = module - return self.__collection_module + self.__bundle_module = module + return self.__bundle_module """ Internal function used to return the current web3 provider used by downstream modules diff --git a/thirdweb/types/bundle/__init__.py b/thirdweb/types/bundle/__init__.py new file mode 100644 index 00000000..650174e2 --- /dev/null +++ b/thirdweb/types/bundle/__init__.py @@ -0,0 +1,31 @@ +from dataclasses import dataclass +from typing import Optional + +from dataclasses_json import dataclass_json + +from ..nft import NftMetadata +from ..metadata import Metadata + + +@dataclass_json +@dataclass +class BundleMetadata: + id: Optional[int] = None + creator: Optional[str] = None + supply: Optional[int] = None + metadata: Optional[NftMetadata] = None + + +@dataclass_json +@dataclass +class CreateBundleArg: + metadata: Optional[Metadata] = None + supply: Optional[int] = None + + +@dataclass_json +@dataclass +class MintBundleArg: + token_id: Optional[int] = None + amount: Optional[int] = None + diff --git a/thirdweb/types/collection/__init__.py b/thirdweb/types/collection/__init__.py index 6d7cfb88..03ae6b57 100644 --- a/thirdweb/types/collection/__init__.py +++ b/thirdweb/types/collection/__init__.py @@ -10,6 +10,9 @@ @dataclass_json @dataclass class CollectionMetadata: + """ + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + """ id: Optional[int] = None creator: Optional[str] = None supply: Optional[int] = None @@ -19,6 +22,9 @@ class CollectionMetadata: @dataclass_json @dataclass class CreateCollectionArg: + """ + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + """ metadata: Optional[Metadata] = None supply: Optional[int] = None @@ -26,6 +32,9 @@ class CreateCollectionArg: @dataclass_json @dataclass class MintCollectionArg: + """ + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + """ token_id: Optional[int] = None amount: Optional[int] = None diff --git a/thirdweb/types/listing.py b/thirdweb/types/listing.py index 49fae6b5..2c9268e3 100644 --- a/thirdweb/types/listing.py +++ b/thirdweb/types/listing.py @@ -11,13 +11,13 @@ @dataclass_json @dataclass class Listing: - """A listing of an some asset (e.g. a NFT, Collection, Pack, etc.) + """A listing of an some asset (e.g. a NFT, Bundle, Pack, etc.) Attributes: id (str): The id of the listing seller (str): The wallet address of the seller token_contract (str): The address of the token contract - token_id (str): The id of the token (e.g. id of NFT, Pack, or Collection) + token_id (str): The id of the token (e.g. id of NFT, Pack, or Bundle) quantity (int): The quantity of token being listed (a single listing could sell >= 1 token) currency_contract (str): The address of the currency contract. This property is set to 0x0 if the listing is free. price_per_token (int): The price per token. E.g. if the currency_contract is pointing to a contract with token symbol $DAI, then this listing costs (price_per_token * $DAI). From 72e498dd4a27445f3ebd6331c97fda4255d4a67c Mon Sep 17 00:00:00 2001 From: Ayush Pathak <62694274+ayshptk@users.noreply.github.com> Date: Thu, 11 Nov 2021 19:07:05 +0530 Subject: [PATCH 02/11] Update Readme - Added deprecation notice - Added instructions for documentation --- README.md | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0691e0fc..b499b2e0 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ PyPi package found [here](https://pypi.org/project/thirdweb-sdk). -## Deprecation Notice +## Deprecation Notices > The `nftlabs-sdk` pypi package will be deprecated on November 30th, 2021 > @@ -10,6 +10,18 @@ PyPi package found [here](https://pypi.org/project/thirdweb-sdk). > > In your code, update all imports to use the `thirdweb` package and switch to using the `ThirdwebSdk` package (instead of the `NftlabsSdk` package) +--- + +> The `collection` module has been renamed to `bundle` and will be deprecated on November 30th, 2021 +> +> All references to `collection` module and its associated classes should be updated to `bundle` and its newely created classes. +> +> You can find the detailed documentation for the `bundle` module [here](https://python-docs.nftlabs.co/modules.bundle.html) + + + + + ### Docs https://docs.nftlabs.co @@ -76,3 +88,30 @@ $ abi-gen --language Python -o nftlabs/abi --abis ../nftlabs-protocols/abi/NFT.j ``` Anytime there are ABI contract changes, you should regenerate the abi wrappers. + + +### Writing Documentation + +This package uses [`PyDoctor`](https://github.com/twisted/pydoctor) to auto-generate docs. Each method, class and variable should have a detailed description of what it is meant for as a comment enclosed in triple quoation marks (`""" """`) just below the line they are defined. + +Example: + +Do: +```python +def my_method(self, arg1, arg2): + """ + This part goes into the documentation. + """ + return arg1 + arg2 +``` + +Don't: +```python +""" +This part will not go into the documentation. +""" + +def my_method(self, arg1, arg2): + return arg1 + arg2 +``` + From 474ea8db33b4ecdfa6b5e3f0a90e91c247919f33 Mon Sep 17 00:00:00 2001 From: Ayush Pathak <62694274+ayshptk@users.noreply.github.com> Date: Thu, 11 Nov 2021 19:11:25 +0530 Subject: [PATCH 03/11] Update README.md --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index b499b2e0..245eceee 100644 --- a/README.md +++ b/README.md @@ -4,14 +4,19 @@ PyPi package found [here](https://pypi.org/project/thirdweb-sdk). ## Deprecation Notices +> 1 of 2 +> > The `nftlabs-sdk` pypi package will be deprecated on November 30th, 2021 > > Please make sure you install the new `thirdweb-sdk` package found [here](https://pypi.org/project/thirdweb-sdk) > > In your code, update all imports to use the `thirdweb` package and switch to using the `ThirdwebSdk` package (instead of the `NftlabsSdk` package) + --- +> 2 of 2 +> > The `collection` module has been renamed to `bundle` and will be deprecated on November 30th, 2021 > > All references to `collection` module and its associated classes should be updated to `bundle` and its newely created classes. @@ -115,3 +120,12 @@ def my_method(self, arg1, arg2): return arg1 + arg2 ``` + +Addtionally, each module should also have a docstring at the top of the file. This will be used as a breif descroption of the module on the [homepage of the documentation](https://python-docs.nftlabs.co/). + +Example: +```python +1 """Interact with the NFT module of the app""" # docstring +2 # Module code starts from here +3 # ... +``` \ No newline at end of file From f099703fb4596a1c998a62e5dd9d3ef87e89b04d Mon Sep 17 00:00:00 2001 From: Ayush Pathak <62694274+ayshptk@users.noreply.github.com> Date: Thu, 11 Nov 2021 19:28:00 +0530 Subject: [PATCH 04/11] Added warning --- thirdweb/modules/collection.py | 78 ++++++++++++++++++++++------------ 1 file changed, 52 insertions(+), 26 deletions(-) diff --git a/thirdweb/modules/collection.py b/thirdweb/modules/collection.py index 8d0e0738..8c3bc7f2 100644 --- a/thirdweb/modules/collection.py +++ b/thirdweb/modules/collection.py @@ -1,4 +1,5 @@ from typing import List +import warnings from thirdweb_web3 import Web3 @@ -12,7 +13,7 @@ class CollectionModule(BaseModule): """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. .Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html """ address: str __abi_module: NFTCollection @@ -24,8 +25,9 @@ def __init__(self, address: str, client: Web3): def get(self, token_id: int) -> CollectionMetadata: """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html """ + warnings.warn("COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html") uri = self.__abi_module.uri.call(token_id) meta_str = self.get_storage().get(uri) meta: NftMetadata = NftMetadata.from_json(meta_str) @@ -39,8 +41,9 @@ def get(self, token_id: int) -> CollectionMetadata: def get_all(self) -> List[CollectionMetadata]: """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html """ + warnings.warn("COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html") return [self.get(i) for i in range(self.__abi_module.next_token_id.call())] ''' @@ -49,8 +52,9 @@ def get_all(self) -> List[CollectionMetadata]: def balance_of(self, address: str, token_id: int) -> int: """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html """ + warnings.warn("COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html") return self.__abi_module.balance_of.call(address, token_id) ''' @@ -59,8 +63,9 @@ def balance_of(self, address: str, token_id: int) -> int: def balance(self, token_id: int) -> int: """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html """ + warnings.warn("COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html") return self.__abi_module.balance_of.call( self.get_signer_address(), token_id @@ -68,8 +73,9 @@ def balance(self, token_id: int) -> int: def is_approved(self, address: str, operator: str) -> bool: """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html """ + warnings.warn("COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html") return self.__abi_module.is_approved_for_all.call( address, operator @@ -77,44 +83,50 @@ def is_approved(self, address: str, operator: str) -> bool: def set_approval(self, operator: str, approved: bool = True): """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html """ + warnings.warn("COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html") self.execute_tx(self.__abi_module.set_approval_for_all.build_transaction( operator, approved, self.get_transact_opts() )) def transfer(self, to_address: str, token_id: int, amount: int): """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html """ + warnings.warn("COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html") self.execute_tx(self.__abi_module.safe_transfer_from.build_transaction( self.get_signer_address(), to_address, token_id, amount, "", self.get_transact_opts() )) def create(self, metadata: Metadata) -> CollectionMetadata: """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html """ + warnings.warn("COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html") return self.create_batch([metadata])[0] def create_batch(self, metas: List[Metadata]) -> List[CollectionMetadata]: """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html """ + warnings.warn("COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html") meta_with_supply = [CreateCollectionArg( metadata=m, supply=0) for m in metas] return self.create_and_mint_batch(meta_with_supply) def create_and_mint(self, meta_with_supply: CreateCollectionArg) -> CollectionMetadata: """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html """ + warnings.warn("COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html") return self.create_and_mint_batch([meta_with_supply])[0] def create_and_mint_batch(self, meta_with_supply: List[CreateCollectionArg]) -> List[CollectionMetadata]: """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html """ + warnings.warn("COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html") uris = [self.get_storage().upload(meta.to_json(), self.address, self.get_signer_address()) for meta in meta_with_supply] supplies = [a.supply for a in meta_with_supply] @@ -128,8 +140,9 @@ def create_and_mint_batch(self, meta_with_supply: List[CreateCollectionArg]) -> def create_with_erc20(self, token_contract: str, token_amount: int, arg: CreateCollectionArg): """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html """ + warnings.warn("COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html") uri = self.get_storage().upload( arg.metadata, self.address, self.get_signer_address()) self.execute_tx(self.__abi_module.wrap_erc20.build_transaction( @@ -138,8 +151,9 @@ def create_with_erc20(self, token_contract: str, token_amount: int, arg: CreateC def create_with_erc721(self, token_contract: str, token_id: int, metadata): """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html """ + warnings.warn("COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html") uri = self.get_storage().upload( metadata.metadata, self.address, self.get_signer_address()) self.execute_tx(self.__abi_module.wrap_erc721.build_transaction( @@ -148,28 +162,32 @@ def create_with_erc721(self, token_contract: str, token_id: int, metadata): def mint(self, args: MintCollectionArg): """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html """ + warnings.warn("COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html") self.mint_to(self.get_signer_address(), args) def mint_to(self, to_address: str, arg: MintCollectionArg): """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html """ + warnings.warn("COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html") self.execute_tx(self.__abi_module.mint.build_transaction( to_address, arg.token_id, arg.amount, "", self.get_transact_opts() )) def mint_batch(self, args: List[MintCollectionArg]): """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html """ + warnings.warn("COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html") self.mint_batch_to(self.get_signer_address(), args) def mint_batch_to(self, to_address, args: List[MintCollectionArg]): """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html """ + warnings.warn("COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html") ids = [a.token_id for a in args] amounts = [a.amount for a in args] tx = self.__abi_module.mint_batch.build_transaction( @@ -178,28 +196,32 @@ def mint_batch_to(self, to_address, args: List[MintCollectionArg]): def burn(self, args: MintCollectionArg): """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html """ + warnings.warn("COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html") self.burn_from(self.get_signer_address(), args) def burn_batch(self, args: List[MintCollectionArg]): """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html """ + warnings.warn("COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html") self.burn_batch_from(self.get_signer_address(), args) def burn_from(self, account: str, args: MintCollectionArg): """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html """ + warnings.warn("COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html") self.execute_tx(self.__abi_module.burn.build_transaction( account, args.token_id, args.amount, self.get_transact_opts() )) def burn_batch_from(self, account: str, args: List[MintCollectionArg]): """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html """ + warnings.warn("COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html") self.execute_tx(self.__abi_module.burn_batch.build_transaction( account, [i.id for i in args], [ i.amount for i in args], self.get_transact_opts() @@ -207,30 +229,34 @@ def burn_batch_from(self, account: str, args: List[MintCollectionArg]): def transfer_from(self, from_address: str, to_address: str, args: MintCollectionArg): """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html """ + warnings.warn("COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html") self.execute_tx(self.__abi_module.safe_transfer_from.build_transaction( from_address, to_address, args.token_id, args.amount, "", self.get_transact_opts() )) def transfer_batch_from(self, from_address: str, to_address: str, args): """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html """ + warnings.warn("COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html") self.execute_tx(self.__abi_module.safe_batch_transfer_from.build_transaction( from_address, to_address, args.token_id, args.amount, "", self.get_transact_opts() )) def set_royalty_bps(self, amount: int): """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html """ + warnings.warn("COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html") self.execute_tx(self.__abi_module.set_royalty_bps.build_transaction( amount, self.get_transact_opts() )) def get_abi_module(self) -> NFTCollection: """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. + COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html """ + warnings.warn("COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html") return self.__abi_module From 4f26135db1c20ddeaa973374a70321c5e18f5766 Mon Sep 17 00:00:00 2001 From: Ibrahim Ahmed Date: Thu, 11 Nov 2021 12:58:48 -0800 Subject: [PATCH 05/11] Move to ipfs.io gateway and set strict fetch timeout --- thirdweb/options/sdk_options.py | 2 +- thirdweb/storage/ipfs_storage.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/thirdweb/options/sdk_options.py b/thirdweb/options/sdk_options.py index 4846023c..734768cb 100644 --- a/thirdweb/options/sdk_options.py +++ b/thirdweb/options/sdk_options.py @@ -3,7 +3,7 @@ @dataclasses.dataclass class SdkOptions: - ipfs_gateway_url: str = "https://cloudflare-ipfs.com/ipfs/" + ipfs_gateway_url: str = "https://ipfs.io/ipfs/" registry_contract_address: str = "" max_gas_price_in_gwei: int = 100 gas_speed: str = "fastest" diff --git a/thirdweb/storage/ipfs_storage.py b/thirdweb/storage/ipfs_storage.py index c16cc25e..1ec1812f 100644 --- a/thirdweb/storage/ipfs_storage.py +++ b/thirdweb/storage/ipfs_storage.py @@ -3,6 +3,7 @@ from requests import get, post import json + class IpfsStorage: __nftlabsApiUrl = "https://upload.nftlabs.co" @@ -14,7 +15,7 @@ def __init__(self, gateway_uri: str): def get(self, uri: str) -> str: ipfs_uri = replace_ipfs_prefix_with_gateway(uri, self.gateway_uri) - response = get(ipfs_uri) + response = get(ipfs_uri, timeout=10) if response.status_code != 200: raise Exception("Failed to download metadata") @@ -24,6 +25,7 @@ def get(self, uri: str) -> str: """ Upload data to IPFS, data parameter """ + def upload(self, data, contract_address: str, signer_address: str) -> str: if isinstance(data, str) and data.startswith("ipfs://"): return data @@ -40,7 +42,7 @@ def upload(self, data, contract_address: str, signer_address: str) -> str: response = result.json() return response['IpfsUri'] - + def upload_metadata(self, metadata: str, contract_address: str, signer_address: str) -> str: if type(metadata) == str: return self.upload(metadata, contract_address, signer_address) From c314bf68efae3fa376dd63497eed716471eed808 Mon Sep 17 00:00:00 2001 From: Ibrahim Ahmed Date: Thu, 11 Nov 2021 13:00:41 -0800 Subject: [PATCH 06/11] Change gateway fallback --- thirdweb/sdk.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/thirdweb/sdk.py b/thirdweb/sdk.py index 2dd60bf7..25fb8d07 100644 --- a/thirdweb/sdk.py +++ b/thirdweb/sdk.py @@ -59,7 +59,7 @@ def __init__(self, options: SdkOptions, url: str): self.storage = IpfsStorage( options.ipfs_gateway_url if options.ipfs_gateway_url - else "https://cloudflare-ipfs.com/ipfs/") + else "https://ipfs.io/ipfs/") self.client = Web3(HTTPProvider(url)) if not self.client.isConnected(): From 9e60a7e222eaf4503dd664014ad133502b2c9a6c Mon Sep 17 00:00:00 2001 From: Ibrahim Ahmed Date: Thu, 11 Nov 2021 13:14:08 -0800 Subject: [PATCH 07/11] Fix function missing return --- thirdweb/sdk.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/thirdweb/sdk.py b/thirdweb/sdk.py index 25fb8d07..3296c00f 100644 --- a/thirdweb/sdk.py +++ b/thirdweb/sdk.py @@ -139,7 +139,7 @@ def get_collection_module(self, address: str) -> CollectionModule: """ COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. """ - get_bundle_module(self, address) + return self.get_bundle_module(address) def get_bundle_module(self, address: str) -> BundleModule: From c1ad584830c485093afcee815f4581c6f81ba797 Mon Sep 17 00:00:00 2001 From: Ibrahim Ahmed Date: Thu, 11 Nov 2021 13:15:52 -0800 Subject: [PATCH 08/11] Mirror types instead of replacements --- thirdweb/modules/__init__.py | 2 +- thirdweb/modules/collection.py | 262 ------------------------ thirdweb/modules/collection/__init__.py | 3 + thirdweb/types/collection/__init__.py | 41 +--- 4 files changed, 5 insertions(+), 303 deletions(-) delete mode 100644 thirdweb/modules/collection.py create mode 100644 thirdweb/modules/collection/__init__.py diff --git a/thirdweb/modules/__init__.py b/thirdweb/modules/__init__.py index aaa41b7c..034658d8 100644 --- a/thirdweb/modules/__init__.py +++ b/thirdweb/modules/__init__.py @@ -5,5 +5,5 @@ from .currency import * from .market import * from .pack import * -from .collection import * +from .collection import CollectionModule from .bundle import * diff --git a/thirdweb/modules/collection.py b/thirdweb/modules/collection.py deleted file mode 100644 index 8c3bc7f2..00000000 --- a/thirdweb/modules/collection.py +++ /dev/null @@ -1,262 +0,0 @@ -from typing import List -import warnings - -from thirdweb_web3 import Web3 - -from ..abi.nft_collection import NFTCollection -from ..types.collection import (CollectionMetadata, CreateCollectionArg, - MintCollectionArg) -from ..types.metadata import Metadata -from ..types.nft import NftMetadata -from .base import BaseModule - - -class CollectionModule(BaseModule): - """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. .Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html - """ - address: str - __abi_module: NFTCollection - - def __init__(self, address: str, client: Web3): - super().__init__() - self.address = address - self.__abi_module = NFTCollection(client, address) - - def get(self, token_id: int) -> CollectionMetadata: - """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html - """ - warnings.warn("COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html") - uri = self.__abi_module.uri.call(token_id) - meta_str = self.get_storage().get(uri) - meta: NftMetadata = NftMetadata.from_json(meta_str) - meta.id = token_id - return CollectionMetadata( - metadata=meta, - supply=self.__abi_module.total_supply.call(token_id), - creator=self.__abi_module.creator.call(token_id), - id=token_id - ) - - def get_all(self) -> List[CollectionMetadata]: - """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html - """ - warnings.warn("COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html") - return [self.get(i) for i in range(self.__abi_module.next_token_id.call())] - - ''' - Returns the balance for a given token at owned by a specific address - ''' - - def balance_of(self, address: str, token_id: int) -> int: - """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html - """ - warnings.warn("COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html") - return self.__abi_module.balance_of.call(address, token_id) - - ''' - Returns the balance for a given token id for the current signers address - ''' - - def balance(self, token_id: int) -> int: - """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html - """ - warnings.warn("COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html") - return self.__abi_module.balance_of.call( - self.get_signer_address(), - token_id - ) - - def is_approved(self, address: str, operator: str) -> bool: - """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html - """ - warnings.warn("COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html") - return self.__abi_module.is_approved_for_all.call( - address, - operator - ) - - def set_approval(self, operator: str, approved: bool = True): - """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html - """ - warnings.warn("COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html") - self.execute_tx(self.__abi_module.set_approval_for_all.build_transaction( - operator, approved, self.get_transact_opts() - )) - - def transfer(self, to_address: str, token_id: int, amount: int): - """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html - """ - warnings.warn("COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html") - self.execute_tx(self.__abi_module.safe_transfer_from.build_transaction( - self.get_signer_address(), to_address, token_id, amount, "", self.get_transact_opts() - )) - - def create(self, metadata: Metadata) -> CollectionMetadata: - """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html - """ - warnings.warn("COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html") - return self.create_batch([metadata])[0] - - def create_batch(self, metas: List[Metadata]) -> List[CollectionMetadata]: - """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html - """ - warnings.warn("COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html") - meta_with_supply = [CreateCollectionArg( - metadata=m, supply=0) for m in metas] - return self.create_and_mint_batch(meta_with_supply) - - def create_and_mint(self, meta_with_supply: CreateCollectionArg) -> CollectionMetadata: - """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html - """ - warnings.warn("COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html") - return self.create_and_mint_batch([meta_with_supply])[0] - - def create_and_mint_batch(self, meta_with_supply: List[CreateCollectionArg]) -> List[CollectionMetadata]: - """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html - """ - warnings.warn("COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html") - uris = [self.get_storage().upload(meta.to_json(), self.address, - self.get_signer_address()) for meta in meta_with_supply] - supplies = [a.supply for a in meta_with_supply] - receipt = self.execute_tx(self.__abi_module.create_native_tokens.build_transaction( - self.get_signer_address(), uris, supplies, "", self.get_transact_opts() - )) - result = self.__abi_module.get_native_tokens_event( - tx_hash=receipt.transactionHash.hex()) - token_ids = result[0]['args']['tokenIds'] - return [self.get(i) for i in token_ids] - - def create_with_erc20(self, token_contract: str, token_amount: int, arg: CreateCollectionArg): - """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html - """ - warnings.warn("COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html") - uri = self.get_storage().upload( - arg.metadata, self.address, self.get_signer_address()) - self.execute_tx(self.__abi_module.wrap_erc20.build_transaction( - token_contract, token_amount, arg.supply, uri, self.get_transact_opts() - )) - - def create_with_erc721(self, token_contract: str, token_id: int, metadata): - """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html - """ - warnings.warn("COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html") - uri = self.get_storage().upload( - metadata.metadata, self.address, self.get_signer_address()) - self.execute_tx(self.__abi_module.wrap_erc721.build_transaction( - token_contract, token_id, uri, self.get_transact_opts() - )) - - def mint(self, args: MintCollectionArg): - """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html - """ - warnings.warn("COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html") - self.mint_to(self.get_signer_address(), args) - - def mint_to(self, to_address: str, arg: MintCollectionArg): - """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html - """ - warnings.warn("COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html") - self.execute_tx(self.__abi_module.mint.build_transaction( - to_address, arg.token_id, arg.amount, "", self.get_transact_opts() - )) - - def mint_batch(self, args: List[MintCollectionArg]): - """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html - """ - warnings.warn("COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html") - self.mint_batch_to(self.get_signer_address(), args) - - def mint_batch_to(self, to_address, args: List[MintCollectionArg]): - """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html - """ - warnings.warn("COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html") - ids = [a.token_id for a in args] - amounts = [a.amount for a in args] - tx = self.__abi_module.mint_batch.build_transaction( - to_address, ids, amounts, self.get_transact_opts()) - self.execute_tx(tx) - - def burn(self, args: MintCollectionArg): - """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html - """ - warnings.warn("COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html") - self.burn_from(self.get_signer_address(), args) - - def burn_batch(self, args: List[MintCollectionArg]): - """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html - """ - warnings.warn("COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html") - self.burn_batch_from(self.get_signer_address(), args) - - def burn_from(self, account: str, args: MintCollectionArg): - """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html - """ - warnings.warn("COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html") - self.execute_tx(self.__abi_module.burn.build_transaction( - account, args.token_id, args.amount, self.get_transact_opts() - )) - - def burn_batch_from(self, account: str, args: List[MintCollectionArg]): - """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html - """ - warnings.warn("COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html") - self.execute_tx(self.__abi_module.burn_batch.build_transaction( - account, [i.id for i in args], [ - i.amount for i in args], self.get_transact_opts() - )) - - def transfer_from(self, from_address: str, to_address: str, args: MintCollectionArg): - """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html - """ - warnings.warn("COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html") - self.execute_tx(self.__abi_module.safe_transfer_from.build_transaction( - from_address, to_address, args.token_id, args.amount, "", self.get_transact_opts() - )) - - def transfer_batch_from(self, from_address: str, to_address: str, args): - """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html - """ - warnings.warn("COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html") - self.execute_tx(self.__abi_module.safe_batch_transfer_from.build_transaction( - from_address, to_address, args.token_id, args.amount, "", self.get_transact_opts() - )) - - def set_royalty_bps(self, amount: int): - """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html - """ - warnings.warn("COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html") - self.execute_tx(self.__abi_module.set_royalty_bps.build_transaction( - amount, self.get_transact_opts() - )) - - def get_abi_module(self) -> NFTCollection: - """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html - """ - warnings.warn("COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. Detailed documentation is available at https://python-docs.nftlabs.co/modules.bundle.html") - return self.__abi_module diff --git a/thirdweb/modules/collection/__init__.py b/thirdweb/modules/collection/__init__.py new file mode 100644 index 00000000..b74b5d85 --- /dev/null +++ b/thirdweb/modules/collection/__init__.py @@ -0,0 +1,3 @@ +from ..bundle import BundleModule + +CollectionModule = BundleModule diff --git a/thirdweb/types/collection/__init__.py b/thirdweb/types/collection/__init__.py index 03ae6b57..c26e3d74 100644 --- a/thirdweb/types/collection/__init__.py +++ b/thirdweb/types/collection/__init__.py @@ -1,40 +1 @@ -from dataclasses import dataclass -from typing import Optional - -from dataclasses_json import dataclass_json - -from ..nft import NftMetadata -from ..metadata import Metadata - - -@dataclass_json -@dataclass -class CollectionMetadata: - """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. - """ - id: Optional[int] = None - creator: Optional[str] = None - supply: Optional[int] = None - metadata: Optional[NftMetadata] = None - - -@dataclass_json -@dataclass -class CreateCollectionArg: - """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. - """ - metadata: Optional[Metadata] = None - supply: Optional[int] = None - - -@dataclass_json -@dataclass -class MintCollectionArg: - """ - COLLECTION MODULE AND ALL ITS CLASSES WILL BE DEPRECATED SOON. USE BUNDLE MODULE INSTEAD. - """ - token_id: Optional[int] = None - amount: Optional[int] = None - +from .types import CreateCollectionArg, CollectionMetadata, MintCollectionArg From 9d55a6f136b6a2612315f63eaeb253042b34193e Mon Sep 17 00:00:00 2001 From: Ibrahim Ahmed Date: Thu, 11 Nov 2021 13:17:26 -0800 Subject: [PATCH 09/11] Added tests for bundle to ensure backwards compatibility --- tests/test_bundle.py | 59 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 tests/test_bundle.py diff --git a/tests/test_bundle.py b/tests/test_bundle.py new file mode 100644 index 00000000..9f068925 --- /dev/null +++ b/tests/test_bundle.py @@ -0,0 +1,59 @@ +import unittest +from os import environ + +from dataclasses_json.api import A + +from thirdweb import SdkOptions, ThirdwebSdk +from thirdweb.modules.bundle import BundleModule +from thirdweb.modules.collection import CollectionModule +from thirdweb.types.collection import CreateCollectionArg + + +class TestRoles(unittest.TestCase): + sdk: ThirdwebSdk + module: BundleModule + old_module: CollectionModule + + @classmethod + def setUpClass(self): + self.sdk = ThirdwebSdk(SdkOptions( + private_key=environ['PKEY'] + ), "https://rpc-mumbai.maticvigil.com") + self.module = self.sdk.get_bundle_module( + "0x5CF412451f4Cef34293604048238bd18D2BD1e71") + self.old_module = self.sdk.get_collection_module( + "0x5CF412451f4Cef34293604048238bd18D2BD1e71") + + def test_bundle_get_all(self): + """ + Test that tries to instantiate the NFT module + """ + result = self.module.get_all() + self.assertGreater( + len(result), 0, "There should be at least 1 token in the contract") + + def test_collection_get_all(self): + """ + Test that tries to instantiate the Collection module + """ + result = self.old_module.get_all() + self.assertGreater( + len(result), 0, "There should be at least 1 token in the contract") + + # def test_collection_mint(self): + # """ + # Test that tries to instantiate the Collection module + # """ + # result = self.old_module.create_and_mint(meta_with_supply=CreateCollectionArg( + # metadata={"name": "Test"}, + # supply=10, + # )) + # print("Minted", result) + # result = self.module.create_and_mint(meta_with_supply=CreateCollectionArg( + # metadata={"name": "Test"}, + # supply=10, + # )) + + +if __name__ == '__main__': + unittest.main() From 0c3a7a5c1450bd36857219c8053b7a64ea9b76c0 Mon Sep 17 00:00:00 2001 From: Ibrahim Ahmed Date: Thu, 11 Nov 2021 13:18:37 -0800 Subject: [PATCH 10/11] Added mirrored types file to avoid exporting bundle types --- thirdweb/types/collection/types.py | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 thirdweb/types/collection/types.py diff --git a/thirdweb/types/collection/types.py b/thirdweb/types/collection/types.py new file mode 100644 index 00000000..e93abc42 --- /dev/null +++ b/thirdweb/types/collection/types.py @@ -0,0 +1,5 @@ +from ..bundle import BundleMetadata, CreateBundleArg, MintBundleArg + +CollectionMetadata = BundleMetadata +CreateCollectionArg = CreateBundleArg +MintCollectionArg = MintBundleArg From f23ab284589e1de3002f99732715945b4e91af4f Mon Sep 17 00:00:00 2001 From: Ibrahim Ahmed Date: Thu, 11 Nov 2021 13:20:49 -0800 Subject: [PATCH 11/11] Updated requirements --- requirements.txt | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/requirements.txt b/requirements.txt index 48bd1e7d..4d8a5469 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,15 +1,15 @@ -thirdweb-web3==5.24.8 -thirdweb-contract-wrappers==2.0.3 0x-contract-addresses==3.0.0 0x-contract-artifacts==3.0.0 -0x-contract-wrappers==2.0.0 0x-json-schemas==2.1.0 0x-order-utils==4.0.1 +aiohttp==3.7.4.post0 async-timeout==3.0.1 attrs==21.2.0 +autopep8==1.6.0 base58==2.1.0 bitarray==1.2.2 certifi==2021.10.8 +chardet==4.0.0 charset-normalizer==2.0.6 cytoolz==0.11.0 dataclasses-json==0.5.6 @@ -35,19 +35,22 @@ mypy-extensions==0.4.3 netaddr==0.8.0 parsimonious==0.8.1 protobuf==3.18.1 +pycodestyle==2.8.0 pycryptodome==3.11.0 pyrsistent==0.18.0 requests==2.26.0 rlp==2.0.1 six==1.16.0 stringcase==1.2.0 +thirdweb-contract-wrappers==2.0.3 +thirdweb-web3==5.24.8 +toml==0.10.2 toolz==0.11.1 typing-extensions==3.10.0.2 typing-inspect==0.7.1 urllib3==1.26.7 varint==1.0.2 web3==5.24.0 -thirdweb-web3==5.24.8 websockets==9.1 wrapt==1.13.1 yarl==1.7.0