Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removed concise and implicit contract #2505

Merged
merged 3 commits into from
Jun 9, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions newsfragments/2505.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Removed ConciseContract and ImplicitContract from contract.
137 changes: 0 additions & 137 deletions tests/core/contracts/test_concise_contract.py

This file was deleted.

119 changes: 0 additions & 119 deletions tests/core/contracts/test_implicit_contract.py

This file was deleted.

108 changes: 0 additions & 108 deletions web3/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
to_tuple,
)
from eth_utils.toolz import (
compose,
partial,
)
from hexbytes import (
Expand Down Expand Up @@ -79,9 +78,6 @@
from web3._utils.datatypes import (
PropertyCheckingFactory,
)
from web3._utils.decorators import (
deprecated_for,
)
from web3._utils.empty import (
empty,
)
Expand Down Expand Up @@ -933,110 +929,6 @@ def __prepared_function(self, *args: Any, **kwargs: Any) -> 'ContractFunction':
return getattr(self._function(*args), modifier)(modifier_dict)


class ConciseContract:
"""
An alternative Contract Factory which invokes all methods as `call()`,
unless you add a keyword argument. The keyword argument assigns the prep method.

This call

> contract.withdraw(amount, transact={'from': eth.accounts[1], 'gas': 100000, ...})

is equivalent to this call in the classic contract:

> contract.functions.withdraw(amount).transact({'from': eth.accounts[1], 'gas': 100000, ...})
"""
@deprecated_for(
"contract.caller.<method name> or contract.caller({transaction_dict}).<method name>"
)
def __init__(
self,
classic_contract: Contract,
method_class: Union[Type['ConciseMethod'], Type['ImplicitMethod']] = ConciseMethod
) -> None:
classic_contract._return_data_normalizers += CONCISE_NORMALIZERS
self._classic_contract = classic_contract
self.address = self._classic_contract.address

protected_fn_names = [fn for fn in dir(self) if not fn.endswith('__')]

for fn_name in self._classic_contract.functions:

# Override namespace collisions
if fn_name in protected_fn_names:
_concise_method = cast('ConciseMethod', mk_collision_prop(fn_name))

else:
_classic_method = getattr(
self._classic_contract.functions,
fn_name)

_concise_method = method_class(
_classic_method,
self._classic_contract._return_data_normalizers
)

setattr(self, fn_name, _concise_method)

@classmethod
def factory(cls, *args: Any, **kwargs: Any) -> Contract:
return compose(cls, Contract.factory(*args, **kwargs))


def _none_addr(datatype: str, data: ChecksumAddress) -> Tuple[str, Optional[ChecksumAddress]]:
if datatype == 'address' and int(data, base=16) == 0:
return (datatype, None)
else:
return (datatype, data)


CONCISE_NORMALIZERS: Tuple[Callable[..., Any]] = (
_none_addr,
)


class ImplicitMethod(ConciseMethod):
def __call_by_default(self, args: Any) -> bool:
function_abi = find_matching_fn_abi(self._function.contract_abi,
self._function.w3.codec,
fn_identifier=self._function.function_identifier,
args=args)

return function_abi['constant'] if 'constant' in function_abi.keys() else False

@deprecated_for("classic contract syntax. Ex: contract.functions.withdraw(amount).transact({})")
def __call__(self, *args: Any, **kwargs: Any) -> 'ContractFunction':
# Modifier is not provided and method is not constant/pure do a transaction instead
if not kwargs and not self.__call_by_default(args):
return super().__call__(*args, transact={})
else:
return super().__call__(*args, **kwargs)


class ImplicitContract(ConciseContract):
"""
ImplicitContract class is similar to the ConciseContract class
however it performs a transaction instead of a call if no modifier
is given and the method is not marked 'constant' in the ABI.

The transaction will use the default account to send the transaction.

This call

> contract.withdraw(amount)

is equivalent to this call in the classic contract:

> contract.functions.withdraw(amount).transact({})
"""
def __init__(
self,
classic_contract: Contract,
method_class: Union[Type[ImplicitMethod], Type[ConciseMethod]] = ImplicitMethod
) -> None:
super().__init__(classic_contract, method_class=method_class)


class NonExistentFallbackFunction:
@staticmethod
def _raise_exception() -> NoReturn:
Expand Down
Loading