From 27e8ef7d905aa8dadb1eff870a01715c17b762a3 Mon Sep 17 00:00:00 2001 From: Ayush Pathak <62694274+ayshptk@users.noreply.github.com> Date: Tue, 19 Oct 2021 23:43:34 +0530 Subject: [PATCH 01/10] (wip) draft `market` module --- nftlabs/abi/market/__init__.py | 1608 +++++++++++++++++++++++++++++++ nftlabs/modules/currency.py | 2 +- nftlabs/modules/market.py | 121 +++ nftlabs/modules/market_types.py | 23 + nftlabs/modules/nft.py | 20 +- nftlabs/types/listing.py | 15 + nftlabs/types/role.py | 1 + 7 files changed, 1781 insertions(+), 9 deletions(-) create mode 100644 nftlabs/abi/market/__init__.py create mode 100644 nftlabs/modules/market.py create mode 100644 nftlabs/modules/market_types.py create mode 100644 nftlabs/types/listing.py diff --git a/nftlabs/abi/market/__init__.py b/nftlabs/abi/market/__init__.py new file mode 100644 index 00000000..edce1e79 --- /dev/null +++ b/nftlabs/abi/market/__init__.py @@ -0,0 +1,1608 @@ +"""Generated wrapper for Market Solidity contract.""" + +# pylint: disable=too-many-arguments + +import json +from typing import ( # pylint: disable=unused-import + Any, + List, + Optional, + Tuple, + Union, +) + +from eth_utils import to_checksum_address +from mypy_extensions import TypedDict # pylint: disable=unused-import +from hexbytes import HexBytes +from web3 import Web3 +from web3.contract import ContractFunction +from web3.datastructures import AttributeDict +from web3.providers.base import BaseProvider + +from zero_ex.contract_wrappers.bases import ContractMethod, Validator +from zero_ex.contract_wrappers.tx_params import TxParams + + +# Try to import a custom validator class definition; if there isn't one, +# declare one that we can instantiate for the default argument to the +# constructor for Market below. +try: + # both mypy and pylint complain about what we're doing here, but this + # works just fine, so their messages have been disabled here. + from . import ( # type: ignore # pylint: disable=import-self + MarketValidator, + ) +except ImportError: + + class MarketValidator( # type: ignore + Validator + ): + """No-op input validator.""" + + +try: + from .middleware import MIDDLEWARE # type: ignore +except ImportError: + pass + + +class MarketListing(TypedDict): + """Python representation of a tuple or struct. + + Solidity compiler output does not include the names of structs that appear + in method definitions. A tuple found in an ABI may have been written in + Solidity as a literal, anonymous tuple, or it may have been written as a + named `struct`:code:, but there is no way to tell from the compiler + output. This class represents a tuple that appeared in a method + definition. Its name is derived from a hash of that tuple's field names, + and every method whose ABI refers to a tuple with that same list of field + names will have a generated wrapper method that refers to this class. + + Any members of type `bytes`:code: should be encoded as UTF-8, which can be + accomplished via `str.encode("utf_8")`:code: + """ + + listingId: int + + seller: str + + assetContract: str + + tokenId: int + + quantity: int + + currency: str + + pricePerToken: int + + saleStart: int + + saleEnd: int + + tokensPerBuyer: int + + tokenType: int + + +class ContractUri_Method(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the _contractURI method.""" + + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address) + self._underlying_method = contract_function + + def call(self, tx_params: Optional[TxParams] = None) -> str: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method().call(tx_params.as_dict()) + return str(returned) + + def send_transaction(self, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method().transact(tx_params.as_dict()) + + def build_transaction(self, tx_params: Optional[TxParams] = None) -> dict: + """Construct calldata to be used as input to the method.""" + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method().buildTransaction(tx_params.as_dict()) + + def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int: + """Estimate gas consumption of method call.""" + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method().estimateGas(tx_params.as_dict()) + +class AddToListingMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the addToListing method.""" + + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction, validator: Validator=None): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs(self, listing_id: int, quantity: int): + """Validate the inputs to the addToListing method.""" + self.validator.assert_valid( + method_name='addToListing', + parameter_name='_listingId', + argument_value=listing_id, + ) + # safeguard against fractional inputs + listing_id = int(listing_id) + self.validator.assert_valid( + method_name='addToListing', + parameter_name='_quantity', + argument_value=quantity, + ) + # safeguard against fractional inputs + quantity = int(quantity) + return (listing_id, quantity) + + def call(self, listing_id: int, quantity: int, tx_params: Optional[TxParams] = None) -> None: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (listing_id, quantity) = self.validate_and_normalize_inputs(listing_id, quantity) + tx_params = super().normalize_tx_params(tx_params) + self._underlying_method(listing_id, quantity).call(tx_params.as_dict()) + + def send_transaction(self, listing_id: int, quantity: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (listing_id, quantity) = self.validate_and_normalize_inputs(listing_id, quantity) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(listing_id, quantity).transact(tx_params.as_dict()) + + def build_transaction(self, listing_id: int, quantity: int, tx_params: Optional[TxParams] = None) -> dict: + """Construct calldata to be used as input to the method.""" + (listing_id, quantity) = self.validate_and_normalize_inputs(listing_id, quantity) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(listing_id, quantity).buildTransaction(tx_params.as_dict()) + + def estimate_gas(self, listing_id: int, quantity: int, tx_params: Optional[TxParams] = None) -> int: + """Estimate gas consumption of method call.""" + (listing_id, quantity) = self.validate_and_normalize_inputs(listing_id, quantity) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(listing_id, quantity).estimateGas(tx_params.as_dict()) + +class BoughtFromListingMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the boughtFromListing method.""" + + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction, validator: Validator=None): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs(self, index_0: int, index_1: str): + """Validate the inputs to the boughtFromListing method.""" + self.validator.assert_valid( + method_name='boughtFromListing', + parameter_name='index_0', + argument_value=index_0, + ) + # safeguard against fractional inputs + index_0 = int(index_0) + self.validator.assert_valid( + method_name='boughtFromListing', + parameter_name='index_1', + argument_value=index_1, + ) + index_1 = self.validate_and_checksum_address(index_1) + return (index_0, index_1) + + def call(self, index_0: int, index_1: str, tx_params: Optional[TxParams] = None) -> int: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (index_0, index_1) = self.validate_and_normalize_inputs(index_0, index_1) + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method(index_0, index_1).call(tx_params.as_dict()) + return int(returned) + + def send_transaction(self, index_0: int, index_1: str, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (index_0, index_1) = self.validate_and_normalize_inputs(index_0, index_1) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(index_0, index_1).transact(tx_params.as_dict()) + + def build_transaction(self, index_0: int, index_1: str, tx_params: Optional[TxParams] = None) -> dict: + """Construct calldata to be used as input to the method.""" + (index_0, index_1) = self.validate_and_normalize_inputs(index_0, index_1) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(index_0, index_1).buildTransaction(tx_params.as_dict()) + + def estimate_gas(self, index_0: int, index_1: str, tx_params: Optional[TxParams] = None) -> int: + """Estimate gas consumption of method call.""" + (index_0, index_1) = self.validate_and_normalize_inputs(index_0, index_1) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(index_0, index_1).estimateGas(tx_params.as_dict()) + +class BuyMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the buy method.""" + + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction, validator: Validator=None): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs(self, listing_id: int, quantity: int): + """Validate the inputs to the buy method.""" + self.validator.assert_valid( + method_name='buy', + parameter_name='_listingId', + argument_value=listing_id, + ) + # safeguard against fractional inputs + listing_id = int(listing_id) + self.validator.assert_valid( + method_name='buy', + parameter_name='_quantity', + argument_value=quantity, + ) + # safeguard against fractional inputs + quantity = int(quantity) + return (listing_id, quantity) + + def call(self, listing_id: int, quantity: int, tx_params: Optional[TxParams] = None) -> None: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (listing_id, quantity) = self.validate_and_normalize_inputs(listing_id, quantity) + tx_params = super().normalize_tx_params(tx_params) + self._underlying_method(listing_id, quantity).call(tx_params.as_dict()) + + def send_transaction(self, listing_id: int, quantity: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (listing_id, quantity) = self.validate_and_normalize_inputs(listing_id, quantity) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(listing_id, quantity).transact(tx_params.as_dict()) + + def build_transaction(self, listing_id: int, quantity: int, tx_params: Optional[TxParams] = None) -> dict: + """Construct calldata to be used as input to the method.""" + (listing_id, quantity) = self.validate_and_normalize_inputs(listing_id, quantity) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(listing_id, quantity).buildTransaction(tx_params.as_dict()) + + def estimate_gas(self, listing_id: int, quantity: int, tx_params: Optional[TxParams] = None) -> int: + """Estimate gas consumption of method call.""" + (listing_id, quantity) = self.validate_and_normalize_inputs(listing_id, quantity) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(listing_id, quantity).estimateGas(tx_params.as_dict()) + +class ContractUriMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the contractURI method.""" + + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address) + self._underlying_method = contract_function + + def call(self, tx_params: Optional[TxParams] = None) -> str: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method().call(tx_params.as_dict()) + return str(returned) + + def send_transaction(self, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method().transact(tx_params.as_dict()) + + def build_transaction(self, tx_params: Optional[TxParams] = None) -> dict: + """Construct calldata to be used as input to the method.""" + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method().buildTransaction(tx_params.as_dict()) + + def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int: + """Estimate gas consumption of method call.""" + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method().estimateGas(tx_params.as_dict()) + +class GetAllListingsMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the getAllListings method.""" + + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address) + self._underlying_method = contract_function + + def call(self, tx_params: Optional[TxParams] = None) -> List[MarketListing]: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method().call(tx_params.as_dict()) + return [MarketListing(listingId=element[0],seller=element[1],assetContract=element[2],tokenId=element[3],quantity=element[4],currency=element[5],pricePerToken=element[6],saleStart=element[7],saleEnd=element[8],tokensPerBuyer=element[9],tokenType=element[10],) for element in returned] + + def send_transaction(self, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method().transact(tx_params.as_dict()) + + def build_transaction(self, tx_params: Optional[TxParams] = None) -> dict: + """Construct calldata to be used as input to the method.""" + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method().buildTransaction(tx_params.as_dict()) + + def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int: + """Estimate gas consumption of method call.""" + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method().estimateGas(tx_params.as_dict()) + +class GetListingMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the getListing method.""" + + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction, validator: Validator=None): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs(self, listing_id: int): + """Validate the inputs to the getListing method.""" + self.validator.assert_valid( + method_name='getListing', + parameter_name='_listingId', + argument_value=listing_id, + ) + # safeguard against fractional inputs + listing_id = int(listing_id) + return (listing_id) + + def call(self, listing_id: int, tx_params: Optional[TxParams] = None) -> MarketListing: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (listing_id) = self.validate_and_normalize_inputs(listing_id) + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method(listing_id).call(tx_params.as_dict()) + return MarketListing(listingId=returned[0],seller=returned[1],assetContract=returned[2],tokenId=returned[3],quantity=returned[4],currency=returned[5],pricePerToken=returned[6],saleStart=returned[7],saleEnd=returned[8],tokensPerBuyer=returned[9],tokenType=returned[10],) + + def send_transaction(self, listing_id: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (listing_id) = self.validate_and_normalize_inputs(listing_id) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(listing_id).transact(tx_params.as_dict()) + + def build_transaction(self, listing_id: int, tx_params: Optional[TxParams] = None) -> dict: + """Construct calldata to be used as input to the method.""" + (listing_id) = self.validate_and_normalize_inputs(listing_id) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(listing_id).buildTransaction(tx_params.as_dict()) + + def estimate_gas(self, listing_id: int, tx_params: Optional[TxParams] = None) -> int: + """Estimate gas consumption of method call.""" + (listing_id) = self.validate_and_normalize_inputs(listing_id) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(listing_id).estimateGas(tx_params.as_dict()) + +class GetListingsByAssetMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the getListingsByAsset method.""" + + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction, validator: Validator=None): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs(self, asset_contract: str, token_id: int): + """Validate the inputs to the getListingsByAsset method.""" + self.validator.assert_valid( + method_name='getListingsByAsset', + parameter_name='_assetContract', + argument_value=asset_contract, + ) + asset_contract = self.validate_and_checksum_address(asset_contract) + self.validator.assert_valid( + method_name='getListingsByAsset', + parameter_name='_tokenId', + argument_value=token_id, + ) + # safeguard against fractional inputs + token_id = int(token_id) + return (asset_contract, token_id) + + def call(self, asset_contract: str, token_id: int, tx_params: Optional[TxParams] = None) -> List[MarketListing]: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (asset_contract, token_id) = self.validate_and_normalize_inputs(asset_contract, token_id) + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method(asset_contract, token_id).call(tx_params.as_dict()) + return [MarketListing(listingId=element[0],seller=element[1],assetContract=element[2],tokenId=element[3],quantity=element[4],currency=element[5],pricePerToken=element[6],saleStart=element[7],saleEnd=element[8],tokensPerBuyer=element[9],tokenType=element[10],) for element in returned] + + def send_transaction(self, asset_contract: str, token_id: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (asset_contract, token_id) = self.validate_and_normalize_inputs(asset_contract, token_id) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(asset_contract, token_id).transact(tx_params.as_dict()) + + def build_transaction(self, asset_contract: str, token_id: int, tx_params: Optional[TxParams] = None) -> dict: + """Construct calldata to be used as input to the method.""" + (asset_contract, token_id) = self.validate_and_normalize_inputs(asset_contract, token_id) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(asset_contract, token_id).buildTransaction(tx_params.as_dict()) + + def estimate_gas(self, asset_contract: str, token_id: int, tx_params: Optional[TxParams] = None) -> int: + """Estimate gas consumption of method call.""" + (asset_contract, token_id) = self.validate_and_normalize_inputs(asset_contract, token_id) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(asset_contract, token_id).estimateGas(tx_params.as_dict()) + +class GetListingsByAssetContractMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the getListingsByAssetContract method.""" + + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction, validator: Validator=None): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs(self, asset_contract: str): + """Validate the inputs to the getListingsByAssetContract method.""" + self.validator.assert_valid( + method_name='getListingsByAssetContract', + parameter_name='_assetContract', + argument_value=asset_contract, + ) + asset_contract = self.validate_and_checksum_address(asset_contract) + return (asset_contract) + + def call(self, asset_contract: str, tx_params: Optional[TxParams] = None) -> List[MarketListing]: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (asset_contract) = self.validate_and_normalize_inputs(asset_contract) + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method(asset_contract).call(tx_params.as_dict()) + return [MarketListing(listingId=element[0],seller=element[1],assetContract=element[2],tokenId=element[3],quantity=element[4],currency=element[5],pricePerToken=element[6],saleStart=element[7],saleEnd=element[8],tokensPerBuyer=element[9],tokenType=element[10],) for element in returned] + + def send_transaction(self, asset_contract: str, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (asset_contract) = self.validate_and_normalize_inputs(asset_contract) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(asset_contract).transact(tx_params.as_dict()) + + def build_transaction(self, asset_contract: str, tx_params: Optional[TxParams] = None) -> dict: + """Construct calldata to be used as input to the method.""" + (asset_contract) = self.validate_and_normalize_inputs(asset_contract) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(asset_contract).buildTransaction(tx_params.as_dict()) + + def estimate_gas(self, asset_contract: str, tx_params: Optional[TxParams] = None) -> int: + """Estimate gas consumption of method call.""" + (asset_contract) = self.validate_and_normalize_inputs(asset_contract) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(asset_contract).estimateGas(tx_params.as_dict()) + +class GetListingsBySellerMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the getListingsBySeller method.""" + + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction, validator: Validator=None): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs(self, seller: str): + """Validate the inputs to the getListingsBySeller method.""" + self.validator.assert_valid( + method_name='getListingsBySeller', + parameter_name='_seller', + argument_value=seller, + ) + seller = self.validate_and_checksum_address(seller) + return (seller) + + def call(self, seller: str, tx_params: Optional[TxParams] = None) -> List[MarketListing]: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (seller) = self.validate_and_normalize_inputs(seller) + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method(seller).call(tx_params.as_dict()) + return [MarketListing(listingId=element[0],seller=element[1],assetContract=element[2],tokenId=element[3],quantity=element[4],currency=element[5],pricePerToken=element[6],saleStart=element[7],saleEnd=element[8],tokensPerBuyer=element[9],tokenType=element[10],) for element in returned] + + def send_transaction(self, seller: str, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (seller) = self.validate_and_normalize_inputs(seller) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(seller).transact(tx_params.as_dict()) + + def build_transaction(self, seller: str, tx_params: Optional[TxParams] = None) -> dict: + """Construct calldata to be used as input to the method.""" + (seller) = self.validate_and_normalize_inputs(seller) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(seller).buildTransaction(tx_params.as_dict()) + + def estimate_gas(self, seller: str, tx_params: Optional[TxParams] = None) -> int: + """Estimate gas consumption of method call.""" + (seller) = self.validate_and_normalize_inputs(seller) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(seller).estimateGas(tx_params.as_dict()) + +class IsTrustedForwarderMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the isTrustedForwarder method.""" + + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction, validator: Validator=None): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs(self, forwarder: str): + """Validate the inputs to the isTrustedForwarder method.""" + self.validator.assert_valid( + method_name='isTrustedForwarder', + parameter_name='forwarder', + argument_value=forwarder, + ) + forwarder = self.validate_and_checksum_address(forwarder) + return (forwarder) + + def call(self, forwarder: str, tx_params: Optional[TxParams] = None) -> bool: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (forwarder) = self.validate_and_normalize_inputs(forwarder) + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method(forwarder).call(tx_params.as_dict()) + return bool(returned) + + def send_transaction(self, forwarder: str, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (forwarder) = self.validate_and_normalize_inputs(forwarder) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(forwarder).transact(tx_params.as_dict()) + + def build_transaction(self, forwarder: str, tx_params: Optional[TxParams] = None) -> dict: + """Construct calldata to be used as input to the method.""" + (forwarder) = self.validate_and_normalize_inputs(forwarder) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(forwarder).buildTransaction(tx_params.as_dict()) + + def estimate_gas(self, forwarder: str, tx_params: Optional[TxParams] = None) -> int: + """Estimate gas consumption of method call.""" + (forwarder) = self.validate_and_normalize_inputs(forwarder) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(forwarder).estimateGas(tx_params.as_dict()) + +class ListMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the list method.""" + + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction, validator: Validator=None): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs(self, asset_contract: str, token_id: int, currency: str, price_per_token: int, quantity: int, tokens_per_buyer: int, seconds_until_start: int, seconds_until_end: int): + """Validate the inputs to the list method.""" + self.validator.assert_valid( + method_name='list', + parameter_name='_assetContract', + argument_value=asset_contract, + ) + asset_contract = self.validate_and_checksum_address(asset_contract) + self.validator.assert_valid( + method_name='list', + parameter_name='_tokenId', + argument_value=token_id, + ) + # safeguard against fractional inputs + token_id = int(token_id) + self.validator.assert_valid( + method_name='list', + parameter_name='_currency', + argument_value=currency, + ) + currency = self.validate_and_checksum_address(currency) + self.validator.assert_valid( + method_name='list', + parameter_name='_pricePerToken', + argument_value=price_per_token, + ) + # safeguard against fractional inputs + price_per_token = int(price_per_token) + self.validator.assert_valid( + method_name='list', + parameter_name='_quantity', + argument_value=quantity, + ) + # safeguard against fractional inputs + quantity = int(quantity) + self.validator.assert_valid( + method_name='list', + parameter_name='_tokensPerBuyer', + argument_value=tokens_per_buyer, + ) + # safeguard against fractional inputs + tokens_per_buyer = int(tokens_per_buyer) + self.validator.assert_valid( + method_name='list', + parameter_name='_secondsUntilStart', + argument_value=seconds_until_start, + ) + # safeguard against fractional inputs + seconds_until_start = int(seconds_until_start) + self.validator.assert_valid( + method_name='list', + parameter_name='_secondsUntilEnd', + argument_value=seconds_until_end, + ) + # safeguard against fractional inputs + seconds_until_end = int(seconds_until_end) + return (asset_contract, token_id, currency, price_per_token, quantity, tokens_per_buyer, seconds_until_start, seconds_until_end) + + def call(self, asset_contract: str, token_id: int, currency: str, price_per_token: int, quantity: int, tokens_per_buyer: int, seconds_until_start: int, seconds_until_end: int, tx_params: Optional[TxParams] = None) -> None: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (asset_contract, token_id, currency, price_per_token, quantity, tokens_per_buyer, seconds_until_start, seconds_until_end) = self.validate_and_normalize_inputs(asset_contract, token_id, currency, price_per_token, quantity, tokens_per_buyer, seconds_until_start, seconds_until_end) + tx_params = super().normalize_tx_params(tx_params) + self._underlying_method(asset_contract, token_id, currency, price_per_token, quantity, tokens_per_buyer, seconds_until_start, seconds_until_end).call(tx_params.as_dict()) + + def send_transaction(self, asset_contract: str, token_id: int, currency: str, price_per_token: int, quantity: int, tokens_per_buyer: int, seconds_until_start: int, seconds_until_end: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (asset_contract, token_id, currency, price_per_token, quantity, tokens_per_buyer, seconds_until_start, seconds_until_end) = self.validate_and_normalize_inputs(asset_contract, token_id, currency, price_per_token, quantity, tokens_per_buyer, seconds_until_start, seconds_until_end) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(asset_contract, token_id, currency, price_per_token, quantity, tokens_per_buyer, seconds_until_start, seconds_until_end).transact(tx_params.as_dict()) + + def build_transaction(self, asset_contract: str, token_id: int, currency: str, price_per_token: int, quantity: int, tokens_per_buyer: int, seconds_until_start: int, seconds_until_end: int, tx_params: Optional[TxParams] = None) -> dict: + """Construct calldata to be used as input to the method.""" + (asset_contract, token_id, currency, price_per_token, quantity, tokens_per_buyer, seconds_until_start, seconds_until_end) = self.validate_and_normalize_inputs(asset_contract, token_id, currency, price_per_token, quantity, tokens_per_buyer, seconds_until_start, seconds_until_end) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(asset_contract, token_id, currency, price_per_token, quantity, tokens_per_buyer, seconds_until_start, seconds_until_end).buildTransaction(tx_params.as_dict()) + + def estimate_gas(self, asset_contract: str, token_id: int, currency: str, price_per_token: int, quantity: int, tokens_per_buyer: int, seconds_until_start: int, seconds_until_end: int, tx_params: Optional[TxParams] = None) -> int: + """Estimate gas consumption of method call.""" + (asset_contract, token_id, currency, price_per_token, quantity, tokens_per_buyer, seconds_until_start, seconds_until_end) = self.validate_and_normalize_inputs(asset_contract, token_id, currency, price_per_token, quantity, tokens_per_buyer, seconds_until_start, seconds_until_end) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(asset_contract, token_id, currency, price_per_token, quantity, tokens_per_buyer, seconds_until_start, seconds_until_end).estimateGas(tx_params.as_dict()) + +class ListingsMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the listings method.""" + + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction, validator: Validator=None): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs(self, index_0: int): + """Validate the inputs to the listings method.""" + self.validator.assert_valid( + method_name='listings', + parameter_name='index_0', + argument_value=index_0, + ) + # safeguard against fractional inputs + index_0 = int(index_0) + return (index_0) + + def call(self, index_0: int, tx_params: Optional[TxParams] = None) -> Tuple[int, str, str, int, int, str, int, int, int, int, int]: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (index_0) = self.validate_and_normalize_inputs(index_0) + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method(index_0).call(tx_params.as_dict()) + return (returned[0],returned[1],returned[2],returned[3],returned[4],returned[5],returned[6],returned[7],returned[8],returned[9],returned[10],) + + def send_transaction(self, index_0: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (index_0) = self.validate_and_normalize_inputs(index_0) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(index_0).transact(tx_params.as_dict()) + + def build_transaction(self, index_0: int, tx_params: Optional[TxParams] = None) -> dict: + """Construct calldata to be used as input to the method.""" + (index_0) = self.validate_and_normalize_inputs(index_0) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(index_0).buildTransaction(tx_params.as_dict()) + + def estimate_gas(self, index_0: int, tx_params: Optional[TxParams] = None) -> int: + """Estimate gas consumption of method call.""" + (index_0) = self.validate_and_normalize_inputs(index_0) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(index_0).estimateGas(tx_params.as_dict()) + +class MarketFeeBpsMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the marketFeeBps method.""" + + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address) + self._underlying_method = contract_function + + def call(self, tx_params: Optional[TxParams] = None) -> int: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method().call(tx_params.as_dict()) + return int(returned) + + def send_transaction(self, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method().transact(tx_params.as_dict()) + + def build_transaction(self, tx_params: Optional[TxParams] = None) -> dict: + """Construct calldata to be used as input to the method.""" + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method().buildTransaction(tx_params.as_dict()) + + def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int: + """Estimate gas consumption of method call.""" + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method().estimateGas(tx_params.as_dict()) + +class OnErc1155BatchReceivedMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the onERC1155BatchReceived method.""" + + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction, validator: Validator=None): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs(self, index_0: str, index_1: str, index_2: List[int], index_3: List[int], index_4: Union[bytes, str]): + """Validate the inputs to the onERC1155BatchReceived method.""" + self.validator.assert_valid( + method_name='onERC1155BatchReceived', + parameter_name='index_0', + argument_value=index_0, + ) + index_0 = self.validate_and_checksum_address(index_0) + self.validator.assert_valid( + method_name='onERC1155BatchReceived', + parameter_name='index_1', + argument_value=index_1, + ) + index_1 = self.validate_and_checksum_address(index_1) + self.validator.assert_valid( + method_name='onERC1155BatchReceived', + parameter_name='index_2', + argument_value=index_2, + ) + self.validator.assert_valid( + method_name='onERC1155BatchReceived', + parameter_name='index_3', + argument_value=index_3, + ) + self.validator.assert_valid( + method_name='onERC1155BatchReceived', + parameter_name='index_4', + argument_value=index_4, + ) + return (index_0, index_1, index_2, index_3, index_4) + + def call(self, index_0: str, index_1: str, index_2: List[int], index_3: List[int], index_4: Union[bytes, str], tx_params: Optional[TxParams] = None) -> Union[bytes, str]: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (index_0, index_1, index_2, index_3, index_4) = self.validate_and_normalize_inputs(index_0, index_1, index_2, index_3, index_4) + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method(index_0, index_1, index_2, index_3, index_4).call(tx_params.as_dict()) + return Union[bytes, str](returned) + + def send_transaction(self, index_0: str, index_1: str, index_2: List[int], index_3: List[int], index_4: Union[bytes, str], tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (index_0, index_1, index_2, index_3, index_4) = self.validate_and_normalize_inputs(index_0, index_1, index_2, index_3, index_4) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(index_0, index_1, index_2, index_3, index_4).transact(tx_params.as_dict()) + + def build_transaction(self, index_0: str, index_1: str, index_2: List[int], index_3: List[int], index_4: Union[bytes, str], tx_params: Optional[TxParams] = None) -> dict: + """Construct calldata to be used as input to the method.""" + (index_0, index_1, index_2, index_3, index_4) = self.validate_and_normalize_inputs(index_0, index_1, index_2, index_3, index_4) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(index_0, index_1, index_2, index_3, index_4).buildTransaction(tx_params.as_dict()) + + def estimate_gas(self, index_0: str, index_1: str, index_2: List[int], index_3: List[int], index_4: Union[bytes, str], tx_params: Optional[TxParams] = None) -> int: + """Estimate gas consumption of method call.""" + (index_0, index_1, index_2, index_3, index_4) = self.validate_and_normalize_inputs(index_0, index_1, index_2, index_3, index_4) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(index_0, index_1, index_2, index_3, index_4).estimateGas(tx_params.as_dict()) + +class OnErc1155ReceivedMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the onERC1155Received method.""" + + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction, validator: Validator=None): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs(self, index_0: str, index_1: str, index_2: int, index_3: int, index_4: Union[bytes, str]): + """Validate the inputs to the onERC1155Received method.""" + self.validator.assert_valid( + method_name='onERC1155Received', + parameter_name='index_0', + argument_value=index_0, + ) + index_0 = self.validate_and_checksum_address(index_0) + self.validator.assert_valid( + method_name='onERC1155Received', + parameter_name='index_1', + argument_value=index_1, + ) + index_1 = self.validate_and_checksum_address(index_1) + self.validator.assert_valid( + method_name='onERC1155Received', + parameter_name='index_2', + argument_value=index_2, + ) + # safeguard against fractional inputs + index_2 = int(index_2) + self.validator.assert_valid( + method_name='onERC1155Received', + parameter_name='index_3', + argument_value=index_3, + ) + # safeguard against fractional inputs + index_3 = int(index_3) + self.validator.assert_valid( + method_name='onERC1155Received', + parameter_name='index_4', + argument_value=index_4, + ) + return (index_0, index_1, index_2, index_3, index_4) + + def call(self, index_0: str, index_1: str, index_2: int, index_3: int, index_4: Union[bytes, str], tx_params: Optional[TxParams] = None) -> Union[bytes, str]: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (index_0, index_1, index_2, index_3, index_4) = self.validate_and_normalize_inputs(index_0, index_1, index_2, index_3, index_4) + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method(index_0, index_1, index_2, index_3, index_4).call(tx_params.as_dict()) + return Union[bytes, str](returned) + + def send_transaction(self, index_0: str, index_1: str, index_2: int, index_3: int, index_4: Union[bytes, str], tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (index_0, index_1, index_2, index_3, index_4) = self.validate_and_normalize_inputs(index_0, index_1, index_2, index_3, index_4) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(index_0, index_1, index_2, index_3, index_4).transact(tx_params.as_dict()) + + def build_transaction(self, index_0: str, index_1: str, index_2: int, index_3: int, index_4: Union[bytes, str], tx_params: Optional[TxParams] = None) -> dict: + """Construct calldata to be used as input to the method.""" + (index_0, index_1, index_2, index_3, index_4) = self.validate_and_normalize_inputs(index_0, index_1, index_2, index_3, index_4) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(index_0, index_1, index_2, index_3, index_4).buildTransaction(tx_params.as_dict()) + + def estimate_gas(self, index_0: str, index_1: str, index_2: int, index_3: int, index_4: Union[bytes, str], tx_params: Optional[TxParams] = None) -> int: + """Estimate gas consumption of method call.""" + (index_0, index_1, index_2, index_3, index_4) = self.validate_and_normalize_inputs(index_0, index_1, index_2, index_3, index_4) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(index_0, index_1, index_2, index_3, index_4).estimateGas(tx_params.as_dict()) + +class OnErc721ReceivedMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the onERC721Received method.""" + + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction, validator: Validator=None): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs(self, index_0: str, index_1: str, index_2: int, index_3: Union[bytes, str]): + """Validate the inputs to the onERC721Received method.""" + self.validator.assert_valid( + method_name='onERC721Received', + parameter_name='index_0', + argument_value=index_0, + ) + index_0 = self.validate_and_checksum_address(index_0) + self.validator.assert_valid( + method_name='onERC721Received', + parameter_name='index_1', + argument_value=index_1, + ) + index_1 = self.validate_and_checksum_address(index_1) + self.validator.assert_valid( + method_name='onERC721Received', + parameter_name='index_2', + argument_value=index_2, + ) + # safeguard against fractional inputs + index_2 = int(index_2) + self.validator.assert_valid( + method_name='onERC721Received', + parameter_name='index_3', + argument_value=index_3, + ) + return (index_0, index_1, index_2, index_3) + + def call(self, index_0: str, index_1: str, index_2: int, index_3: Union[bytes, str], tx_params: Optional[TxParams] = None) -> Union[bytes, str]: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (index_0, index_1, index_2, index_3) = self.validate_and_normalize_inputs(index_0, index_1, index_2, index_3) + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method(index_0, index_1, index_2, index_3).call(tx_params.as_dict()) + return Union[bytes, str](returned) + + def send_transaction(self, index_0: str, index_1: str, index_2: int, index_3: Union[bytes, str], tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (index_0, index_1, index_2, index_3) = self.validate_and_normalize_inputs(index_0, index_1, index_2, index_3) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(index_0, index_1, index_2, index_3).transact(tx_params.as_dict()) + + def build_transaction(self, index_0: str, index_1: str, index_2: int, index_3: Union[bytes, str], tx_params: Optional[TxParams] = None) -> dict: + """Construct calldata to be used as input to the method.""" + (index_0, index_1, index_2, index_3) = self.validate_and_normalize_inputs(index_0, index_1, index_2, index_3) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(index_0, index_1, index_2, index_3).buildTransaction(tx_params.as_dict()) + + def estimate_gas(self, index_0: str, index_1: str, index_2: int, index_3: Union[bytes, str], tx_params: Optional[TxParams] = None) -> int: + """Estimate gas consumption of method call.""" + (index_0, index_1, index_2, index_3) = self.validate_and_normalize_inputs(index_0, index_1, index_2, index_3) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(index_0, index_1, index_2, index_3).estimateGas(tx_params.as_dict()) + +class SetContractUriMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the setContractURI method.""" + + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction, validator: Validator=None): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs(self, uri: str): + """Validate the inputs to the setContractURI method.""" + self.validator.assert_valid( + method_name='setContractURI', + parameter_name='_URI', + argument_value=uri, + ) + return (uri) + + def call(self, uri: str, tx_params: Optional[TxParams] = None) -> None: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (uri) = self.validate_and_normalize_inputs(uri) + tx_params = super().normalize_tx_params(tx_params) + self._underlying_method(uri).call(tx_params.as_dict()) + + def send_transaction(self, uri: str, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (uri) = self.validate_and_normalize_inputs(uri) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(uri).transact(tx_params.as_dict()) + + def build_transaction(self, uri: str, tx_params: Optional[TxParams] = None) -> dict: + """Construct calldata to be used as input to the method.""" + (uri) = self.validate_and_normalize_inputs(uri) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(uri).buildTransaction(tx_params.as_dict()) + + def estimate_gas(self, uri: str, tx_params: Optional[TxParams] = None) -> int: + """Estimate gas consumption of method call.""" + (uri) = self.validate_and_normalize_inputs(uri) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(uri).estimateGas(tx_params.as_dict()) + +class SetMarketFeeBpsMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the setMarketFeeBps method.""" + + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction, validator: Validator=None): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs(self, fee_bps: int): + """Validate the inputs to the setMarketFeeBps method.""" + self.validator.assert_valid( + method_name='setMarketFeeBps', + parameter_name='feeBps', + argument_value=fee_bps, + ) + return (fee_bps) + + def call(self, fee_bps: int, tx_params: Optional[TxParams] = None) -> None: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (fee_bps) = self.validate_and_normalize_inputs(fee_bps) + tx_params = super().normalize_tx_params(tx_params) + self._underlying_method(fee_bps).call(tx_params.as_dict()) + + def send_transaction(self, fee_bps: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (fee_bps) = self.validate_and_normalize_inputs(fee_bps) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(fee_bps).transact(tx_params.as_dict()) + + def build_transaction(self, fee_bps: int, tx_params: Optional[TxParams] = None) -> dict: + """Construct calldata to be used as input to the method.""" + (fee_bps) = self.validate_and_normalize_inputs(fee_bps) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(fee_bps).buildTransaction(tx_params.as_dict()) + + def estimate_gas(self, fee_bps: int, tx_params: Optional[TxParams] = None) -> int: + """Estimate gas consumption of method call.""" + (fee_bps) = self.validate_and_normalize_inputs(fee_bps) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(fee_bps).estimateGas(tx_params.as_dict()) + +class SupportsInterfaceMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the supportsInterface method.""" + + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction, validator: Validator=None): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs(self, interface_id: Union[bytes, str]): + """Validate the inputs to the supportsInterface method.""" + self.validator.assert_valid( + method_name='supportsInterface', + parameter_name='interfaceId', + argument_value=interface_id, + ) + return (interface_id) + + def call(self, interface_id: Union[bytes, str], tx_params: Optional[TxParams] = None) -> bool: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (interface_id) = self.validate_and_normalize_inputs(interface_id) + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method(interface_id).call(tx_params.as_dict()) + return bool(returned) + + def send_transaction(self, interface_id: Union[bytes, str], tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (interface_id) = self.validate_and_normalize_inputs(interface_id) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(interface_id).transact(tx_params.as_dict()) + + def build_transaction(self, interface_id: Union[bytes, str], tx_params: Optional[TxParams] = None) -> dict: + """Construct calldata to be used as input to the method.""" + (interface_id) = self.validate_and_normalize_inputs(interface_id) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(interface_id).buildTransaction(tx_params.as_dict()) + + def estimate_gas(self, interface_id: Union[bytes, str], tx_params: Optional[TxParams] = None) -> int: + """Estimate gas consumption of method call.""" + (interface_id) = self.validate_and_normalize_inputs(interface_id) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(interface_id).estimateGas(tx_params.as_dict()) + +class TotalListingsMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the totalListings method.""" + + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address) + self._underlying_method = contract_function + + def call(self, tx_params: Optional[TxParams] = None) -> int: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method().call(tx_params.as_dict()) + return int(returned) + + def send_transaction(self, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method().transact(tx_params.as_dict()) + + def build_transaction(self, tx_params: Optional[TxParams] = None) -> dict: + """Construct calldata to be used as input to the method.""" + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method().buildTransaction(tx_params.as_dict()) + + def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int: + """Estimate gas consumption of method call.""" + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method().estimateGas(tx_params.as_dict()) + +class UnlistMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the unlist method.""" + + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction, validator: Validator=None): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs(self, listing_id: int, quantity: int): + """Validate the inputs to the unlist method.""" + self.validator.assert_valid( + method_name='unlist', + parameter_name='_listingId', + argument_value=listing_id, + ) + # safeguard against fractional inputs + listing_id = int(listing_id) + self.validator.assert_valid( + method_name='unlist', + parameter_name='_quantity', + argument_value=quantity, + ) + # safeguard against fractional inputs + quantity = int(quantity) + return (listing_id, quantity) + + def call(self, listing_id: int, quantity: int, tx_params: Optional[TxParams] = None) -> None: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (listing_id, quantity) = self.validate_and_normalize_inputs(listing_id, quantity) + tx_params = super().normalize_tx_params(tx_params) + self._underlying_method(listing_id, quantity).call(tx_params.as_dict()) + + def send_transaction(self, listing_id: int, quantity: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (listing_id, quantity) = self.validate_and_normalize_inputs(listing_id, quantity) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(listing_id, quantity).transact(tx_params.as_dict()) + + def build_transaction(self, listing_id: int, quantity: int, tx_params: Optional[TxParams] = None) -> dict: + """Construct calldata to be used as input to the method.""" + (listing_id, quantity) = self.validate_and_normalize_inputs(listing_id, quantity) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(listing_id, quantity).buildTransaction(tx_params.as_dict()) + + def estimate_gas(self, listing_id: int, quantity: int, tx_params: Optional[TxParams] = None) -> int: + """Estimate gas consumption of method call.""" + (listing_id, quantity) = self.validate_and_normalize_inputs(listing_id, quantity) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(listing_id, quantity).estimateGas(tx_params.as_dict()) + +class UpdateListingParamsMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the updateListingParams method.""" + + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction, validator: Validator=None): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs(self, listing_id: int, price_per_token: int, currency: str, tokens_per_buyer: int, seconds_until_start: int, seconds_until_end: int): + """Validate the inputs to the updateListingParams method.""" + self.validator.assert_valid( + method_name='updateListingParams', + parameter_name='_listingId', + argument_value=listing_id, + ) + # safeguard against fractional inputs + listing_id = int(listing_id) + self.validator.assert_valid( + method_name='updateListingParams', + parameter_name='_pricePerToken', + argument_value=price_per_token, + ) + # safeguard against fractional inputs + price_per_token = int(price_per_token) + self.validator.assert_valid( + method_name='updateListingParams', + parameter_name='_currency', + argument_value=currency, + ) + currency = self.validate_and_checksum_address(currency) + self.validator.assert_valid( + method_name='updateListingParams', + parameter_name='_tokensPerBuyer', + argument_value=tokens_per_buyer, + ) + # safeguard against fractional inputs + tokens_per_buyer = int(tokens_per_buyer) + self.validator.assert_valid( + method_name='updateListingParams', + parameter_name='_secondsUntilStart', + argument_value=seconds_until_start, + ) + # safeguard against fractional inputs + seconds_until_start = int(seconds_until_start) + self.validator.assert_valid( + method_name='updateListingParams', + parameter_name='_secondsUntilEnd', + argument_value=seconds_until_end, + ) + # safeguard against fractional inputs + seconds_until_end = int(seconds_until_end) + return (listing_id, price_per_token, currency, tokens_per_buyer, seconds_until_start, seconds_until_end) + + def call(self, listing_id: int, price_per_token: int, currency: str, tokens_per_buyer: int, seconds_until_start: int, seconds_until_end: int, tx_params: Optional[TxParams] = None) -> None: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (listing_id, price_per_token, currency, tokens_per_buyer, seconds_until_start, seconds_until_end) = self.validate_and_normalize_inputs(listing_id, price_per_token, currency, tokens_per_buyer, seconds_until_start, seconds_until_end) + tx_params = super().normalize_tx_params(tx_params) + self._underlying_method(listing_id, price_per_token, currency, tokens_per_buyer, seconds_until_start, seconds_until_end).call(tx_params.as_dict()) + + def send_transaction(self, listing_id: int, price_per_token: int, currency: str, tokens_per_buyer: int, seconds_until_start: int, seconds_until_end: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (listing_id, price_per_token, currency, tokens_per_buyer, seconds_until_start, seconds_until_end) = self.validate_and_normalize_inputs(listing_id, price_per_token, currency, tokens_per_buyer, seconds_until_start, seconds_until_end) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(listing_id, price_per_token, currency, tokens_per_buyer, seconds_until_start, seconds_until_end).transact(tx_params.as_dict()) + + def build_transaction(self, listing_id: int, price_per_token: int, currency: str, tokens_per_buyer: int, seconds_until_start: int, seconds_until_end: int, tx_params: Optional[TxParams] = None) -> dict: + """Construct calldata to be used as input to the method.""" + (listing_id, price_per_token, currency, tokens_per_buyer, seconds_until_start, seconds_until_end) = self.validate_and_normalize_inputs(listing_id, price_per_token, currency, tokens_per_buyer, seconds_until_start, seconds_until_end) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(listing_id, price_per_token, currency, tokens_per_buyer, seconds_until_start, seconds_until_end).buildTransaction(tx_params.as_dict()) + + def estimate_gas(self, listing_id: int, price_per_token: int, currency: str, tokens_per_buyer: int, seconds_until_start: int, seconds_until_end: int, tx_params: Optional[TxParams] = None) -> int: + """Estimate gas consumption of method call.""" + (listing_id, price_per_token, currency, tokens_per_buyer, seconds_until_start, seconds_until_end) = self.validate_and_normalize_inputs(listing_id, price_per_token, currency, tokens_per_buyer, seconds_until_start, seconds_until_end) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(listing_id, price_per_token, currency, tokens_per_buyer, seconds_until_start, seconds_until_end).estimateGas(tx_params.as_dict()) + +# pylint: disable=too-many-public-methods,too-many-instance-attributes +class Market: + """Wrapper class for Market Solidity contract. + + All method parameters of type `bytes`:code: should be encoded as UTF-8, + which can be accomplished via `str.encode("utf_8")`:code:. + """ + contract_uri_: ContractUri_Method + """Constructor-initialized instance of + :class:`ContractUri_Method`. + """ + + add_to_listing: AddToListingMethod + """Constructor-initialized instance of + :class:`AddToListingMethod`. + """ + + bought_from_listing: BoughtFromListingMethod + """Constructor-initialized instance of + :class:`BoughtFromListingMethod`. + """ + + buy: BuyMethod + """Constructor-initialized instance of + :class:`BuyMethod`. + """ + + contract_uri: ContractUriMethod + """Constructor-initialized instance of + :class:`ContractUriMethod`. + """ + + get_all_listings: GetAllListingsMethod + """Constructor-initialized instance of + :class:`GetAllListingsMethod`. + """ + + get_listing: GetListingMethod + """Constructor-initialized instance of + :class:`GetListingMethod`. + """ + + get_listings_by_asset: GetListingsByAssetMethod + """Constructor-initialized instance of + :class:`GetListingsByAssetMethod`. + """ + + get_listings_by_asset_contract: GetListingsByAssetContractMethod + """Constructor-initialized instance of + :class:`GetListingsByAssetContractMethod`. + """ + + get_listings_by_seller: GetListingsBySellerMethod + """Constructor-initialized instance of + :class:`GetListingsBySellerMethod`. + """ + + is_trusted_forwarder: IsTrustedForwarderMethod + """Constructor-initialized instance of + :class:`IsTrustedForwarderMethod`. + """ + + _list: ListMethod + """Constructor-initialized instance of + :class:`ListMethod`. + """ + + listings: ListingsMethod + """Constructor-initialized instance of + :class:`ListingsMethod`. + """ + + market_fee_bps: MarketFeeBpsMethod + """Constructor-initialized instance of + :class:`MarketFeeBpsMethod`. + """ + + on_erc1155_batch_received: OnErc1155BatchReceivedMethod + """Constructor-initialized instance of + :class:`OnErc1155BatchReceivedMethod`. + """ + + on_erc1155_received: OnErc1155ReceivedMethod + """Constructor-initialized instance of + :class:`OnErc1155ReceivedMethod`. + """ + + on_erc721_received: OnErc721ReceivedMethod + """Constructor-initialized instance of + :class:`OnErc721ReceivedMethod`. + """ + + set_contract_uri: SetContractUriMethod + """Constructor-initialized instance of + :class:`SetContractUriMethod`. + """ + + set_market_fee_bps: SetMarketFeeBpsMethod + """Constructor-initialized instance of + :class:`SetMarketFeeBpsMethod`. + """ + + supports_interface: SupportsInterfaceMethod + """Constructor-initialized instance of + :class:`SupportsInterfaceMethod`. + """ + + total_listings: TotalListingsMethod + """Constructor-initialized instance of + :class:`TotalListingsMethod`. + """ + + unlist: UnlistMethod + """Constructor-initialized instance of + :class:`UnlistMethod`. + """ + + update_listing_params: UpdateListingParamsMethod + """Constructor-initialized instance of + :class:`UpdateListingParamsMethod`. + """ + + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + validator: MarketValidator = None, + ): + """Get an instance of wrapper for smart contract. + + :param web3_or_provider: Either an instance of `web3.Web3`:code: or + `web3.providers.base.BaseProvider`:code: + :param contract_address: where the contract has been deployed + :param validator: for validation of method inputs. + """ + # pylint: disable=too-many-statements + + self.contract_address = contract_address + + if not validator: + validator = MarketValidator(web3_or_provider, contract_address) + + web3 = None + if isinstance(web3_or_provider, BaseProvider): + web3 = Web3(web3_or_provider) + elif isinstance(web3_or_provider, Web3): + web3 = web3_or_provider + else: + raise TypeError( + "Expected parameter 'web3_or_provider' to be an instance of either" + + " Web3 or BaseProvider" + ) + + # if any middleware was imported, inject it + try: + MIDDLEWARE + except NameError: + pass + else: + try: + for middleware in MIDDLEWARE: + web3.middleware_onion.inject( + middleware['function'], layer=middleware['layer'], + ) + except ValueError as value_error: + if value_error.args == ("You can't add the same un-named instance twice",): + pass + + self._web3_eth = web3.eth + + functions = self._web3_eth.contract(address=to_checksum_address(contract_address), abi=Market.abi()).functions + + self.contract_uri_ = ContractUri_Method(web3_or_provider, contract_address, functions._contractURI) + + self.add_to_listing = AddToListingMethod(web3_or_provider, contract_address, functions.addToListing, validator) + + self.bought_from_listing = BoughtFromListingMethod(web3_or_provider, contract_address, functions.boughtFromListing, validator) + + self.buy = BuyMethod(web3_or_provider, contract_address, functions.buy, validator) + + self.contract_uri = ContractUriMethod(web3_or_provider, contract_address, functions.contractURI) + + self.get_all_listings = GetAllListingsMethod(web3_or_provider, contract_address, functions.getAllListings) + + self.get_listing = GetListingMethod(web3_or_provider, contract_address, functions.getListing, validator) + + self.get_listings_by_asset = GetListingsByAssetMethod(web3_or_provider, contract_address, functions.getListingsByAsset, validator) + + self.get_listings_by_asset_contract = GetListingsByAssetContractMethod(web3_or_provider, contract_address, functions.getListingsByAssetContract, validator) + + self.get_listings_by_seller = GetListingsBySellerMethod(web3_or_provider, contract_address, functions.getListingsBySeller, validator) + + self.is_trusted_forwarder = IsTrustedForwarderMethod(web3_or_provider, contract_address, functions.isTrustedForwarder, validator) + + self._list = ListMethod(web3_or_provider, contract_address, functions.list, validator) + + self.listings = ListingsMethod(web3_or_provider, contract_address, functions.listings, validator) + + self.market_fee_bps = MarketFeeBpsMethod(web3_or_provider, contract_address, functions.marketFeeBps) + + self.on_erc1155_batch_received = OnErc1155BatchReceivedMethod(web3_or_provider, contract_address, functions.onERC1155BatchReceived, validator) + + self.on_erc1155_received = OnErc1155ReceivedMethod(web3_or_provider, contract_address, functions.onERC1155Received, validator) + + self.on_erc721_received = OnErc721ReceivedMethod(web3_or_provider, contract_address, functions.onERC721Received, validator) + + self.set_contract_uri = SetContractUriMethod(web3_or_provider, contract_address, functions.setContractURI, validator) + + self.set_market_fee_bps = SetMarketFeeBpsMethod(web3_or_provider, contract_address, functions.setMarketFeeBps, validator) + + self.supports_interface = SupportsInterfaceMethod(web3_or_provider, contract_address, functions.supportsInterface, validator) + + self.total_listings = TotalListingsMethod(web3_or_provider, contract_address, functions.totalListings) + + self.unlist = UnlistMethod(web3_or_provider, contract_address, functions.unlist, validator) + + self.update_listing_params = UpdateListingParamsMethod(web3_or_provider, contract_address, functions.updateListingParams, validator) + + def get_listing_update_event( + self, tx_hash: Union[HexBytes, bytes] + ) -> Tuple[AttributeDict]: + """Get log entry for ListingUpdate event. + + :param tx_hash: hash of transaction emitting ListingUpdate event + """ + tx_receipt = self._web3_eth.getTransactionReceipt(tx_hash) + return self._web3_eth.contract(address=to_checksum_address(self.contract_address), abi=Market.abi()).events.ListingUpdate().processReceipt(tx_receipt) + def get_market_fee_update_event( + self, tx_hash: Union[HexBytes, bytes] + ) -> Tuple[AttributeDict]: + """Get log entry for MarketFeeUpdate event. + + :param tx_hash: hash of transaction emitting MarketFeeUpdate event + """ + tx_receipt = self._web3_eth.getTransactionReceipt(tx_hash) + return self._web3_eth.contract(address=to_checksum_address(self.contract_address), abi=Market.abi()).events.MarketFeeUpdate().processReceipt(tx_receipt) + def get_new_listing_event( + self, tx_hash: Union[HexBytes, bytes] + ) -> Tuple[AttributeDict]: + """Get log entry for NewListing event. + + :param tx_hash: hash of transaction emitting NewListing event + """ + tx_receipt = self._web3_eth.getTransactionReceipt(tx_hash) + return self._web3_eth.contract(address=to_checksum_address(self.contract_address), abi=Market.abi()).events.NewListing().processReceipt(tx_receipt) + def get_new_sale_event( + self, tx_hash: Union[HexBytes, bytes] + ) -> Tuple[AttributeDict]: + """Get log entry for NewSale event. + + :param tx_hash: hash of transaction emitting NewSale event + """ + tx_receipt = self._web3_eth.getTransactionReceipt(tx_hash) + return self._web3_eth.contract(address=to_checksum_address(self.contract_address), abi=Market.abi()).events.NewSale().processReceipt(tx_receipt) + + @staticmethod + def abi(): + """Return the ABI to the underlying contract.""" + return json.loads( + '[{"inputs":[{"internalType":"address payable","name":"_controlCenter","type":"address"},{"internalType":"address","name":"_trustedForwarder","type":"address"},{"internalType":"string","name":"_uri","type":"string"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"seller","type":"address"},{"indexed":true,"internalType":"uint256","name":"listingId","type":"uint256"},{"components":[{"internalType":"uint256","name":"listingId","type":"uint256"},{"internalType":"address","name":"seller","type":"address"},{"internalType":"address","name":"assetContract","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"quantity","type":"uint256"},{"internalType":"address","name":"currency","type":"address"},{"internalType":"uint256","name":"pricePerToken","type":"uint256"},{"internalType":"uint256","name":"saleStart","type":"uint256"},{"internalType":"uint256","name":"saleEnd","type":"uint256"},{"internalType":"uint256","name":"tokensPerBuyer","type":"uint256"},{"internalType":"enum Market.TokenType","name":"tokenType","type":"uint8"}],"indexed":false,"internalType":"struct Market.Listing","name":"listing","type":"tuple"}],"name":"ListingUpdate","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint128","name":"newFee","type":"uint128"}],"name":"MarketFeeUpdate","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"assetContract","type":"address"},{"indexed":true,"internalType":"address","name":"seller","type":"address"},{"indexed":true,"internalType":"uint256","name":"listingId","type":"uint256"},{"components":[{"internalType":"uint256","name":"listingId","type":"uint256"},{"internalType":"address","name":"seller","type":"address"},{"internalType":"address","name":"assetContract","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"quantity","type":"uint256"},{"internalType":"address","name":"currency","type":"address"},{"internalType":"uint256","name":"pricePerToken","type":"uint256"},{"internalType":"uint256","name":"saleStart","type":"uint256"},{"internalType":"uint256","name":"saleEnd","type":"uint256"},{"internalType":"uint256","name":"tokensPerBuyer","type":"uint256"},{"internalType":"enum Market.TokenType","name":"tokenType","type":"uint8"}],"indexed":false,"internalType":"struct Market.Listing","name":"listing","type":"tuple"}],"name":"NewListing","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"assetContract","type":"address"},{"indexed":true,"internalType":"address","name":"seller","type":"address"},{"indexed":true,"internalType":"uint256","name":"listingId","type":"uint256"},{"indexed":false,"internalType":"address","name":"buyer","type":"address"},{"indexed":false,"internalType":"uint256","name":"quantity","type":"uint256"},{"components":[{"internalType":"uint256","name":"listingId","type":"uint256"},{"internalType":"address","name":"seller","type":"address"},{"internalType":"address","name":"assetContract","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"quantity","type":"uint256"},{"internalType":"address","name":"currency","type":"address"},{"internalType":"uint256","name":"pricePerToken","type":"uint256"},{"internalType":"uint256","name":"saleStart","type":"uint256"},{"internalType":"uint256","name":"saleEnd","type":"uint256"},{"internalType":"uint256","name":"tokensPerBuyer","type":"uint256"},{"internalType":"enum Market.TokenType","name":"tokenType","type":"uint8"}],"indexed":false,"internalType":"struct Market.Listing","name":"listing","type":"tuple"}],"name":"NewSale","type":"event"},{"inputs":[],"name":"_contractURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_listingId","type":"uint256"},{"internalType":"uint256","name":"_quantity","type":"uint256"}],"name":"addToListing","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"index_0","type":"uint256"},{"internalType":"address","name":"index_1","type":"address"}],"name":"boughtFromListing","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_listingId","type":"uint256"},{"internalType":"uint256","name":"_quantity","type":"uint256"}],"name":"buy","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"contractURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getAllListings","outputs":[{"components":[{"internalType":"uint256","name":"listingId","type":"uint256"},{"internalType":"address","name":"seller","type":"address"},{"internalType":"address","name":"assetContract","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"quantity","type":"uint256"},{"internalType":"address","name":"currency","type":"address"},{"internalType":"uint256","name":"pricePerToken","type":"uint256"},{"internalType":"uint256","name":"saleStart","type":"uint256"},{"internalType":"uint256","name":"saleEnd","type":"uint256"},{"internalType":"uint256","name":"tokensPerBuyer","type":"uint256"},{"internalType":"enum Market.TokenType","name":"tokenType","type":"uint8"}],"internalType":"struct Market.Listing[]","name":"allListings","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_listingId","type":"uint256"}],"name":"getListing","outputs":[{"components":[{"internalType":"uint256","name":"listingId","type":"uint256"},{"internalType":"address","name":"seller","type":"address"},{"internalType":"address","name":"assetContract","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"quantity","type":"uint256"},{"internalType":"address","name":"currency","type":"address"},{"internalType":"uint256","name":"pricePerToken","type":"uint256"},{"internalType":"uint256","name":"saleStart","type":"uint256"},{"internalType":"uint256","name":"saleEnd","type":"uint256"},{"internalType":"uint256","name":"tokensPerBuyer","type":"uint256"},{"internalType":"enum Market.TokenType","name":"tokenType","type":"uint8"}],"internalType":"struct Market.Listing","name":"listing","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_assetContract","type":"address"},{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"getListingsByAsset","outputs":[{"components":[{"internalType":"uint256","name":"listingId","type":"uint256"},{"internalType":"address","name":"seller","type":"address"},{"internalType":"address","name":"assetContract","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"quantity","type":"uint256"},{"internalType":"address","name":"currency","type":"address"},{"internalType":"uint256","name":"pricePerToken","type":"uint256"},{"internalType":"uint256","name":"saleStart","type":"uint256"},{"internalType":"uint256","name":"saleEnd","type":"uint256"},{"internalType":"uint256","name":"tokensPerBuyer","type":"uint256"},{"internalType":"enum Market.TokenType","name":"tokenType","type":"uint8"}],"internalType":"struct Market.Listing[]","name":"tokenListings","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_assetContract","type":"address"}],"name":"getListingsByAssetContract","outputs":[{"components":[{"internalType":"uint256","name":"listingId","type":"uint256"},{"internalType":"address","name":"seller","type":"address"},{"internalType":"address","name":"assetContract","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"quantity","type":"uint256"},{"internalType":"address","name":"currency","type":"address"},{"internalType":"uint256","name":"pricePerToken","type":"uint256"},{"internalType":"uint256","name":"saleStart","type":"uint256"},{"internalType":"uint256","name":"saleEnd","type":"uint256"},{"internalType":"uint256","name":"tokensPerBuyer","type":"uint256"},{"internalType":"enum Market.TokenType","name":"tokenType","type":"uint8"}],"internalType":"struct Market.Listing[]","name":"tokenListings","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_seller","type":"address"}],"name":"getListingsBySeller","outputs":[{"components":[{"internalType":"uint256","name":"listingId","type":"uint256"},{"internalType":"address","name":"seller","type":"address"},{"internalType":"address","name":"assetContract","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"quantity","type":"uint256"},{"internalType":"address","name":"currency","type":"address"},{"internalType":"uint256","name":"pricePerToken","type":"uint256"},{"internalType":"uint256","name":"saleStart","type":"uint256"},{"internalType":"uint256","name":"saleEnd","type":"uint256"},{"internalType":"uint256","name":"tokensPerBuyer","type":"uint256"},{"internalType":"enum Market.TokenType","name":"tokenType","type":"uint8"}],"internalType":"struct Market.Listing[]","name":"sellerListings","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"forwarder","type":"address"}],"name":"isTrustedForwarder","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_assetContract","type":"address"},{"internalType":"uint256","name":"_tokenId","type":"uint256"},{"internalType":"address","name":"_currency","type":"address"},{"internalType":"uint256","name":"_pricePerToken","type":"uint256"},{"internalType":"uint256","name":"_quantity","type":"uint256"},{"internalType":"uint256","name":"_tokensPerBuyer","type":"uint256"},{"internalType":"uint256","name":"_secondsUntilStart","type":"uint256"},{"internalType":"uint256","name":"_secondsUntilEnd","type":"uint256"}],"name":"list","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"index_0","type":"uint256"}],"name":"listings","outputs":[{"internalType":"uint256","name":"listingId","type":"uint256"},{"internalType":"address","name":"seller","type":"address"},{"internalType":"address","name":"assetContract","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"quantity","type":"uint256"},{"internalType":"address","name":"currency","type":"address"},{"internalType":"uint256","name":"pricePerToken","type":"uint256"},{"internalType":"uint256","name":"saleStart","type":"uint256"},{"internalType":"uint256","name":"saleEnd","type":"uint256"},{"internalType":"uint256","name":"tokensPerBuyer","type":"uint256"},{"internalType":"enum Market.TokenType","name":"tokenType","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"marketFeeBps","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"index_0","type":"address"},{"internalType":"address","name":"index_1","type":"address"},{"internalType":"uint256[]","name":"index_2","type":"uint256[]"},{"internalType":"uint256[]","name":"index_3","type":"uint256[]"},{"internalType":"bytes","name":"index_4","type":"bytes"}],"name":"onERC1155BatchReceived","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"index_0","type":"address"},{"internalType":"address","name":"index_1","type":"address"},{"internalType":"uint256","name":"index_2","type":"uint256"},{"internalType":"uint256","name":"index_3","type":"uint256"},{"internalType":"bytes","name":"index_4","type":"bytes"}],"name":"onERC1155Received","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"index_0","type":"address"},{"internalType":"address","name":"index_1","type":"address"},{"internalType":"uint256","name":"index_2","type":"uint256"},{"internalType":"bytes","name":"index_3","type":"bytes"}],"name":"onERC721Received","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"string","name":"_URI","type":"string"}],"name":"setContractURI","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint128","name":"feeBps","type":"uint128"}],"name":"setMarketFeeBps","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalListings","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_listingId","type":"uint256"},{"internalType":"uint256","name":"_quantity","type":"uint256"}],"name":"unlist","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_listingId","type":"uint256"},{"internalType":"uint256","name":"_pricePerToken","type":"uint256"},{"internalType":"address","name":"_currency","type":"address"},{"internalType":"uint256","name":"_tokensPerBuyer","type":"uint256"},{"internalType":"uint256","name":"_secondsUntilStart","type":"uint256"},{"internalType":"uint256","name":"_secondsUntilEnd","type":"uint256"}],"name":"updateListingParams","outputs":[],"stateMutability":"nonpayable","type":"function"}]' # noqa: E501 (line-too-long) + ) + +# pylint: disable=too-many-lines diff --git a/nftlabs/modules/currency.py b/nftlabs/modules/currency.py index 430b740d..7defe202 100644 --- a/nftlabs/modules/currency.py +++ b/nftlabs/modules/currency.py @@ -6,7 +6,7 @@ from ..abi.erc20 import ERC20 from web3 import Web3 from typing import List, Dict - + class CurrencyModule(BaseModule): address: str diff --git a/nftlabs/modules/market.py b/nftlabs/modules/market.py new file mode 100644 index 00000000..cc82603b --- /dev/null +++ b/nftlabs/modules/market.py @@ -0,0 +1,121 @@ +from web3 import Web3 +from typing import List, Dict +from . import BaseModule +from ..types import Role, Listing as ListingType +from ..abi.market import Market +#_types + + + +# from ..errors import NoSignerException +# from ..abi.erc20 import ERC20 + + +class MarketModule(BaseModule): + address: str + __abi_module: Market + def __init__(self, client: Web3, address: str): + super().__init__() + self.address = address + self.__abi_module = Market(client, address) + + #todo: return types + def list_item(self, arg: ListArg): + if arg.properties is None: + arg.properties = {} + else: + final_properties = copy.copy(arg.properties) + tx = self.__abi_module.list.build_transaction( + arg.asset_contract, + arg.token_id, + arg.currency, + arg.price_per_token, + arg.quantity, + arg.tokens_per_buyer, + arg.seconds_until_start, + arg.seconds_until_end, + self.get_transact_opts() + ) + self.execute_tx(tx) + + def unlist_item(self, listing_id, quantity): + tx = self.__abi_module.unlist.build_transaction( + listing_id, + quantity, + self.get_transact_opts() + ) + self.execute_tx(tx) + + def add_to_listing(self, listing_id, quantity): + tx = self.__abi_module.add_to_listing.build_transaction( + listing_id, + quantity, + self.get_transact_opts() + ) + self.execute_tx(tx) + + def updateListingParams(self, args: ListUpdate): + tx = self.__abi_module.updateListingParams( + args.listing_id, + args.price_per_token, + args.currency, + args.tokens_per_buyer, + args.seconds_until_start, + args.seconds_until_end + ) + self.execute_tx(tx) + + def buy(self, listing_id: int, quantity: int): + tx = self.__abi_module.buy.build_transaction( + listing_id, + quantity, + buyer, + self.get_transact_opts() + ) + self.execute_tx(tx) + + def set_market_fee_bps(self, amount: int): + tx = self.__abi_module.set_market_fee_bps.build_transaction( + amount, + self.get_transact_opts()) + self.execute_tx(tx) + + def get(self, listing_id) -> List: + self.__abi_module.get_listing.call(listing_id) + + def get_all(self) -> List[ListingType]: + self.__abi_module.get_all_listings.call() + + def get_all_by_seller(self, seller: str) -> List[ListingType]: + self.__abi_module.get_listings_by_seller.call(seller) + + def get_all_by_asset_contract(self, asset_contract: str) -> List[ListingType]: + self.__abi_module.get_listings_by_asset_contract.call(asset_contract) + + def get_all_by_asset(self, asset: str) -> List[ListingType]: + self.__abi_module.get_listings_by_asset.call(asset) + + + def grant_role(self, role: Role, address: str): + role_hash = role.get_hash() + tx = self.__abi_module.grant_role.build_transaction( + role_hash, + address, + self.get_transact_opts() + ) + + self.execute_tx(tx) + + def revoke_role(self, role: Role, address: str): + role_hash = role.get_hash() + tx = self.__abi_module.revoke_role.build_transaction( + role_hash, + address, + self.get_transact_opts() + ) + self.execute_tx(tx) + + def total_supply(self) -> int: + self.__abi_module.total_listings.call() + + diff --git a/nftlabs/modules/market_types.py b/nftlabs/modules/market_types.py new file mode 100644 index 00000000..c8e87370 --- /dev/null +++ b/nftlabs/modules/market_types.py @@ -0,0 +1,23 @@ +from dataclasses import dataclass + + +@dataclass.dataclass +class ListArg: + asset_contract: str + token_id: int + currency: str + price_per_token: int + quantity: int + tokens_per_buyer: int + seconds_until_start: int + seconds_until_end: int + + +@dataclass.dataclass +class ListUpdate: + listing_id : int + price_per_token: int + currency: int + tokens_per_buyer: int + seconds_until_start: int + seconds_until_end: int \ No newline at end of file diff --git a/nftlabs/modules/nft.py b/nftlabs/modules/nft.py index 0f34f9fa..62525d14 100644 --- a/nftlabs/modules/nft.py +++ b/nftlabs/modules/nft.py @@ -10,7 +10,7 @@ from ..types import NFT as NftType, Role from .nft_types import MintArg - + class NftModule(BaseModule): address: str @@ -54,9 +54,6 @@ def total_supply(self) -> int: return self.__abi_module.total_supply.call() def get(self, nft_id: int) -> NftType: - return self.__get_metadata(nft_id) - - def __get_metadata(self, nft_id: int) -> NftType: uri = self.__get_metadata_uri(nft_id) meta = self.get_storage().get(uri) meta_obj: NftType = NftType.from_json(meta) @@ -107,6 +104,7 @@ def transfer_from(self, from_address: str, to_address: str, token_id: int): """ Transfers NFT from the current signers wallet to another wallet """ + def transfer(self, to_address: str, token_id: int): tx = self.__abi_module.safe_transfer_from1.build_transaction( self.get_signer_address(), @@ -138,6 +136,10 @@ def get_owned(self, address: str = "") -> List[NftType]: def __token_of_owner_by_index(self, address: str, token_id: int) -> int: return self.__abi_module.token_of_owner_by_index.call(address, token_id) + + def get_creator(self, token_id: int) -> str: + return self.__abi_module.get_creator.call(token_id) + """ Returns balance of the current signers wallet @@ -161,11 +163,13 @@ def set_approval(self, operator: str, approved: bool = True): def grant_role(self, role: Role, address: str): role_hash = role.get_hash() - self.execute_tx(self.__abi_module.grant_role.build_transaction( - role_hash, address, self.get_transact_opts() - )) + tx = self.__abi_module.grant_role.build_transaction( + role_hash, address, + self.get_transact_opts() + ) + self.execute_tx(tx) - def revoke_role(self, role, address: str): + def revoke_role(self, role: Role, address: str): role_hash = role.get_hash() self.execute_tx(self.__abi_module.revoke_role.build_transaction( role_hash, address, self.get_transact_opts() diff --git a/nftlabs/types/listing.py b/nftlabs/types/listing.py new file mode 100644 index 00000000..00c12cf1 --- /dev/null +++ b/nftlabs/types/listing.py @@ -0,0 +1,15 @@ +from dataclasses import dataclass +from typing import Optional, Union + +from dataclasses_json import dataclass_json + + +@dataclass_json +@dataclass +class Listing: + name: str + description: str + image: str + properties: Optional[Union[str, dict]] = None + token_id: int + uri: str \ No newline at end of file diff --git a/nftlabs/types/role.py b/nftlabs/types/role.py index 6e5e4f4f..3451663a 100644 --- a/nftlabs/types/role.py +++ b/nftlabs/types/role.py @@ -7,6 +7,7 @@ class Role(enum.Enum): minter = "MINTER_ROLE" transfer = "TRANSFER_ROLE" pauser = "PAUSER_ROLE" + lister = "LISTER_ROLE" def get_hash(self) -> bytes: if self.name == "admin": From fb809cc8ac75fcdfddbde8fd47ab1e54d567ef64 Mon Sep 17 00:00:00 2001 From: Ayush Pathak <62694274+ayshptk@users.noreply.github.com> Date: Thu, 21 Oct 2021 00:52:14 +0530 Subject: [PATCH 02/10] minor changes - resolved everything except `list` and `buy` function - would need help with debugging - removed list updates type - added filter types - added ABIs for `ERC1155` and `ERC165` --- nftlabs/abi/erc1155/__init__.py | 675 ++++++++++++++++++++++++++++++++ nftlabs/abi/erc165/__init__.py | 170 ++++++++ nftlabs/modules/market.py | 164 ++++---- nftlabs/modules/market_types.py | 14 +- 4 files changed, 936 insertions(+), 87 deletions(-) create mode 100644 nftlabs/abi/erc1155/__init__.py create mode 100644 nftlabs/abi/erc165/__init__.py diff --git a/nftlabs/abi/erc1155/__init__.py b/nftlabs/abi/erc1155/__init__.py new file mode 100644 index 00000000..27fd3770 --- /dev/null +++ b/nftlabs/abi/erc1155/__init__.py @@ -0,0 +1,675 @@ +"""Generated wrapper for ERC1155 Solidity contract.""" + +# pylint: disable=too-many-arguments + +import json +from typing import ( # pylint: disable=unused-import + Any, + List, + Optional, + Tuple, + Union, +) + +from eth_utils import to_checksum_address +from mypy_extensions import TypedDict # pylint: disable=unused-import +from hexbytes import HexBytes +from web3 import Web3 +from web3.contract import ContractFunction +from web3.datastructures import AttributeDict +from web3.providers.base import BaseProvider + +from zero_ex.contract_wrappers.bases import ContractMethod, Validator +from zero_ex.contract_wrappers.tx_params import TxParams + + +# Try to import a custom validator class definition; if there isn't one, +# declare one that we can instantiate for the default argument to the +# constructor for ERC1155 below. +try: + # both mypy and pylint complain about what we're doing here, but this + # works just fine, so their messages have been disabled here. + from . import ( # type: ignore # pylint: disable=import-self + ERC1155Validator, + ) +except ImportError: + + class ERC1155Validator( # type: ignore + Validator + ): + """No-op input validator.""" + + +try: + from .middleware import MIDDLEWARE # type: ignore +except ImportError: + pass + + + + + +class BalanceOfMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the balanceOf method.""" + + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction, validator: Validator=None): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs(self, account: str, _id: int): + """Validate the inputs to the balanceOf method.""" + self.validator.assert_valid( + method_name='balanceOf', + parameter_name='account', + argument_value=account, + ) + account = self.validate_and_checksum_address(account) + self.validator.assert_valid( + method_name='balanceOf', + parameter_name='id', + argument_value=_id, + ) + # safeguard against fractional inputs + _id = int(_id) + return (account, _id) + + def call(self, account: str, _id: int, tx_params: Optional[TxParams] = None) -> int: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (account, _id) = self.validate_and_normalize_inputs(account, _id) + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method(account, _id).call(tx_params.as_dict()) + return int(returned) + + def send_transaction(self, account: str, _id: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (account, _id) = self.validate_and_normalize_inputs(account, _id) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(account, _id).transact(tx_params.as_dict()) + + def build_transaction(self, account: str, _id: int, tx_params: Optional[TxParams] = None) -> dict: + """Construct calldata to be used as input to the method.""" + (account, _id) = self.validate_and_normalize_inputs(account, _id) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(account, _id).buildTransaction(tx_params.as_dict()) + + def estimate_gas(self, account: str, _id: int, tx_params: Optional[TxParams] = None) -> int: + """Estimate gas consumption of method call.""" + (account, _id) = self.validate_and_normalize_inputs(account, _id) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(account, _id).estimateGas(tx_params.as_dict()) + +class BalanceOfBatchMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the balanceOfBatch method.""" + + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction, validator: Validator=None): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs(self, accounts: List[str], ids: List[int]): + """Validate the inputs to the balanceOfBatch method.""" + self.validator.assert_valid( + method_name='balanceOfBatch', + parameter_name='accounts', + argument_value=accounts, + ) + self.validator.assert_valid( + method_name='balanceOfBatch', + parameter_name='ids', + argument_value=ids, + ) + return (accounts, ids) + + def call(self, accounts: List[str], ids: List[int], tx_params: Optional[TxParams] = None) -> List[int]: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (accounts, ids) = self.validate_and_normalize_inputs(accounts, ids) + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method(accounts, ids).call(tx_params.as_dict()) + return [int(element) for element in returned] + + def send_transaction(self, accounts: List[str], ids: List[int], tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (accounts, ids) = self.validate_and_normalize_inputs(accounts, ids) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(accounts, ids).transact(tx_params.as_dict()) + + def build_transaction(self, accounts: List[str], ids: List[int], tx_params: Optional[TxParams] = None) -> dict: + """Construct calldata to be used as input to the method.""" + (accounts, ids) = self.validate_and_normalize_inputs(accounts, ids) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(accounts, ids).buildTransaction(tx_params.as_dict()) + + def estimate_gas(self, accounts: List[str], ids: List[int], tx_params: Optional[TxParams] = None) -> int: + """Estimate gas consumption of method call.""" + (accounts, ids) = self.validate_and_normalize_inputs(accounts, ids) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(accounts, ids).estimateGas(tx_params.as_dict()) + +class IsApprovedForAllMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the isApprovedForAll method.""" + + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction, validator: Validator=None): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs(self, account: str, operator: str): + """Validate the inputs to the isApprovedForAll method.""" + self.validator.assert_valid( + method_name='isApprovedForAll', + parameter_name='account', + argument_value=account, + ) + account = self.validate_and_checksum_address(account) + self.validator.assert_valid( + method_name='isApprovedForAll', + parameter_name='operator', + argument_value=operator, + ) + operator = self.validate_and_checksum_address(operator) + return (account, operator) + + def call(self, account: str, operator: str, tx_params: Optional[TxParams] = None) -> bool: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (account, operator) = self.validate_and_normalize_inputs(account, operator) + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method(account, operator).call(tx_params.as_dict()) + return bool(returned) + + def send_transaction(self, account: str, operator: str, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (account, operator) = self.validate_and_normalize_inputs(account, operator) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(account, operator).transact(tx_params.as_dict()) + + def build_transaction(self, account: str, operator: str, tx_params: Optional[TxParams] = None) -> dict: + """Construct calldata to be used as input to the method.""" + (account, operator) = self.validate_and_normalize_inputs(account, operator) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(account, operator).buildTransaction(tx_params.as_dict()) + + def estimate_gas(self, account: str, operator: str, tx_params: Optional[TxParams] = None) -> int: + """Estimate gas consumption of method call.""" + (account, operator) = self.validate_and_normalize_inputs(account, operator) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(account, operator).estimateGas(tx_params.as_dict()) + +class SafeBatchTransferFromMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the safeBatchTransferFrom method.""" + + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction, validator: Validator=None): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs(self, _from: str, to: str, ids: List[int], amounts: List[int], data: Union[bytes, str]): + """Validate the inputs to the safeBatchTransferFrom method.""" + self.validator.assert_valid( + method_name='safeBatchTransferFrom', + parameter_name='from', + argument_value=_from, + ) + _from = self.validate_and_checksum_address(_from) + self.validator.assert_valid( + method_name='safeBatchTransferFrom', + parameter_name='to', + argument_value=to, + ) + to = self.validate_and_checksum_address(to) + self.validator.assert_valid( + method_name='safeBatchTransferFrom', + parameter_name='ids', + argument_value=ids, + ) + self.validator.assert_valid( + method_name='safeBatchTransferFrom', + parameter_name='amounts', + argument_value=amounts, + ) + self.validator.assert_valid( + method_name='safeBatchTransferFrom', + parameter_name='data', + argument_value=data, + ) + return (_from, to, ids, amounts, data) + + def call(self, _from: str, to: str, ids: List[int], amounts: List[int], data: Union[bytes, str], tx_params: Optional[TxParams] = None) -> None: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (_from, to, ids, amounts, data) = self.validate_and_normalize_inputs(_from, to, ids, amounts, data) + tx_params = super().normalize_tx_params(tx_params) + self._underlying_method(_from, to, ids, amounts, data).call(tx_params.as_dict()) + + def send_transaction(self, _from: str, to: str, ids: List[int], amounts: List[int], data: Union[bytes, str], tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (_from, to, ids, amounts, data) = self.validate_and_normalize_inputs(_from, to, ids, amounts, data) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(_from, to, ids, amounts, data).transact(tx_params.as_dict()) + + def build_transaction(self, _from: str, to: str, ids: List[int], amounts: List[int], data: Union[bytes, str], tx_params: Optional[TxParams] = None) -> dict: + """Construct calldata to be used as input to the method.""" + (_from, to, ids, amounts, data) = self.validate_and_normalize_inputs(_from, to, ids, amounts, data) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(_from, to, ids, amounts, data).buildTransaction(tx_params.as_dict()) + + def estimate_gas(self, _from: str, to: str, ids: List[int], amounts: List[int], data: Union[bytes, str], tx_params: Optional[TxParams] = None) -> int: + """Estimate gas consumption of method call.""" + (_from, to, ids, amounts, data) = self.validate_and_normalize_inputs(_from, to, ids, amounts, data) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(_from, to, ids, amounts, data).estimateGas(tx_params.as_dict()) + +class SafeTransferFromMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the safeTransferFrom method.""" + + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction, validator: Validator=None): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs(self, _from: str, to: str, _id: int, amount: int, data: Union[bytes, str]): + """Validate the inputs to the safeTransferFrom method.""" + self.validator.assert_valid( + method_name='safeTransferFrom', + parameter_name='from', + argument_value=_from, + ) + _from = self.validate_and_checksum_address(_from) + self.validator.assert_valid( + method_name='safeTransferFrom', + parameter_name='to', + argument_value=to, + ) + to = self.validate_and_checksum_address(to) + self.validator.assert_valid( + method_name='safeTransferFrom', + parameter_name='id', + argument_value=_id, + ) + # safeguard against fractional inputs + _id = int(_id) + self.validator.assert_valid( + method_name='safeTransferFrom', + parameter_name='amount', + argument_value=amount, + ) + # safeguard against fractional inputs + amount = int(amount) + self.validator.assert_valid( + method_name='safeTransferFrom', + parameter_name='data', + argument_value=data, + ) + return (_from, to, _id, amount, data) + + def call(self, _from: str, to: str, _id: int, amount: int, data: Union[bytes, str], tx_params: Optional[TxParams] = None) -> None: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (_from, to, _id, amount, data) = self.validate_and_normalize_inputs(_from, to, _id, amount, data) + tx_params = super().normalize_tx_params(tx_params) + self._underlying_method(_from, to, _id, amount, data).call(tx_params.as_dict()) + + def send_transaction(self, _from: str, to: str, _id: int, amount: int, data: Union[bytes, str], tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (_from, to, _id, amount, data) = self.validate_and_normalize_inputs(_from, to, _id, amount, data) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(_from, to, _id, amount, data).transact(tx_params.as_dict()) + + def build_transaction(self, _from: str, to: str, _id: int, amount: int, data: Union[bytes, str], tx_params: Optional[TxParams] = None) -> dict: + """Construct calldata to be used as input to the method.""" + (_from, to, _id, amount, data) = self.validate_and_normalize_inputs(_from, to, _id, amount, data) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(_from, to, _id, amount, data).buildTransaction(tx_params.as_dict()) + + def estimate_gas(self, _from: str, to: str, _id: int, amount: int, data: Union[bytes, str], tx_params: Optional[TxParams] = None) -> int: + """Estimate gas consumption of method call.""" + (_from, to, _id, amount, data) = self.validate_and_normalize_inputs(_from, to, _id, amount, data) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(_from, to, _id, amount, data).estimateGas(tx_params.as_dict()) + +class SetApprovalForAllMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the setApprovalForAll method.""" + + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction, validator: Validator=None): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs(self, operator: str, approved: bool): + """Validate the inputs to the setApprovalForAll method.""" + self.validator.assert_valid( + method_name='setApprovalForAll', + parameter_name='operator', + argument_value=operator, + ) + operator = self.validate_and_checksum_address(operator) + self.validator.assert_valid( + method_name='setApprovalForAll', + parameter_name='approved', + argument_value=approved, + ) + return (operator, approved) + + def call(self, operator: str, approved: bool, tx_params: Optional[TxParams] = None) -> None: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (operator, approved) = self.validate_and_normalize_inputs(operator, approved) + tx_params = super().normalize_tx_params(tx_params) + self._underlying_method(operator, approved).call(tx_params.as_dict()) + + def send_transaction(self, operator: str, approved: bool, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (operator, approved) = self.validate_and_normalize_inputs(operator, approved) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(operator, approved).transact(tx_params.as_dict()) + + def build_transaction(self, operator: str, approved: bool, tx_params: Optional[TxParams] = None) -> dict: + """Construct calldata to be used as input to the method.""" + (operator, approved) = self.validate_and_normalize_inputs(operator, approved) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(operator, approved).buildTransaction(tx_params.as_dict()) + + def estimate_gas(self, operator: str, approved: bool, tx_params: Optional[TxParams] = None) -> int: + """Estimate gas consumption of method call.""" + (operator, approved) = self.validate_and_normalize_inputs(operator, approved) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(operator, approved).estimateGas(tx_params.as_dict()) + +class SupportsInterfaceMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the supportsInterface method.""" + + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction, validator: Validator=None): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs(self, interface_id: Union[bytes, str]): + """Validate the inputs to the supportsInterface method.""" + self.validator.assert_valid( + method_name='supportsInterface', + parameter_name='interfaceId', + argument_value=interface_id, + ) + return (interface_id) + + def call(self, interface_id: Union[bytes, str], tx_params: Optional[TxParams] = None) -> bool: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (interface_id) = self.validate_and_normalize_inputs(interface_id) + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method(interface_id).call(tx_params.as_dict()) + return bool(returned) + + def send_transaction(self, interface_id: Union[bytes, str], tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (interface_id) = self.validate_and_normalize_inputs(interface_id) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(interface_id).transact(tx_params.as_dict()) + + def build_transaction(self, interface_id: Union[bytes, str], tx_params: Optional[TxParams] = None) -> dict: + """Construct calldata to be used as input to the method.""" + (interface_id) = self.validate_and_normalize_inputs(interface_id) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(interface_id).buildTransaction(tx_params.as_dict()) + + def estimate_gas(self, interface_id: Union[bytes, str], tx_params: Optional[TxParams] = None) -> int: + """Estimate gas consumption of method call.""" + (interface_id) = self.validate_and_normalize_inputs(interface_id) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(interface_id).estimateGas(tx_params.as_dict()) + +class UriMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the uri method.""" + + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction, validator: Validator=None): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs(self, index_0: int): + """Validate the inputs to the uri method.""" + self.validator.assert_valid( + method_name='uri', + parameter_name='index_0', + argument_value=index_0, + ) + # safeguard against fractional inputs + index_0 = int(index_0) + return (index_0) + + def call(self, index_0: int, tx_params: Optional[TxParams] = None) -> str: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (index_0) = self.validate_and_normalize_inputs(index_0) + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method(index_0).call(tx_params.as_dict()) + return str(returned) + + def send_transaction(self, index_0: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (index_0) = self.validate_and_normalize_inputs(index_0) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(index_0).transact(tx_params.as_dict()) + + def build_transaction(self, index_0: int, tx_params: Optional[TxParams] = None) -> dict: + """Construct calldata to be used as input to the method.""" + (index_0) = self.validate_and_normalize_inputs(index_0) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(index_0).buildTransaction(tx_params.as_dict()) + + def estimate_gas(self, index_0: int, tx_params: Optional[TxParams] = None) -> int: + """Estimate gas consumption of method call.""" + (index_0) = self.validate_and_normalize_inputs(index_0) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(index_0).estimateGas(tx_params.as_dict()) + +# pylint: disable=too-many-public-methods,too-many-instance-attributes +class ERC1155: + """Wrapper class for ERC1155 Solidity contract. + + All method parameters of type `bytes`:code: should be encoded as UTF-8, + which can be accomplished via `str.encode("utf_8")`:code:. + """ + balance_of: BalanceOfMethod + """Constructor-initialized instance of + :class:`BalanceOfMethod`. + """ + + balance_of_batch: BalanceOfBatchMethod + """Constructor-initialized instance of + :class:`BalanceOfBatchMethod`. + """ + + is_approved_for_all: IsApprovedForAllMethod + """Constructor-initialized instance of + :class:`IsApprovedForAllMethod`. + """ + + safe_batch_transfer_from: SafeBatchTransferFromMethod + """Constructor-initialized instance of + :class:`SafeBatchTransferFromMethod`. + """ + + safe_transfer_from: SafeTransferFromMethod + """Constructor-initialized instance of + :class:`SafeTransferFromMethod`. + """ + + set_approval_for_all: SetApprovalForAllMethod + """Constructor-initialized instance of + :class:`SetApprovalForAllMethod`. + """ + + supports_interface: SupportsInterfaceMethod + """Constructor-initialized instance of + :class:`SupportsInterfaceMethod`. + """ + + uri: UriMethod + """Constructor-initialized instance of + :class:`UriMethod`. + """ + + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + validator: ERC1155Validator = None, + ): + """Get an instance of wrapper for smart contract. + + :param web3_or_provider: Either an instance of `web3.Web3`:code: or + `web3.providers.base.BaseProvider`:code: + :param contract_address: where the contract has been deployed + :param validator: for validation of method inputs. + """ + # pylint: disable=too-many-statements + + self.contract_address = contract_address + + if not validator: + validator = ERC1155Validator(web3_or_provider, contract_address) + + web3 = None + if isinstance(web3_or_provider, BaseProvider): + web3 = Web3(web3_or_provider) + elif isinstance(web3_or_provider, Web3): + web3 = web3_or_provider + else: + raise TypeError( + "Expected parameter 'web3_or_provider' to be an instance of either" + + " Web3 or BaseProvider" + ) + + # if any middleware was imported, inject it + try: + MIDDLEWARE + except NameError: + pass + else: + try: + for middleware in MIDDLEWARE: + web3.middleware_onion.inject( + middleware['function'], layer=middleware['layer'], + ) + except ValueError as value_error: + if value_error.args == ("You can't add the same un-named instance twice",): + pass + + self._web3_eth = web3.eth + + functions = self._web3_eth.contract(address=to_checksum_address(contract_address), abi=ERC1155.abi()).functions + + self.balance_of = BalanceOfMethod(web3_or_provider, contract_address, functions.balanceOf, validator) + + self.balance_of_batch = BalanceOfBatchMethod(web3_or_provider, contract_address, functions.balanceOfBatch, validator) + + self.is_approved_for_all = IsApprovedForAllMethod(web3_or_provider, contract_address, functions.isApprovedForAll, validator) + + self.safe_batch_transfer_from = SafeBatchTransferFromMethod(web3_or_provider, contract_address, functions.safeBatchTransferFrom, validator) + + self.safe_transfer_from = SafeTransferFromMethod(web3_or_provider, contract_address, functions.safeTransferFrom, validator) + + self.set_approval_for_all = SetApprovalForAllMethod(web3_or_provider, contract_address, functions.setApprovalForAll, validator) + + self.supports_interface = SupportsInterfaceMethod(web3_or_provider, contract_address, functions.supportsInterface, validator) + + self.uri = UriMethod(web3_or_provider, contract_address, functions.uri, validator) + + def get_approval_for_all_event( + self, tx_hash: Union[HexBytes, bytes] + ) -> Tuple[AttributeDict]: + """Get log entry for ApprovalForAll event. + + :param tx_hash: hash of transaction emitting ApprovalForAll event + """ + tx_receipt = self._web3_eth.getTransactionReceipt(tx_hash) + return self._web3_eth.contract(address=to_checksum_address(self.contract_address), abi=ERC1155.abi()).events.ApprovalForAll().processReceipt(tx_receipt) + def get_transfer_batch_event( + self, tx_hash: Union[HexBytes, bytes] + ) -> Tuple[AttributeDict]: + """Get log entry for TransferBatch event. + + :param tx_hash: hash of transaction emitting TransferBatch event + """ + tx_receipt = self._web3_eth.getTransactionReceipt(tx_hash) + return self._web3_eth.contract(address=to_checksum_address(self.contract_address), abi=ERC1155.abi()).events.TransferBatch().processReceipt(tx_receipt) + def get_transfer_single_event( + self, tx_hash: Union[HexBytes, bytes] + ) -> Tuple[AttributeDict]: + """Get log entry for TransferSingle event. + + :param tx_hash: hash of transaction emitting TransferSingle event + """ + tx_receipt = self._web3_eth.getTransactionReceipt(tx_hash) + return self._web3_eth.contract(address=to_checksum_address(self.contract_address), abi=ERC1155.abi()).events.TransferSingle().processReceipt(tx_receipt) + def get_uri_event( + self, tx_hash: Union[HexBytes, bytes] + ) -> Tuple[AttributeDict]: + """Get log entry for URI event. + + :param tx_hash: hash of transaction emitting URI event + """ + tx_receipt = self._web3_eth.getTransactionReceipt(tx_hash) + return self._web3_eth.contract(address=to_checksum_address(self.contract_address), abi=ERC1155.abi()).events.URI().processReceipt(tx_receipt) + + @staticmethod + def abi(): + """Return the ABI to the underlying contract.""" + return json.loads( + '[{"inputs":[{"internalType":"string","name":"uri_","type":"string"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"ApprovalForAll","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256[]","name":"ids","type":"uint256[]"},{"indexed":false,"internalType":"uint256[]","name":"values","type":"uint256[]"}],"name":"TransferBatch","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"TransferSingle","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"value","type":"string"},{"indexed":true,"internalType":"uint256","name":"id","type":"uint256"}],"name":"URI","type":"event"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"accounts","type":"address[]"},{"internalType":"uint256[]","name":"ids","type":"uint256[]"}],"name":"balanceOfBatch","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"address","name":"operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256[]","name":"ids","type":"uint256[]"},{"internalType":"uint256[]","name":"amounts","type":"uint256[]"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"safeBatchTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index_0","type":"uint256"}],"name":"uri","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"}]' # noqa: E501 (line-too-long) + ) + +# pylint: disable=too-many-lines diff --git a/nftlabs/abi/erc165/__init__.py b/nftlabs/abi/erc165/__init__.py new file mode 100644 index 00000000..158ba582 --- /dev/null +++ b/nftlabs/abi/erc165/__init__.py @@ -0,0 +1,170 @@ +"""Generated wrapper for ERC165 Solidity contract.""" + +# pylint: disable=too-many-arguments + +import json +from typing import ( # pylint: disable=unused-import + Any, + List, + Optional, + Tuple, + Union, +) + +from eth_utils import to_checksum_address +from mypy_extensions import TypedDict # pylint: disable=unused-import +from hexbytes import HexBytes +from web3 import Web3 +from web3.contract import ContractFunction +from web3.datastructures import AttributeDict +from web3.providers.base import BaseProvider + +from zero_ex.contract_wrappers.bases import ContractMethod, Validator +from zero_ex.contract_wrappers.tx_params import TxParams + + +# Try to import a custom validator class definition; if there isn't one, +# declare one that we can instantiate for the default argument to the +# constructor for ERC165 below. +try: + # both mypy and pylint complain about what we're doing here, but this + # works just fine, so their messages have been disabled here. + from . import ( # type: ignore # pylint: disable=import-self + ERC165Validator, + ) +except ImportError: + + class ERC165Validator( # type: ignore + Validator + ): + """No-op input validator.""" + + +try: + from .middleware import MIDDLEWARE # type: ignore +except ImportError: + pass + + + + + +class SupportsInterfaceMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the supportsInterface method.""" + + def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function: ContractFunction, validator: Validator=None): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs(self, interface_id: Union[bytes, str]): + """Validate the inputs to the supportsInterface method.""" + self.validator.assert_valid( + method_name='supportsInterface', + parameter_name='interfaceId', + argument_value=interface_id, + ) + return (interface_id) + + def call(self, interface_id: Union[bytes, str], tx_params: Optional[TxParams] = None) -> bool: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (interface_id) = self.validate_and_normalize_inputs(interface_id) + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method(interface_id).call(tx_params.as_dict()) + return bool(returned) + + def send_transaction(self, interface_id: Union[bytes, str], tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (interface_id) = self.validate_and_normalize_inputs(interface_id) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(interface_id).transact(tx_params.as_dict()) + + def build_transaction(self, interface_id: Union[bytes, str], tx_params: Optional[TxParams] = None) -> dict: + """Construct calldata to be used as input to the method.""" + (interface_id) = self.validate_and_normalize_inputs(interface_id) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(interface_id).buildTransaction(tx_params.as_dict()) + + def estimate_gas(self, interface_id: Union[bytes, str], tx_params: Optional[TxParams] = None) -> int: + """Estimate gas consumption of method call.""" + (interface_id) = self.validate_and_normalize_inputs(interface_id) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(interface_id).estimateGas(tx_params.as_dict()) + +# pylint: disable=too-many-public-methods,too-many-instance-attributes +class ERC165: + """Wrapper class for ERC165 Solidity contract.""" + supports_interface: SupportsInterfaceMethod + """Constructor-initialized instance of + :class:`SupportsInterfaceMethod`. + """ + + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + validator: ERC165Validator = None, + ): + """Get an instance of wrapper for smart contract. + + :param web3_or_provider: Either an instance of `web3.Web3`:code: or + `web3.providers.base.BaseProvider`:code: + :param contract_address: where the contract has been deployed + :param validator: for validation of method inputs. + """ + # pylint: disable=too-many-statements + + self.contract_address = contract_address + + if not validator: + validator = ERC165Validator(web3_or_provider, contract_address) + + web3 = None + if isinstance(web3_or_provider, BaseProvider): + web3 = Web3(web3_or_provider) + elif isinstance(web3_or_provider, Web3): + web3 = web3_or_provider + else: + raise TypeError( + "Expected parameter 'web3_or_provider' to be an instance of either" + + " Web3 or BaseProvider" + ) + + # if any middleware was imported, inject it + try: + MIDDLEWARE + except NameError: + pass + else: + try: + for middleware in MIDDLEWARE: + web3.middleware_onion.inject( + middleware['function'], layer=middleware['layer'], + ) + except ValueError as value_error: + if value_error.args == ("You can't add the same un-named instance twice",): + pass + + self._web3_eth = web3.eth + + functions = self._web3_eth.contract(address=to_checksum_address(contract_address), abi=ERC165.abi()).functions + + self.supports_interface = SupportsInterfaceMethod(web3_or_provider, contract_address, functions.supportsInterface, validator) + + + @staticmethod + def abi(): + """Return the ABI to the underlying contract.""" + return json.loads( + '[{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"}]' # noqa: E501 (line-too-long) + ) + +# pylint: disable=too-many-lines diff --git a/nftlabs/modules/market.py b/nftlabs/modules/market.py index cc82603b..91eabe08 100644 --- a/nftlabs/modules/market.py +++ b/nftlabs/modules/market.py @@ -3,119 +3,125 @@ from . import BaseModule from ..types import Role, Listing as ListingType from ..abi.market import Market -#_types - - - -# from ..errors import NoSignerException -# from ..abi.erc20 import ERC20 +from market_types import ListArg, Filter +from ..abi.erc20 import ERC20 +from ..abi.erc165 import ERC165 +from ..abi.erc1155 import ERC1155 +from ..abi.nft import NFT class MarketModule(BaseModule): address: str __abi_module: Market + def __init__(self, client: Web3, address: str): super().__init__() self.address = address self.__abi_module = Market(client, address) - + #todo: return types def list_item(self, arg: ListArg): - if arg.properties is None: - arg.properties = {} + from_address = self.get_signer_address() + client = self.get_client() + erc165 = ERC165(client, arg.asset_contract) + isERC165 = erc165.supports_interface(client, arg.asset_contract) + if isERC165: + asset = NFT(client, arg.asset_contract) + approved = asset.is_approved_for_all( + arg.asset_contract, from_address) + if not approved: + asset.approve_for_all(from_address, arg.asset_contract) + is_token_approved = (asset.get_approved( + arg.token_id).lower() == self.address.lower()) + if not is_token_approved: + asset.set_approval_for_all(arg.asset_contract, True) else: - final_properties = copy.copy(arg.properties) + asset = ERC1155(client, arg.asset_contract) + approved = asset.is_approved_for_all( + arg.asset_contract, from_address) + if not approved: + asset.approve_for_all(from_address, arg.asset_contract) + is_token_approved = (asset.get_approved( + arg.token_id).lower() == self.address.lower()) + if not is_token_approved: + asset.set_approval_for_all(self.address, True) + tx = self.__abi_module.list.build_transaction( - arg.asset_contract, - arg.token_id, - arg.currency, + arg.asset_contract, + arg.token_id, + arg.currency_contract, arg.price_per_token, - arg.quantity, - arg.tokens_per_buyer, - arg.seconds_until_start, + arg.quantity, + arg.tokens_per_buyer, + arg.seconds_until_start, arg.seconds_until_end, self.get_transact_opts() ) - self.execute_tx(tx) - + + receipt = self.execute_tx(tx) + result = self.__abi_module.get_minted_batch_event( + tx_hash=receipt.transactionHash.hex()) + def unlist_item(self, listing_id, quantity): tx = self.__abi_module.unlist.build_transaction( - listing_id, + listing_id, quantity, self.get_transact_opts() - ) - self.execute_tx(tx) - - def add_to_listing(self, listing_id, quantity): - tx = self.__abi_module.add_to_listing.build_transaction( - listing_id, - quantity, - self.get_transact_opts() - ) - self.execute_tx(tx) - - def updateListingParams(self, args: ListUpdate): - tx = self.__abi_module.updateListingParams( - args.listing_id, - args.price_per_token, - args.currency, - args.tokens_per_buyer, - args.seconds_until_start, - args.seconds_until_end ) self.execute_tx(tx) - + def buy(self, listing_id: int, quantity: int): + listing = get(listing_id) + owner = self.get_signer_address() + spender = self.address + total_price = listing.price_per_token * quantity + if listing.currency_contract is not None and listing.currency_contract != "0x0000000000000000000000000000000000000000": + erc20 = ERC20(self.get_client(), listing.currency_contract) + allowance = erc20.allowance(owner, spender) + if allowance <= total_price: + erc20.increase_allowance( + spender, + total_price, + self.get_transact_opts() + ) + tx = self.__abi_module.buy.build_transaction( - listing_id, - quantity, - buyer, + listing_id, + quantity, self.get_transact_opts() - ) - self.execute_tx(tx) + ) + receipt = self.execute_tx(tx) + result = self.__abi_module.get_minted_batch_event( + tx_hash=receipt.transactionHash.hex()) def set_market_fee_bps(self, amount: int): tx = self.__abi_module.set_market_fee_bps.build_transaction( - amount, + amount, self.get_transact_opts()) self.execute_tx(tx) - + def get(self, listing_id) -> List: self.__abi_module.get_listing.call(listing_id) - - def get_all(self) -> List[ListingType]: - self.__abi_module.get_all_listings.call() - - def get_all_by_seller(self, seller: str) -> List[ListingType]: - self.__abi_module.get_listings_by_seller.call(seller) - - def get_all_by_asset_contract(self, asset_contract: str) -> List[ListingType]: - self.__abi_module.get_listings_by_asset_contract.call(asset_contract) - - def get_all_by_asset(self, asset: str) -> List[ListingType]: - self.__abi_module.get_listings_by_asset.call(asset) - - - def grant_role(self, role: Role, address: str): - role_hash = role.get_hash() - tx = self.__abi_module.grant_role.build_transaction( - role_hash, - address, - self.get_transact_opts() - ) - self.execute_tx(tx) - - def revoke_role(self, role: Role, address: str): - role_hash = role.get_hash() - tx = self.__abi_module.revoke_role.build_transaction( - role_hash, - address, - self.get_transact_opts() - ) - self.execute_tx(tx) + def get_all(self, search_filter: Filter = None) -> List[ListingType]: + if search_filter is None: + self.__abi_module.get_all_listings.call() + elif search_filter.asset_contract is not None: + if search_filter.token_id is not None: + self.__abi_module.get_listings_by_asset.call( + filer.asset_contract, + filer.token_id + ) + else: + self.__abi_module.get_listings_by_asset_contract.call( + filer.asset_contract + ) + elif search_filter.seller is not None: + self.__abi_module.get_listings_by_seller.call( + filer.seller + ) + else: + self.__abi_module.get_all_listings.call() def total_supply(self) -> int: self.__abi_module.total_listings.call() - - diff --git a/nftlabs/modules/market_types.py b/nftlabs/modules/market_types.py index c8e87370..a2fd57de 100644 --- a/nftlabs/modules/market_types.py +++ b/nftlabs/modules/market_types.py @@ -1,11 +1,12 @@ from dataclasses import dataclass +from typing import Optional @dataclass.dataclass class ListArg: asset_contract: str token_id: int - currency: str + currency_contract: str price_per_token: int quantity: int tokens_per_buyer: int @@ -14,10 +15,7 @@ class ListArg: @dataclass.dataclass -class ListUpdate: - listing_id : int - price_per_token: int - currency: int - tokens_per_buyer: int - seconds_until_start: int - seconds_until_end: int \ No newline at end of file +class Filter: + seller: Optional[str] = None + tokenContract: Optional[str] = None + tokenId: Optional[int] = None \ No newline at end of file From 739c0a62645faf68ec1657966b06219a08432d0a Mon Sep 17 00:00:00 2001 From: Ayush Pathak <62694274+ayshptk@users.noreply.github.com> Date: Thu, 21 Oct 2021 13:43:45 +0530 Subject: [PATCH 03/10] Update market.py --- nftlabs/modules/market.py | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/nftlabs/modules/market.py b/nftlabs/modules/market.py index 91eabe08..82d26449 100644 --- a/nftlabs/modules/market.py +++ b/nftlabs/modules/market.py @@ -20,29 +20,26 @@ def __init__(self, client: Web3, address: str): self.__abi_module = Market(client, address) #todo: return types - def list_item(self, arg: ListArg): + def list(self, arg: ListArg): from_address = self.get_signer_address() client = self.get_client() erc165 = ERC165(client, arg.asset_contract) - isERC165 = erc165.supports_interface(client, arg.asset_contract) - if isERC165: - asset = NFT(client, arg.asset_contract) + isERC721 = erc165.supports_interface(client, interface_id=print(bytearray.fromhex("80ac58cd"))) + if isERC721: + asset = NFT(from_address, arg.asset_contract) approved = asset.is_approved_for_all( arg.asset_contract, from_address) if not approved: - asset.approve_for_all(from_address, arg.asset_contract) - is_token_approved = (asset.get_approved( - arg.token_id).lower() == self.address.lower()) + asset.is_approve_for_all(from_address, arg.asset_contract) + is_token_approved = (asset.is_approved_for_all(arg.token_id).lower() == self.address.lower()) if not is_token_approved: asset.set_approval_for_all(arg.asset_contract, True) else: - asset = ERC1155(client, arg.asset_contract) - approved = asset.is_approved_for_all( - arg.asset_contract, from_address) + asset = ERC1155(from_address, arg.asset_contract) + approved = asset.is_approved_for_all(arg.asset_contract, from_address) if not approved: - asset.approve_for_all(from_address, arg.asset_contract) - is_token_approved = (asset.get_approved( - arg.token_id).lower() == self.address.lower()) + asset.set_approval_for_all(from_address, arg.asset_contract) + is_token_approved = (asset.get_approved(arg.token_id).lower() == self.address.lower()) if not is_token_approved: asset.set_approval_for_all(self.address, True) @@ -59,10 +56,9 @@ def list_item(self, arg: ListArg): ) receipt = self.execute_tx(tx) - result = self.__abi_module.get_minted_batch_event( - tx_hash=receipt.transactionHash.hex()) + result = self.__abi_module.get_new_listing_event(tx_hash=receipt.transactionHash.hex()) - def unlist_item(self, listing_id, quantity): + def unlist(self, listing_id, quantity): tx = self.__abi_module.unlist.build_transaction( listing_id, quantity, @@ -78,21 +74,19 @@ def buy(self, listing_id: int, quantity: int): if listing.currency_contract is not None and listing.currency_contract != "0x0000000000000000000000000000000000000000": erc20 = ERC20(self.get_client(), listing.currency_contract) allowance = erc20.allowance(owner, spender) - if allowance <= total_price: + if allowance < total_price: erc20.increase_allowance( spender, total_price, self.get_transact_opts() ) - tx = self.__abi_module.buy.build_transaction( listing_id, quantity, self.get_transact_opts() ) receipt = self.execute_tx(tx) - result = self.__abi_module.get_minted_batch_event( - tx_hash=receipt.transactionHash.hex()) + result = self.__abi_module.get_new_sale_event(tx_hash=receipt.transactionHash.hex()) def set_market_fee_bps(self, amount: int): tx = self.__abi_module.set_market_fee_bps.build_transaction( From 2d447b5afb77e9a8ba8a9a94905c913db8f3ee91 Mon Sep 17 00:00:00 2001 From: Ayush Pathak <62694274+ayshptk@users.noreply.github.com> Date: Sat, 23 Oct 2021 00:51:22 +0530 Subject: [PATCH 04/10] fixed issues --- .gitignore | 3 + nftlabs/abi/nft_collection/__init__.py | 5150 ++++++++++++++++++++++++ nftlabs/modules/currency.py | 7 +- nftlabs/modules/market.py | 15 +- nftlabs/types/listing.py | 20 +- 5 files changed, 5178 insertions(+), 17 deletions(-) create mode 100644 nftlabs/abi/nft_collection/__init__.py diff --git a/.gitignore b/.gitignore index 9fe3b71d..3a800a51 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,6 @@ build/ dist nftlabs_sdk.egg-info/ +nftlabs/modules/collection.py +nftlabs/.DS_Store +nftlabs/modules/docs/* diff --git a/nftlabs/abi/nft_collection/__init__.py b/nftlabs/abi/nft_collection/__init__.py new file mode 100644 index 00000000..877003d5 --- /dev/null +++ b/nftlabs/abi/nft_collection/__init__.py @@ -0,0 +1,5150 @@ +"""Generated wrapper for NFTCollection Solidity contract.""" + +# pylint: disable=too-many-arguments + +import json +from typing import ( # pylint: disable=unused-import + Any, + List, + Optional, + Tuple, + Union, +) + +from eth_utils import to_checksum_address +from mypy_extensions import TypedDict # pylint: disable=unused-import +from hexbytes import HexBytes +from web3 import Web3 +from web3.contract import ContractFunction +from web3.datastructures import AttributeDict +from web3.providers.base import BaseProvider + +from zero_ex.contract_wrappers.bases import ContractMethod, Validator +from zero_ex.contract_wrappers.tx_params import TxParams + + +# Try to import a custom validator class definition; if there isn't one, +# declare one that we can instantiate for the default argument to the +# constructor for NFTCollection below. +try: + # both mypy and pylint complain about what we're doing here, but this + # works just fine, so their messages have been disabled here. + from . import ( # type: ignore # pylint: disable=import-self + NFTCollectionValidator, + ) +except ImportError: + + class NFTCollectionValidator(Validator): # type: ignore + """No-op input validator.""" + + +try: + from .middleware import MIDDLEWARE # type: ignore +except ImportError: + pass + + +class DefaultAdminRoleMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the DEFAULT_ADMIN_ROLE method.""" + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + contract_function: ContractFunction, + ): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address) + self._underlying_method = contract_function + + def call(self, tx_params: Optional[TxParams] = None) -> Union[bytes, str]: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method().call(tx_params.as_dict()) + return Union[bytes, str](returned) + + def send_transaction( + self, tx_params: Optional[TxParams] = None + ) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method().transact(tx_params.as_dict()) + + def build_transaction(self, tx_params: Optional[TxParams] = None) -> dict: + """Construct calldata to be used as input to the method.""" + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method().buildTransaction(tx_params.as_dict()) + + def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int: + """Estimate gas consumption of method call.""" + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method().estimateGas(tx_params.as_dict()) + + +class MinterRoleMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the MINTER_ROLE method.""" + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + contract_function: ContractFunction, + ): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address) + self._underlying_method = contract_function + + def call(self, tx_params: Optional[TxParams] = None) -> Union[bytes, str]: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method().call(tx_params.as_dict()) + return Union[bytes, str](returned) + + def send_transaction( + self, tx_params: Optional[TxParams] = None + ) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method().transact(tx_params.as_dict()) + + def build_transaction(self, tx_params: Optional[TxParams] = None) -> dict: + """Construct calldata to be used as input to the method.""" + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method().buildTransaction(tx_params.as_dict()) + + def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int: + """Estimate gas consumption of method call.""" + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method().estimateGas(tx_params.as_dict()) + + +class PauserRoleMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the PAUSER_ROLE method.""" + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + contract_function: ContractFunction, + ): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address) + self._underlying_method = contract_function + + def call(self, tx_params: Optional[TxParams] = None) -> Union[bytes, str]: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method().call(tx_params.as_dict()) + return Union[bytes, str](returned) + + def send_transaction( + self, tx_params: Optional[TxParams] = None + ) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method().transact(tx_params.as_dict()) + + def build_transaction(self, tx_params: Optional[TxParams] = None) -> dict: + """Construct calldata to be used as input to the method.""" + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method().buildTransaction(tx_params.as_dict()) + + def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int: + """Estimate gas consumption of method call.""" + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method().estimateGas(tx_params.as_dict()) + + +class TransferRoleMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the TRANSFER_ROLE method.""" + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + contract_function: ContractFunction, + ): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address) + self._underlying_method = contract_function + + def call(self, tx_params: Optional[TxParams] = None) -> Union[bytes, str]: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method().call(tx_params.as_dict()) + return Union[bytes, str](returned) + + def send_transaction( + self, tx_params: Optional[TxParams] = None + ) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method().transact(tx_params.as_dict()) + + def build_transaction(self, tx_params: Optional[TxParams] = None) -> dict: + """Construct calldata to be used as input to the method.""" + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method().buildTransaction(tx_params.as_dict()) + + def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int: + """Estimate gas consumption of method call.""" + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method().estimateGas(tx_params.as_dict()) + + +class ContractUri_Method(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the _contractURI method.""" + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + contract_function: ContractFunction, + ): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address) + self._underlying_method = contract_function + + def call(self, tx_params: Optional[TxParams] = None) -> str: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method().call(tx_params.as_dict()) + return str(returned) + + def send_transaction( + self, tx_params: Optional[TxParams] = None + ) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method().transact(tx_params.as_dict()) + + def build_transaction(self, tx_params: Optional[TxParams] = None) -> dict: + """Construct calldata to be used as input to the method.""" + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method().buildTransaction(tx_params.as_dict()) + + def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int: + """Estimate gas consumption of method call.""" + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method().estimateGas(tx_params.as_dict()) + + +class BalanceOfMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the balanceOf method.""" + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + contract_function: ContractFunction, + validator: Validator = None, + ): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs(self, account: str, _id: int): + """Validate the inputs to the balanceOf method.""" + self.validator.assert_valid( + method_name="balanceOf", + parameter_name="account", + argument_value=account, + ) + account = self.validate_and_checksum_address(account) + self.validator.assert_valid( + method_name="balanceOf", + parameter_name="id", + argument_value=_id, + ) + # safeguard against fractional inputs + _id = int(_id) + return (account, _id) + + def call( + self, account: str, _id: int, tx_params: Optional[TxParams] = None + ) -> int: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (account, _id) = self.validate_and_normalize_inputs(account, _id) + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method(account, _id).call( + tx_params.as_dict() + ) + return int(returned) + + def send_transaction( + self, account: str, _id: int, tx_params: Optional[TxParams] = None + ) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (account, _id) = self.validate_and_normalize_inputs(account, _id) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(account, _id).transact( + tx_params.as_dict() + ) + + def build_transaction( + self, account: str, _id: int, tx_params: Optional[TxParams] = None + ) -> dict: + """Construct calldata to be used as input to the method.""" + (account, _id) = self.validate_and_normalize_inputs(account, _id) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(account, _id).buildTransaction( + tx_params.as_dict() + ) + + def estimate_gas( + self, account: str, _id: int, tx_params: Optional[TxParams] = None + ) -> int: + """Estimate gas consumption of method call.""" + (account, _id) = self.validate_and_normalize_inputs(account, _id) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(account, _id).estimateGas( + tx_params.as_dict() + ) + + +class BalanceOfBatchMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the balanceOfBatch method.""" + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + contract_function: ContractFunction, + validator: Validator = None, + ): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs( + self, accounts: List[str], ids: List[int] + ): + """Validate the inputs to the balanceOfBatch method.""" + self.validator.assert_valid( + method_name="balanceOfBatch", + parameter_name="accounts", + argument_value=accounts, + ) + self.validator.assert_valid( + method_name="balanceOfBatch", + parameter_name="ids", + argument_value=ids, + ) + return (accounts, ids) + + def call( + self, + accounts: List[str], + ids: List[int], + tx_params: Optional[TxParams] = None, + ) -> List[int]: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (accounts, ids) = self.validate_and_normalize_inputs(accounts, ids) + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method(accounts, ids).call( + tx_params.as_dict() + ) + return [int(element) for element in returned] + + def send_transaction( + self, + accounts: List[str], + ids: List[int], + tx_params: Optional[TxParams] = None, + ) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (accounts, ids) = self.validate_and_normalize_inputs(accounts, ids) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(accounts, ids).transact( + tx_params.as_dict() + ) + + def build_transaction( + self, + accounts: List[str], + ids: List[int], + tx_params: Optional[TxParams] = None, + ) -> dict: + """Construct calldata to be used as input to the method.""" + (accounts, ids) = self.validate_and_normalize_inputs(accounts, ids) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(accounts, ids).buildTransaction( + tx_params.as_dict() + ) + + def estimate_gas( + self, + accounts: List[str], + ids: List[int], + tx_params: Optional[TxParams] = None, + ) -> int: + """Estimate gas consumption of method call.""" + (accounts, ids) = self.validate_and_normalize_inputs(accounts, ids) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(accounts, ids).estimateGas( + tx_params.as_dict() + ) + + +class BurnMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the burn method.""" + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + contract_function: ContractFunction, + validator: Validator = None, + ): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs( + self, account: str, _id: int, value: int + ): + """Validate the inputs to the burn method.""" + self.validator.assert_valid( + method_name="burn", + parameter_name="account", + argument_value=account, + ) + account = self.validate_and_checksum_address(account) + self.validator.assert_valid( + method_name="burn", + parameter_name="id", + argument_value=_id, + ) + # safeguard against fractional inputs + _id = int(_id) + self.validator.assert_valid( + method_name="burn", + parameter_name="value", + argument_value=value, + ) + # safeguard against fractional inputs + value = int(value) + return (account, _id, value) + + def call( + self, + account: str, + _id: int, + value: int, + tx_params: Optional[TxParams] = None, + ) -> None: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (account, _id, value) = self.validate_and_normalize_inputs( + account, _id, value + ) + tx_params = super().normalize_tx_params(tx_params) + self._underlying_method(account, _id, value).call(tx_params.as_dict()) + + def send_transaction( + self, + account: str, + _id: int, + value: int, + tx_params: Optional[TxParams] = None, + ) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (account, _id, value) = self.validate_and_normalize_inputs( + account, _id, value + ) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(account, _id, value).transact( + tx_params.as_dict() + ) + + def build_transaction( + self, + account: str, + _id: int, + value: int, + tx_params: Optional[TxParams] = None, + ) -> dict: + """Construct calldata to be used as input to the method.""" + (account, _id, value) = self.validate_and_normalize_inputs( + account, _id, value + ) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(account, _id, value).buildTransaction( + tx_params.as_dict() + ) + + def estimate_gas( + self, + account: str, + _id: int, + value: int, + tx_params: Optional[TxParams] = None, + ) -> int: + """Estimate gas consumption of method call.""" + (account, _id, value) = self.validate_and_normalize_inputs( + account, _id, value + ) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(account, _id, value).estimateGas( + tx_params.as_dict() + ) + + +class BurnBatchMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the burnBatch method.""" + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + contract_function: ContractFunction, + validator: Validator = None, + ): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs( + self, account: str, ids: List[int], values: List[int] + ): + """Validate the inputs to the burnBatch method.""" + self.validator.assert_valid( + method_name="burnBatch", + parameter_name="account", + argument_value=account, + ) + account = self.validate_and_checksum_address(account) + self.validator.assert_valid( + method_name="burnBatch", + parameter_name="ids", + argument_value=ids, + ) + self.validator.assert_valid( + method_name="burnBatch", + parameter_name="values", + argument_value=values, + ) + return (account, ids, values) + + def call( + self, + account: str, + ids: List[int], + values: List[int], + tx_params: Optional[TxParams] = None, + ) -> None: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (account, ids, values) = self.validate_and_normalize_inputs( + account, ids, values + ) + tx_params = super().normalize_tx_params(tx_params) + self._underlying_method(account, ids, values).call(tx_params.as_dict()) + + def send_transaction( + self, + account: str, + ids: List[int], + values: List[int], + tx_params: Optional[TxParams] = None, + ) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (account, ids, values) = self.validate_and_normalize_inputs( + account, ids, values + ) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(account, ids, values).transact( + tx_params.as_dict() + ) + + def build_transaction( + self, + account: str, + ids: List[int], + values: List[int], + tx_params: Optional[TxParams] = None, + ) -> dict: + """Construct calldata to be used as input to the method.""" + (account, ids, values) = self.validate_and_normalize_inputs( + account, ids, values + ) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(account, ids, values).buildTransaction( + tx_params.as_dict() + ) + + def estimate_gas( + self, + account: str, + ids: List[int], + values: List[int], + tx_params: Optional[TxParams] = None, + ) -> int: + """Estimate gas consumption of method call.""" + (account, ids, values) = self.validate_and_normalize_inputs( + account, ids, values + ) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(account, ids, values).estimateGas( + tx_params.as_dict() + ) + + +class ContractUriMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the contractURI method.""" + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + contract_function: ContractFunction, + ): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address) + self._underlying_method = contract_function + + def call(self, tx_params: Optional[TxParams] = None) -> str: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method().call(tx_params.as_dict()) + return str(returned) + + def send_transaction( + self, tx_params: Optional[TxParams] = None + ) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method().transact(tx_params.as_dict()) + + def build_transaction(self, tx_params: Optional[TxParams] = None) -> dict: + """Construct calldata to be used as input to the method.""" + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method().buildTransaction(tx_params.as_dict()) + + def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int: + """Estimate gas consumption of method call.""" + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method().estimateGas(tx_params.as_dict()) + + +class CreateNativeTokensMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the createNativeTokens method.""" + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + contract_function: ContractFunction, + validator: Validator = None, + ): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs( + self, + to: str, + nft_ur_is: List[str], + nft_supplies: List[int], + data: Union[bytes, str], + ): + """Validate the inputs to the createNativeTokens method.""" + self.validator.assert_valid( + method_name="createNativeTokens", + parameter_name="to", + argument_value=to, + ) + to = self.validate_and_checksum_address(to) + self.validator.assert_valid( + method_name="createNativeTokens", + parameter_name="_nftURIs", + argument_value=nft_ur_is, + ) + self.validator.assert_valid( + method_name="createNativeTokens", + parameter_name="_nftSupplies", + argument_value=nft_supplies, + ) + self.validator.assert_valid( + method_name="createNativeTokens", + parameter_name="data", + argument_value=data, + ) + return (to, nft_ur_is, nft_supplies, data) + + def call( + self, + to: str, + nft_ur_is: List[str], + nft_supplies: List[int], + data: Union[bytes, str], + tx_params: Optional[TxParams] = None, + ) -> List[int]: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + ( + to, + nft_ur_is, + nft_supplies, + data, + ) = self.validate_and_normalize_inputs( + to, nft_ur_is, nft_supplies, data + ) + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method( + to, nft_ur_is, nft_supplies, data + ).call(tx_params.as_dict()) + return [int(element) for element in returned] + + def send_transaction( + self, + to: str, + nft_ur_is: List[str], + nft_supplies: List[int], + data: Union[bytes, str], + tx_params: Optional[TxParams] = None, + ) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + ( + to, + nft_ur_is, + nft_supplies, + data, + ) = self.validate_and_normalize_inputs( + to, nft_ur_is, nft_supplies, data + ) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method( + to, nft_ur_is, nft_supplies, data + ).transact(tx_params.as_dict()) + + def build_transaction( + self, + to: str, + nft_ur_is: List[str], + nft_supplies: List[int], + data: Union[bytes, str], + tx_params: Optional[TxParams] = None, + ) -> dict: + """Construct calldata to be used as input to the method.""" + ( + to, + nft_ur_is, + nft_supplies, + data, + ) = self.validate_and_normalize_inputs( + to, nft_ur_is, nft_supplies, data + ) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method( + to, nft_ur_is, nft_supplies, data + ).buildTransaction(tx_params.as_dict()) + + def estimate_gas( + self, + to: str, + nft_ur_is: List[str], + nft_supplies: List[int], + data: Union[bytes, str], + tx_params: Optional[TxParams] = None, + ) -> int: + """Estimate gas consumption of method call.""" + ( + to, + nft_ur_is, + nft_supplies, + data, + ) = self.validate_and_normalize_inputs( + to, nft_ur_is, nft_supplies, data + ) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method( + to, nft_ur_is, nft_supplies, data + ).estimateGas(tx_params.as_dict()) + + +class CreatorMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the creator method.""" + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + contract_function: ContractFunction, + validator: Validator = None, + ): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs(self, nft_id: int): + """Validate the inputs to the creator method.""" + self.validator.assert_valid( + method_name="creator", + parameter_name="_nftId", + argument_value=nft_id, + ) + # safeguard against fractional inputs + nft_id = int(nft_id) + return nft_id + + def call(self, nft_id: int, tx_params: Optional[TxParams] = None) -> str: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (nft_id) = self.validate_and_normalize_inputs(nft_id) + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method(nft_id).call(tx_params.as_dict()) + return str(returned) + + def send_transaction( + self, nft_id: int, tx_params: Optional[TxParams] = None + ) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (nft_id) = self.validate_and_normalize_inputs(nft_id) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(nft_id).transact(tx_params.as_dict()) + + def build_transaction( + self, nft_id: int, tx_params: Optional[TxParams] = None + ) -> dict: + """Construct calldata to be used as input to the method.""" + (nft_id) = self.validate_and_normalize_inputs(nft_id) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(nft_id).buildTransaction( + tx_params.as_dict() + ) + + def estimate_gas( + self, nft_id: int, tx_params: Optional[TxParams] = None + ) -> int: + """Estimate gas consumption of method call.""" + (nft_id) = self.validate_and_normalize_inputs(nft_id) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(nft_id).estimateGas(tx_params.as_dict()) + + +class Erc20WrappedTokensMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the erc20WrappedTokens method.""" + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + contract_function: ContractFunction, + validator: Validator = None, + ): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs(self, index_0: int): + """Validate the inputs to the erc20WrappedTokens method.""" + self.validator.assert_valid( + method_name="erc20WrappedTokens", + parameter_name="index_0", + argument_value=index_0, + ) + # safeguard against fractional inputs + index_0 = int(index_0) + return index_0 + + def call( + self, index_0: int, tx_params: Optional[TxParams] = None + ) -> Tuple[str, int, int]: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (index_0) = self.validate_and_normalize_inputs(index_0) + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method(index_0).call(tx_params.as_dict()) + return ( + returned[0], + returned[1], + returned[2], + ) + + def send_transaction( + self, index_0: int, tx_params: Optional[TxParams] = None + ) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (index_0) = self.validate_and_normalize_inputs(index_0) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(index_0).transact(tx_params.as_dict()) + + def build_transaction( + self, index_0: int, tx_params: Optional[TxParams] = None + ) -> dict: + """Construct calldata to be used as input to the method.""" + (index_0) = self.validate_and_normalize_inputs(index_0) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(index_0).buildTransaction( + tx_params.as_dict() + ) + + def estimate_gas( + self, index_0: int, tx_params: Optional[TxParams] = None + ) -> int: + """Estimate gas consumption of method call.""" + (index_0) = self.validate_and_normalize_inputs(index_0) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(index_0).estimateGas( + tx_params.as_dict() + ) + + +class Erc721WrappedTokensMethod( + ContractMethod +): # pylint: disable=invalid-name + """Various interfaces to the erc721WrappedTokens method.""" + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + contract_function: ContractFunction, + validator: Validator = None, + ): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs(self, index_0: int): + """Validate the inputs to the erc721WrappedTokens method.""" + self.validator.assert_valid( + method_name="erc721WrappedTokens", + parameter_name="index_0", + argument_value=index_0, + ) + # safeguard against fractional inputs + index_0 = int(index_0) + return index_0 + + def call( + self, index_0: int, tx_params: Optional[TxParams] = None + ) -> Tuple[str, int]: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (index_0) = self.validate_and_normalize_inputs(index_0) + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method(index_0).call(tx_params.as_dict()) + return ( + returned[0], + returned[1], + ) + + def send_transaction( + self, index_0: int, tx_params: Optional[TxParams] = None + ) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (index_0) = self.validate_and_normalize_inputs(index_0) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(index_0).transact(tx_params.as_dict()) + + def build_transaction( + self, index_0: int, tx_params: Optional[TxParams] = None + ) -> dict: + """Construct calldata to be used as input to the method.""" + (index_0) = self.validate_and_normalize_inputs(index_0) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(index_0).buildTransaction( + tx_params.as_dict() + ) + + def estimate_gas( + self, index_0: int, tx_params: Optional[TxParams] = None + ) -> int: + """Estimate gas consumption of method call.""" + (index_0) = self.validate_and_normalize_inputs(index_0) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(index_0).estimateGas( + tx_params.as_dict() + ) + + +class GetRoleAdminMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the getRoleAdmin method.""" + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + contract_function: ContractFunction, + validator: Validator = None, + ): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs(self, role: Union[bytes, str]): + """Validate the inputs to the getRoleAdmin method.""" + self.validator.assert_valid( + method_name="getRoleAdmin", + parameter_name="role", + argument_value=role, + ) + return role + + def call( + self, role: Union[bytes, str], tx_params: Optional[TxParams] = None + ) -> Union[bytes, str]: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (role) = self.validate_and_normalize_inputs(role) + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method(role).call(tx_params.as_dict()) + return Union[bytes, str](returned) + + def send_transaction( + self, role: Union[bytes, str], tx_params: Optional[TxParams] = None + ) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (role) = self.validate_and_normalize_inputs(role) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(role).transact(tx_params.as_dict()) + + def build_transaction( + self, role: Union[bytes, str], tx_params: Optional[TxParams] = None + ) -> dict: + """Construct calldata to be used as input to the method.""" + (role) = self.validate_and_normalize_inputs(role) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(role).buildTransaction( + tx_params.as_dict() + ) + + def estimate_gas( + self, role: Union[bytes, str], tx_params: Optional[TxParams] = None + ) -> int: + """Estimate gas consumption of method call.""" + (role) = self.validate_and_normalize_inputs(role) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(role).estimateGas(tx_params.as_dict()) + + +class GetRoleMemberMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the getRoleMember method.""" + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + contract_function: ContractFunction, + validator: Validator = None, + ): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs( + self, role: Union[bytes, str], index: int + ): + """Validate the inputs to the getRoleMember method.""" + self.validator.assert_valid( + method_name="getRoleMember", + parameter_name="role", + argument_value=role, + ) + self.validator.assert_valid( + method_name="getRoleMember", + parameter_name="index", + argument_value=index, + ) + # safeguard against fractional inputs + index = int(index) + return (role, index) + + def call( + self, + role: Union[bytes, str], + index: int, + tx_params: Optional[TxParams] = None, + ) -> str: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (role, index) = self.validate_and_normalize_inputs(role, index) + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method(role, index).call( + tx_params.as_dict() + ) + return str(returned) + + def send_transaction( + self, + role: Union[bytes, str], + index: int, + tx_params: Optional[TxParams] = None, + ) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (role, index) = self.validate_and_normalize_inputs(role, index) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(role, index).transact( + tx_params.as_dict() + ) + + def build_transaction( + self, + role: Union[bytes, str], + index: int, + tx_params: Optional[TxParams] = None, + ) -> dict: + """Construct calldata to be used as input to the method.""" + (role, index) = self.validate_and_normalize_inputs(role, index) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(role, index).buildTransaction( + tx_params.as_dict() + ) + + def estimate_gas( + self, + role: Union[bytes, str], + index: int, + tx_params: Optional[TxParams] = None, + ) -> int: + """Estimate gas consumption of method call.""" + (role, index) = self.validate_and_normalize_inputs(role, index) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(role, index).estimateGas( + tx_params.as_dict() + ) + + +class GetRoleMemberCountMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the getRoleMemberCount method.""" + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + contract_function: ContractFunction, + validator: Validator = None, + ): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs(self, role: Union[bytes, str]): + """Validate the inputs to the getRoleMemberCount method.""" + self.validator.assert_valid( + method_name="getRoleMemberCount", + parameter_name="role", + argument_value=role, + ) + return role + + def call( + self, role: Union[bytes, str], tx_params: Optional[TxParams] = None + ) -> int: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (role) = self.validate_and_normalize_inputs(role) + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method(role).call(tx_params.as_dict()) + return int(returned) + + def send_transaction( + self, role: Union[bytes, str], tx_params: Optional[TxParams] = None + ) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (role) = self.validate_and_normalize_inputs(role) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(role).transact(tx_params.as_dict()) + + def build_transaction( + self, role: Union[bytes, str], tx_params: Optional[TxParams] = None + ) -> dict: + """Construct calldata to be used as input to the method.""" + (role) = self.validate_and_normalize_inputs(role) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(role).buildTransaction( + tx_params.as_dict() + ) + + def estimate_gas( + self, role: Union[bytes, str], tx_params: Optional[TxParams] = None + ) -> int: + """Estimate gas consumption of method call.""" + (role) = self.validate_and_normalize_inputs(role) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(role).estimateGas(tx_params.as_dict()) + + +class GrantRoleMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the grantRole method.""" + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + contract_function: ContractFunction, + validator: Validator = None, + ): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs( + self, role: Union[bytes, str], account: str + ): + """Validate the inputs to the grantRole method.""" + self.validator.assert_valid( + method_name="grantRole", + parameter_name="role", + argument_value=role, + ) + self.validator.assert_valid( + method_name="grantRole", + parameter_name="account", + argument_value=account, + ) + account = self.validate_and_checksum_address(account) + return (role, account) + + def call( + self, + role: Union[bytes, str], + account: str, + tx_params: Optional[TxParams] = None, + ) -> None: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (role, account) = self.validate_and_normalize_inputs(role, account) + tx_params = super().normalize_tx_params(tx_params) + self._underlying_method(role, account).call(tx_params.as_dict()) + + def send_transaction( + self, + role: Union[bytes, str], + account: str, + tx_params: Optional[TxParams] = None, + ) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (role, account) = self.validate_and_normalize_inputs(role, account) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(role, account).transact( + tx_params.as_dict() + ) + + def build_transaction( + self, + role: Union[bytes, str], + account: str, + tx_params: Optional[TxParams] = None, + ) -> dict: + """Construct calldata to be used as input to the method.""" + (role, account) = self.validate_and_normalize_inputs(role, account) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(role, account).buildTransaction( + tx_params.as_dict() + ) + + def estimate_gas( + self, + role: Union[bytes, str], + account: str, + tx_params: Optional[TxParams] = None, + ) -> int: + """Estimate gas consumption of method call.""" + (role, account) = self.validate_and_normalize_inputs(role, account) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(role, account).estimateGas( + tx_params.as_dict() + ) + + +class HasRoleMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the hasRole method.""" + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + contract_function: ContractFunction, + validator: Validator = None, + ): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs( + self, role: Union[bytes, str], account: str + ): + """Validate the inputs to the hasRole method.""" + self.validator.assert_valid( + method_name="hasRole", + parameter_name="role", + argument_value=role, + ) + self.validator.assert_valid( + method_name="hasRole", + parameter_name="account", + argument_value=account, + ) + account = self.validate_and_checksum_address(account) + return (role, account) + + def call( + self, + role: Union[bytes, str], + account: str, + tx_params: Optional[TxParams] = None, + ) -> bool: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (role, account) = self.validate_and_normalize_inputs(role, account) + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method(role, account).call( + tx_params.as_dict() + ) + return bool(returned) + + def send_transaction( + self, + role: Union[bytes, str], + account: str, + tx_params: Optional[TxParams] = None, + ) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (role, account) = self.validate_and_normalize_inputs(role, account) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(role, account).transact( + tx_params.as_dict() + ) + + def build_transaction( + self, + role: Union[bytes, str], + account: str, + tx_params: Optional[TxParams] = None, + ) -> dict: + """Construct calldata to be used as input to the method.""" + (role, account) = self.validate_and_normalize_inputs(role, account) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(role, account).buildTransaction( + tx_params.as_dict() + ) + + def estimate_gas( + self, + role: Union[bytes, str], + account: str, + tx_params: Optional[TxParams] = None, + ) -> int: + """Estimate gas consumption of method call.""" + (role, account) = self.validate_and_normalize_inputs(role, account) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(role, account).estimateGas( + tx_params.as_dict() + ) + + +class IsApprovedForAllMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the isApprovedForAll method.""" + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + contract_function: ContractFunction, + validator: Validator = None, + ): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs(self, account: str, operator: str): + """Validate the inputs to the isApprovedForAll method.""" + self.validator.assert_valid( + method_name="isApprovedForAll", + parameter_name="account", + argument_value=account, + ) + account = self.validate_and_checksum_address(account) + self.validator.assert_valid( + method_name="isApprovedForAll", + parameter_name="operator", + argument_value=operator, + ) + operator = self.validate_and_checksum_address(operator) + return (account, operator) + + def call( + self, account: str, operator: str, tx_params: Optional[TxParams] = None + ) -> bool: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (account, operator) = self.validate_and_normalize_inputs( + account, operator + ) + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method(account, operator).call( + tx_params.as_dict() + ) + return bool(returned) + + def send_transaction( + self, account: str, operator: str, tx_params: Optional[TxParams] = None + ) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (account, operator) = self.validate_and_normalize_inputs( + account, operator + ) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(account, operator).transact( + tx_params.as_dict() + ) + + def build_transaction( + self, account: str, operator: str, tx_params: Optional[TxParams] = None + ) -> dict: + """Construct calldata to be used as input to the method.""" + (account, operator) = self.validate_and_normalize_inputs( + account, operator + ) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(account, operator).buildTransaction( + tx_params.as_dict() + ) + + def estimate_gas( + self, account: str, operator: str, tx_params: Optional[TxParams] = None + ) -> int: + """Estimate gas consumption of method call.""" + (account, operator) = self.validate_and_normalize_inputs( + account, operator + ) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(account, operator).estimateGas( + tx_params.as_dict() + ) + + +class IsTrustedForwarderMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the isTrustedForwarder method.""" + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + contract_function: ContractFunction, + validator: Validator = None, + ): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs(self, forwarder: str): + """Validate the inputs to the isTrustedForwarder method.""" + self.validator.assert_valid( + method_name="isTrustedForwarder", + parameter_name="forwarder", + argument_value=forwarder, + ) + forwarder = self.validate_and_checksum_address(forwarder) + return forwarder + + def call( + self, forwarder: str, tx_params: Optional[TxParams] = None + ) -> bool: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (forwarder) = self.validate_and_normalize_inputs(forwarder) + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method(forwarder).call(tx_params.as_dict()) + return bool(returned) + + def send_transaction( + self, forwarder: str, tx_params: Optional[TxParams] = None + ) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (forwarder) = self.validate_and_normalize_inputs(forwarder) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(forwarder).transact(tx_params.as_dict()) + + def build_transaction( + self, forwarder: str, tx_params: Optional[TxParams] = None + ) -> dict: + """Construct calldata to be used as input to the method.""" + (forwarder) = self.validate_and_normalize_inputs(forwarder) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(forwarder).buildTransaction( + tx_params.as_dict() + ) + + def estimate_gas( + self, forwarder: str, tx_params: Optional[TxParams] = None + ) -> int: + """Estimate gas consumption of method call.""" + (forwarder) = self.validate_and_normalize_inputs(forwarder) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(forwarder).estimateGas( + tx_params.as_dict() + ) + + +class MintMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the mint method.""" + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + contract_function: ContractFunction, + validator: Validator = None, + ): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs( + self, to: str, _id: int, amount: int, data: Union[bytes, str] + ): + """Validate the inputs to the mint method.""" + self.validator.assert_valid( + method_name="mint", + parameter_name="to", + argument_value=to, + ) + to = self.validate_and_checksum_address(to) + self.validator.assert_valid( + method_name="mint", + parameter_name="id", + argument_value=_id, + ) + # safeguard against fractional inputs + _id = int(_id) + self.validator.assert_valid( + method_name="mint", + parameter_name="amount", + argument_value=amount, + ) + # safeguard against fractional inputs + amount = int(amount) + self.validator.assert_valid( + method_name="mint", + parameter_name="data", + argument_value=data, + ) + return (to, _id, amount, data) + + def call( + self, + to: str, + _id: int, + amount: int, + data: Union[bytes, str], + tx_params: Optional[TxParams] = None, + ) -> None: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (to, _id, amount, data) = self.validate_and_normalize_inputs( + to, _id, amount, data + ) + tx_params = super().normalize_tx_params(tx_params) + self._underlying_method(to, _id, amount, data).call( + tx_params.as_dict() + ) + + def send_transaction( + self, + to: str, + _id: int, + amount: int, + data: Union[bytes, str], + tx_params: Optional[TxParams] = None, + ) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (to, _id, amount, data) = self.validate_and_normalize_inputs( + to, _id, amount, data + ) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(to, _id, amount, data).transact( + tx_params.as_dict() + ) + + def build_transaction( + self, + to: str, + _id: int, + amount: int, + data: Union[bytes, str], + tx_params: Optional[TxParams] = None, + ) -> dict: + """Construct calldata to be used as input to the method.""" + (to, _id, amount, data) = self.validate_and_normalize_inputs( + to, _id, amount, data + ) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(to, _id, amount, data).buildTransaction( + tx_params.as_dict() + ) + + def estimate_gas( + self, + to: str, + _id: int, + amount: int, + data: Union[bytes, str], + tx_params: Optional[TxParams] = None, + ) -> int: + """Estimate gas consumption of method call.""" + (to, _id, amount, data) = self.validate_and_normalize_inputs( + to, _id, amount, data + ) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(to, _id, amount, data).estimateGas( + tx_params.as_dict() + ) + + +class MintBatchMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the mintBatch method.""" + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + contract_function: ContractFunction, + validator: Validator = None, + ): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs( + self, + to: str, + ids: List[int], + amounts: List[int], + data: Union[bytes, str], + ): + """Validate the inputs to the mintBatch method.""" + self.validator.assert_valid( + method_name="mintBatch", + parameter_name="to", + argument_value=to, + ) + to = self.validate_and_checksum_address(to) + self.validator.assert_valid( + method_name="mintBatch", + parameter_name="ids", + argument_value=ids, + ) + self.validator.assert_valid( + method_name="mintBatch", + parameter_name="amounts", + argument_value=amounts, + ) + self.validator.assert_valid( + method_name="mintBatch", + parameter_name="data", + argument_value=data, + ) + return (to, ids, amounts, data) + + def call( + self, + to: str, + ids: List[int], + amounts: List[int], + data: Union[bytes, str], + tx_params: Optional[TxParams] = None, + ) -> None: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (to, ids, amounts, data) = self.validate_and_normalize_inputs( + to, ids, amounts, data + ) + tx_params = super().normalize_tx_params(tx_params) + self._underlying_method(to, ids, amounts, data).call( + tx_params.as_dict() + ) + + def send_transaction( + self, + to: str, + ids: List[int], + amounts: List[int], + data: Union[bytes, str], + tx_params: Optional[TxParams] = None, + ) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (to, ids, amounts, data) = self.validate_and_normalize_inputs( + to, ids, amounts, data + ) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(to, ids, amounts, data).transact( + tx_params.as_dict() + ) + + def build_transaction( + self, + to: str, + ids: List[int], + amounts: List[int], + data: Union[bytes, str], + tx_params: Optional[TxParams] = None, + ) -> dict: + """Construct calldata to be used as input to the method.""" + (to, ids, amounts, data) = self.validate_and_normalize_inputs( + to, ids, amounts, data + ) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method( + to, ids, amounts, data + ).buildTransaction(tx_params.as_dict()) + + def estimate_gas( + self, + to: str, + ids: List[int], + amounts: List[int], + data: Union[bytes, str], + tx_params: Optional[TxParams] = None, + ) -> int: + """Estimate gas consumption of method call.""" + (to, ids, amounts, data) = self.validate_and_normalize_inputs( + to, ids, amounts, data + ) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(to, ids, amounts, data).estimateGas( + tx_params.as_dict() + ) + + +class MulticallMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the multicall method.""" + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + contract_function: ContractFunction, + validator: Validator = None, + ): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs(self, data: List[Union[bytes, str]]): + """Validate the inputs to the multicall method.""" + self.validator.assert_valid( + method_name="multicall", + parameter_name="data", + argument_value=data, + ) + return data + + def call( + self, + data: List[Union[bytes, str]], + tx_params: Optional[TxParams] = None, + ) -> List[Union[bytes, str]]: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (data) = self.validate_and_normalize_inputs(data) + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method(data).call(tx_params.as_dict()) + return [Union[bytes, str](element) for element in returned] + + def send_transaction( + self, + data: List[Union[bytes, str]], + tx_params: Optional[TxParams] = None, + ) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (data) = self.validate_and_normalize_inputs(data) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(data).transact(tx_params.as_dict()) + + def build_transaction( + self, + data: List[Union[bytes, str]], + tx_params: Optional[TxParams] = None, + ) -> dict: + """Construct calldata to be used as input to the method.""" + (data) = self.validate_and_normalize_inputs(data) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(data).buildTransaction( + tx_params.as_dict() + ) + + def estimate_gas( + self, + data: List[Union[bytes, str]], + tx_params: Optional[TxParams] = None, + ) -> int: + """Estimate gas consumption of method call.""" + (data) = self.validate_and_normalize_inputs(data) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(data).estimateGas(tx_params.as_dict()) + + +class NextTokenIdMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the nextTokenId method.""" + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + contract_function: ContractFunction, + ): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address) + self._underlying_method = contract_function + + def call(self, tx_params: Optional[TxParams] = None) -> int: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method().call(tx_params.as_dict()) + return int(returned) + + def send_transaction( + self, tx_params: Optional[TxParams] = None + ) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method().transact(tx_params.as_dict()) + + def build_transaction(self, tx_params: Optional[TxParams] = None) -> dict: + """Construct calldata to be used as input to the method.""" + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method().buildTransaction(tx_params.as_dict()) + + def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int: + """Estimate gas consumption of method call.""" + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method().estimateGas(tx_params.as_dict()) + + +class OnErc1155BatchReceivedMethod( + ContractMethod +): # pylint: disable=invalid-name + """Various interfaces to the onERC1155BatchReceived method.""" + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + contract_function: ContractFunction, + validator: Validator = None, + ): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs( + self, + index_0: str, + index_1: str, + index_2: List[int], + index_3: List[int], + index_4: Union[bytes, str], + ): + """Validate the inputs to the onERC1155BatchReceived method.""" + self.validator.assert_valid( + method_name="onERC1155BatchReceived", + parameter_name="index_0", + argument_value=index_0, + ) + index_0 = self.validate_and_checksum_address(index_0) + self.validator.assert_valid( + method_name="onERC1155BatchReceived", + parameter_name="index_1", + argument_value=index_1, + ) + index_1 = self.validate_and_checksum_address(index_1) + self.validator.assert_valid( + method_name="onERC1155BatchReceived", + parameter_name="index_2", + argument_value=index_2, + ) + self.validator.assert_valid( + method_name="onERC1155BatchReceived", + parameter_name="index_3", + argument_value=index_3, + ) + self.validator.assert_valid( + method_name="onERC1155BatchReceived", + parameter_name="index_4", + argument_value=index_4, + ) + return (index_0, index_1, index_2, index_3, index_4) + + def call( + self, + index_0: str, + index_1: str, + index_2: List[int], + index_3: List[int], + index_4: Union[bytes, str], + tx_params: Optional[TxParams] = None, + ) -> Union[bytes, str]: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + ( + index_0, + index_1, + index_2, + index_3, + index_4, + ) = self.validate_and_normalize_inputs( + index_0, index_1, index_2, index_3, index_4 + ) + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method( + index_0, index_1, index_2, index_3, index_4 + ).call(tx_params.as_dict()) + return Union[bytes, str](returned) + + def send_transaction( + self, + index_0: str, + index_1: str, + index_2: List[int], + index_3: List[int], + index_4: Union[bytes, str], + tx_params: Optional[TxParams] = None, + ) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + ( + index_0, + index_1, + index_2, + index_3, + index_4, + ) = self.validate_and_normalize_inputs( + index_0, index_1, index_2, index_3, index_4 + ) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method( + index_0, index_1, index_2, index_3, index_4 + ).transact(tx_params.as_dict()) + + def build_transaction( + self, + index_0: str, + index_1: str, + index_2: List[int], + index_3: List[int], + index_4: Union[bytes, str], + tx_params: Optional[TxParams] = None, + ) -> dict: + """Construct calldata to be used as input to the method.""" + ( + index_0, + index_1, + index_2, + index_3, + index_4, + ) = self.validate_and_normalize_inputs( + index_0, index_1, index_2, index_3, index_4 + ) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method( + index_0, index_1, index_2, index_3, index_4 + ).buildTransaction(tx_params.as_dict()) + + def estimate_gas( + self, + index_0: str, + index_1: str, + index_2: List[int], + index_3: List[int], + index_4: Union[bytes, str], + tx_params: Optional[TxParams] = None, + ) -> int: + """Estimate gas consumption of method call.""" + ( + index_0, + index_1, + index_2, + index_3, + index_4, + ) = self.validate_and_normalize_inputs( + index_0, index_1, index_2, index_3, index_4 + ) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method( + index_0, index_1, index_2, index_3, index_4 + ).estimateGas(tx_params.as_dict()) + + +class OnErc1155ReceivedMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the onERC1155Received method.""" + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + contract_function: ContractFunction, + validator: Validator = None, + ): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs( + self, + index_0: str, + index_1: str, + index_2: int, + index_3: int, + index_4: Union[bytes, str], + ): + """Validate the inputs to the onERC1155Received method.""" + self.validator.assert_valid( + method_name="onERC1155Received", + parameter_name="index_0", + argument_value=index_0, + ) + index_0 = self.validate_and_checksum_address(index_0) + self.validator.assert_valid( + method_name="onERC1155Received", + parameter_name="index_1", + argument_value=index_1, + ) + index_1 = self.validate_and_checksum_address(index_1) + self.validator.assert_valid( + method_name="onERC1155Received", + parameter_name="index_2", + argument_value=index_2, + ) + # safeguard against fractional inputs + index_2 = int(index_2) + self.validator.assert_valid( + method_name="onERC1155Received", + parameter_name="index_3", + argument_value=index_3, + ) + # safeguard against fractional inputs + index_3 = int(index_3) + self.validator.assert_valid( + method_name="onERC1155Received", + parameter_name="index_4", + argument_value=index_4, + ) + return (index_0, index_1, index_2, index_3, index_4) + + def call( + self, + index_0: str, + index_1: str, + index_2: int, + index_3: int, + index_4: Union[bytes, str], + tx_params: Optional[TxParams] = None, + ) -> Union[bytes, str]: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + ( + index_0, + index_1, + index_2, + index_3, + index_4, + ) = self.validate_and_normalize_inputs( + index_0, index_1, index_2, index_3, index_4 + ) + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method( + index_0, index_1, index_2, index_3, index_4 + ).call(tx_params.as_dict()) + return Union[bytes, str](returned) + + def send_transaction( + self, + index_0: str, + index_1: str, + index_2: int, + index_3: int, + index_4: Union[bytes, str], + tx_params: Optional[TxParams] = None, + ) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + ( + index_0, + index_1, + index_2, + index_3, + index_4, + ) = self.validate_and_normalize_inputs( + index_0, index_1, index_2, index_3, index_4 + ) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method( + index_0, index_1, index_2, index_3, index_4 + ).transact(tx_params.as_dict()) + + def build_transaction( + self, + index_0: str, + index_1: str, + index_2: int, + index_3: int, + index_4: Union[bytes, str], + tx_params: Optional[TxParams] = None, + ) -> dict: + """Construct calldata to be used as input to the method.""" + ( + index_0, + index_1, + index_2, + index_3, + index_4, + ) = self.validate_and_normalize_inputs( + index_0, index_1, index_2, index_3, index_4 + ) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method( + index_0, index_1, index_2, index_3, index_4 + ).buildTransaction(tx_params.as_dict()) + + def estimate_gas( + self, + index_0: str, + index_1: str, + index_2: int, + index_3: int, + index_4: Union[bytes, str], + tx_params: Optional[TxParams] = None, + ) -> int: + """Estimate gas consumption of method call.""" + ( + index_0, + index_1, + index_2, + index_3, + index_4, + ) = self.validate_and_normalize_inputs( + index_0, index_1, index_2, index_3, index_4 + ) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method( + index_0, index_1, index_2, index_3, index_4 + ).estimateGas(tx_params.as_dict()) + + +class OnErc721ReceivedMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the onERC721Received method.""" + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + contract_function: ContractFunction, + validator: Validator = None, + ): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs( + self, + index_0: str, + index_1: str, + index_2: int, + index_3: Union[bytes, str], + ): + """Validate the inputs to the onERC721Received method.""" + self.validator.assert_valid( + method_name="onERC721Received", + parameter_name="index_0", + argument_value=index_0, + ) + index_0 = self.validate_and_checksum_address(index_0) + self.validator.assert_valid( + method_name="onERC721Received", + parameter_name="index_1", + argument_value=index_1, + ) + index_1 = self.validate_and_checksum_address(index_1) + self.validator.assert_valid( + method_name="onERC721Received", + parameter_name="index_2", + argument_value=index_2, + ) + # safeguard against fractional inputs + index_2 = int(index_2) + self.validator.assert_valid( + method_name="onERC721Received", + parameter_name="index_3", + argument_value=index_3, + ) + return (index_0, index_1, index_2, index_3) + + def call( + self, + index_0: str, + index_1: str, + index_2: int, + index_3: Union[bytes, str], + tx_params: Optional[TxParams] = None, + ) -> Union[bytes, str]: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + ( + index_0, + index_1, + index_2, + index_3, + ) = self.validate_and_normalize_inputs( + index_0, index_1, index_2, index_3 + ) + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method( + index_0, index_1, index_2, index_3 + ).call(tx_params.as_dict()) + return Union[bytes, str](returned) + + def send_transaction( + self, + index_0: str, + index_1: str, + index_2: int, + index_3: Union[bytes, str], + tx_params: Optional[TxParams] = None, + ) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + ( + index_0, + index_1, + index_2, + index_3, + ) = self.validate_and_normalize_inputs( + index_0, index_1, index_2, index_3 + ) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method( + index_0, index_1, index_2, index_3 + ).transact(tx_params.as_dict()) + + def build_transaction( + self, + index_0: str, + index_1: str, + index_2: int, + index_3: Union[bytes, str], + tx_params: Optional[TxParams] = None, + ) -> dict: + """Construct calldata to be used as input to the method.""" + ( + index_0, + index_1, + index_2, + index_3, + ) = self.validate_and_normalize_inputs( + index_0, index_1, index_2, index_3 + ) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method( + index_0, index_1, index_2, index_3 + ).buildTransaction(tx_params.as_dict()) + + def estimate_gas( + self, + index_0: str, + index_1: str, + index_2: int, + index_3: Union[bytes, str], + tx_params: Optional[TxParams] = None, + ) -> int: + """Estimate gas consumption of method call.""" + ( + index_0, + index_1, + index_2, + index_3, + ) = self.validate_and_normalize_inputs( + index_0, index_1, index_2, index_3 + ) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method( + index_0, index_1, index_2, index_3 + ).estimateGas(tx_params.as_dict()) + + +class PauseMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the pause method.""" + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + contract_function: ContractFunction, + ): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address) + self._underlying_method = contract_function + + def call(self, tx_params: Optional[TxParams] = None) -> None: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + tx_params = super().normalize_tx_params(tx_params) + self._underlying_method().call(tx_params.as_dict()) + + def send_transaction( + self, tx_params: Optional[TxParams] = None + ) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method().transact(tx_params.as_dict()) + + def build_transaction(self, tx_params: Optional[TxParams] = None) -> dict: + """Construct calldata to be used as input to the method.""" + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method().buildTransaction(tx_params.as_dict()) + + def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int: + """Estimate gas consumption of method call.""" + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method().estimateGas(tx_params.as_dict()) + + +class PausedMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the paused method.""" + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + contract_function: ContractFunction, + ): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address) + self._underlying_method = contract_function + + def call(self, tx_params: Optional[TxParams] = None) -> bool: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method().call(tx_params.as_dict()) + return bool(returned) + + def send_transaction( + self, tx_params: Optional[TxParams] = None + ) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method().transact(tx_params.as_dict()) + + def build_transaction(self, tx_params: Optional[TxParams] = None) -> dict: + """Construct calldata to be used as input to the method.""" + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method().buildTransaction(tx_params.as_dict()) + + def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int: + """Estimate gas consumption of method call.""" + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method().estimateGas(tx_params.as_dict()) + + +class RedeemErc20Method(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the redeemERC20 method.""" + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + contract_function: ContractFunction, + validator: Validator = None, + ): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs(self, nft_id: int, amount: int): + """Validate the inputs to the redeemERC20 method.""" + self.validator.assert_valid( + method_name="redeemERC20", + parameter_name="_nftId", + argument_value=nft_id, + ) + # safeguard against fractional inputs + nft_id = int(nft_id) + self.validator.assert_valid( + method_name="redeemERC20", + parameter_name="_amount", + argument_value=amount, + ) + # safeguard against fractional inputs + amount = int(amount) + return (nft_id, amount) + + def call( + self, nft_id: int, amount: int, tx_params: Optional[TxParams] = None + ) -> None: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (nft_id, amount) = self.validate_and_normalize_inputs(nft_id, amount) + tx_params = super().normalize_tx_params(tx_params) + self._underlying_method(nft_id, amount).call(tx_params.as_dict()) + + def send_transaction( + self, nft_id: int, amount: int, tx_params: Optional[TxParams] = None + ) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (nft_id, amount) = self.validate_and_normalize_inputs(nft_id, amount) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(nft_id, amount).transact( + tx_params.as_dict() + ) + + def build_transaction( + self, nft_id: int, amount: int, tx_params: Optional[TxParams] = None + ) -> dict: + """Construct calldata to be used as input to the method.""" + (nft_id, amount) = self.validate_and_normalize_inputs(nft_id, amount) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(nft_id, amount).buildTransaction( + tx_params.as_dict() + ) + + def estimate_gas( + self, nft_id: int, amount: int, tx_params: Optional[TxParams] = None + ) -> int: + """Estimate gas consumption of method call.""" + (nft_id, amount) = self.validate_and_normalize_inputs(nft_id, amount) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(nft_id, amount).estimateGas( + tx_params.as_dict() + ) + + +class RedeemErc721Method(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the redeemERC721 method.""" + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + contract_function: ContractFunction, + validator: Validator = None, + ): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs(self, nft_id: int): + """Validate the inputs to the redeemERC721 method.""" + self.validator.assert_valid( + method_name="redeemERC721", + parameter_name="_nftId", + argument_value=nft_id, + ) + # safeguard against fractional inputs + nft_id = int(nft_id) + return nft_id + + def call(self, nft_id: int, tx_params: Optional[TxParams] = None) -> None: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (nft_id) = self.validate_and_normalize_inputs(nft_id) + tx_params = super().normalize_tx_params(tx_params) + self._underlying_method(nft_id).call(tx_params.as_dict()) + + def send_transaction( + self, nft_id: int, tx_params: Optional[TxParams] = None + ) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (nft_id) = self.validate_and_normalize_inputs(nft_id) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(nft_id).transact(tx_params.as_dict()) + + def build_transaction( + self, nft_id: int, tx_params: Optional[TxParams] = None + ) -> dict: + """Construct calldata to be used as input to the method.""" + (nft_id) = self.validate_and_normalize_inputs(nft_id) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(nft_id).buildTransaction( + tx_params.as_dict() + ) + + def estimate_gas( + self, nft_id: int, tx_params: Optional[TxParams] = None + ) -> int: + """Estimate gas consumption of method call.""" + (nft_id) = self.validate_and_normalize_inputs(nft_id) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(nft_id).estimateGas(tx_params.as_dict()) + + +class RenounceRoleMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the renounceRole method.""" + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + contract_function: ContractFunction, + validator: Validator = None, + ): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs( + self, role: Union[bytes, str], account: str + ): + """Validate the inputs to the renounceRole method.""" + self.validator.assert_valid( + method_name="renounceRole", + parameter_name="role", + argument_value=role, + ) + self.validator.assert_valid( + method_name="renounceRole", + parameter_name="account", + argument_value=account, + ) + account = self.validate_and_checksum_address(account) + return (role, account) + + def call( + self, + role: Union[bytes, str], + account: str, + tx_params: Optional[TxParams] = None, + ) -> None: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (role, account) = self.validate_and_normalize_inputs(role, account) + tx_params = super().normalize_tx_params(tx_params) + self._underlying_method(role, account).call(tx_params.as_dict()) + + def send_transaction( + self, + role: Union[bytes, str], + account: str, + tx_params: Optional[TxParams] = None, + ) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (role, account) = self.validate_and_normalize_inputs(role, account) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(role, account).transact( + tx_params.as_dict() + ) + + def build_transaction( + self, + role: Union[bytes, str], + account: str, + tx_params: Optional[TxParams] = None, + ) -> dict: + """Construct calldata to be used as input to the method.""" + (role, account) = self.validate_and_normalize_inputs(role, account) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(role, account).buildTransaction( + tx_params.as_dict() + ) + + def estimate_gas( + self, + role: Union[bytes, str], + account: str, + tx_params: Optional[TxParams] = None, + ) -> int: + """Estimate gas consumption of method call.""" + (role, account) = self.validate_and_normalize_inputs(role, account) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(role, account).estimateGas( + tx_params.as_dict() + ) + + +class RevokeRoleMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the revokeRole method.""" + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + contract_function: ContractFunction, + validator: Validator = None, + ): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs( + self, role: Union[bytes, str], account: str + ): + """Validate the inputs to the revokeRole method.""" + self.validator.assert_valid( + method_name="revokeRole", + parameter_name="role", + argument_value=role, + ) + self.validator.assert_valid( + method_name="revokeRole", + parameter_name="account", + argument_value=account, + ) + account = self.validate_and_checksum_address(account) + return (role, account) + + def call( + self, + role: Union[bytes, str], + account: str, + tx_params: Optional[TxParams] = None, + ) -> None: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (role, account) = self.validate_and_normalize_inputs(role, account) + tx_params = super().normalize_tx_params(tx_params) + self._underlying_method(role, account).call(tx_params.as_dict()) + + def send_transaction( + self, + role: Union[bytes, str], + account: str, + tx_params: Optional[TxParams] = None, + ) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (role, account) = self.validate_and_normalize_inputs(role, account) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(role, account).transact( + tx_params.as_dict() + ) + + def build_transaction( + self, + role: Union[bytes, str], + account: str, + tx_params: Optional[TxParams] = None, + ) -> dict: + """Construct calldata to be used as input to the method.""" + (role, account) = self.validate_and_normalize_inputs(role, account) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(role, account).buildTransaction( + tx_params.as_dict() + ) + + def estimate_gas( + self, + role: Union[bytes, str], + account: str, + tx_params: Optional[TxParams] = None, + ) -> int: + """Estimate gas consumption of method call.""" + (role, account) = self.validate_and_normalize_inputs(role, account) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(role, account).estimateGas( + tx_params.as_dict() + ) + + +class RoyaltyBpsMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the royaltyBps method.""" + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + contract_function: ContractFunction, + ): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address) + self._underlying_method = contract_function + + def call(self, tx_params: Optional[TxParams] = None) -> int: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method().call(tx_params.as_dict()) + return int(returned) + + def send_transaction( + self, tx_params: Optional[TxParams] = None + ) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method().transact(tx_params.as_dict()) + + def build_transaction(self, tx_params: Optional[TxParams] = None) -> dict: + """Construct calldata to be used as input to the method.""" + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method().buildTransaction(tx_params.as_dict()) + + def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int: + """Estimate gas consumption of method call.""" + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method().estimateGas(tx_params.as_dict()) + + +class RoyaltyInfoMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the royaltyInfo method.""" + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + contract_function: ContractFunction, + validator: Validator = None, + ): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs(self, index_0: int, sale_price: int): + """Validate the inputs to the royaltyInfo method.""" + self.validator.assert_valid( + method_name="royaltyInfo", + parameter_name="index_0", + argument_value=index_0, + ) + # safeguard against fractional inputs + index_0 = int(index_0) + self.validator.assert_valid( + method_name="royaltyInfo", + parameter_name="salePrice", + argument_value=sale_price, + ) + # safeguard against fractional inputs + sale_price = int(sale_price) + return (index_0, sale_price) + + def call( + self, + index_0: int, + sale_price: int, + tx_params: Optional[TxParams] = None, + ) -> Tuple[str, int]: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (index_0, sale_price) = self.validate_and_normalize_inputs( + index_0, sale_price + ) + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method(index_0, sale_price).call( + tx_params.as_dict() + ) + return ( + returned[0], + returned[1], + ) + + def send_transaction( + self, + index_0: int, + sale_price: int, + tx_params: Optional[TxParams] = None, + ) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (index_0, sale_price) = self.validate_and_normalize_inputs( + index_0, sale_price + ) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(index_0, sale_price).transact( + tx_params.as_dict() + ) + + def build_transaction( + self, + index_0: int, + sale_price: int, + tx_params: Optional[TxParams] = None, + ) -> dict: + """Construct calldata to be used as input to the method.""" + (index_0, sale_price) = self.validate_and_normalize_inputs( + index_0, sale_price + ) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(index_0, sale_price).buildTransaction( + tx_params.as_dict() + ) + + def estimate_gas( + self, + index_0: int, + sale_price: int, + tx_params: Optional[TxParams] = None, + ) -> int: + """Estimate gas consumption of method call.""" + (index_0, sale_price) = self.validate_and_normalize_inputs( + index_0, sale_price + ) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(index_0, sale_price).estimateGas( + tx_params.as_dict() + ) + + +class SafeBatchTransferFromMethod( + ContractMethod +): # pylint: disable=invalid-name + """Various interfaces to the safeBatchTransferFrom method.""" + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + contract_function: ContractFunction, + validator: Validator = None, + ): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs( + self, + _from: str, + to: str, + ids: List[int], + amounts: List[int], + data: Union[bytes, str], + ): + """Validate the inputs to the safeBatchTransferFrom method.""" + self.validator.assert_valid( + method_name="safeBatchTransferFrom", + parameter_name="from", + argument_value=_from, + ) + _from = self.validate_and_checksum_address(_from) + self.validator.assert_valid( + method_name="safeBatchTransferFrom", + parameter_name="to", + argument_value=to, + ) + to = self.validate_and_checksum_address(to) + self.validator.assert_valid( + method_name="safeBatchTransferFrom", + parameter_name="ids", + argument_value=ids, + ) + self.validator.assert_valid( + method_name="safeBatchTransferFrom", + parameter_name="amounts", + argument_value=amounts, + ) + self.validator.assert_valid( + method_name="safeBatchTransferFrom", + parameter_name="data", + argument_value=data, + ) + return (_from, to, ids, amounts, data) + + def call( + self, + _from: str, + to: str, + ids: List[int], + amounts: List[int], + data: Union[bytes, str], + tx_params: Optional[TxParams] = None, + ) -> None: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (_from, to, ids, amounts, data) = self.validate_and_normalize_inputs( + _from, to, ids, amounts, data + ) + tx_params = super().normalize_tx_params(tx_params) + self._underlying_method(_from, to, ids, amounts, data).call( + tx_params.as_dict() + ) + + def send_transaction( + self, + _from: str, + to: str, + ids: List[int], + amounts: List[int], + data: Union[bytes, str], + tx_params: Optional[TxParams] = None, + ) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (_from, to, ids, amounts, data) = self.validate_and_normalize_inputs( + _from, to, ids, amounts, data + ) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(_from, to, ids, amounts, data).transact( + tx_params.as_dict() + ) + + def build_transaction( + self, + _from: str, + to: str, + ids: List[int], + amounts: List[int], + data: Union[bytes, str], + tx_params: Optional[TxParams] = None, + ) -> dict: + """Construct calldata to be used as input to the method.""" + (_from, to, ids, amounts, data) = self.validate_and_normalize_inputs( + _from, to, ids, amounts, data + ) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method( + _from, to, ids, amounts, data + ).buildTransaction(tx_params.as_dict()) + + def estimate_gas( + self, + _from: str, + to: str, + ids: List[int], + amounts: List[int], + data: Union[bytes, str], + tx_params: Optional[TxParams] = None, + ) -> int: + """Estimate gas consumption of method call.""" + (_from, to, ids, amounts, data) = self.validate_and_normalize_inputs( + _from, to, ids, amounts, data + ) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method( + _from, to, ids, amounts, data + ).estimateGas(tx_params.as_dict()) + + +class SafeTransferFromMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the safeTransferFrom method.""" + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + contract_function: ContractFunction, + validator: Validator = None, + ): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs( + self, + _from: str, + to: str, + _id: int, + amount: int, + data: Union[bytes, str], + ): + """Validate the inputs to the safeTransferFrom method.""" + self.validator.assert_valid( + method_name="safeTransferFrom", + parameter_name="from", + argument_value=_from, + ) + _from = self.validate_and_checksum_address(_from) + self.validator.assert_valid( + method_name="safeTransferFrom", + parameter_name="to", + argument_value=to, + ) + to = self.validate_and_checksum_address(to) + self.validator.assert_valid( + method_name="safeTransferFrom", + parameter_name="id", + argument_value=_id, + ) + # safeguard against fractional inputs + _id = int(_id) + self.validator.assert_valid( + method_name="safeTransferFrom", + parameter_name="amount", + argument_value=amount, + ) + # safeguard against fractional inputs + amount = int(amount) + self.validator.assert_valid( + method_name="safeTransferFrom", + parameter_name="data", + argument_value=data, + ) + return (_from, to, _id, amount, data) + + def call( + self, + _from: str, + to: str, + _id: int, + amount: int, + data: Union[bytes, str], + tx_params: Optional[TxParams] = None, + ) -> None: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (_from, to, _id, amount, data) = self.validate_and_normalize_inputs( + _from, to, _id, amount, data + ) + tx_params = super().normalize_tx_params(tx_params) + self._underlying_method(_from, to, _id, amount, data).call( + tx_params.as_dict() + ) + + def send_transaction( + self, + _from: str, + to: str, + _id: int, + amount: int, + data: Union[bytes, str], + tx_params: Optional[TxParams] = None, + ) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (_from, to, _id, amount, data) = self.validate_and_normalize_inputs( + _from, to, _id, amount, data + ) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(_from, to, _id, amount, data).transact( + tx_params.as_dict() + ) + + def build_transaction( + self, + _from: str, + to: str, + _id: int, + amount: int, + data: Union[bytes, str], + tx_params: Optional[TxParams] = None, + ) -> dict: + """Construct calldata to be used as input to the method.""" + (_from, to, _id, amount, data) = self.validate_and_normalize_inputs( + _from, to, _id, amount, data + ) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method( + _from, to, _id, amount, data + ).buildTransaction(tx_params.as_dict()) + + def estimate_gas( + self, + _from: str, + to: str, + _id: int, + amount: int, + data: Union[bytes, str], + tx_params: Optional[TxParams] = None, + ) -> int: + """Estimate gas consumption of method call.""" + (_from, to, _id, amount, data) = self.validate_and_normalize_inputs( + _from, to, _id, amount, data + ) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method( + _from, to, _id, amount, data + ).estimateGas(tx_params.as_dict()) + + +class SetApprovalForAllMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the setApprovalForAll method.""" + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + contract_function: ContractFunction, + validator: Validator = None, + ): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs(self, operator: str, approved: bool): + """Validate the inputs to the setApprovalForAll method.""" + self.validator.assert_valid( + method_name="setApprovalForAll", + parameter_name="operator", + argument_value=operator, + ) + operator = self.validate_and_checksum_address(operator) + self.validator.assert_valid( + method_name="setApprovalForAll", + parameter_name="approved", + argument_value=approved, + ) + return (operator, approved) + + def call( + self, + operator: str, + approved: bool, + tx_params: Optional[TxParams] = None, + ) -> None: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (operator, approved) = self.validate_and_normalize_inputs( + operator, approved + ) + tx_params = super().normalize_tx_params(tx_params) + self._underlying_method(operator, approved).call(tx_params.as_dict()) + + def send_transaction( + self, + operator: str, + approved: bool, + tx_params: Optional[TxParams] = None, + ) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (operator, approved) = self.validate_and_normalize_inputs( + operator, approved + ) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(operator, approved).transact( + tx_params.as_dict() + ) + + def build_transaction( + self, + operator: str, + approved: bool, + tx_params: Optional[TxParams] = None, + ) -> dict: + """Construct calldata to be used as input to the method.""" + (operator, approved) = self.validate_and_normalize_inputs( + operator, approved + ) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(operator, approved).buildTransaction( + tx_params.as_dict() + ) + + def estimate_gas( + self, + operator: str, + approved: bool, + tx_params: Optional[TxParams] = None, + ) -> int: + """Estimate gas consumption of method call.""" + (operator, approved) = self.validate_and_normalize_inputs( + operator, approved + ) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(operator, approved).estimateGas( + tx_params.as_dict() + ) + + +class SetContractUriMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the setContractURI method.""" + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + contract_function: ContractFunction, + validator: Validator = None, + ): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs(self, uri: str): + """Validate the inputs to the setContractURI method.""" + self.validator.assert_valid( + method_name="setContractURI", + parameter_name="_URI", + argument_value=uri, + ) + return uri + + def call(self, uri: str, tx_params: Optional[TxParams] = None) -> None: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (uri) = self.validate_and_normalize_inputs(uri) + tx_params = super().normalize_tx_params(tx_params) + self._underlying_method(uri).call(tx_params.as_dict()) + + def send_transaction( + self, uri: str, tx_params: Optional[TxParams] = None + ) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (uri) = self.validate_and_normalize_inputs(uri) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(uri).transact(tx_params.as_dict()) + + def build_transaction( + self, uri: str, tx_params: Optional[TxParams] = None + ) -> dict: + """Construct calldata to be used as input to the method.""" + (uri) = self.validate_and_normalize_inputs(uri) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(uri).buildTransaction( + tx_params.as_dict() + ) + + def estimate_gas( + self, uri: str, tx_params: Optional[TxParams] = None + ) -> int: + """Estimate gas consumption of method call.""" + (uri) = self.validate_and_normalize_inputs(uri) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(uri).estimateGas(tx_params.as_dict()) + + +class SetRestrictedTransferMethod( + ContractMethod +): # pylint: disable=invalid-name + """Various interfaces to the setRestrictedTransfer method.""" + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + contract_function: ContractFunction, + validator: Validator = None, + ): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs(self, restricted_transfer: bool): + """Validate the inputs to the setRestrictedTransfer method.""" + self.validator.assert_valid( + method_name="setRestrictedTransfer", + parameter_name="_restrictedTransfer", + argument_value=restricted_transfer, + ) + return restricted_transfer + + def call( + self, restricted_transfer: bool, tx_params: Optional[TxParams] = None + ) -> None: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (restricted_transfer) = self.validate_and_normalize_inputs( + restricted_transfer + ) + tx_params = super().normalize_tx_params(tx_params) + self._underlying_method(restricted_transfer).call(tx_params.as_dict()) + + def send_transaction( + self, restricted_transfer: bool, tx_params: Optional[TxParams] = None + ) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (restricted_transfer) = self.validate_and_normalize_inputs( + restricted_transfer + ) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(restricted_transfer).transact( + tx_params.as_dict() + ) + + def build_transaction( + self, restricted_transfer: bool, tx_params: Optional[TxParams] = None + ) -> dict: + """Construct calldata to be used as input to the method.""" + (restricted_transfer) = self.validate_and_normalize_inputs( + restricted_transfer + ) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(restricted_transfer).buildTransaction( + tx_params.as_dict() + ) + + def estimate_gas( + self, restricted_transfer: bool, tx_params: Optional[TxParams] = None + ) -> int: + """Estimate gas consumption of method call.""" + (restricted_transfer) = self.validate_and_normalize_inputs( + restricted_transfer + ) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(restricted_transfer).estimateGas( + tx_params.as_dict() + ) + + +class SetRoyaltyBpsMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the setRoyaltyBps method.""" + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + contract_function: ContractFunction, + validator: Validator = None, + ): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs(self, royalty_bps: int): + """Validate the inputs to the setRoyaltyBps method.""" + self.validator.assert_valid( + method_name="setRoyaltyBps", + parameter_name="_royaltyBps", + argument_value=royalty_bps, + ) + # safeguard against fractional inputs + royalty_bps = int(royalty_bps) + return royalty_bps + + def call( + self, royalty_bps: int, tx_params: Optional[TxParams] = None + ) -> None: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (royalty_bps) = self.validate_and_normalize_inputs(royalty_bps) + tx_params = super().normalize_tx_params(tx_params) + self._underlying_method(royalty_bps).call(tx_params.as_dict()) + + def send_transaction( + self, royalty_bps: int, tx_params: Optional[TxParams] = None + ) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (royalty_bps) = self.validate_and_normalize_inputs(royalty_bps) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(royalty_bps).transact( + tx_params.as_dict() + ) + + def build_transaction( + self, royalty_bps: int, tx_params: Optional[TxParams] = None + ) -> dict: + """Construct calldata to be used as input to the method.""" + (royalty_bps) = self.validate_and_normalize_inputs(royalty_bps) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(royalty_bps).buildTransaction( + tx_params.as_dict() + ) + + def estimate_gas( + self, royalty_bps: int, tx_params: Optional[TxParams] = None + ) -> int: + """Estimate gas consumption of method call.""" + (royalty_bps) = self.validate_and_normalize_inputs(royalty_bps) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(royalty_bps).estimateGas( + tx_params.as_dict() + ) + + +class SupportsInterfaceMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the supportsInterface method.""" + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + contract_function: ContractFunction, + validator: Validator = None, + ): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs(self, interface_id: Union[bytes, str]): + """Validate the inputs to the supportsInterface method.""" + self.validator.assert_valid( + method_name="supportsInterface", + parameter_name="interfaceId", + argument_value=interface_id, + ) + return interface_id + + def call( + self, + interface_id: Union[bytes, str], + tx_params: Optional[TxParams] = None, + ) -> bool: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (interface_id) = self.validate_and_normalize_inputs(interface_id) + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method(interface_id).call( + tx_params.as_dict() + ) + return bool(returned) + + def send_transaction( + self, + interface_id: Union[bytes, str], + tx_params: Optional[TxParams] = None, + ) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (interface_id) = self.validate_and_normalize_inputs(interface_id) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(interface_id).transact( + tx_params.as_dict() + ) + + def build_transaction( + self, + interface_id: Union[bytes, str], + tx_params: Optional[TxParams] = None, + ) -> dict: + """Construct calldata to be used as input to the method.""" + (interface_id) = self.validate_and_normalize_inputs(interface_id) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(interface_id).buildTransaction( + tx_params.as_dict() + ) + + def estimate_gas( + self, + interface_id: Union[bytes, str], + tx_params: Optional[TxParams] = None, + ) -> int: + """Estimate gas consumption of method call.""" + (interface_id) = self.validate_and_normalize_inputs(interface_id) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(interface_id).estimateGas( + tx_params.as_dict() + ) + + +class TokenStateMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the tokenState method.""" + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + contract_function: ContractFunction, + validator: Validator = None, + ): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs(self, index_0: int): + """Validate the inputs to the tokenState method.""" + self.validator.assert_valid( + method_name="tokenState", + parameter_name="index_0", + argument_value=index_0, + ) + # safeguard against fractional inputs + index_0 = int(index_0) + return index_0 + + def call( + self, index_0: int, tx_params: Optional[TxParams] = None + ) -> Tuple[str, str, int]: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (index_0) = self.validate_and_normalize_inputs(index_0) + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method(index_0).call(tx_params.as_dict()) + return ( + returned[0], + returned[1], + returned[2], + ) + + def send_transaction( + self, index_0: int, tx_params: Optional[TxParams] = None + ) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (index_0) = self.validate_and_normalize_inputs(index_0) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(index_0).transact(tx_params.as_dict()) + + def build_transaction( + self, index_0: int, tx_params: Optional[TxParams] = None + ) -> dict: + """Construct calldata to be used as input to the method.""" + (index_0) = self.validate_and_normalize_inputs(index_0) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(index_0).buildTransaction( + tx_params.as_dict() + ) + + def estimate_gas( + self, index_0: int, tx_params: Optional[TxParams] = None + ) -> int: + """Estimate gas consumption of method call.""" + (index_0) = self.validate_and_normalize_inputs(index_0) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(index_0).estimateGas( + tx_params.as_dict() + ) + + +class TokenUriMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the tokenURI method.""" + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + contract_function: ContractFunction, + validator: Validator = None, + ): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs(self, nft_id: int): + """Validate the inputs to the tokenURI method.""" + self.validator.assert_valid( + method_name="tokenURI", + parameter_name="_nftId", + argument_value=nft_id, + ) + # safeguard against fractional inputs + nft_id = int(nft_id) + return nft_id + + def call(self, nft_id: int, tx_params: Optional[TxParams] = None) -> str: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (nft_id) = self.validate_and_normalize_inputs(nft_id) + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method(nft_id).call(tx_params.as_dict()) + return str(returned) + + def send_transaction( + self, nft_id: int, tx_params: Optional[TxParams] = None + ) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (nft_id) = self.validate_and_normalize_inputs(nft_id) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(nft_id).transact(tx_params.as_dict()) + + def build_transaction( + self, nft_id: int, tx_params: Optional[TxParams] = None + ) -> dict: + """Construct calldata to be used as input to the method.""" + (nft_id) = self.validate_and_normalize_inputs(nft_id) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(nft_id).buildTransaction( + tx_params.as_dict() + ) + + def estimate_gas( + self, nft_id: int, tx_params: Optional[TxParams] = None + ) -> int: + """Estimate gas consumption of method call.""" + (nft_id) = self.validate_and_normalize_inputs(nft_id) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(nft_id).estimateGas(tx_params.as_dict()) + + +class TotalSupplyMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the totalSupply method.""" + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + contract_function: ContractFunction, + validator: Validator = None, + ): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs(self, _id: int): + """Validate the inputs to the totalSupply method.""" + self.validator.assert_valid( + method_name="totalSupply", + parameter_name="id", + argument_value=_id, + ) + # safeguard against fractional inputs + _id = int(_id) + return _id + + def call(self, _id: int, tx_params: Optional[TxParams] = None) -> int: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (_id) = self.validate_and_normalize_inputs(_id) + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method(_id).call(tx_params.as_dict()) + return int(returned) + + def send_transaction( + self, _id: int, tx_params: Optional[TxParams] = None + ) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (_id) = self.validate_and_normalize_inputs(_id) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(_id).transact(tx_params.as_dict()) + + def build_transaction( + self, _id: int, tx_params: Optional[TxParams] = None + ) -> dict: + """Construct calldata to be used as input to the method.""" + (_id) = self.validate_and_normalize_inputs(_id) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(_id).buildTransaction( + tx_params.as_dict() + ) + + def estimate_gas( + self, _id: int, tx_params: Optional[TxParams] = None + ) -> int: + """Estimate gas consumption of method call.""" + (_id) = self.validate_and_normalize_inputs(_id) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(_id).estimateGas(tx_params.as_dict()) + + +class TransfersRestrictedMethod( + ContractMethod +): # pylint: disable=invalid-name + """Various interfaces to the transfersRestricted method.""" + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + contract_function: ContractFunction, + ): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address) + self._underlying_method = contract_function + + def call(self, tx_params: Optional[TxParams] = None) -> bool: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method().call(tx_params.as_dict()) + return bool(returned) + + def send_transaction( + self, tx_params: Optional[TxParams] = None + ) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method().transact(tx_params.as_dict()) + + def build_transaction(self, tx_params: Optional[TxParams] = None) -> dict: + """Construct calldata to be used as input to the method.""" + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method().buildTransaction(tx_params.as_dict()) + + def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int: + """Estimate gas consumption of method call.""" + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method().estimateGas(tx_params.as_dict()) + + +class UnpauseMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the unpause method.""" + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + contract_function: ContractFunction, + ): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address) + self._underlying_method = contract_function + + def call(self, tx_params: Optional[TxParams] = None) -> None: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + tx_params = super().normalize_tx_params(tx_params) + self._underlying_method().call(tx_params.as_dict()) + + def send_transaction( + self, tx_params: Optional[TxParams] = None + ) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method().transact(tx_params.as_dict()) + + def build_transaction(self, tx_params: Optional[TxParams] = None) -> dict: + """Construct calldata to be used as input to the method.""" + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method().buildTransaction(tx_params.as_dict()) + + def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int: + """Estimate gas consumption of method call.""" + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method().estimateGas(tx_params.as_dict()) + + +class UriMethod(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the uri method.""" + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + contract_function: ContractFunction, + validator: Validator = None, + ): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs(self, nft_id: int): + """Validate the inputs to the uri method.""" + self.validator.assert_valid( + method_name="uri", + parameter_name="_nftId", + argument_value=nft_id, + ) + # safeguard against fractional inputs + nft_id = int(nft_id) + return nft_id + + def call(self, nft_id: int, tx_params: Optional[TxParams] = None) -> str: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (nft_id) = self.validate_and_normalize_inputs(nft_id) + tx_params = super().normalize_tx_params(tx_params) + returned = self._underlying_method(nft_id).call(tx_params.as_dict()) + return str(returned) + + def send_transaction( + self, nft_id: int, tx_params: Optional[TxParams] = None + ) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (nft_id) = self.validate_and_normalize_inputs(nft_id) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(nft_id).transact(tx_params.as_dict()) + + def build_transaction( + self, nft_id: int, tx_params: Optional[TxParams] = None + ) -> dict: + """Construct calldata to be used as input to the method.""" + (nft_id) = self.validate_and_normalize_inputs(nft_id) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(nft_id).buildTransaction( + tx_params.as_dict() + ) + + def estimate_gas( + self, nft_id: int, tx_params: Optional[TxParams] = None + ) -> int: + """Estimate gas consumption of method call.""" + (nft_id) = self.validate_and_normalize_inputs(nft_id) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method(nft_id).estimateGas(tx_params.as_dict()) + + +class WrapErc20Method(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the wrapERC20 method.""" + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + contract_function: ContractFunction, + validator: Validator = None, + ): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs( + self, + token_contract: str, + token_amount: int, + num_of_nfts_to_mint: int, + nft_uri: str, + ): + """Validate the inputs to the wrapERC20 method.""" + self.validator.assert_valid( + method_name="wrapERC20", + parameter_name="_tokenContract", + argument_value=token_contract, + ) + token_contract = self.validate_and_checksum_address(token_contract) + self.validator.assert_valid( + method_name="wrapERC20", + parameter_name="_tokenAmount", + argument_value=token_amount, + ) + # safeguard against fractional inputs + token_amount = int(token_amount) + self.validator.assert_valid( + method_name="wrapERC20", + parameter_name="_numOfNftsToMint", + argument_value=num_of_nfts_to_mint, + ) + # safeguard against fractional inputs + num_of_nfts_to_mint = int(num_of_nfts_to_mint) + self.validator.assert_valid( + method_name="wrapERC20", + parameter_name="_nftURI", + argument_value=nft_uri, + ) + return (token_contract, token_amount, num_of_nfts_to_mint, nft_uri) + + def call( + self, + token_contract: str, + token_amount: int, + num_of_nfts_to_mint: int, + nft_uri: str, + tx_params: Optional[TxParams] = None, + ) -> None: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + ( + token_contract, + token_amount, + num_of_nfts_to_mint, + nft_uri, + ) = self.validate_and_normalize_inputs( + token_contract, token_amount, num_of_nfts_to_mint, nft_uri + ) + tx_params = super().normalize_tx_params(tx_params) + self._underlying_method( + token_contract, token_amount, num_of_nfts_to_mint, nft_uri + ).call(tx_params.as_dict()) + + def send_transaction( + self, + token_contract: str, + token_amount: int, + num_of_nfts_to_mint: int, + nft_uri: str, + tx_params: Optional[TxParams] = None, + ) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + ( + token_contract, + token_amount, + num_of_nfts_to_mint, + nft_uri, + ) = self.validate_and_normalize_inputs( + token_contract, token_amount, num_of_nfts_to_mint, nft_uri + ) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method( + token_contract, token_amount, num_of_nfts_to_mint, nft_uri + ).transact(tx_params.as_dict()) + + def build_transaction( + self, + token_contract: str, + token_amount: int, + num_of_nfts_to_mint: int, + nft_uri: str, + tx_params: Optional[TxParams] = None, + ) -> dict: + """Construct calldata to be used as input to the method.""" + ( + token_contract, + token_amount, + num_of_nfts_to_mint, + nft_uri, + ) = self.validate_and_normalize_inputs( + token_contract, token_amount, num_of_nfts_to_mint, nft_uri + ) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method( + token_contract, token_amount, num_of_nfts_to_mint, nft_uri + ).buildTransaction(tx_params.as_dict()) + + def estimate_gas( + self, + token_contract: str, + token_amount: int, + num_of_nfts_to_mint: int, + nft_uri: str, + tx_params: Optional[TxParams] = None, + ) -> int: + """Estimate gas consumption of method call.""" + ( + token_contract, + token_amount, + num_of_nfts_to_mint, + nft_uri, + ) = self.validate_and_normalize_inputs( + token_contract, token_amount, num_of_nfts_to_mint, nft_uri + ) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method( + token_contract, token_amount, num_of_nfts_to_mint, nft_uri + ).estimateGas(tx_params.as_dict()) + + +class WrapErc721Method(ContractMethod): # pylint: disable=invalid-name + """Various interfaces to the wrapERC721 method.""" + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + contract_function: ContractFunction, + validator: Validator = None, + ): + """Persist instance data.""" + super().__init__(web3_or_provider, contract_address, validator) + self._underlying_method = contract_function + + def validate_and_normalize_inputs( + self, nft_contract: str, token_id: int, nft_uri: str + ): + """Validate the inputs to the wrapERC721 method.""" + self.validator.assert_valid( + method_name="wrapERC721", + parameter_name="_nftContract", + argument_value=nft_contract, + ) + nft_contract = self.validate_and_checksum_address(nft_contract) + self.validator.assert_valid( + method_name="wrapERC721", + parameter_name="_tokenId", + argument_value=token_id, + ) + # safeguard against fractional inputs + token_id = int(token_id) + self.validator.assert_valid( + method_name="wrapERC721", + parameter_name="_nftURI", + argument_value=nft_uri, + ) + return (nft_contract, token_id, nft_uri) + + def call( + self, + nft_contract: str, + token_id: int, + nft_uri: str, + tx_params: Optional[TxParams] = None, + ) -> None: + """Execute underlying contract method via eth_call. + + :param tx_params: transaction parameters + :returns: the return value of the underlying method. + """ + (nft_contract, token_id, nft_uri) = self.validate_and_normalize_inputs( + nft_contract, token_id, nft_uri + ) + tx_params = super().normalize_tx_params(tx_params) + self._underlying_method(nft_contract, token_id, nft_uri).call( + tx_params.as_dict() + ) + + def send_transaction( + self, + nft_contract: str, + token_id: int, + nft_uri: str, + tx_params: Optional[TxParams] = None, + ) -> Union[HexBytes, bytes]: + """Execute underlying contract method via eth_sendTransaction. + + :param tx_params: transaction parameters + """ + (nft_contract, token_id, nft_uri) = self.validate_and_normalize_inputs( + nft_contract, token_id, nft_uri + ) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method( + nft_contract, token_id, nft_uri + ).transact(tx_params.as_dict()) + + def build_transaction( + self, + nft_contract: str, + token_id: int, + nft_uri: str, + tx_params: Optional[TxParams] = None, + ) -> dict: + """Construct calldata to be used as input to the method.""" + (nft_contract, token_id, nft_uri) = self.validate_and_normalize_inputs( + nft_contract, token_id, nft_uri + ) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method( + nft_contract, token_id, nft_uri + ).buildTransaction(tx_params.as_dict()) + + def estimate_gas( + self, + nft_contract: str, + token_id: int, + nft_uri: str, + tx_params: Optional[TxParams] = None, + ) -> int: + """Estimate gas consumption of method call.""" + (nft_contract, token_id, nft_uri) = self.validate_and_normalize_inputs( + nft_contract, token_id, nft_uri + ) + tx_params = super().normalize_tx_params(tx_params) + return self._underlying_method( + nft_contract, token_id, nft_uri + ).estimateGas(tx_params.as_dict()) + + +# pylint: disable=too-many-public-methods,too-many-instance-attributes +class NFTCollection: + """Wrapper class for NFTCollection Solidity contract. + + All method parameters of type `bytes`:code: should be encoded as UTF-8, + which can be accomplished via `str.encode("utf_8")`:code:. + """ + + default_admin_role: DefaultAdminRoleMethod + """Constructor-initialized instance of + :class:`DefaultAdminRoleMethod`. + """ + + minter_role: MinterRoleMethod + """Constructor-initialized instance of + :class:`MinterRoleMethod`. + """ + + pauser_role: PauserRoleMethod + """Constructor-initialized instance of + :class:`PauserRoleMethod`. + """ + + transfer_role: TransferRoleMethod + """Constructor-initialized instance of + :class:`TransferRoleMethod`. + """ + + contract_uri_: ContractUri_Method + """Constructor-initialized instance of + :class:`ContractUri_Method`. + """ + + balance_of: BalanceOfMethod + """Constructor-initialized instance of + :class:`BalanceOfMethod`. + """ + + balance_of_batch: BalanceOfBatchMethod + """Constructor-initialized instance of + :class:`BalanceOfBatchMethod`. + """ + + burn: BurnMethod + """Constructor-initialized instance of + :class:`BurnMethod`. + """ + + burn_batch: BurnBatchMethod + """Constructor-initialized instance of + :class:`BurnBatchMethod`. + """ + + contract_uri: ContractUriMethod + """Constructor-initialized instance of + :class:`ContractUriMethod`. + """ + + create_native_tokens: CreateNativeTokensMethod + """Constructor-initialized instance of + :class:`CreateNativeTokensMethod`. + """ + + creator: CreatorMethod + """Constructor-initialized instance of + :class:`CreatorMethod`. + """ + + erc20_wrapped_tokens: Erc20WrappedTokensMethod + """Constructor-initialized instance of + :class:`Erc20WrappedTokensMethod`. + """ + + erc721_wrapped_tokens: Erc721WrappedTokensMethod + """Constructor-initialized instance of + :class:`Erc721WrappedTokensMethod`. + """ + + get_role_admin: GetRoleAdminMethod + """Constructor-initialized instance of + :class:`GetRoleAdminMethod`. + """ + + get_role_member: GetRoleMemberMethod + """Constructor-initialized instance of + :class:`GetRoleMemberMethod`. + """ + + get_role_member_count: GetRoleMemberCountMethod + """Constructor-initialized instance of + :class:`GetRoleMemberCountMethod`. + """ + + grant_role: GrantRoleMethod + """Constructor-initialized instance of + :class:`GrantRoleMethod`. + """ + + has_role: HasRoleMethod + """Constructor-initialized instance of + :class:`HasRoleMethod`. + """ + + is_approved_for_all: IsApprovedForAllMethod + """Constructor-initialized instance of + :class:`IsApprovedForAllMethod`. + """ + + is_trusted_forwarder: IsTrustedForwarderMethod + """Constructor-initialized instance of + :class:`IsTrustedForwarderMethod`. + """ + + mint: MintMethod + """Constructor-initialized instance of + :class:`MintMethod`. + """ + + mint_batch: MintBatchMethod + """Constructor-initialized instance of + :class:`MintBatchMethod`. + """ + + multicall: MulticallMethod + """Constructor-initialized instance of + :class:`MulticallMethod`. + """ + + next_token_id: NextTokenIdMethod + """Constructor-initialized instance of + :class:`NextTokenIdMethod`. + """ + + on_erc1155_batch_received: OnErc1155BatchReceivedMethod + """Constructor-initialized instance of + :class:`OnErc1155BatchReceivedMethod`. + """ + + on_erc1155_received: OnErc1155ReceivedMethod + """Constructor-initialized instance of + :class:`OnErc1155ReceivedMethod`. + """ + + on_erc721_received: OnErc721ReceivedMethod + """Constructor-initialized instance of + :class:`OnErc721ReceivedMethod`. + """ + + pause: PauseMethod + """Constructor-initialized instance of + :class:`PauseMethod`. + """ + + paused: PausedMethod + """Constructor-initialized instance of + :class:`PausedMethod`. + """ + + redeem_erc20: RedeemErc20Method + """Constructor-initialized instance of + :class:`RedeemErc20Method`. + """ + + redeem_erc721: RedeemErc721Method + """Constructor-initialized instance of + :class:`RedeemErc721Method`. + """ + + renounce_role: RenounceRoleMethod + """Constructor-initialized instance of + :class:`RenounceRoleMethod`. + """ + + revoke_role: RevokeRoleMethod + """Constructor-initialized instance of + :class:`RevokeRoleMethod`. + """ + + royalty_bps: RoyaltyBpsMethod + """Constructor-initialized instance of + :class:`RoyaltyBpsMethod`. + """ + + royalty_info: RoyaltyInfoMethod + """Constructor-initialized instance of + :class:`RoyaltyInfoMethod`. + """ + + safe_batch_transfer_from: SafeBatchTransferFromMethod + """Constructor-initialized instance of + :class:`SafeBatchTransferFromMethod`. + """ + + safe_transfer_from: SafeTransferFromMethod + """Constructor-initialized instance of + :class:`SafeTransferFromMethod`. + """ + + set_approval_for_all: SetApprovalForAllMethod + """Constructor-initialized instance of + :class:`SetApprovalForAllMethod`. + """ + + set_contract_uri: SetContractUriMethod + """Constructor-initialized instance of + :class:`SetContractUriMethod`. + """ + + set_restricted_transfer: SetRestrictedTransferMethod + """Constructor-initialized instance of + :class:`SetRestrictedTransferMethod`. + """ + + set_royalty_bps: SetRoyaltyBpsMethod + """Constructor-initialized instance of + :class:`SetRoyaltyBpsMethod`. + """ + + supports_interface: SupportsInterfaceMethod + """Constructor-initialized instance of + :class:`SupportsInterfaceMethod`. + """ + + token_state: TokenStateMethod + """Constructor-initialized instance of + :class:`TokenStateMethod`. + """ + + token_uri: TokenUriMethod + """Constructor-initialized instance of + :class:`TokenUriMethod`. + """ + + total_supply: TotalSupplyMethod + """Constructor-initialized instance of + :class:`TotalSupplyMethod`. + """ + + transfers_restricted: TransfersRestrictedMethod + """Constructor-initialized instance of + :class:`TransfersRestrictedMethod`. + """ + + unpause: UnpauseMethod + """Constructor-initialized instance of + :class:`UnpauseMethod`. + """ + + uri: UriMethod + """Constructor-initialized instance of + :class:`UriMethod`. + """ + + wrap_erc20: WrapErc20Method + """Constructor-initialized instance of + :class:`WrapErc20Method`. + """ + + wrap_erc721: WrapErc721Method + """Constructor-initialized instance of + :class:`WrapErc721Method`. + """ + + def __init__( + self, + web3_or_provider: Union[Web3, BaseProvider], + contract_address: str, + validator: NFTCollectionValidator = None, + ): + """Get an instance of wrapper for smart contract. + + :param web3_or_provider: Either an instance of `web3.Web3`:code: or + `web3.providers.base.BaseProvider`:code: + :param contract_address: where the contract has been deployed + :param validator: for validation of method inputs. + """ + # pylint: disable=too-many-statements + + self.contract_address = contract_address + + if not validator: + validator = NFTCollectionValidator( + web3_or_provider, contract_address + ) + + web3 = None + if isinstance(web3_or_provider, BaseProvider): + web3 = Web3(web3_or_provider) + elif isinstance(web3_or_provider, Web3): + web3 = web3_or_provider + else: + raise TypeError( + "Expected parameter 'web3_or_provider' to be an instance of either" + + " Web3 or BaseProvider" + ) + + # if any middleware was imported, inject it + try: + MIDDLEWARE + except NameError: + pass + else: + try: + for middleware in MIDDLEWARE: + web3.middleware_onion.inject( + middleware["function"], + layer=middleware["layer"], + ) + except ValueError as value_error: + if value_error.args == ( + "You can't add the same un-named instance twice", + ): + pass + + self._web3_eth = web3.eth + + functions = self._web3_eth.contract( + address=to_checksum_address(contract_address), + abi=NFTCollection.abi(), + ).functions + + self.default_admin_role = DefaultAdminRoleMethod( + web3_or_provider, contract_address, functions.DEFAULT_ADMIN_ROLE + ) + + self.minter_role = MinterRoleMethod( + web3_or_provider, contract_address, functions.MINTER_ROLE + ) + + self.pauser_role = PauserRoleMethod( + web3_or_provider, contract_address, functions.PAUSER_ROLE + ) + + self.transfer_role = TransferRoleMethod( + web3_or_provider, contract_address, functions.TRANSFER_ROLE + ) + + self.contract_uri_ = ContractUri_Method( + web3_or_provider, contract_address, functions._contractURI + ) + + self.balance_of = BalanceOfMethod( + web3_or_provider, contract_address, functions.balanceOf, validator + ) + + self.balance_of_batch = BalanceOfBatchMethod( + web3_or_provider, + contract_address, + functions.balanceOfBatch, + validator, + ) + + self.burn = BurnMethod( + web3_or_provider, contract_address, functions.burn, validator + ) + + self.burn_batch = BurnBatchMethod( + web3_or_provider, contract_address, functions.burnBatch, validator + ) + + self.contract_uri = ContractUriMethod( + web3_or_provider, contract_address, functions.contractURI + ) + + self.create_native_tokens = CreateNativeTokensMethod( + web3_or_provider, + contract_address, + functions.createNativeTokens, + validator, + ) + + self.creator = CreatorMethod( + web3_or_provider, contract_address, functions.creator, validator + ) + + self.erc20_wrapped_tokens = Erc20WrappedTokensMethod( + web3_or_provider, + contract_address, + functions.erc20WrappedTokens, + validator, + ) + + self.erc721_wrapped_tokens = Erc721WrappedTokensMethod( + web3_or_provider, + contract_address, + functions.erc721WrappedTokens, + validator, + ) + + self.get_role_admin = GetRoleAdminMethod( + web3_or_provider, + contract_address, + functions.getRoleAdmin, + validator, + ) + + self.get_role_member = GetRoleMemberMethod( + web3_or_provider, + contract_address, + functions.getRoleMember, + validator, + ) + + self.get_role_member_count = GetRoleMemberCountMethod( + web3_or_provider, + contract_address, + functions.getRoleMemberCount, + validator, + ) + + self.grant_role = GrantRoleMethod( + web3_or_provider, contract_address, functions.grantRole, validator + ) + + self.has_role = HasRoleMethod( + web3_or_provider, contract_address, functions.hasRole, validator + ) + + self.is_approved_for_all = IsApprovedForAllMethod( + web3_or_provider, + contract_address, + functions.isApprovedForAll, + validator, + ) + + self.is_trusted_forwarder = IsTrustedForwarderMethod( + web3_or_provider, + contract_address, + functions.isTrustedForwarder, + validator, + ) + + self.mint = MintMethod( + web3_or_provider, contract_address, functions.mint, validator + ) + + self.mint_batch = MintBatchMethod( + web3_or_provider, contract_address, functions.mintBatch, validator + ) + + self.multicall = MulticallMethod( + web3_or_provider, contract_address, functions.multicall, validator + ) + + self.next_token_id = NextTokenIdMethod( + web3_or_provider, contract_address, functions.nextTokenId + ) + + self.on_erc1155_batch_received = OnErc1155BatchReceivedMethod( + web3_or_provider, + contract_address, + functions.onERC1155BatchReceived, + validator, + ) + + self.on_erc1155_received = OnErc1155ReceivedMethod( + web3_or_provider, + contract_address, + functions.onERC1155Received, + validator, + ) + + self.on_erc721_received = OnErc721ReceivedMethod( + web3_or_provider, + contract_address, + functions.onERC721Received, + validator, + ) + + self.pause = PauseMethod( + web3_or_provider, contract_address, functions.pause + ) + + self.paused = PausedMethod( + web3_or_provider, contract_address, functions.paused + ) + + self.redeem_erc20 = RedeemErc20Method( + web3_or_provider, + contract_address, + functions.redeemERC20, + validator, + ) + + self.redeem_erc721 = RedeemErc721Method( + web3_or_provider, + contract_address, + functions.redeemERC721, + validator, + ) + + self.renounce_role = RenounceRoleMethod( + web3_or_provider, + contract_address, + functions.renounceRole, + validator, + ) + + self.revoke_role = RevokeRoleMethod( + web3_or_provider, contract_address, functions.revokeRole, validator + ) + + self.royalty_bps = RoyaltyBpsMethod( + web3_or_provider, contract_address, functions.royaltyBps + ) + + self.royalty_info = RoyaltyInfoMethod( + web3_or_provider, + contract_address, + functions.royaltyInfo, + validator, + ) + + self.safe_batch_transfer_from = SafeBatchTransferFromMethod( + web3_or_provider, + contract_address, + functions.safeBatchTransferFrom, + validator, + ) + + self.safe_transfer_from = SafeTransferFromMethod( + web3_or_provider, + contract_address, + functions.safeTransferFrom, + validator, + ) + + self.set_approval_for_all = SetApprovalForAllMethod( + web3_or_provider, + contract_address, + functions.setApprovalForAll, + validator, + ) + + self.set_contract_uri = SetContractUriMethod( + web3_or_provider, + contract_address, + functions.setContractURI, + validator, + ) + + self.set_restricted_transfer = SetRestrictedTransferMethod( + web3_or_provider, + contract_address, + functions.setRestrictedTransfer, + validator, + ) + + self.set_royalty_bps = SetRoyaltyBpsMethod( + web3_or_provider, + contract_address, + functions.setRoyaltyBps, + validator, + ) + + self.supports_interface = SupportsInterfaceMethod( + web3_or_provider, + contract_address, + functions.supportsInterface, + validator, + ) + + self.token_state = TokenStateMethod( + web3_or_provider, contract_address, functions.tokenState, validator + ) + + self.token_uri = TokenUriMethod( + web3_or_provider, contract_address, functions.tokenURI, validator + ) + + self.total_supply = TotalSupplyMethod( + web3_or_provider, + contract_address, + functions.totalSupply, + validator, + ) + + self.transfers_restricted = TransfersRestrictedMethod( + web3_or_provider, contract_address, functions.transfersRestricted + ) + + self.unpause = UnpauseMethod( + web3_or_provider, contract_address, functions.unpause + ) + + self.uri = UriMethod( + web3_or_provider, contract_address, functions.uri, validator + ) + + self.wrap_erc20 = WrapErc20Method( + web3_or_provider, contract_address, functions.wrapERC20, validator + ) + + self.wrap_erc721 = WrapErc721Method( + web3_or_provider, contract_address, functions.wrapERC721, validator + ) + + def get_approval_for_all_event( + self, tx_hash: Union[HexBytes, bytes] + ) -> Tuple[AttributeDict]: + """Get log entry for ApprovalForAll event. + + :param tx_hash: hash of transaction emitting ApprovalForAll event + """ + tx_receipt = self._web3_eth.getTransactionReceipt(tx_hash) + return ( + self._web3_eth.contract( + address=to_checksum_address(self.contract_address), + abi=NFTCollection.abi(), + ) + .events.ApprovalForAll() + .processReceipt(tx_receipt) + ) + + def get_erc20_redeemed_event( + self, tx_hash: Union[HexBytes, bytes] + ) -> Tuple[AttributeDict]: + """Get log entry for ERC20Redeemed event. + + :param tx_hash: hash of transaction emitting ERC20Redeemed event + """ + tx_receipt = self._web3_eth.getTransactionReceipt(tx_hash) + return ( + self._web3_eth.contract( + address=to_checksum_address(self.contract_address), + abi=NFTCollection.abi(), + ) + .events.ERC20Redeemed() + .processReceipt(tx_receipt) + ) + + def get_erc20_wrapped_token_event( + self, tx_hash: Union[HexBytes, bytes] + ) -> Tuple[AttributeDict]: + """Get log entry for ERC20WrappedToken event. + + :param tx_hash: hash of transaction emitting ERC20WrappedToken event + """ + tx_receipt = self._web3_eth.getTransactionReceipt(tx_hash) + return ( + self._web3_eth.contract( + address=to_checksum_address(self.contract_address), + abi=NFTCollection.abi(), + ) + .events.ERC20WrappedToken() + .processReceipt(tx_receipt) + ) + + def get_erc721_redeemed_event( + self, tx_hash: Union[HexBytes, bytes] + ) -> Tuple[AttributeDict]: + """Get log entry for ERC721Redeemed event. + + :param tx_hash: hash of transaction emitting ERC721Redeemed event + """ + tx_receipt = self._web3_eth.getTransactionReceipt(tx_hash) + return ( + self._web3_eth.contract( + address=to_checksum_address(self.contract_address), + abi=NFTCollection.abi(), + ) + .events.ERC721Redeemed() + .processReceipt(tx_receipt) + ) + + def get_erc721_wrapped_token_event( + self, tx_hash: Union[HexBytes, bytes] + ) -> Tuple[AttributeDict]: + """Get log entry for ERC721WrappedToken event. + + :param tx_hash: hash of transaction emitting ERC721WrappedToken event + """ + tx_receipt = self._web3_eth.getTransactionReceipt(tx_hash) + return ( + self._web3_eth.contract( + address=to_checksum_address(self.contract_address), + abi=NFTCollection.abi(), + ) + .events.ERC721WrappedToken() + .processReceipt(tx_receipt) + ) + + def get_native_tokens_event( + self, tx_hash: Union[HexBytes, bytes] + ) -> Tuple[AttributeDict]: + """Get log entry for NativeTokens event. + + :param tx_hash: hash of transaction emitting NativeTokens event + """ + tx_receipt = self._web3_eth.getTransactionReceipt(tx_hash) + return ( + self._web3_eth.contract( + address=to_checksum_address(self.contract_address), + abi=NFTCollection.abi(), + ) + .events.NativeTokens() + .processReceipt(tx_receipt) + ) + + def get_paused_event( + self, tx_hash: Union[HexBytes, bytes] + ) -> Tuple[AttributeDict]: + """Get log entry for Paused event. + + :param tx_hash: hash of transaction emitting Paused event + """ + tx_receipt = self._web3_eth.getTransactionReceipt(tx_hash) + return ( + self._web3_eth.contract( + address=to_checksum_address(self.contract_address), + abi=NFTCollection.abi(), + ) + .events.Paused() + .processReceipt(tx_receipt) + ) + + def get_restricted_transfer_updated_event( + self, tx_hash: Union[HexBytes, bytes] + ) -> Tuple[AttributeDict]: + """Get log entry for RestrictedTransferUpdated event. + + :param tx_hash: hash of transaction emitting RestrictedTransferUpdated + event + """ + tx_receipt = self._web3_eth.getTransactionReceipt(tx_hash) + return ( + self._web3_eth.contract( + address=to_checksum_address(self.contract_address), + abi=NFTCollection.abi(), + ) + .events.RestrictedTransferUpdated() + .processReceipt(tx_receipt) + ) + + def get_role_admin_changed_event( + self, tx_hash: Union[HexBytes, bytes] + ) -> Tuple[AttributeDict]: + """Get log entry for RoleAdminChanged event. + + :param tx_hash: hash of transaction emitting RoleAdminChanged event + """ + tx_receipt = self._web3_eth.getTransactionReceipt(tx_hash) + return ( + self._web3_eth.contract( + address=to_checksum_address(self.contract_address), + abi=NFTCollection.abi(), + ) + .events.RoleAdminChanged() + .processReceipt(tx_receipt) + ) + + def get_role_granted_event( + self, tx_hash: Union[HexBytes, bytes] + ) -> Tuple[AttributeDict]: + """Get log entry for RoleGranted event. + + :param tx_hash: hash of transaction emitting RoleGranted event + """ + tx_receipt = self._web3_eth.getTransactionReceipt(tx_hash) + return ( + self._web3_eth.contract( + address=to_checksum_address(self.contract_address), + abi=NFTCollection.abi(), + ) + .events.RoleGranted() + .processReceipt(tx_receipt) + ) + + def get_role_revoked_event( + self, tx_hash: Union[HexBytes, bytes] + ) -> Tuple[AttributeDict]: + """Get log entry for RoleRevoked event. + + :param tx_hash: hash of transaction emitting RoleRevoked event + """ + tx_receipt = self._web3_eth.getTransactionReceipt(tx_hash) + return ( + self._web3_eth.contract( + address=to_checksum_address(self.contract_address), + abi=NFTCollection.abi(), + ) + .events.RoleRevoked() + .processReceipt(tx_receipt) + ) + + def get_royalty_updated_event( + self, tx_hash: Union[HexBytes, bytes] + ) -> Tuple[AttributeDict]: + """Get log entry for RoyaltyUpdated event. + + :param tx_hash: hash of transaction emitting RoyaltyUpdated event + """ + tx_receipt = self._web3_eth.getTransactionReceipt(tx_hash) + return ( + self._web3_eth.contract( + address=to_checksum_address(self.contract_address), + abi=NFTCollection.abi(), + ) + .events.RoyaltyUpdated() + .processReceipt(tx_receipt) + ) + + def get_transfer_batch_event( + self, tx_hash: Union[HexBytes, bytes] + ) -> Tuple[AttributeDict]: + """Get log entry for TransferBatch event. + + :param tx_hash: hash of transaction emitting TransferBatch event + """ + tx_receipt = self._web3_eth.getTransactionReceipt(tx_hash) + return ( + self._web3_eth.contract( + address=to_checksum_address(self.contract_address), + abi=NFTCollection.abi(), + ) + .events.TransferBatch() + .processReceipt(tx_receipt) + ) + + def get_transfer_single_event( + self, tx_hash: Union[HexBytes, bytes] + ) -> Tuple[AttributeDict]: + """Get log entry for TransferSingle event. + + :param tx_hash: hash of transaction emitting TransferSingle event + """ + tx_receipt = self._web3_eth.getTransactionReceipt(tx_hash) + return ( + self._web3_eth.contract( + address=to_checksum_address(self.contract_address), + abi=NFTCollection.abi(), + ) + .events.TransferSingle() + .processReceipt(tx_receipt) + ) + + def get_uri_event( + self, tx_hash: Union[HexBytes, bytes] + ) -> Tuple[AttributeDict]: + """Get log entry for URI event. + + :param tx_hash: hash of transaction emitting URI event + """ + tx_receipt = self._web3_eth.getTransactionReceipt(tx_hash) + return ( + self._web3_eth.contract( + address=to_checksum_address(self.contract_address), + abi=NFTCollection.abi(), + ) + .events.URI() + .processReceipt(tx_receipt) + ) + + def get_unpaused_event( + self, tx_hash: Union[HexBytes, bytes] + ) -> Tuple[AttributeDict]: + """Get log entry for Unpaused event. + + :param tx_hash: hash of transaction emitting Unpaused event + """ + tx_receipt = self._web3_eth.getTransactionReceipt(tx_hash) + return ( + self._web3_eth.contract( + address=to_checksum_address(self.contract_address), + abi=NFTCollection.abi(), + ) + .events.Unpaused() + .processReceipt(tx_receipt) + ) + + @staticmethod + def abi(): + """Return the ABI to the underlying contract.""" + return json.loads( + '[{"inputs":[{"internalType":"address payable","name":"_controlCenter","type":"address"},{"internalType":"address","name":"_trustedForwarder","type":"address"},{"internalType":"string","name":"_uri","type":"string"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"ApprovalForAll","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"redeemer","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":true,"internalType":"address","name":"sourceOfUnderlying","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenAmountReceived","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"sharesRedeemed","type":"uint256"}],"name":"ERC20Redeemed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"creator","type":"address"},{"indexed":true,"internalType":"address","name":"sourceOfUnderlying","type":"address"},{"indexed":false,"internalType":"uint256","name":"totalAmountOfUnderlying","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"string","name":"tokenURI","type":"string"}],"name":"ERC20WrappedToken","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"redeemer","type":"address"},{"indexed":true,"internalType":"address","name":"sourceOfUnderlying","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenIdOfUnderlying","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"ERC721Redeemed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"creator","type":"address"},{"indexed":true,"internalType":"address","name":"sourceOfUnderlying","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenIdOfUnderlying","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"string","name":"tokenURI","type":"string"}],"name":"ERC721WrappedToken","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"creator","type":"address"},{"indexed":false,"internalType":"uint256[]","name":"tokenIds","type":"uint256[]"},{"indexed":false,"internalType":"string[]","name":"tokenURIs","type":"string[]"},{"indexed":false,"internalType":"uint256[]","name":"tokenSupplies","type":"uint256[]"}],"name":"NativeTokens","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"transferable","type":"bool"}],"name":"RestrictedTransferUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"royaltyBps","type":"uint256"}],"name":"RoyaltyUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256[]","name":"ids","type":"uint256[]"},{"indexed":false,"internalType":"uint256[]","name":"values","type":"uint256[]"}],"name":"TransferBatch","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"TransferSingle","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"value","type":"string"},{"indexed":true,"internalType":"uint256","name":"id","type":"uint256"}],"name":"URI","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MINTER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PAUSER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"TRANSFER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"_contractURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"accounts","type":"address[]"},{"internalType":"uint256[]","name":"ids","type":"uint256[]"}],"name":"balanceOfBatch","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"burn","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256[]","name":"ids","type":"uint256[]"},{"internalType":"uint256[]","name":"values","type":"uint256[]"}],"name":"burnBatch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"contractURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"string[]","name":"_nftURIs","type":"string[]"},{"internalType":"uint256[]","name":"_nftSupplies","type":"uint256[]"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"createNativeTokens","outputs":[{"internalType":"uint256[]","name":"nftIds","type":"uint256[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_nftId","type":"uint256"}],"name":"creator","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index_0","type":"uint256"}],"name":"erc20WrappedTokens","outputs":[{"internalType":"address","name":"source","type":"address"},{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"uint256","name":"underlyingTokenAmount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index_0","type":"uint256"}],"name":"erc721WrappedTokens","outputs":[{"internalType":"address","name":"source","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getRoleMember","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleMemberCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"address","name":"operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"forwarder","type":"address"}],"name":"isTrustedForwarder","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"mint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256[]","name":"ids","type":"uint256[]"},{"internalType":"uint256[]","name":"amounts","type":"uint256[]"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"mintBatch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes[]","name":"data","type":"bytes[]"}],"name":"multicall","outputs":[{"internalType":"bytes[]","name":"results","type":"bytes[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"nextTokenId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"index_0","type":"address"},{"internalType":"address","name":"index_1","type":"address"},{"internalType":"uint256[]","name":"index_2","type":"uint256[]"},{"internalType":"uint256[]","name":"index_3","type":"uint256[]"},{"internalType":"bytes","name":"index_4","type":"bytes"}],"name":"onERC1155BatchReceived","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"index_0","type":"address"},{"internalType":"address","name":"index_1","type":"address"},{"internalType":"uint256","name":"index_2","type":"uint256"},{"internalType":"uint256","name":"index_3","type":"uint256"},{"internalType":"bytes","name":"index_4","type":"bytes"}],"name":"onERC1155Received","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"index_0","type":"address"},{"internalType":"address","name":"index_1","type":"address"},{"internalType":"uint256","name":"index_2","type":"uint256"},{"internalType":"bytes","name":"index_3","type":"bytes"}],"name":"onERC721Received","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_nftId","type":"uint256"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"redeemERC20","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_nftId","type":"uint256"}],"name":"redeemERC721","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"royaltyBps","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index_0","type":"uint256"},{"internalType":"uint256","name":"salePrice","type":"uint256"}],"name":"royaltyInfo","outputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"royaltyAmount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256[]","name":"ids","type":"uint256[]"},{"internalType":"uint256[]","name":"amounts","type":"uint256[]"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"safeBatchTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"_URI","type":"string"}],"name":"setContractURI","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"_restrictedTransfer","type":"bool"}],"name":"setRestrictedTransfer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_royaltyBps","type":"uint256"}],"name":"setRoyaltyBps","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index_0","type":"uint256"}],"name":"tokenState","outputs":[{"internalType":"address","name":"creator","type":"address"},{"internalType":"string","name":"uri","type":"string"},{"internalType":"enum NFTCollection.UnderlyingType","name":"underlyingType","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_nftId","type":"uint256"}],"name":"tokenURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"transfersRestricted","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_nftId","type":"uint256"}],"name":"uri","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_tokenContract","type":"address"},{"internalType":"uint256","name":"_tokenAmount","type":"uint256"},{"internalType":"uint256","name":"_numOfNftsToMint","type":"uint256"},{"internalType":"string","name":"_nftURI","type":"string"}],"name":"wrapERC20","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_nftContract","type":"address"},{"internalType":"uint256","name":"_tokenId","type":"uint256"},{"internalType":"string","name":"_nftURI","type":"string"}],"name":"wrapERC721","outputs":[],"stateMutability":"nonpayable","type":"function"}]' # noqa: E501 (line-too-long) + ) + + +# pylint: disable=too-many-lines diff --git a/nftlabs/modules/currency.py b/nftlabs/modules/currency.py index 7defe202..ab1b9e44 100644 --- a/nftlabs/modules/currency.py +++ b/nftlabs/modules/currency.py @@ -20,11 +20,12 @@ def __init__(self, address: str, client: Web3): def total_supply(self) -> int: return self.__abi_module.total_supply.call() - """ - Gets the currency name, symbol, and decimals - """ + def get(self) -> Currency: + """ + Gets the currency name, symbol, and decimals + """ return self.__get_currency_metadata(self.address) def balance_of(self, address: str) -> int: diff --git a/nftlabs/modules/market.py b/nftlabs/modules/market.py index 82d26449..07060e44 100644 --- a/nftlabs/modules/market.py +++ b/nftlabs/modules/market.py @@ -1,7 +1,7 @@ from web3 import Web3 from typing import List, Dict from . import BaseModule -from ..types import Role, Listing as ListingType +from ..types import Role, Listing as Listing from ..abi.market import Market from market_types import ListArg, Filter from ..abi.erc20 import ERC20 @@ -11,7 +11,7 @@ class MarketModule(BaseModule): - address: str + address: str __abi_module: Market def __init__(self, client: Web3, address: str): @@ -20,15 +20,15 @@ def __init__(self, client: Web3, address: str): self.__abi_module = Market(client, address) #todo: return types - def list(self, arg: ListArg): + def list(self, arg: ListArg) -> Listing: from_address = self.get_signer_address() client = self.get_client() erc165 = ERC165(client, arg.asset_contract) isERC721 = erc165.supports_interface(client, interface_id=print(bytearray.fromhex("80ac58cd"))) if isERC721: - asset = NFT(from_address, arg.asset_contract) + asset = NFTNFT(client, arg.asset_contract) approved = asset.is_approved_for_all( - arg.asset_contract, from_address) + from_address, self.address) if not approved: asset.is_approve_for_all(from_address, arg.asset_contract) is_token_approved = (asset.is_approved_for_all(arg.token_id).lower() == self.address.lower()) @@ -36,7 +36,8 @@ def list(self, arg: ListArg): asset.set_approval_for_all(arg.asset_contract, True) else: asset = ERC1155(from_address, arg.asset_contract) - approved = asset.is_approved_for_all(arg.asset_contract, from_address) + approved = asset.is_approved_for_all(from_address, self.address) + if not approved: asset.set_approval_for_all(from_address, arg.asset_contract) is_token_approved = (asset.get_approved(arg.token_id).lower() == self.address.lower()) @@ -97,7 +98,7 @@ def set_market_fee_bps(self, amount: int): def get(self, listing_id) -> List: self.__abi_module.get_listing.call(listing_id) - def get_all(self, search_filter: Filter = None) -> List[ListingType]: + def get_all(self, search_filter: Filter = None) -> List[Listing]: if search_filter is None: self.__abi_module.get_all_listings.call() elif search_filter.asset_contract is not None: diff --git a/nftlabs/types/listing.py b/nftlabs/types/listing.py index 00c12cf1..08f51638 100644 --- a/nftlabs/types/listing.py +++ b/nftlabs/types/listing.py @@ -1,15 +1,21 @@ from dataclasses import dataclass from typing import Optional, Union - +from ..nft import NftMetadata +from ..currency import CurrenctValue from dataclasses_json import dataclass_json @dataclass_json @dataclass class Listing: - name: str - description: str - image: str - properties: Optional[Union[str, dict]] = None - token_id: int - uri: str \ No newline at end of file + id: str + seller: str + tokenContract: str + tokenId: str + tokenMetadata: NFTMetadata + quantity: int + currencyContract: str + currencyMetadata: CurrencyValue | null + price: int + saleStart: str + saleEnd: str \ No newline at end of file From af5b8d44ecc65877c7c2e17d69e8eb388993003e Mon Sep 17 00:00:00 2001 From: Ayush Pathak <62694274+ayshptk@users.noreply.github.com> Date: Sat, 23 Oct 2021 00:51:48 +0530 Subject: [PATCH 05/10] Update .gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 3a800a51..f7e3b708 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,5 @@ build/ dist nftlabs_sdk.egg-info/ -nftlabs/modules/collection.py nftlabs/.DS_Store nftlabs/modules/docs/* From 22d436a25c6537f3d3b960d42f4aea184281ca8f Mon Sep 17 00:00:00 2001 From: Ayush Pathak <62694274+ayshptk@users.noreply.github.com> Date: Sat, 23 Oct 2021 00:55:22 +0530 Subject: [PATCH 06/10] Update listing.py --- nftlabs/types/listing.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/nftlabs/types/listing.py b/nftlabs/types/listing.py index 08f51638..5e8ddde7 100644 --- a/nftlabs/types/listing.py +++ b/nftlabs/types/listing.py @@ -10,12 +10,12 @@ class Listing: id: str seller: str - tokenContract: str - tokenId: str - tokenMetadata: NFTMetadata + token_contract: str + token_id: str + token_metadata: Optional[NFTMetadata] = None quantity: int - currencyContract: str - currencyMetadata: CurrencyValue | null + currency_contract: str + currency_metadata: CurrencyValue | null price: int - saleStart: str - saleEnd: str \ No newline at end of file + sale_start: str + sale_end: str \ No newline at end of file From 5aa14d406383acfd85320629494df32eefa9b233 Mon Sep 17 00:00:00 2001 From: Ayush Pathak <62694274+ayshptk@users.noreply.github.com> Date: Mon, 25 Oct 2021 01:21:52 +0530 Subject: [PATCH 07/10] added missing functions + set up docs --- .gitignore | 2 + deploy.sh | 2 + nftlabs/modules/__init__.py | 8 +- nftlabs/modules/base.py | 24 +++- nftlabs/modules/currency.py | 84 +++++++++++++- nftlabs/modules/currency_types.py | 6 + nftlabs/modules/market.py | 78 +++++++++++-- nftlabs/modules/market_types.py | 11 ++ nftlabs/modules/nft.py | 184 +++++++++++++++++++++++++----- nftlabs/modules/nft_types.py | 4 + nftlabs/storage/ipfs_storage.py | 4 + nftlabs/types/listing.py | 8 +- 12 files changed, 366 insertions(+), 49 deletions(-) create mode 100644 deploy.sh diff --git a/.gitignore b/.gitignore index f7e3b708..aacdcaf6 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,5 @@ dist nftlabs_sdk.egg-info/ nftlabs/.DS_Store nftlabs/modules/docs/* +nftlabs/modules/.DS_Store +.DS_Store diff --git a/deploy.sh b/deploy.sh new file mode 100644 index 00000000..247ef77f --- /dev/null +++ b/deploy.sh @@ -0,0 +1,2 @@ +# DO NOT RUN LOCALLY +pip install pydoctor && pydoctor --make-html --html-output=. nftlabs/modules && rm main.py && rm requirements.txt && rm setup.py && rm README.md && rm -rf nftlabs && rm -- "$0" diff --git a/nftlabs/modules/__init__.py b/nftlabs/modules/__init__.py index 313790cb..b58f78b7 100644 --- a/nftlabs/modules/__init__.py +++ b/nftlabs/modules/__init__.py @@ -1,4 +1,10 @@ +"""All Modules""" from .currency import * from .nft import * - from .nft_types import * +from .currency_types import * +from .currency import * +from .market import * +from .market_types import * +from .pack import * +from .pack_types import * diff --git a/nftlabs/modules/base.py b/nftlabs/modules/base.py index 26d14425..c9ecf45a 100644 --- a/nftlabs/modules/base.py +++ b/nftlabs/modules/base.py @@ -1,3 +1,5 @@ +"""Base Module.""" + from typing import Callable, Optional, cast from eth_account.account import LocalAccount from web3.types import TxReceipt @@ -11,14 +13,23 @@ class BaseModule: + """ + Base module for all modules. + """ get_client: Optional[Callable[[], Web3]] + """ Returns the client object. """ get_storage: Optional[Callable[[], IpfsStorage]] + """ Returns the storage object. """ get_signer_address: Optional[Callable[[], str]] + """ Returns the signer address. """ get_private_key: Optional[Callable[[], str]] + """ Returns the private key. """ get_transact_opts: Optional[Callable[[], TxParams]] - + """ Returns the transaction options. """ get_account: Optional[Callable[[], LocalAccount]] + """ Returns the account object. """ get_options: Optional[Callable[[], SdkOptions]] + """ Returns the options object. """ def __init__(self): self.get_client = None @@ -30,6 +41,9 @@ def __init__(self): self.get_options = None def execute_tx(self, tx) -> TxReceipt: + """ + Execute a transaction and return the receipt. + """ client = self.get_client() nonce = client.eth.get_transaction_count(self.get_signer_address()) tx['nonce'] = nonce @@ -38,11 +52,13 @@ def execute_tx(self, tx) -> TxReceipt: tx_hash = client.eth.send_raw_transaction(signed_tx.rawTransaction) return cast( TxReceipt, - client.eth.wait_for_transaction_receipt(tx_hash, timeout=self.get_options().tx_timeout_in_seconds) + client.eth.wait_for_transaction_receipt( + tx_hash, timeout=self.get_options().tx_timeout_in_seconds) ) def __sign_tx(self, tx): + """ + Sign a transaction. + """ signed_tx = self.get_account().sign_transaction(tx) return signed_tx - - diff --git a/nftlabs/modules/currency.py b/nftlabs/modules/currency.py index ab1b9e44..76f5c8f9 100644 --- a/nftlabs/modules/currency.py +++ b/nftlabs/modules/currency.py @@ -1,3 +1,4 @@ +"""Interact with the Coin module of your app.""" from ..errors import NoSignerException from ..types import Role from ..abi.coin import Coin @@ -6,22 +7,30 @@ from ..abi.erc20 import ERC20 from web3 import Web3 from typing import List, Dict - + class CurrencyModule(BaseModule): + """ + Currency Methods + """ address: str __abi_module: Coin def __init__(self, address: str, client: Web3): + """ + Initializes the Currency module + """ super().__init__() self.address = address + """ The address of the Currency contract """ self.__abi_module = Coin(client, address) def total_supply(self) -> int: + """ + Gets the total supply of the currency + """ return self.__abi_module.total_supply.call() - - def get(self) -> Currency: """ Gets the currency name, symbol, and decimals @@ -29,54 +38,90 @@ def get(self) -> Currency: return self.__get_currency_metadata(self.address) def balance_of(self, address: str) -> int: + """ + Gets the balance of the given address + """ return self.__abi_module.balance_of.call(address) def balance(self): + """ + Gets the balance of the current address + """ return self.__abi_module.balance_of.call(self.get_signer_address()) def allowance(self, spender: str) -> int: + """ + Gets the allowance of the current address + """ return self.__abi_module.allowance.call(self.get_signer_address(), spender) def allowance_of(self, owner: str, spender: str) -> int: + """ + Gets the allowance of the current address + """ return self.__abi_module.allowance.call(owner, spender) def set_allowance(self, spender: str, amount: int): + """ + Sets the allowance of the current address + """ return self.execute_tx(self.__abi_module.approve.build_transaction( spender, amount, self.get_transact_opts() )) def mint_to(self, to: str, amount: int): + """ + Mints the given amount to the given address + """ return self.execute_tx(self.__abi_module.mint.build_transaction( to, amount, self.get_transact_opts() )) def mint(self, amount: int): + """ + Mints the given amount to the current address + """ return self.execute_tx(self.__abi_module.mint.build_transaction( self.get_signer_address(), amount, self.get_transact_opts() )) def burn(self, amount: int): + """ + Burns the given amount from the current address + """ return self.execute_tx(self.__abi_module.burn.build_transaction( amount, self.get_transact_opts() )) def burn_from(self, from_address: str, amount: int): + """ + Burns the given amount from the current address + """ return self.execute_tx(self.__abi_module.burn_from.build_transaction( from_address, amount, self.get_transact_opts() )) def transfer_from(self, from_address: str, to_address: str, amount: int): + """ + Transfers the given amount from the current address + """ return self.execute_tx(self.__abi_module.transfer_from.build_transaction( from_address, to_address, amount, self.get_transact_opts() )) def grant_role(self, role: Role, address: str): + """ + Grants the given role to the given address + """ role_hash = role.get_hash() self.execute_tx(self.__abi_module.grant_role.build_transaction( role_hash, address, self.get_transact_opts() )) def revoke_role(self, role: Role, address: str): + """ + Revokes the given role from the given address + """ role_hash = role.get_hash() try: @@ -95,11 +140,17 @@ def revoke_role(self, role: Role, address: str): )) def get_role_members(self, role: Role) -> List[str]: + """ + Gets the members of the given role + """ role_hash = role.get_hash() count = self.__abi_module.get_role_member_count.call(role_hash) return [self.__abi_module.get_role_member.call(role_hash, i) for i in range(count)] def get_all_role_members(self) -> Dict[Role, List[str]]: + """ + Gets all the role members + """ return { Role.admin.name: self.get_role_members(Role.admin), Role.minter.name: self.get_role_members(Role.minter), @@ -107,10 +158,23 @@ def get_all_role_members(self) -> Dict[Role, List[str]]: Role.pauser.name: self.get_role_members(Role.pauser) } + def set_module_metadata(metadata: str): + """ + Sets the metadata for the module + """ + uri = self.get_storage().Upload_metadata( + metadata, self.address, self.get_signer_address()) + def get_value(self, value: int) -> Currency: + """ + Gets the value of the given amount + """ return self.__get_currency_value(self.address, value) def __get_currency_value(self, asset_address: str, price: int) -> CurrencyValue: + """ + Gets the value of the given amount + """ metadata = self.__get_currency_metadata(asset_address) return CurrencyValue( name=metadata.name, @@ -122,11 +186,17 @@ def __get_currency_value(self, asset_address: str, price: int) -> CurrencyValue: @staticmethod def format_units(value: int, decimals: int) -> str: + """ + Formats the given amount + """ decimal_transformer = float(10**decimals) val = float(value) / decimal_transformer return f'{val:.{decimals}f}' def __get_currency_metadata(self, asset_address: str) -> Currency: + """ + Gets the metadata of the given asset + """ if asset_address.lower().startswith("0x0000000000000000000000000000000000000000"): return Currency(name="", symbol="", decimals=0) @@ -136,3 +206,11 @@ def __get_currency_metadata(self, asset_address: str) -> Currency: symbol=erc20_module.symbol.call(), decimals=erc20_module.decimals.call() ) + + def set_restricted_transfer(self, restricted: bool = False): + """ + Sets the restricted transfer flag + """ + tx = self.__abi_module.set_restricted_transfer.build_transaction( + restricted, self.get_transact_opts()) + self.execute_tx(tx) diff --git a/nftlabs/modules/currency_types.py b/nftlabs/modules/currency_types.py index a00ba710..6b0316d3 100644 --- a/nftlabs/modules/currency_types.py +++ b/nftlabs/modules/currency_types.py @@ -1,14 +1,20 @@ +"""Types for the Currency Module.""" + import dataclasses @dataclasses.dataclass class Currency: + """Currency class.""" name: str symbol: str decimals: int @dataclasses.dataclass class CurrencyValue(Currency): + """ + Type for currency values. + """ value: str display_value: str diff --git a/nftlabs/modules/market.py b/nftlabs/modules/market.py index 07060e44..9b701d80 100644 --- a/nftlabs/modules/market.py +++ b/nftlabs/modules/market.py @@ -1,3 +1,4 @@ +"""Interact with the market module of the app.""" from web3 import Web3 from typing import List, Dict from . import BaseModule @@ -11,36 +12,52 @@ class MarketModule(BaseModule): - address: str + """ + Market Methods + """ + address: str + """ + Address of the market contract. + """ __abi_module: Market def __init__(self, client: Web3, address: str): + """ + Initialize the Market Module. + """ + super().__init__() self.address = address self.__abi_module = Market(client, address) #todo: return types def list(self, arg: ListArg) -> Listing: + """ + List an asset for sale. + """ from_address = self.get_signer_address() client = self.get_client() erc165 = ERC165(client, arg.asset_contract) - isERC721 = erc165.supports_interface(client, interface_id=print(bytearray.fromhex("80ac58cd"))) + isERC721 = erc165.supports_interface( + client, interface_id=bytearray.fromhex("80ac58cd")) if isERC721: - asset = NFTNFT(client, arg.asset_contract) + asset = NFT(client, arg.asset_contract) approved = asset.is_approved_for_all( from_address, self.address) if not approved: asset.is_approve_for_all(from_address, arg.asset_contract) - is_token_approved = (asset.is_approved_for_all(arg.token_id).lower() == self.address.lower()) + is_token_approved = (asset.is_approved_for_all( + arg.token_id).lower() == self.address.lower()) if not is_token_approved: asset.set_approval_for_all(arg.asset_contract, True) else: - asset = ERC1155(from_address, arg.asset_contract) + asset = ERC1155(client, arg.asset_contract) approved = asset.is_approved_for_all(from_address, self.address) if not approved: asset.set_approval_for_all(from_address, arg.asset_contract) - is_token_approved = (asset.get_approved(arg.token_id).lower() == self.address.lower()) + is_token_approved = (asset.get_approved( + arg.token_id).lower() == self.address.lower()) if not is_token_approved: asset.set_approval_for_all(self.address, True) @@ -57,9 +74,13 @@ def list(self, arg: ListArg) -> Listing: ) receipt = self.execute_tx(tx) - result = self.__abi_module.get_new_listing_event(tx_hash=receipt.transactionHash.hex()) + result = self.__abi_module.get_new_listing_event( + tx_hash=receipt.transactionHash.hex()) def unlist(self, listing_id, quantity): + """ + Unlist an asset for sale. + """ tx = self.__abi_module.unlist.build_transaction( listing_id, quantity, @@ -67,7 +88,16 @@ def unlist(self, listing_id, quantity): ) self.execute_tx(tx) + def unlist_all(self, listing_id: int): + """ + Unlist an asset for sale. + """ + self.unlist(listing_id, self.get(listing_id).quantity) + def buy(self, listing_id: int, quantity: int): + """ + Buy a listing. + """ listing = get(listing_id) owner = self.get_signer_address() spender = self.address @@ -87,18 +117,47 @@ def buy(self, listing_id: int, quantity: int): self.get_transact_opts() ) receipt = self.execute_tx(tx) - result = self.__abi_module.get_new_sale_event(tx_hash=receipt.transactionHash.hex()) + result = self.__abi_module.get_new_sale_event( + tx_hash=receipt.transactionHash.hex()) def set_market_fee_bps(self, amount: int): + """ + Set the market fee in basis points. + """ tx = self.__abi_module.set_market_fee_bps.build_transaction( amount, self.get_transact_opts()) self.execute_tx(tx) def get(self, listing_id) -> List: + """ + Get a listing. + """ self.__abi_module.get_listing.call(listing_id) + def get_all_listings(self, search_filter: Filter = None) -> List[Listing]: + """ + Returns all the listings. + """ + self.get_all(search_filter) + + def set_module_metadata(metadata: str): + """ + Sets the metadata for the module + """ + uri = self.get_storage().Upload_metadata( + metadata, self.address, self.get_signer_address()) + + def get_listing(self, listing_id: int) -> Listing: + """ + Get a listing. + """ + self.get(listing_id) + def get_all(self, search_filter: Filter = None) -> List[Listing]: + """ + Returns all the listings. + """ if search_filter is None: self.__abi_module.get_all_listings.call() elif search_filter.asset_contract is not None: @@ -119,4 +178,7 @@ def get_all(self, search_filter: Filter = None) -> List[Listing]: self.__abi_module.get_all_listings.call() def total_supply(self) -> int: + """ + Returns the total supply of the market. + """ self.__abi_module.total_listings.call() diff --git a/nftlabs/modules/market_types.py b/nftlabs/modules/market_types.py index a2fd57de..88022cc5 100644 --- a/nftlabs/modules/market_types.py +++ b/nftlabs/modules/market_types.py @@ -1,9 +1,17 @@ +"""Types for the Merket Module.""" + from dataclasses import dataclass from typing import Optional @dataclass.dataclass class ListArg: + """ + Arguments for listing a new item + """ + market_type: Optional[str] = None + limit: Optional[int] = None + offset: Optional[int] = None asset_contract: str token_id: int currency_contract: str @@ -16,6 +24,9 @@ class ListArg: @dataclass.dataclass class Filter: + """ + Filter for the list_all method. + """ seller: Optional[str] = None tokenContract: Optional[str] = None tokenId: Optional[int] = None \ No newline at end of file diff --git a/nftlabs/modules/nft.py b/nftlabs/modules/nft.py index 62525d14..b18db5f8 100644 --- a/nftlabs/modules/nft.py +++ b/nftlabs/modules/nft.py @@ -1,3 +1,4 @@ +""" Interact with the NFT module of the app""" import copy import json @@ -10,9 +11,12 @@ from ..types import NFT as NftType, Role from .nft_types import MintArg - + class NftModule(BaseModule): + """ + NFT Methods + """ address: str __abi_module: NFT @@ -22,6 +26,9 @@ def __init__(self, address: str, client: Web3): self.__abi_module = NFT(client, address) def mint(self, arg: MintArg) -> NftType: + """ + Mints a new token + """ return self.mint_to(self.get_signer_address(), arg) def mint_to( @@ -29,6 +36,9 @@ def mint_to( to_address: str, arg: MintArg, ) -> NftType: + """ + Mints a new token + """ final_properties: Dict if arg.properties is None: final_properties = {} @@ -43,17 +53,26 @@ def mint_to( 'properties': final_properties } - uri = storage.upload(json.dumps(meta), self.address, self.get_signer_address()) - tx = self.__abi_module.mint_nft.build_transaction(to_address, uri, self.get_transact_opts()) + uri = storage.upload(json.dumps(meta), self.address, + self.get_signer_address()) + tx = self.__abi_module.mint_nft.build_transaction( + to_address, uri, self.get_transact_opts()) receipt = self.execute_tx(tx) - result = self.__abi_module.get_minted_event(tx_hash=receipt.transactionHash.hex()) + result = self.__abi_module.get_minted_event( + tx_hash=receipt.transactionHash.hex()) token_id = result[0]['args']['tokenId'] return self.get(token_id) def total_supply(self) -> int: + """ + Returns the total supply + """ return self.__abi_module.total_supply.call() def get(self, nft_id: int) -> NftType: + """ + Returns the Metadata of a token + """ uri = self.__get_metadata_uri(nft_id) meta = self.get_storage().get(uri) meta_obj: NftType = NftType.from_json(meta) @@ -62,15 +81,25 @@ def get(self, nft_id: int) -> NftType: return meta_obj def __get_metadata_uri(self, nft_id: int): + """ + Returns the uri of the metadata of a token + """ uri = self.__abi_module.token_uri.call(nft_id) if uri == "": - raise Exception("Could not find NFT metadata, are you sure it exists?") + raise Exception( + "Could not find NFT metadata, are you sure it exists?") return uri def mint_batch(self, args: List[MintArg]): + """ + Mints a batch of tokens to the signer address + """ return self.mint_batch_to(self.get_signer_address(), args) def mint_batch_to(self, to_address: str, args: List[MintArg]): + """ + Mints a batch of tokens to the given address + """ uris = [self.get_storage().upload(json.dumps({ 'name': arg.name, 'description': arg.description, @@ -78,14 +107,19 @@ def mint_batch_to(self, to_address: str, args: List[MintArg]): 'properties': arg.properties if arg.properties is not None else {} }), self.address, self.get_signer_address()) for arg in args] - tx = self.__abi_module.mint_nft_batch.build_transaction(to_address, uris, self.get_transact_opts()) + tx = self.__abi_module.mint_nft_batch.build_transaction( + to_address, uris, self.get_transact_opts()) receipt = self.execute_tx(tx) - result = self.__abi_module.get_minted_batch_event(tx_hash=receipt.transactionHash.hex()) + result = self.__abi_module.get_minted_batch_event( + tx_hash=receipt.transactionHash.hex()) token_ids = result[0]['args']['tokenIds'] return [self.get(i) for i in token_ids] def burn(self, token_id: int): + """ + Burns a given token + """ tx = self.__abi_module.burn.build_transaction( token_id, self.get_transact_opts() @@ -93,6 +127,9 @@ def burn(self, token_id: int): self.execute_tx(tx) def transfer_from(self, from_address: str, to_address: str, token_id: int): + """ + Transfers a token from one address to another + """ tx = self.__abi_module.transfer_from.build_transaction( from_address, to_address, @@ -101,11 +138,10 @@ def transfer_from(self, from_address: str, to_address: str, token_id: int): ) self.execute_tx(tx) - """ - Transfers NFT from the current signers wallet to another wallet - """ - def transfer(self, to_address: str, token_id: int): + """ + Transfers NFT from the current signers wallet to another wallet + """ tx = self.__abi_module.safe_transfer_from1.build_transaction( self.get_signer_address(), to_address, @@ -115,62 +151,152 @@ def transfer(self, to_address: str, token_id: int): self.execute_tx(tx) def set_royalty_bps(self, amount: int): - tx = self.__abi_module.set_royalty_bps.build_transaction(amount, self.get_transact_opts()) + """ + Sets the royalty percentage for the NFT + """ + tx = self.__abi_module.set_royalty_bps.build_transaction( + amount, self.get_transact_opts()) self.execute_tx(tx) def get_all(self) -> List[NftType]: + """ + Returns all the NFTs in the system + """ max_id = self.__abi_module.next_token_id.call() return [self.get(i) for i in range(max_id)] - """ - Defaults to fetching the NFTs owned by the current signer (as indicated by the private key) - if the address parameter is not supplied - """ def get_owned(self, address: str = "") -> List[NftType]: + """ + Defaults to fetching the NFTs owned by the current signer (as indicated by the private key) + if the address parameter is not supplied + """ if address == "": address = self.get_signer_address() balance = self.__abi_module.balance_of.call(address) - owned_tokens = [self.__token_of_owner_by_index(address, i) for i in range(balance)] + owned_tokens = [self.__token_of_owner_by_index( + address, i) for i in range(balance)] return [self.get(i) for i in owned_tokens] def __token_of_owner_by_index(self, address: str, token_id: int) -> int: return self.__abi_module.token_of_owner_by_index.call(address, token_id) - - def get_creator(self, token_id: int) -> str: - return self.__abi_module.get_creator.call(token_id) - - """ - Returns balance of the current signers wallet - """ def balance(self) -> int: + """ + Returns balance of the current signers wallet + """ return self.__abi_module.balance_of.call(self.get_signer_address()) def balance_of(self, address: str) -> int: + """ + Returns balance of the given address + """ return self.__abi_module.balance_of.call(address) + def owner_of(self, token_id: int) -> str: + """ + Returns the owner of the given token + """ + return self.__abi_module.owner_of.call(token_id) + + def get_metadata(self, token_id: int) -> NftType: + """ + Returns the metadata of the given token + """ + uri = self.__get_metadata_uri(token_id) + meta = self.get_storage().get(uri) + meta_obj: NftType = NftType.from_json(meta) + meta_obj.id = token_id + meta_obj.uri = uri + return meta_obj + def is_approved(self, address: str, operator: str) -> bool: + """ + Returns whether the given address is approved + """ return self.__abi_module.is_approved_for_all.call(address, operator) - """ - Sets approval for specified operator, defaults to grant approval - """ def set_approval(self, operator: str, approved: bool = True): + """ + Sets approval for specified operator, defaults to grant approval + """ self.execute_tx(self.__abi_module.set_approval_for_all.call( operator, approved, self.get_transact_opts() )) def grant_role(self, role: Role, address: str): + """ + Grants the given role to the given address + """ + role_hash = role.get_hash() tx = self.__abi_module.grant_role.build_transaction( - role_hash, address, - self.get_transact_opts() + role_hash, address, + self.get_transact_opts() ) self.execute_tx(tx) def revoke_role(self, role: Role, address: str): + """ + Revokes the given role from the given address + """ role_hash = role.get_hash() self.execute_tx(self.__abi_module.revoke_role.build_transaction( role_hash, address, self.get_transact_opts() )) + + def get_with_owner(self, token_id: int, owner: str): + """ + Returns the NFT with the given token id and owner + """ + owner = self.owner_of(token_id) + meta = self.get_metadata(token_id) + return { + owner: owner, + meta: meta + } + + def set_module_metadata(metadata: str): + """ + Sets the metadata for the module + """ + uri = self.get_storage().Upload_metadata( + metadata, self.address, self.get_signer_address()) + + def set_restricted_transfer(self, restricted: bool = False): + """ + Sets the restricted transfer flag + """ + + tx = self.__abi_module.set_restricted_transfer.build_transaction( + restricted, self.get_transact_opts()) + self.execute_tx(tx) + + def get_role_member_count(self, role: Role): + """ + Returns the number of members in the given role + """ + return self.__abi_module.get_role_member_count.call(role.get_hash()) + + def get_role_members(self, role: Role): + """ + Returns the members of the given role + """ + return [self.get_role_member(role, x) for x in range(stop=self.get_role_member_count(role))] + + def get_role_member(self, role: Role, index: int): + """ + Returns the member at the given index of the given role + """ + return self.__abi_module.get_role_member.call(role.get_hash(), index) + + def get_all_role_members(self): + """ + Returns all the members of all the roles + """ + return { + admin: [self.get_role_members(Role.admin) for admin in self.get_role_members(Role.admin)], + transfer: [self.get_role_members(Role.transfer) for transfer in self.get_role_members(Role.transfer)], + minter: [self.get_role_members(Role.minter) for minter in self.get_role_members(Role.minter)], + pauser: [self.get_role_members(Role.pauser) for pauser in self.get_role_members(Role.pauser)], + } diff --git a/nftlabs/modules/nft_types.py b/nftlabs/modules/nft_types.py index c48257a1..c8b1932a 100644 --- a/nftlabs/modules/nft_types.py +++ b/nftlabs/modules/nft_types.py @@ -1,9 +1,13 @@ +"""Types for the NFT Module.""" from dataclasses import dataclass from typing import Optional @dataclass class MintArg: + """ + Arguments for minting new tokens + """ name: str description: str = "" image_uri: str = "" diff --git a/nftlabs/storage/ipfs_storage.py b/nftlabs/storage/ipfs_storage.py index 4f3b51b1..e34b2fe6 100644 --- a/nftlabs/storage/ipfs_storage.py +++ b/nftlabs/storage/ipfs_storage.py @@ -37,3 +37,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) diff --git a/nftlabs/types/listing.py b/nftlabs/types/listing.py index 5e8ddde7..229b77b6 100644 --- a/nftlabs/types/listing.py +++ b/nftlabs/types/listing.py @@ -1,9 +1,9 @@ from dataclasses import dataclass from typing import Optional, Union from ..nft import NftMetadata -from ..currency import CurrenctValue +from ..currency import CurrencyValue from dataclasses_json import dataclass_json - +import datetime @dataclass_json @dataclass @@ -17,5 +17,5 @@ class Listing: currency_contract: str currency_metadata: CurrencyValue | null price: int - sale_start: str - sale_end: str \ No newline at end of file + sale_start: datetime.datetime + sale_end: datetime.datetime \ No newline at end of file From 4ac3d90031a3121a536a603730a225e006d69fe5 Mon Sep 17 00:00:00 2001 From: Ayush Pathak <62694274+ayshptk@users.noreply.github.com> Date: Mon, 25 Oct 2021 12:13:27 +0530 Subject: [PATCH 08/10] =?UTF-8?q?=E2=98=91=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nftlabs/modules/market.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/nftlabs/modules/market.py b/nftlabs/modules/market.py index c72b05fe..015d34e2 100644 --- a/nftlabs/modules/market.py +++ b/nftlabs/modules/market.py @@ -133,13 +133,13 @@ def get(self, listing_id) -> List: """ Get a listing. """ - self.__abi_module.get_listing.call(listing_id) + return self.__abi_module.get_listing.call(listing_id) def get_all_listings(self, search_filter: Filter = None) -> List[Listing]: """ Returns all the listings. """ - self.get_all(search_filter) + return self.get_all(search_filter) def set_module_metadata(metadata: str): """ @@ -152,30 +152,30 @@ def get_listing(self, listing_id: int) -> Listing: """ Get a listing. """ - self.get(listing_id) + return self.get(listing_id) def get_all(self, search_filter: Filter = None) -> List[Listing]: """ Returns all the listings. """ if search_filter is None: - self.__abi_module.get_all_listings.call() + return self.__abi_module.get_all_listings.call() elif search_filter.asset_contract is not None: if search_filter.token_id is not None: - self.__abi_module.get_listings_by_asset.call( + return self.__abi_module.get_listings_by_asset.call( filer.asset_contract, filer.token_id ) else: - self.__abi_module.get_listings_by_asset_contract.call( + return self.__abi_module.get_listings_by_asset_contract.call( filer.asset_contract ) elif search_filter.seller is not None: - self.__abi_module.get_listings_by_seller.call( + return self.__abi_module.get_listings_by_seller.call( filer.seller ) else: - self.__abi_module.get_all_listings.call() + return self.__abi_module.get_all_listings.call() def total_supply(self) -> int: """ From 9f90899fe3097a1d737eec9ae839af847518041f Mon Sep 17 00:00:00 2001 From: Ayush Pathak <62694274+ayshptk@users.noreply.github.com> Date: Mon, 25 Oct 2021 12:41:40 +0530 Subject: [PATCH 09/10] Update market.py --- nftlabs/modules/market.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/nftlabs/modules/market.py b/nftlabs/modules/market.py index 015d34e2..39237ff5 100644 --- a/nftlabs/modules/market.py +++ b/nftlabs/modules/market.py @@ -2,9 +2,10 @@ from web3 import Web3 from typing import List, Dict from . import BaseModule -from ..types import Role, Listing as Listing +from ..types import Role from ..abi.market import Market from ..types.market import ListArg, Filter +from ..types.listing import Listing from ..abi.erc20 import ERC20 from ..abi.erc165 import ERC165 from ..abi.erc1155 import ERC1155 @@ -74,8 +75,9 @@ def list(self, arg: ListArg) -> Listing: ) receipt = self.execute_tx(tx) - result = self.__abi_module.get_new_listing_event( - tx_hash=receipt.transactionHash.hex()) + result = self.__abi_module.get_new_listing_event(tx_hash=receipt.transactionHash.hex()) + # listing_id = result[0]['args']['token_id'] + # return self.get(listing_id) def unlist(self, listing_id, quantity): """ @@ -177,7 +179,7 @@ def get_all(self, search_filter: Filter = None) -> List[Listing]: else: return self.__abi_module.get_all_listings.call() - def total_supply(self) -> int: + def total_listings(self) -> int: """ Returns the total supply of the market. """ From 69b749ef6970328f547e94a270cc636a5038b744 Mon Sep 17 00:00:00 2001 From: Ayush Pathak <62694274+ayshptk@users.noreply.github.com> Date: Mon, 25 Oct 2021 12:50:25 +0530 Subject: [PATCH 10/10] tiny changes --- nftlabs/modules/currency.py | 2 +- nftlabs/modules/market.py | 4 ++-- nftlabs/modules/nft.py | 2 +- nftlabs/storage/ipfs_storage.py | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/nftlabs/modules/currency.py b/nftlabs/modules/currency.py index 6d361fc1..cbbb39c7 100644 --- a/nftlabs/modules/currency.py +++ b/nftlabs/modules/currency.py @@ -163,7 +163,7 @@ def set_module_metadata(metadata: str): """ Sets the metadata for the module """ - uri = self.get_storage().Upload_metadata( + uri = self.get_storage().upload_metadata( metadata, self.address, self.get_signer_address()) def get_value(self, value: int) -> Currency: diff --git a/nftlabs/modules/market.py b/nftlabs/modules/market.py index 39237ff5..06733224 100644 --- a/nftlabs/modules/market.py +++ b/nftlabs/modules/market.py @@ -32,7 +32,7 @@ def __init__(self, client: Web3, address: str): self.__abi_module = Market(client, address) #todo: return types - def list(self, arg: ListArg) -> Listing: + def list(self, arg: ListArg): """ List an asset for sale. """ @@ -147,7 +147,7 @@ def set_module_metadata(metadata: str): """ Sets the metadata for the module """ - uri = self.get_storage().Upload_metadata( + uri = self.get_storage().upload_metadata( metadata, self.address, self.get_signer_address()) def get_listing(self, listing_id: int) -> Listing: diff --git a/nftlabs/modules/nft.py b/nftlabs/modules/nft.py index 7ec983ab..71bccd47 100644 --- a/nftlabs/modules/nft.py +++ b/nftlabs/modules/nft.py @@ -271,7 +271,7 @@ def set_module_metadata(metadata: str): """ Sets the metadata for the module """ - uri = self.get_storage().Upload_metadata( + uri = self.get_storage().upload_metadata( metadata, self.address, self.get_signer_address()) def set_restricted_transfer(self, restricted: bool = False): diff --git a/nftlabs/storage/ipfs_storage.py b/nftlabs/storage/ipfs_storage.py index 51cf6ba2..c16cc25e 100644 --- a/nftlabs/storage/ipfs_storage.py +++ b/nftlabs/storage/ipfs_storage.py @@ -41,6 +41,6 @@ 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: + 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)