Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on May 3, 2024. It is now read-only.

Commit b457f2d

Browse files
authored
Switched to Pydoc Standard Documentation, Removed one duplicate method in NFT module (#25)
* Added pydoc standard documentation for all 5 modules. * Bug: Removed Extra import * fixed output * fixed errors, changed gitignore * Update __init__.py * added documentation for missing methods/modules * added types documentation
1 parent 1bb89f0 commit b457f2d

File tree

18 files changed

+610
-35
lines changed

18 files changed

+610
-35
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ nftlabs/modules/.DS_Store
1717
x.sh
1818
examples/test.py
1919

20+
docs/
2021
**/*.pyc
2122

2223
*.egg-info

thirdweb/modules/bundle.py

Lines changed: 194 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
from typing import List
1+
"""
2+
Interact with the Bundle module of the app. Previously `collection`.
3+
"""
24

5+
from typing import List
36
from thirdweb_web3 import Web3
4-
57
from ..abi.erc20 import ERC20
68
from ..abi.nft import NFT
79
from ..abi.nft_collection import NFTCollection as NFTBundle
@@ -13,15 +15,33 @@
1315

1416

1517
class BundleModule(BaseModule):
18+
"""
19+
Interact with the Bundle module of the app. Previously `collection`.
20+
"""
1621
address: str
22+
"""
23+
Address of the module
24+
"""
1725
__abi_module: NFTBundle
1826

1927
def __init__(self, address: str, client: Web3):
28+
"""
29+
:param address: The address of the module
30+
:param client: Web3 client
31+
32+
Initializes the module
33+
"""
2034
super().__init__()
2135
self.address = address
2236
self.__abi_module = NFTBundle(client, address)
2337

2438
def get(self, token_id: int) -> BundleMetadata:
39+
"""
40+
:param token_id: The token id to get
41+
:return: Metadata of the bundle
42+
43+
Get the metadata for a given token id
44+
"""
2545
uri = self.__abi_module.uri.call(token_id)
2646
meta_str = self.get_storage().get(uri)
2747
meta: NftMetadata = NftMetadata.from_json(meta_str)
@@ -35,50 +55,110 @@ def get(self, token_id: int) -> BundleMetadata:
3555

3656
def get_all(self) -> List[BundleMetadata]:
3757
'''
58+
:return: A list of metadata
59+
3860
Returns all the bundles in the contract
61+
3962
'''
4063
return [self.get(i) for i in range(self.__abi_module.next_token_id.call())]
4164

4265
def balance_of(self, address: str, token_id: int) -> int:
4366
'''
67+
:param address: The address to check
68+
:param token_id: The token id to check
69+
:return: The balance
70+
4471
Returns the balance for a given token at owned by a specific address
72+
4573
'''
4674
return self.__abi_module.balance_of.call(address, token_id)
4775

4876
def balance(self, token_id: int) -> int:
4977
'''
78+
:param token_id: The token id to check
79+
:return: The balance
80+
5081
Returns the balance for a given token id for the current signers address
82+
5183
'''
5284
return self.__abi_module.balance_of.call(
5385
self.get_signer_address(),
5486
token_id
5587
)
5688

5789
def is_approved(self, address: str, operator: str) -> bool:
90+
"""
91+
:param address: The address to check
92+
:param operator: The operator to check
93+
:return: True if approved, False otherwise
94+
95+
"""
5896
return self.__abi_module.is_approved_for_all.call(address, operator)
5997

6098
def set_approval(self, operator: str, approved: bool = True):
99+
"""
100+
:param operator: The operator to set approval for
101+
:param approved: True if you want to approve, False otherwise
102+
"""
61103
self.execute_tx(self.__abi_module.set_approval_for_all.build_transaction(
62104
operator, approved, self.get_transact_opts()
63105
))
64106

65107
def transfer(self, to_address: str, token_id: int, amount: int):
108+
"""
109+
:param to_address: The address to transfer to
110+
:param token_id: The token id to transfer
111+
:param amount: The amount to transfer
112+
113+
Transfers a token to a new owner
114+
115+
"""
66116
self.execute_tx(self.__abi_module.safe_transfer_from.build_transaction(
67117
self.get_signer_address(), to_address, token_id, amount, "", self.get_transact_opts()
68118
))
69119

70120
def create(self, metadata: Metadata) -> BundleMetadata:
121+
"""
122+
:param metadata: The metadata to be stored
123+
:return: Metadata of the bundle
124+
125+
Creates a bundle.
126+
127+
"""
71128
return self.create_batch([metadata])[0]
72129

73130
def create_batch(self, metas: List[Metadata]) -> List[BundleMetadata]:
131+
"""
132+
:param metas: The metadata to be stored
133+
:return: List of metadatas of the bundles
134+
135+
Creates a bundle of NFTs
136+
137+
"""
74138
meta_with_supply = [CreateBundleArg(
75139
metadata=m, supply=0) for m in metas]
76140
return self.create_and_mint_batch(meta_with_supply)
77141

78142
def create_and_mint(self, meta_with_supply: CreateBundleArg) -> BundleMetadata:
143+
"""
144+
:param meta_with_supply: Metadata with supply
145+
:return: A metadata with supply
146+
147+
Create a bundle and mint it to the current signer address
148+
149+
"""
79150
return self.create_and_mint_batch([meta_with_supply])[0]
80151

81152
def create_and_mint_batch(self, meta_with_supply: List[CreateBundleArg]) -> List[BundleMetadata]:
153+
"""
154+
:param meta_with_supply: A list of metadata with supply
155+
:return: A list of metadata with supply
156+
157+
Creates bundles and mints them to the current signer address
158+
159+
"""
160+
if len(meta_with_supply) == 0:
161+
raise Exception("No metadata supplied")
82162
uris = [self.upload_metadata(meta.metadata)
83163
for meta in meta_with_supply]
84164
supplies = [a.supply for a in meta_with_supply]
@@ -92,7 +172,12 @@ def create_and_mint_batch(self, meta_with_supply: List[CreateBundleArg]) -> List
92172

93173
def create_with_token(self, token_contract: str, token_amount: int, metadata: dict = None):
94174
"""
95-
WIP: This method is not yet complete.
175+
:param token_contract: The address of the token contract
176+
:param token_amount: The amount of tokens to mint
177+
:param metadata: The metadata to be stored
178+
179+
WIP: This method is not yet complete.
180+
96181
"""
97182
if token_contract == "" or token_contract is None or not self.get_client().isAddress(token_contract):
98183
raise Exception("token_contract not a valid address")
@@ -115,11 +200,13 @@ def create_with_token(self, token_contract: str, token_amount: int, metadata: di
115200

116201
def create_with_nft(self, token_contract: str, token_id: int, metadata):
117202
"""
203+
:param token_contract: The address of the token contract
204+
:param token_id: The id of the token
205+
:param metadata: The metadata to be stored
206+
118207
WIP: This method is not yet complete.
119-
"""
120-
#token_module = sdk.get_nft_module(token_contract)
121-
nft_module = NFT(self.get_client(), token_contract)
122208
209+
"""
123210
asset = NFT(self.get_client(), token_contract)
124211
approved = asset.is_approved_for_all.call(
125212
self.get_signer_address(), self.address)
@@ -137,60 +224,161 @@ def create_with_nft(self, token_contract: str, token_id: int, metadata):
137224
))
138225

139226
def create_with_erc721(self, token_contract: str, token_id: int, metadata):
227+
"""
228+
:param token_contract: The address of the token contract
229+
:param token_id: The id of the token
230+
:param metadata: The metadata to be stored
231+
232+
WIP: This method is not yet complete. Same as create_with_nft()
233+
234+
"""
140235
return self.create_with_nft(token_contract, token_id, metadata)
141236

142237
def create_with_erc20(self, token_contract: str, token_amount: int, metadata):
238+
"""
239+
:param token_contract: The address of the token contract
240+
:param token_amount: The amount of tokens to mint
241+
:param metadata: The metadata to be stored
242+
243+
WIP: This method is not yet complete. Same as create_with_token()
244+
245+
"""
143246
return self.create_with_token(token_contract, token_amount, metadata)
144247

145248
def mint(self, args: MintBundleArg):
249+
"""
250+
:param args: The arguments for the mint
251+
252+
Mints a bundle to the current signer address
253+
254+
"""
146255
self.mint_to(self.get_signer_address(), args)
147256

148257
def mint_to(self, to_address: str, arg: MintBundleArg):
258+
"""
259+
:param to_address: The address to mint to
260+
:param arg: The arguments for the mint
261+
262+
Mints a bundle to the given address
263+
264+
"""
149265
self.execute_tx(self.__abi_module.mint.build_transaction(
150266
to_address, arg.token_id, arg.amount, "", self.get_transact_opts()
151267
))
152268

153269
def mint_batch(self, args: List[MintBundleArg]):
270+
"""
271+
:param args: The arguments for the mint
272+
273+
Mints a list of bundles to the current signer address
274+
275+
"""
154276
self.mint_batch_to(self.get_signer_address(), args)
155277

156278
def mint_batch_to(self, to_address, args: List[MintBundleArg]):
279+
"""
280+
:param to_address: The address to mint to
281+
:param args: The arguments for the mint
282+
:return: A list of minted bundles
283+
284+
Mints a list of bundles to the given address
285+
286+
"""
287+
157288
ids = [a.token_id for a in args]
158289
amounts = [a.amount for a in args]
159290
tx = self.__abi_module.mint_batch.build_transaction(
160291
to_address, ids, amounts, self.get_transact_opts())
161292
self.execute_tx(tx)
162293

163294
def burn(self, args: MintBundleArg):
295+
"""
296+
:param args: The arguments for the burn
297+
298+
Burns a bundle from the current signer address
299+
300+
"""
301+
164302
self.burn_from(self.get_signer_address(), args)
165303

166304
def burn_batch(self, args: List[MintBundleArg]):
305+
"""
306+
:param args: List of the arguments to burn
307+
308+
Burns a list of bundles from the current signer address
309+
310+
"""
167311
self.burn_batch_from(self.get_signer_address(), args)
168312

169313
def burn_from(self, account: str, args: MintBundleArg):
314+
"""
315+
:param account: The account to burn from
316+
:param args: The arguments for the burn
317+
318+
Burns a bundle from the given account
319+
320+
"""
321+
170322
self.execute_tx(self.__abi_module.burn.build_transaction(
171323
account, args.token_id, args.amount, self.get_transact_opts()
172324
))
173325

174326
def burn_batch_from(self, account: str, args: List[MintBundleArg]):
327+
"""
328+
:param account: The account to burn from
329+
:param args: The arguments for the burn
330+
331+
Burns a list of bundles from the given account
332+
333+
"""
334+
175335
self.execute_tx(self.__abi_module.burn_batch.build_transaction(
176336
account, [i.id for i in args], [
177337
i.amount for i in args], self.get_transact_opts()
178338
))
179339

180340
def transfer_from(self, from_address: str, to_address: str, args: MintBundleArg):
341+
"""
342+
:param from_address: The account to transfer from
343+
:param to_address: The address to transfer to
344+
:param args: The arguments for the transfer
345+
346+
Transfers a bundle from the given account to the given address
347+
348+
"""
181349
self.execute_tx(self.__abi_module.safe_transfer_from.build_transaction(
182350
from_address, to_address, args.token_id, args.amount, "", self.get_transact_opts()
183351
))
184352

185353
def transfer_batch_from(self, from_address: str, to_address: str, args):
354+
"""
355+
:param from_address: The account to transfer from
356+
:param to_address: The address to transfer to
357+
:param args: The arguments for the transfer
358+
359+
Transfers a list of bundles from the given account to the given address
360+
361+
"""
186362
self.execute_tx(self.__abi_module.safe_batch_transfer_from.build_transaction(
187363
from_address, to_address, args.token_id, args.amount, "", self.get_transact_opts()
188364
))
189365

190366
def set_royalty_bps(self, amount: int):
367+
"""
368+
:param amount: The amount of BPS to set
369+
370+
Sets the royalty BPS
371+
372+
"""
373+
191374
self.execute_tx(self.__abi_module.set_royalty_bps.build_transaction(
192375
amount, self.get_transact_opts()
193376
))
194377

195378
def get_abi_module(self) -> NFTBundle:
379+
"""
380+
:return: The ABI module
381+
382+
Returns the ABI module
383+
"""
196384
return self.__abi_module
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
"""
2+
Deprecated. Use `bundle` instead.
3+
"""
14
from ..bundle import BundleModule
25

36
CollectionModule = BundleModule

0 commit comments

Comments
 (0)