Skip to content

Commit

Permalink
Merge pull request #104 from bugout-dev/add-caldera
Browse files Browse the repository at this point in the history
Add Wyrm support.
  • Loading branch information
Andrei-Dolgolev authored Mar 8, 2023
2 parents 55aaf70 + 150b468 commit e5321e5
Show file tree
Hide file tree
Showing 13 changed files with 24 additions and 79 deletions.
20 changes: 15 additions & 5 deletions moonworm/cli.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import argparse
import json
import os
from multiprocessing.sharedctypes import Value
from pathlib import Path
from shutil import copyfile
from types import MappingProxyType
from typing import Any

from web3.main import Web3
from web3.middleware import geth_poa_middleware

from moonworm.crawler.ethereum_state_provider import Web3StateProvider
from moonworm.watch import watch_contract

from .contracts import CU, ERC20, ERC721, CULands
from .crawler.utils import Network
from .contracts import CU, ERC20, ERC721
from .deployment import find_deployment_block
from .generators.basic import (
generate_contract_cli_content,
Expand Down Expand Up @@ -154,6 +154,9 @@ def handle_watch(args: argparse.Namespace) -> None:
if args.db:
if args.network is None:
raise ValueError("Please specify --network")

from .crawler.networks import Network

network = Network.__members__[args.network]

from .crawler.moonstream_ethereum_state_provider import (
Expand All @@ -180,7 +183,6 @@ def handle_watch(args: argparse.Namespace) -> None:
state_provider.clear_db_session()

else:

watch_contract(
web3=web3,
state_provider=Web3StateProvider(web3),
Expand Down Expand Up @@ -215,6 +217,14 @@ def generate_argument_parser() -> argparse.ArgumentParser:
"""
Generates the command-line argument parser for the "moonworm" command.
"""
networks: MappingProxyType[Any, Any] = MappingProxyType({})
try:
from .crawler.networks import Network

networks = Network.__members__
except Exception:
pass

parser = argparse.ArgumentParser(description="Moonworm: Manage your smart contract")
parser.add_argument(
"-v",
Expand Down Expand Up @@ -256,7 +266,7 @@ def generate_argument_parser() -> argparse.ArgumentParser:

watch_parser.add_argument(
"--network",
choices=Network.__members__,
choices=networks,
default=None,
help="Network name that represents models from db. If --db is set, required",
)
Expand Down
1 change: 0 additions & 1 deletion moonworm/crawler/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
]

def run():

if len(sys.argv) < 2:
print("Usage: eventscanner.py http://your-node-url")
sys.exit(1)
Expand Down
2 changes: 0 additions & 2 deletions moonworm/crawler/log_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@ def get_block_when(block_num):
all_processed = []

for event_type in self.events:

# Callable that takes care of the underlying web3 call
def _fetch_events(_start_block, _end_block):
return _fetch_events_chunk(
Expand Down Expand Up @@ -385,7 +384,6 @@ def scan(
all_processed = []

while current_block <= end_block:

self.state.start_chunk(current_block, chunk_size)

# Print some diagnostics to logs to try to fiddle with real world JSON-RPC API performance
Expand Down
19 changes: 3 additions & 16 deletions moonworm/crawler/moonstream_ethereum_state_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,15 @@
from eth_typing.evm import ChecksumAddress
from hexbytes.main import HexBytes
from sqlalchemy.orm import Session
from sqlalchemy.sql.base import NO_ARG
from web3 import Web3

from .ethereum_state_provider import EthereumStateProvider
from .networks import (
MODELS,
EthereumLabel,
EthereumTransaction,
MumbaiLabel,
MumbaiTransaction,
PolygonLabel,
PolygonTransaction,
XDaiTransaction,
yield_db_session_ctx,
)
from .utils import Network
from .networks import MODELS, Network, tx_raw_types

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)


# TODO(yhtiyar) When getting block from db, filter it by `to` address, it will be faster
# also get blocks in bunch
class MoonstreamEthereumStateProvider(EthereumStateProvider):
Expand Down Expand Up @@ -81,9 +70,7 @@ def get_last_block_number(self) -> int:

@staticmethod
def _transform_to_w3_tx(
tx_raw: Union[
EthereumTransaction, MumbaiTransaction, PolygonTransaction, XDaiTransaction
],
tx_raw: tx_raw_types,
) -> Dict[str, Any]:
tx = {
"blockNumber": tx_raw.block_number,
Expand Down
41 changes: 3 additions & 38 deletions moonworm/crawler/networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,15 @@

try:
from moonstreamdb.db import yield_db_session_ctx
from moonstreamdb.models import (
Base,
from moonstreamdb.models import ( # state/moonstream_event_state dependency maybe removed in the future
EthereumBlock,
EthereumLabel,
EthereumTransaction,
MumbaiBlock,
MumbaiLabel,
MumbaiTransaction,
PolygonBlock,
PolygonLabel,
PolygonTransaction,
XDaiBlock,
XDaiLabel,
XDaiTransaction,
)
from moonstreamdb.networks import MODELS, Network, tx_raw_types

except ImportError:
print("this feature requires moonstreamdb which is not installed")
print("to enable, run: `pip install moonworm[moonstream]`")
raise ImportError(
"moonstreamdb not installed, to install, run: `pip install moonworm[moonstream]`"
)


from .utils import Network

MODELS: Dict[Network, Dict[str, Base]] = {
Network.ethereum: {
"blocks": EthereumBlock,
"labels": EthereumLabel,
"transactions": EthereumTransaction,
},
Network.mumbai: {
"blocks": MumbaiBlock,
"labels": MumbaiLabel,
"transactions": MumbaiTransaction,
},
Network.polygon: {
"blocks": PolygonBlock,
"labels": PolygonLabel,
"transactions": PolygonTransaction,
},
Network.xdai: {
"blocks": XDaiBlock,
"labels": XDaiLabel,
"transactions": XDaiTransaction,
},
}
2 changes: 1 addition & 1 deletion moonworm/crawler/state/moonstream_event_state.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from moonstreamdb.models import EthereumBlock, EthereumLabel
from sqlalchemy.orm import Query, Session
from web3 import Web3

from ..networks import EthereumBlock, EthereumLabel
from .event_scanner_state import EventScannerState

BLOCK_TIMESTAMP_CACHE = {}
Expand Down
8 changes: 0 additions & 8 deletions moonworm/crawler/utils.py

This file was deleted.

1 change: 0 additions & 1 deletion moonworm/generators/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,6 @@ def generate_contract_constructor_function(


def generate_contract_function(func_object: Dict[str, Any]) -> cst.FunctionDef:

default_param_name = "arg"
default_counter = 1
func_params = []
Expand Down
1 change: 0 additions & 1 deletion moonworm/generators/brownie.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ def generate_brownie_contract_function(
f"return self.contract.{func_raw_name}({','.join(param_names)})"
)
else:

func_params.append(
cst.Param(
name=cst.Name(value="block_number"),
Expand Down
3 changes: 0 additions & 3 deletions moonworm/tests/test_tester_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,13 @@ def check_eth_send(
send_value,
tx_receipt,
):

assert receiver_current_balance == receiver_previous_balance + send_value
assert (
sender_current_balance
== sender_previous_balance - send_value - tx_receipt["gasUsed"]
)

def test_submit_transaction(self) -> None:

sender = Web3.toChecksumAddress(PK_ADDRESS)
self.web3.eth.send_transaction
receiver = Web3.toChecksumAddress(self.web3.eth.accounts[1])
Expand Down Expand Up @@ -95,7 +93,6 @@ def test_submit_transaction(self) -> None:
)

def test_submit_signed_transaction(self) -> None:

sender = Web3.toChecksumAddress(PK_ADDRESS)
self.web3.eth.send_transaction
receiver = Web3.toChecksumAddress(self.web3.eth.accounts[1])
Expand Down
2 changes: 1 addition & 1 deletion moonworm/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
MOONWORM_VERSION = "0.6.0"
MOONWORM_VERSION = "0.6.1"
1 change: 0 additions & 1 deletion moonworm/web3_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ def get_nonce(web3: Web3, address: ChecksumAddress) -> Nonce:
def submit_transaction(
web3: Web3, transaction: Union[TxParams, Any], signer_private_key: str
) -> HexBytes:

"""
Signs and submits json transaction to blockchain from the name of signer
"""
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
],
extras_require={
"dev": ["isort", "mypy", "wheel", "web3[tester] >=5.27.0"],
"moonstream": ["moonstreamdb >= 0.3.2"],
"moonstream": ["moonstreamdb >= 0.3.3"],
"distribute": ["setuptools", "twine", "wheel"],
},
description="moonworm: Generate a command line interface to any Ethereum smart contract",
Expand Down

0 comments on commit e5321e5

Please sign in to comment.