Skip to content

Commit

Permalink
perf: lazy load treatment for ape-ethereum core plugin (#2356)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Oct 31, 2024
1 parent 84928c5 commit faed339
Showing 1 changed file with 72 additions and 40 deletions.
112 changes: 72 additions & 40 deletions src/ape_ethereum/__init__.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,32 @@
from ape import plugins
from ape.api.networks import ForkedNetworkAPI, NetworkAPI, create_network_type

from ._converters import WeiConversions
from .ecosystem import (
NETWORKS,
BaseEthereumConfig,
Block,
Ethereum,
EthereumConfig,
ForkedNetworkConfig,
NetworkConfig,
)
from .provider import EthereumNodeProvider, Web3Provider, assert_web3_provider_uri_env_var_not_set
from .query import EthereumQueryProvider
from .trace import CallTrace, Trace, TransactionTrace
from .transactions import (
AccessListTransaction,
BaseTransaction,
DynamicFeeTransaction,
Receipt,
SharedBlobReceipt,
SharedBlobTransaction,
StaticFeeTransaction,
TransactionStatusEnum,
TransactionType,
)


@plugins.register(plugins.Config)
def config_class():
from ape_ethereum.ecosystem import EthereumConfig

return EthereumConfig


@plugins.register(plugins.ConversionPlugin)
def converters():
from ape_ethereum._converters import WeiConversions

yield int, WeiConversions


@plugins.register(plugins.EcosystemPlugin)
def ecosystems():
from ape_ethereum.ecosystem import Ethereum

yield Ethereum


@plugins.register(plugins.NetworkPlugin)
def networks():
from ape.api.networks import ForkedNetworkAPI, NetworkAPI, create_network_type
from ape_ethereum.ecosystem import NETWORKS

for network_name, network_params in NETWORKS.items():
yield "ethereum", network_name, create_network_type(*network_params)
yield "ethereum", f"{network_name}-fork", ForkedNetworkAPI
Expand All @@ -54,29 +37,78 @@ def networks():

@plugins.register(plugins.QueryPlugin)
def query_engines():
from .query import EthereumQueryProvider

yield EthereumQueryProvider


def __getattr__(name):
if name in (
"BaseEthereumConfig",
"Block",
"Ethereum",
"EthereumConfig",
"ForkedNetworkConfig",
"NetworkConfig",
):
import ape_ethereum.ecosystem as ecosystem_module

return getattr(ecosystem_module, name)

elif name in (
"EthereumNodeProvider",
"Web3Provider",
"assert_web3_provider_uri_env_var_not_set",
):
import ape_ethereum.provider as provider_module

return getattr(provider_module, name)

elif name in (
"AccessListTransaction",
"BaseTransaction",
"DynamicFeeTransaction",
"Receipt",
"SharedBlobReceipt",
"SharedBlobTransaction",
"StaticFeeTransaction",
"TransactionStatusEnum",
"TransactionType",
):
import ape_ethereum.transactions as tx_module

return getattr(tx_module, name)

elif name in ("CallTrace", "Trace", "TransactionTrace"):
import ape_ethereum.trace as trace_module

return getattr(trace_module, name)

else:
raise AttributeError(name)


__all__ = [
"Ethereum",
"EthereumConfig",
"NetworkConfig",
"ForkedNetworkConfig",
"AccessListTransaction",
"assert_web3_provider_uri_env_var_not_set",
"BaseEthereumConfig",
"BaseTransaction",
"Block",
"assert_web3_provider_uri_env_var_not_set",
"Web3Provider",
"CallTrace",
"DynamicFeeTransaction",
"Ethereum",
"EthereumConfig",
"EthereumNodeProvider",
"ForkedNetworkConfig",
"NetworkConfig",
"Receipt",
"SharedBlobReceipt",
"SharedBlobTransaction",
"StaticFeeTransaction",
"Trace",
"TransactionTrace",
"CallTrace",
"TransactionStatusEnum",
"TransactionTrace",
"TransactionType",
"BaseTransaction",
"StaticFeeTransaction",
"AccessListTransaction",
"DynamicFeeTransaction",
"SharedBlobTransaction",
"Receipt",
"SharedBlobReceipt",
"Web3Provider",
]

0 comments on commit faed339

Please sign in to comment.