Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PoC: Use event stream #543

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
JSON_RPC_URL=<your-json-rpc-url># e.g. https://lb.drpc.org/ogrpc?network=ethereum&dkey=your-magic-key
NATS_STREAM_NAME=ethereum_events
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ forta.config.json
version.json
.DS_Store
.idea
.env
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,14 @@ And finally:
yarn install
yarn format
```


## Consuming events from DRPC
### Prerequesites:
- [Docker](https://docs.docker.com/get-docker/)
- [Docker Compose](https://docs.docker.com/compose/install/)

### Steps:
1. Rename `.env.example` to `.env` and fill in the required values (DRPC API key).
2. Run `docker-compose up --build`.
3. The bot will start consuming events from DRPC and logging them to the console.
54 changes: 54 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
volumes:
nats:
last_data:

services:
big-ear:
image: feofanov/big-ear
env_file:
- .env
environment:
# - BLOCK=19788401 # uncomment to run only for a specific block (catches Easy Track event)
# - BLOCK=19718592 # uncomment to run only for a specific block (catches Aragon voting event)
- NATS_URL=nats://nats:4222
- LAST_DATA_DIR=/home/appuser/lastdata
depends_on:
- nats
volumes:
- last_data:/home/appuser/last_data
nats:
image: nats
ports:
- "4222:4222"
- "8222:8222"
volumes:
- nats:/data
command:
- "--name=nats"
- "--http_port=8222"
- "--js"
- "--sd=/data"

# bots section
ethereum-governance-v2:
env_file:
- .env
build:
context: ethereum-governance-v2
dockerfile: nats.Dockerfile
environment:
- BOT_NAME=ethereum-governance-v2 # REQUIRED! SHOULD BE UNIQUE!
- NATS_URL=nats://nats:4222
depends_on:
- big-ear
voting-watcher:
env_file:
- .env
build:
context: voting-watcher
dockerfile: nats.Dockerfile
environment:
- BOT_NAME=voting-watcher # REQUIRED! SHOULD BE UNIQUE!
- NATS_URL=nats://nats:4222
depends_on:
- big-ear
1 change: 0 additions & 1 deletion ethereum-governance-v2/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
node_modules/
dist/
forta.config.json
74 changes: 74 additions & 0 deletions ethereum-governance-v2/nats.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# syntax=docker/dockerfile:1

# Comments are provided throughout this file to help you get started.
# If you need more help, visit the nats.Dockerfile reference guide at
# https://docs.docker.com/go/dockerfile-reference/

# Want to help us make this template better? Share your feedback here: https://forms.gle/ybq9Krt8jtBL3iCk7

ARG NODE_VERSION=20.10.0

################################################################################
# Use node image for base image for all stages.
FROM node:${NODE_VERSION}-alpine as base

# Set working directory for all build stages.
WORKDIR /usr/src/app


################################################################################
# Create a stage for installing production dependecies.
FROM base as deps

RUN apk update && apk add --no-cache make protobuf-dev

# Download dependencies as a separate step to take advantage of Docker's caching.
# Leverage a cache mount to /root/.yarn to speed up subsequent builds.
# Leverage bind mounts to package.json and yarn.lock to avoid having to copy them
# into this layer.
RUN --mount=type=bind,source=package.json,target=package.json \
--mount=type=bind,source=yarn.lock,target=yarn.lock \
--mount=type=cache,target=/root/.yarn \
yarn install --production --frozen-lockfile --ignore-scripts

################################################################################
# Create a stage for building the application.
FROM deps as build

# Download additional development dependencies before building, as some projects require
# "devDependencies" to be installed to build. If you don't need this, remove this step.
RUN --mount=type=bind,source=package.json,target=package.json \
--mount=type=bind,source=yarn.lock,target=yarn.lock \
--mount=type=cache,target=/root/.yarn \
yarn install --frozen-lockfile --ignore-scripts

# Copy the rest of the source files into the image.
COPY . .

# Run postinstall script if it exists.
RUN yarn run postinstall

# Run the build script.
RUN yarn run build

################################################################################
# Create a new stage to run the application with minimal runtime dependencies
# where the necessary files are copied from the build stage.
FROM base as final

# Use production node environment by default.
ENV NODE_ENV production

# Run the application as a non-root user.
USER node

# Copy package.json so that package manager commands can be used.
COPY package.json .

# Copy the production dependencies from the deps stage and also
# the built application from the build stage into the image.
COPY --from=deps /usr/src/app/node_modules ./node_modules
COPY --from=build /usr/src/app/dist ./dist

# Run the application.
CMD node dist/main.js
Loading
Loading