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 a26a726

Browse files
authored
Move erc20, erc721, and erc1155 usage to standard interfaces (#122)
Move usage to standard interfaces
1 parent 20d1cfd commit a26a726

File tree

11 files changed

+112
-25
lines changed

11 files changed

+112
-25
lines changed

thirdweb/contracts/edition.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from thirdweb.core.classes.contract_royalty import ContractRoyalty
1010
from thirdweb.core.classes.contract_sales import ContractPrimarySale
1111
from thirdweb.core.classes.contract_wrapper import ContractWrapper
12-
from thirdweb.core.classes.erc_1155 import ERC1155
12+
from thirdweb.core.classes.erc_1155_standard import ERC1155Standard
1313
from thirdweb.core.classes.erc_1155_signature_minting import ERC1155SignatureMinting
1414
from thirdweb.abi import TokenERC1155
1515

@@ -27,7 +27,7 @@
2727
from thirdweb.types.tx import TxResultWithId
2828

2929

30-
class Edition(ERC1155[TokenERC1155]):
30+
class Edition(ERC1155Standard[TokenERC1155]):
3131
"""
3232
Create a collection of NFTs that lets you mint multiple copies of each NFT.
3333
@@ -169,7 +169,7 @@ def mint_additional_supply_to(
169169
:returns: receipt, id, and metadata of the mint
170170
"""
171171

172-
metadata = self._get_token_metadata(token_id)
172+
metadata = self._erc1155._get_token_metadata(token_id)
173173
receipt = self._contract_wrapper.send_transaction(
174174
"mint_to", [to, token_id, metadata.uri, additional_supply]
175175
)

thirdweb/contracts/edition_drop.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from thirdweb.core.classes.contract_royalty import ContractRoyalty
1313
from thirdweb.core.classes.contract_sales import ContractPrimarySale
1414
from thirdweb.core.classes.contract_wrapper import ContractWrapper
15-
from thirdweb.core.classes.erc_1155 import ERC1155
15+
from thirdweb.core.classes.erc_1155_standard import ERC1155Standard
1616
from thirdweb.core.classes.ipfs_storage import IpfsStorage
1717
from thirdweb.types.contract import ContractType
1818
from thirdweb.types.contracts.claim_conditions import ClaimVerification
@@ -28,7 +28,7 @@
2828
from web3.eth import TxReceipt
2929

3030

31-
class EditionDrop(ERC1155[DropERC1155]):
31+
class EditionDrop(ERC1155Standard[DropERC1155]):
3232
"""
3333
Setup a collection of NFTs with a customizable number of each NFT that are minted as users claim them.
3434
@@ -153,7 +153,7 @@ def create_batch(
153153
TxResultWithId(
154154
receipt,
155155
id=id,
156-
data=lambda: self._get_token_metadata(id),
156+
data=lambda: self._erc1155._get_token_metadata(id),
157157
)
158158
)
159159

thirdweb/contracts/multiwrap.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from thirdweb.core.classes.contract_roles import ContractRoles
1313
from thirdweb.core.classes.contract_royalty import ContractRoyalty
1414
from thirdweb.core.classes.contract_wrapper import ContractWrapper
15-
from thirdweb.core.classes.erc_721 import ERC721
15+
from thirdweb.core.classes.erc_721_standard import ERC721Standard
1616
from thirdweb.abi import Multiwrap as MultiwrapABI
1717
from thirdweb.core.classes.ipfs_storage import IpfsStorage
1818
from thirdweb.types.contract import ContractType
@@ -35,7 +35,7 @@
3535
from thirdweb.types.tx import TxResultWithId
3636

3737

38-
class Multiwrap(ERC721[MultiwrapABI]):
38+
class Multiwrap(ERC721Standard[MultiwrapABI]):
3939
"""
4040
Multiwrap lets you wrap any number of ERC20, ERC721, or ERC1155 tokens into
4141
a single wrapped token bundle.

thirdweb/contracts/nft_collection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from thirdweb.core.classes.contract_sales import ContractPrimarySale
1010
from thirdweb.core.classes.contract_wrapper import ContractWrapper
1111
from thirdweb.common.nft import upload_or_extract_uri, upload_or_extract_uris
12-
from thirdweb.core.classes.erc_721 import ERC721
12+
from thirdweb.core.classes.erc_721_standard import ERC721Standard
1313
from thirdweb.core.classes.erc_721_signature_minting import ERC721SignatureMinting
1414
from thirdweb.abi import TokenERC721
1515

@@ -26,7 +26,7 @@
2626
from thirdweb.types.tx import TxResultWithId
2727

2828

29-
class NFTCollection(ERC721[TokenERC721]):
29+
class NFTCollection(ERC721Standard[TokenERC721]):
3030
"""
3131
Create a collection of one-of-one NFTs.
3232

thirdweb/contracts/nft_drop.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from thirdweb.core.classes.contract_sales import ContractPrimarySale
1212
from thirdweb.core.classes.contract_wrapper import ContractWrapper
1313
from thirdweb.core.classes.drop_claim_conditions import DropClaimConditions
14-
from thirdweb.core.classes.erc_721 import ERC721
14+
from thirdweb.core.classes.erc_721_standard import ERC721Standard
1515
from thirdweb.core.classes.ipfs_storage import IpfsStorage
1616
from thirdweb.types.contract import ContractType
1717
from thirdweb.types.contracts.claim_conditions import ClaimVerification
@@ -30,7 +30,7 @@
3030
from thirdweb.types.tx import TxResultWithId
3131

3232

33-
class NFTDrop(ERC721[DropERC721]):
33+
class NFTDrop(ERC721Standard[DropERC721]):
3434
"""
3535
Setup a collection of one-of-one NFTs that are minted as users claim them.
3636

thirdweb/contracts/token.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from thirdweb.core.classes.contract_platform_fee import ContractPlatformFee
1313
from thirdweb.core.classes.contract_roles import ContractRoles
1414
from thirdweb.core.classes.contract_wrapper import ContractWrapper
15-
from thirdweb.core.classes.erc_20 import ERC20
15+
from thirdweb.core.classes.erc_20_standard import ERC20Standard
1616
from thirdweb.core.classes.erc_20_signature_minting import ERC20SignatureMinting
1717
from thirdweb.core.classes.ipfs_storage import IpfsStorage
1818
from thirdweb.types.contract import ContractType
@@ -22,7 +22,7 @@
2222
from thirdweb.types.settings.metadata import TokenContractMetadata
2323

2424

25-
class Token(ERC20):
25+
class Token(ERC20Standard):
2626
"""
2727
Create a standard crypto token or cryptocurrency.
2828
@@ -96,7 +96,7 @@ def get_vote_balance_of(self, account: str) -> CurrencyValue:
9696
:returns: vote balance of the specified wallet
9797
"""
9898

99-
return self._get_value(
99+
return self._erc20._get_value(
100100
self._contract_wrapper._contract_abi.get_votes.call(account)
101101
)
102102

thirdweb/core/classes/erc_1155.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
from typing import Any, Generic, List, Optional, Union, cast
2-
from thirdweb.abi import TokenERC1155
1+
from typing import Generic, List, Union
32
from thirdweb.common.error import NotFoundException
43
from thirdweb.common.nft import fetch_token_metadata
54
from thirdweb.constants.currency import ZERO_ADDRESS
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from typing import Generic
2+
from thirdweb.core.classes.base_contract import BaseContract
3+
from thirdweb.core.classes.contract_wrapper import ContractWrapper
4+
from thirdweb.core.classes.erc_1155 import ERC1155
5+
from thirdweb.core.classes.ipfs_storage import IpfsStorage
6+
from thirdweb.types.contract import TERC1155
7+
8+
9+
class ERC1155Standard(Generic[TERC1155], BaseContract[TERC1155]):
10+
_storage: IpfsStorage
11+
_erc1155: ERC1155
12+
13+
def __init__(self, contract_wrapper: ContractWrapper, storage: IpfsStorage):
14+
super(contract_wrapper)
15+
self._storage = storage
16+
17+
self._erc1155 = ERC1155(contract_wrapper, storage)
18+
self.get = self._erc1155.get
19+
self.get_all = self._erc1155.get_all
20+
self.get_total_count = self._erc1155.get_total_count
21+
self.get_owned = self._erc1155.get_owned
22+
self.total_supply = self._erc1155.total_supply
23+
self.balance = self._erc1155.balance
24+
self.balance_of = self._erc1155.balance_of
25+
self.is_transfer_restricted = self._erc1155.is_transfer_restricted
26+
self.is_approved = self._erc1155.is_approved
27+
self.transfer = self._erc1155.transfer
28+
self.burn = self._erc1155.burn
29+
self.set_approval_for_all = self._erc1155.set_approval_for_all
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from typing import Generic
2+
from thirdweb.abi.token_erc20 import TokenERC20
3+
from thirdweb.core.classes.base_contract import BaseContract
4+
from thirdweb.core.classes.contract_wrapper import ContractWrapper
5+
from thirdweb.core.classes.erc_20 import ERC20
6+
from thirdweb.core.classes.ipfs_storage import IpfsStorage
7+
8+
class ERC20Standard(BaseContract[TokenERC20]):
9+
_storage: IpfsStorage
10+
_erc20: ERC20
11+
12+
def __init__(self, contract_wrapper: ContractWrapper, storage: IpfsStorage):
13+
super(contract_wrapper)
14+
self._storage = storage
15+
16+
self._erc20 = ERC20(contract_wrapper, storage)
17+
self.get = self._erc20.get
18+
self.balance = self._erc20.balance
19+
self.balance_of = self._erc20.balance_of
20+
self.total_supply = self._erc20.total_supply
21+
self.allowance = self._erc20.allowance
22+
self.allowance_of = self._erc20.allowance_of
23+
self.is_transfer_restricted = self._erc20.is_transfer_restricted
24+
self.transfer = self._erc20.transfer
25+
self.transfer_from = self._erc20.transfer_from
26+
self.set_allowance = self._erc20.set_allowance
27+
self.transfer_batch = self._erc20.transfer_batch
28+
self.burn = self._erc20.burn
29+
self.burn_from = self._erc20.burn_from

thirdweb/core/classes/erc_721.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
from typing import List, Generic
1+
from typing import Generic, List
22
from thirdweb.common.error import NotFoundException
33
from thirdweb.common.nft import fetch_token_metadata
44
from thirdweb.constants.currency import ZERO_ADDRESS
55
from thirdweb.constants.role import Role, get_role_hash
6-
from thirdweb.core.classes.contract_wrapper import ContractWrapper
76
from thirdweb.core.classes.base_contract import BaseContract
7+
from thirdweb.core.classes.contract_wrapper import ContractWrapper
88
from thirdweb.core.classes.ipfs_storage import IpfsStorage
99
from thirdweb.types.contract import TERC721
1010
from thirdweb.types.nft import NFTMetadata, NFTMetadataOwner, QueryAllParams
@@ -14,11 +14,7 @@
1414
class ERC721(Generic[TERC721], BaseContract[TERC721]):
1515
_storage: IpfsStorage
1616

17-
def __init__(
18-
self,
19-
contract_wrapper: ContractWrapper,
20-
storage: IpfsStorage,
21-
):
17+
def __init__(self, contract_wrapper: ContractWrapper, storage: IpfsStorage):
2218
super().__init__(contract_wrapper)
2319
self._storage = storage
2420

@@ -224,4 +220,4 @@ def _get_token_metadata(self, token_id: int) -> NFTMetadata:
224220
if not token_uri:
225221
raise NotFoundException(str(token_id))
226222

227-
return fetch_token_metadata(token_id, token_uri, self._storage)
223+
return fetch_token_metadata(token_id, token_uri, self._storage)

0 commit comments

Comments
 (0)