Skip to content

Commit

Permalink
feat: improve provider typing
Browse files Browse the repository at this point in the history
  • Loading branch information
petarTxFusion committed Nov 8, 2024
1 parent a095d5a commit 215168c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
Empty file.
21 changes: 14 additions & 7 deletions zksync2/module/module_builder.py
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

0 comments on commit 215168c

Please sign in to comment.