1
- from typing import List
1
+ """
2
+ Interact with the Bundle module of the app. Previously `collection`.
3
+ """
2
4
5
+ from typing import List
3
6
from thirdweb_web3 import Web3
4
-
5
7
from ..abi .erc20 import ERC20
6
8
from ..abi .nft import NFT
7
9
from ..abi .nft_collection import NFTCollection as NFTBundle
13
15
14
16
15
17
class BundleModule (BaseModule ):
18
+ """
19
+ Interact with the Bundle module of the app. Previously `collection`.
20
+ """
16
21
address : str
22
+ """
23
+ Address of the module
24
+ """
17
25
__abi_module : NFTBundle
18
26
19
27
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
+ """
20
34
super ().__init__ ()
21
35
self .address = address
22
36
self .__abi_module = NFTBundle (client , address )
23
37
24
38
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
+ """
25
45
uri = self .__abi_module .uri .call (token_id )
26
46
meta_str = self .get_storage ().get (uri )
27
47
meta : NftMetadata = NftMetadata .from_json (meta_str )
@@ -35,50 +55,110 @@ def get(self, token_id: int) -> BundleMetadata:
35
55
36
56
def get_all (self ) -> List [BundleMetadata ]:
37
57
'''
58
+ :return: A list of metadata
59
+
38
60
Returns all the bundles in the contract
61
+
39
62
'''
40
63
return [self .get (i ) for i in range (self .__abi_module .next_token_id .call ())]
41
64
42
65
def balance_of (self , address : str , token_id : int ) -> int :
43
66
'''
67
+ :param address: The address to check
68
+ :param token_id: The token id to check
69
+ :return: The balance
70
+
44
71
Returns the balance for a given token at owned by a specific address
72
+
45
73
'''
46
74
return self .__abi_module .balance_of .call (address , token_id )
47
75
48
76
def balance (self , token_id : int ) -> int :
49
77
'''
78
+ :param token_id: The token id to check
79
+ :return: The balance
80
+
50
81
Returns the balance for a given token id for the current signers address
82
+
51
83
'''
52
84
return self .__abi_module .balance_of .call (
53
85
self .get_signer_address (),
54
86
token_id
55
87
)
56
88
57
89
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
+ """
58
96
return self .__abi_module .is_approved_for_all .call (address , operator )
59
97
60
98
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
+ """
61
103
self .execute_tx (self .__abi_module .set_approval_for_all .build_transaction (
62
104
operator , approved , self .get_transact_opts ()
63
105
))
64
106
65
107
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
+ """
66
116
self .execute_tx (self .__abi_module .safe_transfer_from .build_transaction (
67
117
self .get_signer_address (), to_address , token_id , amount , "" , self .get_transact_opts ()
68
118
))
69
119
70
120
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
+ """
71
128
return self .create_batch ([metadata ])[0 ]
72
129
73
130
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
+ """
74
138
meta_with_supply = [CreateBundleArg (
75
139
metadata = m , supply = 0 ) for m in metas ]
76
140
return self .create_and_mint_batch (meta_with_supply )
77
141
78
142
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
+ """
79
150
return self .create_and_mint_batch ([meta_with_supply ])[0 ]
80
151
81
152
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" )
82
162
uris = [self .upload_metadata (meta .metadata )
83
163
for meta in meta_with_supply ]
84
164
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
92
172
93
173
def create_with_token (self , token_contract : str , token_amount : int , metadata : dict = None ):
94
174
"""
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
+
96
181
"""
97
182
if token_contract == "" or token_contract is None or not self .get_client ().isAddress (token_contract ):
98
183
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
115
200
116
201
def create_with_nft (self , token_contract : str , token_id : int , metadata ):
117
202
"""
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
+
118
207
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 )
122
208
209
+ """
123
210
asset = NFT (self .get_client (), token_contract )
124
211
approved = asset .is_approved_for_all .call (
125
212
self .get_signer_address (), self .address )
@@ -137,60 +224,161 @@ def create_with_nft(self, token_contract: str, token_id: int, metadata):
137
224
))
138
225
139
226
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
+ """
140
235
return self .create_with_nft (token_contract , token_id , metadata )
141
236
142
237
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
+ """
143
246
return self .create_with_token (token_contract , token_amount , metadata )
144
247
145
248
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
+ """
146
255
self .mint_to (self .get_signer_address (), args )
147
256
148
257
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
+ """
149
265
self .execute_tx (self .__abi_module .mint .build_transaction (
150
266
to_address , arg .token_id , arg .amount , "" , self .get_transact_opts ()
151
267
))
152
268
153
269
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
+ """
154
276
self .mint_batch_to (self .get_signer_address (), args )
155
277
156
278
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
+
157
288
ids = [a .token_id for a in args ]
158
289
amounts = [a .amount for a in args ]
159
290
tx = self .__abi_module .mint_batch .build_transaction (
160
291
to_address , ids , amounts , self .get_transact_opts ())
161
292
self .execute_tx (tx )
162
293
163
294
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
+
164
302
self .burn_from (self .get_signer_address (), args )
165
303
166
304
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
+ """
167
311
self .burn_batch_from (self .get_signer_address (), args )
168
312
169
313
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
+
170
322
self .execute_tx (self .__abi_module .burn .build_transaction (
171
323
account , args .token_id , args .amount , self .get_transact_opts ()
172
324
))
173
325
174
326
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
+
175
335
self .execute_tx (self .__abi_module .burn_batch .build_transaction (
176
336
account , [i .id for i in args ], [
177
337
i .amount for i in args ], self .get_transact_opts ()
178
338
))
179
339
180
340
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
+ """
181
349
self .execute_tx (self .__abi_module .safe_transfer_from .build_transaction (
182
350
from_address , to_address , args .token_id , args .amount , "" , self .get_transact_opts ()
183
351
))
184
352
185
353
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
+ """
186
362
self .execute_tx (self .__abi_module .safe_batch_transfer_from .build_transaction (
187
363
from_address , to_address , args .token_id , args .amount , "" , self .get_transact_opts ()
188
364
))
189
365
190
366
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
+
191
374
self .execute_tx (self .__abi_module .set_royalty_bps .build_transaction (
192
375
amount , self .get_transact_opts ()
193
376
))
194
377
195
378
def get_abi_module (self ) -> NFTBundle :
379
+ """
380
+ :return: The ABI module
381
+
382
+ Returns the ABI module
383
+ """
196
384
return self .__abi_module
0 commit comments