Skip to content

Feature/asyncify contract #2439

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

Merged
merged 46 commits into from
Apr 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
0a898fe
init commit of async contract
dbfreem Mar 4, 2022
04bf711
more linting, still more to go
dbfreem Mar 4, 2022
e4dface
more linting. I seem to have broken some of the test on this one.
dbfreem Mar 4, 2022
acdae38
fixed broken test
dbfreem Mar 6, 2022
3c63696
This is most of the linting changes so far
dbfreem Mar 7, 2022
7118d24
async test
dbfreem Mar 7, 2022
e15971e
lint rearrange imports
dbfreem Mar 7, 2022
3682aa3
ContractEvents/ContractEvent Async
dbfreem Mar 7, 2022
b74662e
couple more fixes
dbfreem Mar 7, 2022
2944ee9
more work on contract
dbfreem Mar 8, 2022
6473a54
add non-ens normalize_address func (#2384)
Mar 8, 2022
0064b2a
Merge branch 'asyncify-contract' of https://github.com/ethereum/web3.…
dbfreem Mar 9, 2022
d568a5e
continued work on contract and fixed linting
dbfreem Mar 9, 2022
31c1e34
fixes
dbfreem Mar 9, 2022
3c2e26b
linting
dbfreem Mar 9, 2022
722c711
fix test import in the wrong place
dbfreem Mar 9, 2022
79f99dd
fixing combomethod
dbfreem Mar 9, 2022
c7bbd24
init commit of async contract (#2377)
dbfreem Mar 10, 2022
ba4ef33
Merge branch 'asyncify-contract' of https://github.com/ethereum/web3.…
dbfreem Mar 10, 2022
a2170e6
First test added
dbfreem Mar 10, 2022
1c765e8
ContractConstructor
dbfreem Mar 10, 2022
6e2ee8a
linting fixes
dbfreem Mar 11, 2022
ad97b6e
eth.contract and linting
dbfreem Mar 11, 2022
0d723dd
async_parse_block_identifier_int
dbfreem Mar 11, 2022
1bfda9f
Feature/asyncify contract (#2387)
dbfreem Mar 11, 2022
a0dad2d
pull master into asyncify-contract (#2389)
Mar 14, 2022
f1639b8
Merge branch 'asyncify-contract' of https://github.com/ethereum/web3.…
dbfreem Mar 15, 2022
1dc9a62
added two more async functions
dbfreem Mar 15, 2022
e30aa4e
Feature/asyncify contract (#2392)
dbfreem Mar 15, 2022
fa7d429
fill_transaction_defaults async for later use in build_transaction_fo…
dbfreem Mar 18, 2022
fdc6d50
build_transaction in ContractFunction
dbfreem Mar 19, 2022
dafa820
merge
dbfreem Mar 20, 2022
51248eb
estimateGas async in Contract and docs
dbfreem Mar 22, 2022
814d16b
lint
dbfreem Mar 22, 2022
268fe52
docs
dbfreem Mar 22, 2022
9ed1b7a
Feature/asyncify contract (#2394)
dbfreem Mar 23, 2022
e6b352a
setting default contract factory in AsyncEth to AsyncContract
dbfreem Mar 24, 2022
e1c4576
Merge branch 'asyncify-contract' of https://github.com/ethereum/web3.…
dbfreem Mar 24, 2022
fb238c9
Feature/asyncify contract (#2404)
dbfreem Mar 24, 2022
d1675a1
defaultContractFacotry
dbfreem Mar 25, 2022
74c5e47
Merge branch 'asyncify-contract' of https://github.com/ethereum/web3.…
dbfreem Mar 25, 2022
d34b039
defaultContractFactory
dbfreem Mar 25, 2022
17bbcd0
renaming deprecated methods
dbfreem Mar 25, 2022
04674e5
Merge branch 'asyncify-contract' of https://github.com/ethereum/web3.…
dbfreem Apr 22, 2022
d4b96bf
removed buildTransaction and estimateGas
dbfreem Apr 22, 2022
4b52eac
docs update
dbfreem Apr 23, 2022
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
22 changes: 2 additions & 20 deletions docs/contracts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,6 @@ Each Contract Factory exposes the following methods.
>>> txn_receipt['contractAddress']
'0x4c0883a69102937d6231471b5dbb6204fe5129617082792ae468d01a3f362318'

.. py:classmethod:: Contract.constructor(*args, **kwargs).estimateGas(transaction=None, block_identifier=None)
:noindex:

.. warning:: Deprecated: This method is deprecated in favor of :py:meth:`Contract.constructor(*args, **kwargs).estimate_gas`

.. py:classmethod:: Contract.constructor(*args, **kwargs).estimate_gas(transaction=None, block_identifier=None)
:noindex:

Expand All @@ -272,11 +267,6 @@ Each Contract Factory exposes the following methods.
>>> token_contract.constructor(web3.eth.coinbase, 12345).estimate_gas()
12563

.. py:classmethod:: Contract.constructor(*args, **kwargs).buildTransaction(transaction=None)
:noindex:

.. warning:: Deprecated: This method is deprecated in favor of :py:meth:`Contract.constructor(*args, **kwargs).build_transaction`

.. py:classmethod:: Contract.constructor(*args, **kwargs).build_transaction(transaction=None)
:noindex:

Expand Down Expand Up @@ -843,10 +833,6 @@ Methods
a "missing trie node" error, because Ethereum node may have purged the past state from its database.
`More information about archival nodes here <https://ethereum.stackexchange.com/a/84200/620>`_.

.. py:method:: ContractFunction.estimateGas(transaction, block_identifier=None)

.. warning:: Deprecated: This method is deprecated in favor of :class:`~estimate_gas`

.. py:method:: ContractFunction.estimate_gas(transaction, block_identifier=None)

Call a contract function, executing the transaction locally using the
Expand Down Expand Up @@ -874,10 +860,6 @@ Methods
The parameter ``block_identifier`` is not enabled in geth nodes,
hence passing a value of ``block_identifier`` when connected to a geth
nodes would result in an error like: ``ValueError: {'code': -32602, 'message': 'too many arguments, want at most 1'}``

.. py:method:: ContractFunction.buildTransaction(transaction)

.. warning:: Deprecated: This method is deprecated in favor of :class:`~build_transaction`

.. py:method:: ContractFunction.build_transaction(transaction)

Expand Down Expand Up @@ -941,15 +923,15 @@ Fallback Function
Call fallback function, executing the transaction locally using the
``eth_call`` API. This will not create a new public transaction.

.. py:method:: Contract.fallback.estimateGas(transaction)
.. py:method:: Contract.fallback.estimate_gas(transaction)

Call fallback function and return the gas estimation.

.. py:method:: Contract.fallback.transact(transaction)

Execute fallback function by sending a new public transaction.

.. py:method:: Contract.fallback.buildTransaction(transaction)
.. py:method:: Contract.fallback.build_transaction(transaction)

Builds a transaction dictionary based on the contract fallback function call.

Expand Down
4 changes: 2 additions & 2 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ The following example demonstrates a few things:

store_var_contract = w3.eth.contract(address=address, abi=contract_interface["abi"])

gas_estimate = store_var_contract.functions.setVar(255).estimateGas()
gas_estimate = store_var_contract.functions.setVar(255).estimate_gas()
print(f'Gas estimate to transact with setVar: {gas_estimate}')

if gas_estimate < 100000:
Expand Down Expand Up @@ -674,7 +674,7 @@ Just remember that you have to sign all transactions locally, as infura does not

.. code-block:: python

transaction = contract.functions.function_Name(params).buildTransaction()
transaction = contract.functions.function_Name(params).build_transaction()
transaction.update({ 'gas' : appropriate_gas_amount })
transaction.update({ 'nonce' : w3.eth.get_transaction_count('Your_Wallet_Address') })
signed_tx = w3.eth.account.sign_transaction(transaction, private_key)
Expand Down
2 changes: 1 addition & 1 deletion docs/web3.eth.account.rst
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ To sign a transaction locally that will invoke a smart contract:
>>> unicorn_txn = unicorns.functions.transfer(
... '0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359',
... 1,
... ).buildTransaction({
... ).build_transaction({
... 'chainId': 1,
... 'gas': 70000,
... 'maxFeePerGas': w3.toWei('2', 'gwei'),
Expand Down
45 changes: 9 additions & 36 deletions web3/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -868,22 +868,6 @@ def build_transaction(self, transaction: Optional[TxParams] = None) -> TxParams:
built_transaction = self._build_transaction(transaction)
return transactions.fill_transaction_defaults(self.w3, built_transaction)

@combomethod
@deprecated_for("build_transaction")
def buildTransaction(self, transaction: Optional[TxParams] = None) -> TxParams:
"""
Build the transaction dictionary without sending
"""
return self.build_transaction(transaction)

@combomethod
@deprecated_for("estimate_gas")
def estimateGas(
self, transaction: Optional[TxParams] = None,
block_identifier: Optional[BlockIdentifier] = None
) -> int:
return self.estimate_gas(transaction, block_identifier)

@combomethod
def estimate_gas(
self, transaction: Optional[TxParams] = None,
Expand Down Expand Up @@ -924,7 +908,7 @@ async def estimate_gas(


class ConciseMethod:
ALLOWED_MODIFIERS = {'call', 'estimateGas', 'transact', 'buildTransaction'}
ALLOWED_MODIFIERS = {'call', 'estimate_gas', 'transact', 'build_transaction'}

def __init__(
self, function: 'ContractFunction',
Expand Down Expand Up @@ -1178,9 +1162,9 @@ def _estimate_gas(
estimate_gas_transaction = cast(TxParams, dict(**transaction))

if 'data' in estimate_gas_transaction:
raise ValueError("Cannot set 'data' field in estimateGas transaction")
raise ValueError("Cannot set 'data' field in estimate_gas transaction")
if 'to' in estimate_gas_transaction:
raise ValueError("Cannot set to in estimateGas transaction")
raise ValueError("Cannot set to in estimate_gas transaction")

if self.address:
estimate_gas_transaction.setdefault('to', self.address)
Expand All @@ -1191,7 +1175,7 @@ def _estimate_gas(
if 'to' not in estimate_gas_transaction:
if isinstance(self, type):
raise ValueError(
"When using `Contract.estimateGas` from a contract factory "
"When using `Contract.estimate_gas` from a contract factory "
"you must provide a `to` address with the transaction"
)
else:
Expand All @@ -1211,7 +1195,7 @@ def _build_transaction(self, transaction: Optional[TxParams] = None) -> TxParams

if not self.address and 'to' not in built_transaction:
raise ValueError(
"When using `ContractFunction.buildTransaction` from a contract factory "
"When using `ContractFunction.build_transaction` from a contract factory "
"you must provide a `to` address with the transaction"
)
if self.address and 'to' in built_transaction:
Expand Down Expand Up @@ -1339,13 +1323,6 @@ def estimate_gas(
**self.kwargs
)

@deprecated_for("estimate_gas")
def estimateGas(
self, transaction: Optional[TxParams] = None,
block_identifier: Optional[BlockIdentifier] = None
) -> int:
return self.estimate_gas(transaction, block_identifier)

def build_transaction(self, transaction: Optional[TxParams] = None) -> TxParams:

built_transaction = self._build_transaction(transaction)
Expand All @@ -1360,10 +1337,6 @@ def build_transaction(self, transaction: Optional[TxParams] = None) -> TxParams:
**self.kwargs
)

@deprecated_for("build_transaction")
def buildTransaction(self, transaction: Optional[TxParams] = None) -> TxParams:
return self.build_transaction(transaction)


class AsyncContractFunction(BaseContractFunction):

Expand Down Expand Up @@ -2224,7 +2197,7 @@ def estimate_gas_for_function(
**kwargs: Any) -> int:
"""Estimates gas cost a function call would take.

Don't call this directly, instead use :meth:`Contract.estimateGas`
Don't call this directly, instead use :meth:`Contract.estimate_gas`
on your contract instance.
"""
estimate_transaction = prepare_transaction(
Expand Down Expand Up @@ -2253,7 +2226,7 @@ async def async_estimate_gas_for_function(
**kwargs: Any) -> int:
"""Estimates gas cost a function call would take.

Don't call this directly, instead use :meth:`Contract.estimateGas`
Don't call this directly, instead use :meth:`Contract.estimate_gas`
on your contract instance.
"""
estimate_transaction = prepare_transaction(
Expand Down Expand Up @@ -2281,7 +2254,7 @@ def build_transaction_for_function(
**kwargs: Any) -> TxParams:
"""Builds a dictionary with the fields required to make the given transaction

Don't call this directly, instead use :meth:`Contract.buildTransaction`
Don't call this directly, instead use :meth:`Contract.build_transaction`
on your contract instance.
"""
prepared_transaction = prepare_transaction(
Expand Down Expand Up @@ -2311,7 +2284,7 @@ async def async_build_transaction_for_function(
**kwargs: Any) -> TxParams:
"""Builds a dictionary with the fields required to make the given transaction

Don't call this directly, instead use :meth:`Contract.buildTransaction`
Don't call this directly, instead use :meth:`Contract.build_transaction`
on your contract instance.
"""
prepared_transaction = prepare_transaction(
Expand Down