Added docstrings for watch_contract

pull/97/head
Neeraj Kashyap 2022-09-19 19:34:55 -07:00
rodzic 268e46766c
commit e6c1641704
1 zmienionych plików z 44 dodań i 10 usunięć

Wyświetl plik

@ -1,15 +1,9 @@
__doc__ = """
"""
This module implements the moonworm smart contract crawler.
The [`watch_contract`](moonworm.watch.watch_contract) method is the entrypoint to this functionality
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
@ -76,8 +70,48 @@ def watch_contract(
"""
Watches a contract for events and method calls.
Uses a [moonworm.crawler.ethereum_state_provider.EthereumStateProvider]() to access blockchain state
for the crawl.
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 events *will* be reflected in the crawldata.
## Inputs
1. `web3`: A web3 client used to interact with the blockchain being crawled.
2. `state_provider`: An [`EthereumStateProvider`][moonworm.crawler.ethereum_state_provider.EthereumStateProvider]
instance that the crawler uses to access blockchain state and event logs.
3. `contract_address`: Checksum address for the smart contract
4. `contract_abi`: List representing objects in the smart contract ABI. It does not need to be an
exhaustive ABI. Any events not present in the ABI will not be crawled. Any methods not present
in the ABI will be signalled as warnings by the crawler but not stored in the crawldata.
5. `num_confirmations`: The crawler will remain this many blocks behind the current head of the blockchain.
6. `sleep_time`: The number of seconds for which to wait between polls of the state provider. Useful
if the provider rate limits clients.
7. `start_block`: Optional block number from which to start the crawl. If not provided, crawl will
start at block 0.
8. `end_block`: Optional block number at which to end crawl. If not provided, crawl will continue
indefinitely.
9. `min_blocks_batch`: Minimum number of blocks to process at a time. The crawler adapts the batch
size based on the volume of events and transactions it parses for the contract in its current
range of blocks.
10. `min_blocks_batch`: Minimum number of blocks to process at a time. The crawler adapts the batch
size based on the volume of events and transactions it parses for the contract in its current
range of blocks.
11. `max_blocks_batch`: Maximum number of blocks to process at a time. The crawler adapts the batch
size based on the volume of events and transactions it parses for the contract in its current
range of blocks.
12. `batch_size_update_threshold`: Adaptive parameter used to update batch size of blocks crawled
based on number of events processed in the current batch.
13. `only_events`: If this argument is set to True, the crawler will only crawl events and ignore
method calls. Crawling events is much, much faster than crawling method calls.
14. `outfile`: An optional file to which to write events and/or method calls in [JSON Lines format](https://jsonlines.org/).
Data is written to this file in append mode, so the crawler never deletes old data.
## Outputs
None. Results are printed to stdout and, if an outfile has been provided, also to the file.
"""
def _crawl_events(