Skip to content

Commit

Permalink
feat: refactor commands, add readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Romsters committed Sep 22, 2023
1 parent a276071 commit 6b56f39
Show file tree
Hide file tree
Showing 13 changed files with 128 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/app-deploy-feature-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
npm run lint -- --no-fix --max-warnings 0
- name: Test
run: npm run test:unit:ci
run: npm run test:ci

- name: Type check
run: npm run typecheck
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- name: Test
run: |
npm run test:unit:ci
npm run test:ci
- name: App type check
working-directory: ./packages/app
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/validate-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
- name: Test
run: |
npm run test:unit:ci
npm run test:ci
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action/composite@v2
Expand Down
99 changes: 97 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,97 @@
# block-explorer
zkSync Era Block Explorer
<h1 align="center">zkSync Era Block Explorer</h1>

<p align="center">Online blockchain browser for viewing and analyzing <a href="https://zksync.io">zkSync Era</a> blockchain.</p>

## 📌 Overview
This repository is a monorepo consisting of 3 packages:
- [Worker](./packages/worker) - an indexer service for [zkSync Era](https://zksync.io) blockchain data. The purpose of the service is to read the data from the blockchain in real time, transform it and fill in it's database with the data in a way that makes it easy to be queried by the [API](./packegs/api) service.
- [API](./packages/api) - a service providing Web API for retrieving structured [zkSync Era](https://zksync.io) blockchain data collected by [Worker](./packages/worker). It connects to the Worker's database to be able to query the collected data.
- [App](./packages/app) - a front-end app providing an easy-to-use interface for users to view and inspect transactions, blocks, contracts and more. It makes requests to the [API](./packages/api) to get the data and presents it in a way that's easy to read and understand.

## 🏛 Architecture
The following diagram illustrates how are the block explorer components connected:

```mermaid
flowchart
subgraph blockchain[Blockchain]
Blockchain[zkSync Era JSON-RPC API]
end
subgraph explorer[Block explorer]
Database[("Block explorer DB<br/>(PostgreSQL)")]
Worker(Worker service)
API(API service)
App(App)
Worker-.Save processed data.->Database
API-.Query data.->Database
App-."Request data (HTTP)".->API
App-."Request data (HTTP)".->Blockchain
end
Worker-."Request data (HTTP)".->Blockchain
```

[Worker](./packages/worker) service is responsible for getting data from blockchain using [zkSync Era JSON-RPC API](https://era.zksync.io/docs/api/api.html), processing it and saving into the database. [API](./packages/api) service is connected to the same database where it gets the data from to handle API requests. It performs only read requests to the database. The front-end [App](./packages/app) makes HTTP calls to the Block Explorer [API](./packages/api) to get blockchain data and to the [zkSync Era JSON-RPC API](https://era.zksync.io/docs/api/api.html) for reading contracts, performing transactions etc.

## 🚀 Features

- ✅ View transactions, blocks, transfers and logs.
- ✅ Inspect accounts, contracts, tokens and balances.
- ✅ Verify smart contracts.
- ✅ Interact with smart contracts.
- ✅ Standalone HTTP API.
- ✅ Local node support.

## 📋 Prerequisites

- Ensure you have `node >= 18.0.0` and `npm >= 9.0.0` installed.

## 🛠 Installation

```bash
$ npm install
```

## ⚙️ Setting up env variables

Make sure you have set up all the necessary env variables. Follow [Setting up env variables for Worker](./packages/worker#setting-up-env-variables) and [Setting up env variables for API](./packages/api#setting-up-env-variables) for instructions.

## 👨‍💻 Running locally

Before running the solution, make sure you have a database server up and running and you have created a database.

To run all the components (`Worker`, `API` and front-end `App`) in `development` mode run the following command from the root directory.
```bash
$ npm run dev
```

For `production` mode run:
```bash
$ npm run build
$ npm run start
```
To verify front-end `App` is running open http://localhost:3010 in your browser. `API` should be available at http://localhost:3000. `Worker` - http://localhost:3001.

Each component can also be started individually. Follow individual packages `README` for details.

## 🕵️‍♂️ Testing
Run unit tests for all packages:
```bash
$ npm run test
```
Run e2e tests for all packages:
```bash
$ npm run test:e2e
```
Run tests for a specific package:
```bash
$ npm run test -w {package}
```
For more details on testing please check individual packages `README`.

## 💻 Conventional Commits
We follow the Conventional Commits [specification](https://www.conventionalcommits.org/en/v1.0.0/#specification).

## 📘 License
MIT License.
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
"prepare": "husky install",
"lint": "lerna run lint",
"test": "lerna run test",
"test:unit:ci": "lerna run test:unit:ci",
"build": "lerna run build"
"test:ci": "lerna run test:ci",
"test:e2e": "lerna run test:e2e",
"dev": "lerna run dev",
"build": "lerna run build",
"start": "lerna run start"
},
"devDependencies": {
"@commitlint/cli": "^17.1.2",
Expand Down
8 changes: 4 additions & 4 deletions packages/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ You need to have a running Worker database, for instructions on how to run the w

```bash
# development
$ npm run start
$ npm run dev

# watch mode
$ npm run start:dev
$ npm run dev:watch

# debug mode
$ npm run start:debug
$ npm run dev:debug

# production mode
$ npm run start:prod
$ npm run start
```

## Test
Expand Down
2 changes: 1 addition & 1 deletion packages/api/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
build:
context: .
target: development-stage
command: npm run start:debug
command: npm run dev:debug
environment:
- PORT=3000
- METRICS_PORT=3005
Expand Down
10 changes: 5 additions & 5 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
"prebuild": "rimraf dist",
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug 0.0.0.0:9229 --watch",
"start:prod": "node dist/main",
"dev": "nest start",
"dev:watch": "nest start --watch",
"dev:debug": "nest start --debug 0.0.0.0:9229 --watch",
"start": "node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:unit:ci": "jest --coverage",
"test:ci": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json --runInBand --detectOpenHandles",
"test:perf": "artillery run ./performance/load-test.yaml"
Expand Down
2 changes: 1 addition & 1 deletion packages/app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ npm run build
### Run Unit Tests with [Vitest](https://vitest.dev/)

```sh
npm run test:unit
npm run test
```

### Run End-to-End Tests with [Playwright](https://www.playwright.io/)
Expand Down
4 changes: 2 additions & 2 deletions packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"scripts": {
"dev": "vite",
"build": "vue-tsc --noEmit && vite build",
"preview": "vite preview --port 5050",
"start": "vite preview --port 3010",
"test": "TZ=UTC-3 vitest --environment jsdom",
"test:unit:ci": "TZ=UTC-3 vitest --environment jsdom --run --reporter=verbose --reporter=junit --outputFile.junit=./junit.xml",
"test:ci": "TZ=UTC-3 vitest --environment jsdom --run --reporter=verbose --reporter=junit --outputFile.junit=./junit.xml",
"test:e2e": "cucumber-js -t \"not @testnet\"",
"typecheck": "vue-tsc --noEmit -p tsconfig.vitest.json --composite false",
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix",
Expand Down
8 changes: 4 additions & 4 deletions packages/worker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ You need to have a running Postgres server, set the following env variables to p

```bash
# development
$ npm run start
$ npm run dev

# watch mode
$ npm run start:dev
$ npm run dev:watch

# debug mode
$ npm run start:debug
$ npm run dev:debug

# production mode
$ npm run start:prod
$ npm run start
```

## Running the app in Docker
Expand Down
2 changes: 1 addition & 1 deletion packages/worker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
build:
context: .
target: development-stage
command: npm run start:debug
command: npm run dev:debug
environment:
- PORT=3001
- LOG_LEVEL=verbose
Expand Down
10 changes: 5 additions & 5 deletions packages/worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
"prebuild": "rimraf dist",
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug 0.0.0.0:9229 --watch",
"start:prod": "node dist/main",
"dev": "nest start",
"dev:watch": "nest start --watch",
"dev:debug": "nest start --debug 0.0.0.0:9229 --watch",
"start": "node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:unit:ci": "jest --coverage",
"test:ci": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json",
"typeorm": "typeorm-ts-node-commonjs",
Expand Down

0 comments on commit 6b56f39

Please sign in to comment.