Merge pull request #104 from bugout-dev/add-caldera

Add Wyrm support.
pull/105/head^2 v0.6.1
Andrey Dolgolev 2023-03-08 19:20:46 +02:00 zatwierdzone przez GitHub
commit e5321e5eda
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
13 zmienionych plików z 24 dodań i 79 usunięć

Wyświetl plik

@ -1,9 +1,10 @@
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
@ -11,8 +12,7 @@ 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,
@ -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 (
@ -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),
@ -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",
@ -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",
)

Wyświetl plik

@ -43,7 +43,6 @@ if __name__ == "__main__":
]
def run():
if len(sys.argv) < 2:
print("Usage: eventscanner.py http://your-node-url")
sys.exit(1)

Wyświetl plik

@ -303,7 +303,6 @@ class EventScanner:
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(
@ -385,7 +384,6 @@ class EventScanner:
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

Wyświetl plik

@ -4,26 +4,15 @@ from typing import Any, Dict, List, Optional, Union
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):
@ -81,9 +70,7 @@ class MoonstreamEthereumStateProvider(EthereumStateProvider):
@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,

Wyświetl plik

@ -2,50 +2,15 @@ from typing import Dict
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,
},
}

Wyświetl plik

@ -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 = {}

Wyświetl plik

@ -1,8 +0,0 @@
from enum import Enum
class Network(Enum):
ethereum = "ethereum"
polygon = "polygon"
mumbai = "mumbai"
xdai = "xdai"

Wyświetl plik

@ -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 = []

Wyświetl plik

@ -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"),

Wyświetl plik

@ -52,7 +52,6 @@ class MoonwormEthTesterTestCase(unittest.TestCase):
send_value,
tx_receipt,
):
assert receiver_current_balance == receiver_previous_balance + send_value
assert (
sender_current_balance
@ -60,7 +59,6 @@ class MoonwormEthTesterTestCase(unittest.TestCase):
)
def test_submit_transaction(self) -> None:
sender = Web3.toChecksumAddress(PK_ADDRESS)
self.web3.eth.send_transaction
receiver = Web3.toChecksumAddress(self.web3.eth.accounts[1])
@ -95,7 +93,6 @@ class MoonwormEthTesterTestCase(unittest.TestCase):
)
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])

Wyświetl plik

@ -1 +1 @@
MOONWORM_VERSION = "0.6.0"
MOONWORM_VERSION = "0.6.1"

Wyświetl plik

@ -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
"""

Wyświetl plik

@ -22,7 +22,7 @@ setup(
],
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",