-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7541d6e
commit b712f23
Showing
7 changed files
with
51 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
|
||
from dank_mids.brownie_patch.contract import patch_contract | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,29 @@ | ||
|
||
from typing import Optional | ||
from typing import Optional, Union | ||
|
||
from brownie import Contract, network, web3 | ||
from brownie.network.contract import ContractCall, ContractTx, OverloadedMethod | ||
from dank_mids.brownie_patch.call import _patch_call | ||
from dank_mids.brownie_patch.overloaded import _patch_overloaded_method | ||
from dank_mids.brownie_patch.tx import _patch_tx | ||
from web3 import Web3 | ||
|
||
from brownie import Contract, network, web3 | ||
from brownie.network.contract import ContractCall, ContractTx | ||
ContractMethod = Union[ContractCall, ContractTx, OverloadedMethod] | ||
|
||
def _patch_if_method(method: ContractMethod, w3: Web3): | ||
if isinstance(method, ContractCall) or isinstance(method, ContractTx): | ||
_patch_call(method, w3) | ||
# TODO implement this properly | ||
#elif isinstance(method, ContractTx): | ||
# _patch_tx(method, w3) | ||
elif isinstance(method, OverloadedMethod): | ||
_patch_overloaded_method(method, w3) | ||
|
||
|
||
def patch_contract(contract: Contract, w3: Optional[Web3]) -> Contract: | ||
if w3 is None and network.is_connected(): | ||
w3 = web3 | ||
assert w3 is not None, "You must make sure either brownie is connected or you pass in a Web3 instance." | ||
for k, v in contract.__dict__.items(): | ||
if isinstance(v, ContractCall): | ||
_patch_call(v, w3) | ||
# TODO implement this properly | ||
#elif isinstance(v, ContractTx): | ||
# _patch_tx(v, w3) | ||
_patch_if_method(v, w3) | ||
return contract |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import functools | ||
from types import MethodType | ||
from typing import Coroutine, Dict, Tuple, Union | ||
|
||
from brownie.network.contract import ContractCall, ContractTx, OverloadedMethod | ||
from dank_mids.brownie_patch.call import _patch_call | ||
from dank_mids.brownie_patch.tx import _patch_tx | ||
from web3 import Web3 | ||
|
||
|
||
def _patch_overloaded_method(call: OverloadedMethod, w3: Web3) -> None: | ||
@functools.wraps(call) | ||
async def coroutine( | ||
self, | ||
*args: Tuple, | ||
block_identifier: Union[int, str, bytes] = None, | ||
override: Dict = None | ||
) -> Coroutine: | ||
fn = self._get_fn_from_args(args) | ||
kwargs = {"block_identifier": block_identifier, "override": override} | ||
kwargs = {k: v for k, v in kwargs.items() if v is not None} | ||
return await fn.coroutine(*args, **kwargs) | ||
|
||
for args, method in call.__dict__['methods'].items(): | ||
if isinstance(method, ContractCall) or isinstance(method, ContractTx): | ||
_patch_call(method, w3) | ||
# TODO implement this properly | ||
#elif isinstance(call, ContractTx): | ||
#_patch_tx(call, w3) | ||
|
||
call.coroutine = MethodType(coroutine, call) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters