-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #167 from consensusnetworks/feature/clean-crawler
Feature/clean crawler
- Loading branch information
Showing
22 changed files
with
11,367 additions
and
1,838 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
scripts/**/resources | ||
cdk.out | ||
*.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#!/bin/bash | ||
# Run a Casimir crawler | ||
# | ||
# Example: | ||
# | ||
# scripts/crawler/dev -c chains -f fork-name -n network-name -upload whether-to-upload (network overrides fork) | ||
# | ||
# Further information: | ||
# See https://docs.aws.amazon.com/cdk/api/v2/ | ||
# | ||
|
||
# Configure and expose variables | ||
source scripts/aws/configure | ||
|
||
# Set RPC URL bases | ||
ethereum_mainnet=https://eth-mainnet.g.alchemy.com/v2 | ||
ethereum_testnet=https://eth-testnet.g.alchemy.com/v2 | ||
|
||
# Set the stage | ||
export PUBLIC_STAGE=${STAGE} | ||
|
||
# Get args | ||
while getopts :c:f:n:u: flag | ||
do | ||
case "${flag}" in | ||
c) chains=${OPTARG};; | ||
f) fork=${OPTARG};; | ||
n) network=${OPTARG};; | ||
u) upload=${OPTARG};; | ||
esac | ||
done | ||
|
||
# Default to ethereum if chains is not set or set vaguely | ||
if [ -z "$chains" ] || [ "$chains" = true ]; then | ||
chains="ethereum" | ||
fi | ||
|
||
# Default to mainnet if fork is set vaguely | ||
if [ "$fork" = true ]; then | ||
fork="mainnet" | ||
fi | ||
|
||
# Default to mainnet if network is not set or set vaguely | ||
if [ -z "$network" ] || [ "$network" = true ]; then | ||
network="mainnet" | ||
fi | ||
|
||
# Default to true if upload is not set | ||
if [ -z "$upload" ]; then | ||
upload="enabled" | ||
fi | ||
|
||
|
||
export CHAINS=$chains | ||
export FORK=$fork | ||
export NETWORK=$network | ||
export UPLOAD=$upload | ||
|
||
commands=("npm run dev --workspace @casimir/crawler") | ||
|
||
# Loop over comma-separated string of chains | ||
IFS=',' read -r -a chain_list <<< "$chains" | ||
|
||
for chain in "${chain_list[@]}" | ||
do | ||
# Expose RPC URL directly if network is set to mainnet or testnet | ||
if [ -n "$network" ]; then | ||
# Get the RPC API key from AWS | ||
rpc_secret_id=consensus-networks-$chain-$network | ||
rpc_key=$(aws secretsmanager get-secret-value \ | ||
--secret-id $rpc_secret_id \ | ||
--query SecretString \ | ||
--output text \ | ||
--profile $profile) | ||
|
||
CHAIN=$(echo $chain | tr '[:lower:]' '[:upper:]') | ||
rpc_base=${chain}_${network} | ||
export "PUBLIC_${CHAIN}_RPC"="${!rpc_base}/$rpc_key" | ||
else | ||
# Pass fork or network to chain-specific script | ||
commands+=("npm run dev:$chain --fork=$fork") | ||
fi | ||
done | ||
|
||
for command in "${commands[@]}" | ||
do | ||
$command & | ||
done | ||
|
||
wait && pkill -P $$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,34 @@ | ||
## Crawler | ||
# @casimir/crawler | ||
|
||
Identify, structure and stream [@casimir/data events](common/data/src/schemas/event.schema.json) to s3. | ||
|
||
> 🚩 Run all commands from the monorepo root. | ||
## Development | ||
|
||
Run the crawler with default chains and mainnet networks. | ||
|
||
```zsh | ||
npm run dev:crawler # --upload=disabled disables s3 upload | ||
``` | ||
|
||
**Available flags:** | ||
|
||
These flags modify the CHAINS, FORK, NETWORK, UPLOAD AND PUBLIC_${CHAIN}_RPC environment variables. | ||
|
||
| Name | Description | Default | | ||
| - | - | - | | ||
| --chains | Comma-separated list of chains | ethereum | | ||
| --fork | Network state to fork | mainnet | | ||
| --network | Network to query | mainnet | | ||
| --upload | Enable/disable upload to s3 | enabled | | ||
|
||
> Use an equals sign to set flags to variables, like `--upload=disabled`. | ||
## Testing | ||
|
||
Test the crawler with [./test](./test/) files. | ||
|
||
```zsh | ||
npm run test:crawler | ||
``` |
Oops, something went wrong.