-
Notifications
You must be signed in to change notification settings - Fork 199
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
a095d5a
commit 215168c
Showing
2 changed files
with
14 additions
and
7 deletions.
There are no files selected for viewing
Empty file.
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,19 +1,26 @@ | ||
from web3._utils.module import attach_modules | ||
|
||
from zksync2.module.middleware import ZkSyncMiddlewareBuilder | ||
from zksync2.module.zksync_module import ZkSync | ||
from zksync2.module.zksync_provider import ZkSyncProvider | ||
from zksync2.module.middleware import build_zksync_middleware | ||
|
||
from typing import Union | ||
from web3._utils.module import attach_modules | ||
from eth_typing import URI | ||
from web3 import Web3 | ||
|
||
|
||
class ZkWeb3(Web3): | ||
zksync: ZkSync | ||
|
||
def __init__(self, provider): | ||
super().__init__(provider) | ||
# Attach the zksync module | ||
attach_modules(self, {"zksync": (ZkSync,)}) | ||
|
||
|
||
class ZkSyncBuilder: | ||
@classmethod | ||
def build(cls, url: Union[URI, str]) -> Web3: | ||
web3_module = Web3() | ||
def build(cls, url: Union[URI, str]) -> ZkWeb3: | ||
zksync_provider = ZkSyncProvider(url) | ||
zksync_middleware = build_zksync_middleware(zksync_provider) | ||
web3_module.middleware_onion.add(zksync_middleware) | ||
attach_modules(web3_module, {"zksync": (ZkSync,)}) | ||
web3_module = ZkWeb3(zksync_provider) | ||
return web3_module |