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 15890d4

Browse files
committed
Completed remaining collection methods
1 parent 86acd01 commit 15890d4

File tree

2 files changed

+44
-23
lines changed

2 files changed

+44
-23
lines changed

nftlabs/modules/collection.py

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from ..abi.nft_collection import NFTCollection
1111
from web3 import Web3
1212

13-
from ..types.collection import CollectionMetadata, CreateCollectionArg
13+
from ..types.collection import CollectionMetadata, CreateCollectionArg, MintCollectionArg
1414

1515

1616
class CollectionModule(_BaseModule):
@@ -90,10 +90,10 @@ def create_and_mint_batch(self, meta_with_supply: List[CreateCollectionArg]) ->
9090
token_ids = result[0]['args']['tokenIds']
9191
return [self.get(i) for i in token_ids]
9292

93-
def create_with_erc20(self, token_contract: str, token_amount: int, metadata: CreateCollectionArg):
94-
uri = self.get_storage().upload(metadata.metadata, self.address, self.get_signer_address())
93+
def create_with_erc20(self, token_contract: str, token_amount: int, arg: CreateCollectionArg):
94+
uri = self.get_storage().upload(arg.metadata, self.address, self.get_signer_address())
9595
self.execute_tx(self.__abi_module.wrap_erc20.build_transaction(
96-
token_contract, token_amount, metadata.supply, uri, self.get_transact_opts()
96+
token_contract, token_amount, arg.supply, uri, self.get_transact_opts()
9797
))
9898

9999
def create_with_erc721(self, token_contract: str, token_id: int, metadata):
@@ -102,35 +102,49 @@ def create_with_erc721(self, token_contract: str, token_id: int, metadata):
102102
token_contract, token_id, uri, self.get_transact_opts()
103103
))
104104

105-
def mint(self, args):
106-
pass
105+
def mint(self, args: MintCollectionArg):
106+
self.mint_to(self.get_signer_address(), args)
107107

108-
def mint_to(self, to_address: str, args):
109-
pass
108+
def mint_to(self, to_address: str, arg: MintCollectionArg):
109+
self.execute_tx(self.__abi_module.mint.build_transaction(
110+
to_address, arg.token_id, arg.amount, "", self.get_transact_opts()
111+
))
110112

111-
def mint_batch(self, args):
112-
pass
113+
def mint_batch(self, args: List[MintCollectionArg]):
114+
self.mint_batch_to(self.get_signer_address(), args)
113115

114-
def mint_batch_to(self, to_address, args):
115-
pass
116+
def mint_batch_to(self, to_address, args: List[MintCollectionArg]):
117+
ids = [a.id for a in args]
118+
amounts = [a.amount for a in args]
119+
self.execute_tx(self.__abi_module.mint_batch.build_transaction(
120+
to_address, ids, amounts, self.get_transact_opts()
121+
))
116122

117-
def burn(self, args):
118-
pass
123+
def burn(self, args: MintCollectionArg):
124+
self.burn_from(self.get_signer_address(), args)
119125

120-
def burn_batch(self, args):
121-
pass
126+
def burn_batch(self, args: List[MintCollectionArg]):
127+
self.burn_batch_from(self.get_signer_address(), args)
122128

123-
def burn_from(self, account: str, args):
124-
pass
129+
def burn_from(self, account: str, args: MintCollectionArg):
130+
self.execute_tx(self.__abi_module.burn.build_transaction(
131+
account, args.token_id, args.amount, self.get_transact_opts()
132+
))
125133

126-
def burn_batch_from(self, account: str, args):
127-
pass
134+
def burn_batch_from(self, account: str, args: List[MintCollectionArg]):
135+
self.execute_tx(self.__abi_module.burn_batch.build_transaction(
136+
account, [i.id for i in args], [i.amount for i in args], self.get_transact_opts()
137+
))
128138

129-
def transfer_from(self, from_address: str, to_address: str, args):
130-
pass
139+
def transfer_from(self, from_address: str, to_address: str, args: MintCollectionArg):
140+
self.execute_tx(self.__abi_module.safe_transfer_from.build_transaction(
141+
from_address, to_address, args.token_id, args.amount, "", self.get_transact_opts()
142+
))
131143

132144
def transfer_batch_from(self, from_address: str, to_address: str, args):
133-
pass
145+
self.execute_tx(self.__abi_module.safe_batch_transfer_from.build_transaction(
146+
from_address, to_address, args.token_id, args.amount, "", self.get_transact_opts()
147+
))
134148

135149
def set_royalty_bps(self, amount: int):
136150
self.execute_tx(self.__abi_module.set_royalty_bps.build_transaction(

nftlabs/types/collection/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,10 @@ class CreateCollectionArg:
2222
metadata: Optional[Metadata] = None
2323
supply: Optional[int] = None
2424

25+
26+
@dataclass_json
27+
@dataclass
28+
class MintCollectionArg:
29+
token_id: Optional[int] = None
30+
amount: Optional[int] = None
31+

0 commit comments

Comments
 (0)