-
-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support web3.py v7 (in addition to v6) (#2394)
Co-authored-by: Evan <[email protected]>
- Loading branch information
1 parent
5b3ad09
commit df7d7a1
Showing
8 changed files
with
101 additions
and
64 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
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,28 @@ | ||
from eth_account import Account as EthAccount | ||
|
||
try: | ||
# Web3 v7 | ||
from web3.middleware import ExtraDataToPOAMiddleware # type: ignore | ||
except ImportError: | ||
from web3.middleware import geth_poa_middleware as ExtraDataToPOAMiddleware # type: ignore | ||
|
||
try: | ||
from web3.providers import WebsocketProviderV2 as WebsocketProvider # type: ignore | ||
except ImportError: | ||
from web3.providers import WebSocketProvider as WebsocketProvider # type: ignore | ||
|
||
|
||
def sign_hash(msghash, private_key): | ||
try: | ||
# Web3 v7 | ||
return EthAccount.unsafe_sign_hash(msghash, private_key) # type: ignore | ||
except AttributeError: | ||
# Web3 v6 | ||
return EthAccount.signHash(msghash, private_key) # type: ignore | ||
|
||
|
||
__all__ = [ | ||
"ExtraDataToPOAMiddleware", | ||
"sign_hash", | ||
"WebsocketProvider", | ||
] |
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
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