kopia lustrzana https://github.com/bugout-dev/moonworm
Started adding docstrings on "moonworm watch"
rodzic
454b5d7754
commit
268e46766c
|
@ -23,11 +23,17 @@ from .version import MOONWORM_VERSION
|
|||
|
||||
|
||||
def write_file(content: str, path: str):
|
||||
"""
|
||||
Write content to filesystem at the specified path.
|
||||
"""
|
||||
with open(path, "w") as ofp:
|
||||
ofp.write(content)
|
||||
|
||||
|
||||
def copy_web3_util(dest_dir: str, force: bool = False) -> None:
|
||||
"""
|
||||
Copy the web3_util.py file to the given destination directory.
|
||||
"""
|
||||
dest_filepath = os.path.join(dest_dir, "web3_util.py")
|
||||
if os.path.isfile(dest_filepath) and not force:
|
||||
print(f"{dest_filepath} file already exists. Use -f to rewrite")
|
||||
|
@ -36,6 +42,9 @@ def copy_web3_util(dest_dir: str, force: bool = False) -> None:
|
|||
|
||||
|
||||
def create_init_py(dest_dir: str, force: bool = False) -> None:
|
||||
"""
|
||||
Create __init__.py file in destination directory.
|
||||
"""
|
||||
dest_filepath = os.path.join(dest_dir, "__init__.py")
|
||||
if os.path.isfile(dest_filepath) and not force:
|
||||
print(f"{dest_filepath} file already exists. Use -f to rewrite")
|
||||
|
@ -44,6 +53,10 @@ def create_init_py(dest_dir: str, force: bool = False) -> None:
|
|||
|
||||
|
||||
def handle_generate(args: argparse.Namespace) -> None:
|
||||
"""
|
||||
Handler for the "moonworm generate" command, which generates web3.py-compatible interfaces to a
|
||||
given smart contract.
|
||||
"""
|
||||
if not args.interface and not args.cli:
|
||||
print("Please specify what you want to generate:")
|
||||
print("--interface for smart contract interface")
|
||||
|
@ -85,7 +98,10 @@ def handle_generate(args: argparse.Namespace) -> None:
|
|||
|
||||
|
||||
def handle_brownie_generate(args: argparse.Namespace):
|
||||
|
||||
"""
|
||||
Handler for the "moonworm generate-brownie" command, which generates brownie-compatible interfaces
|
||||
to a given smart contract.
|
||||
"""
|
||||
Path(args.outdir).mkdir(exist_ok=True)
|
||||
|
||||
project_directory = args.project
|
||||
|
@ -118,6 +134,10 @@ def handle_brownie_generate(args: argparse.Namespace):
|
|||
|
||||
|
||||
def handle_watch(args: argparse.Namespace) -> None:
|
||||
"""
|
||||
Handler for the "moonworm watch" command, which records all events and transactions against a given
|
||||
smart contract between the specified block range.
|
||||
"""
|
||||
if args.abi == "erc20":
|
||||
contract_abi = ERC20.abi()
|
||||
elif args.abi == "erc721":
|
||||
|
@ -178,6 +198,10 @@ def handle_watch(args: argparse.Namespace) -> None:
|
|||
|
||||
|
||||
def handle_find_deployment(args: argparse.Namespace) -> None:
|
||||
"""
|
||||
Handler for the "moonworm find-deployment" command, which finds the deployment block for a given
|
||||
smart contract.
|
||||
"""
|
||||
web3_client = Web3(Web3.HTTPProvider(args.web3))
|
||||
result = find_deployment_block(web3_client, args.contract, args.interval)
|
||||
if result is None:
|
||||
|
@ -188,6 +212,9 @@ def handle_find_deployment(args: argparse.Namespace) -> None:
|
|||
|
||||
|
||||
def generate_argument_parser() -> argparse.ArgumentParser:
|
||||
"""
|
||||
Generates the command-line argument parser for the "moonworm" command.
|
||||
"""
|
||||
parser = argparse.ArgumentParser(description="Moonworm: Manage your smart contract")
|
||||
parser.add_argument(
|
||||
"-v",
|
||||
|
@ -398,6 +425,9 @@ def generate_argument_parser() -> argparse.ArgumentParser:
|
|||
|
||||
|
||||
def main() -> None:
|
||||
"""
|
||||
Handler for the "moonworm" command.
|
||||
"""
|
||||
parser = generate_argument_parser()
|
||||
args = parser.parse_args()
|
||||
args.func(args)
|
||||
|
|
|
@ -1,3 +1,17 @@
|
|||
__doc__ = """
|
||||
This module implements the moonworm smart contract crawler.
|
||||
|
||||
The [`watch_contract`](moonworm.watch.watch_contract) method is the entrypoint to this functionality
|
||||
and it is what powers the "moonworm watch" command.
|
||||
|
||||
`watch_crawler` currently supports crawling events and direct method calls on a smart contract.
|
||||
|
||||
It does *not* currently support crawling internal messages to a smart contract - this means that any
|
||||
calls made to the target smart contract from *another* smart contract will not be recorded directly
|
||||
in the crawldata. If the internal message resulted in any events being emitted on the target
|
||||
contract, those event *will* be reflected in the crawldata.
|
||||
"""
|
||||
|
||||
import json
|
||||
import pprint as pp
|
||||
import time
|
||||
|
@ -60,7 +74,10 @@ def watch_contract(
|
|||
outfile: Optional[str] = None,
|
||||
) -> None:
|
||||
"""
|
||||
Watches a contract for events and calls.
|
||||
Watches a contract for events and method calls.
|
||||
|
||||
Uses a [moonworm.crawler.ethereum_state_provider.EthereumStateProvider]() to access blockchain state
|
||||
for the crawl.
|
||||
"""
|
||||
|
||||
def _crawl_events(
|
||||
|
|
Ładowanie…
Reference in New Issue