|
1 | 1 | # CAT Tracker
|
2 | 2 |
|
3 |
| -The tracker reads CAT token transactions from the blockchain, stores them in a database (`Postgres`) in a structured way, which can be quickly retrieved via RESTful APIs. The Swagger documentation for all the APIs can be found at http://127.0.0.1:3000 after running. |
| 3 | +The tracker reads CAT token transactions from the blockchain, stores them in Postgres in a structured way, which can be quickly retrieved via RESTful APIs. The Swagger documentation for all the APIs can be found at http://127.0.0.1:3000 after running. |
4 | 4 |
|
5 | 5 | ## Installation
|
6 | 6 |
|
7 | 7 | ```bash
|
8 |
| -yarn install |
| 8 | +yarn install && yarn build |
9 | 9 | ```
|
10 | 10 |
|
11 |
| -## Build |
12 |
| - |
13 |
| -```sh |
14 |
| -yarn build |
15 |
| -``` |
16 |
| - |
17 |
| -## Before Run |
| 11 | +## Prerequisite |
18 | 12 |
|
19 | 13 | The tracker needs a full node and Postgres. We use Fractal node as an example here.
|
20 | 14 |
|
21 |
| -Make sure you have `docker` installed, you can follow this [guide](https://docs.docker.com/engine/install/) to install it. |
| 15 | +Make sure you have `docker` installed, or follow this [guide](https://docs.docker.com/engine/install/) to install it. |
22 | 16 |
|
23 | 17 | 1. Update `.env` file with your own configuration.
|
24 |
| -2. Update directory permission |
| 18 | + |
| 19 | +2. Update directory permission to avoid `docker` doesn't have rights to write data. |
25 | 20 |
|
26 | 21 | ```bash
|
27 |
| -sudo chmod 777 docker/data |
28 |
| -sudo chmod 777 docker/pgdata |
| 22 | +sudo chmod o+w docker/data |
29 | 23 | ```
|
30 | 24 |
|
31 |
| -3. Run `postgresql` and `bitcoind`: |
| 25 | +3. Run `postgresql` and `bitcoind`. |
32 | 26 |
|
33 | 27 | ```bash
|
34 | 28 | docker compose up -d
|
35 | 29 | ```
|
36 | 30 |
|
37 |
| -## Run the tracker service |
38 |
| - |
39 |
| -### Use `Docker` (Recommended) |
| 31 | +## Migration |
40 | 32 |
|
41 |
| -1. Build docker image under the project root directory |
| 33 | +Run the following command to initialize database tables for the first-time run, or migrate data when upgrading from a previous version. |
42 | 34 |
|
43 | 35 | ```bash
|
44 |
| -cd ../../ && docker build -t tracker:latest . |
| 36 | +yarn migration:run |
45 | 37 | ```
|
46 | 38 |
|
47 |
| -2. Run the container |
| 39 | +**Note: If upgrading the tracker from a previous version, migrating the table data may take a few hours. Make a [database backup](https://www.postgresql.org/docs/current/app-pgdump.html) before this.** |
48 | 40 |
|
49 |
| -```bash |
50 |
| -docker run -d \ |
51 |
| - --name tracker \ |
52 |
| - --add-host="host.docker.internal:host-gateway" \ |
53 |
| - -e DATABASE_HOST="host.docker.internal" \ |
54 |
| - -e RPC_HOST="host.docker.internal" \ |
55 |
| - -p 3000:3000 \ |
56 |
| - tracker:latest |
57 |
| -``` |
| 41 | +## Run |
58 | 42 |
|
59 |
| -3. Check tracker logs |
| 43 | +The tracker consists of two modules: |
60 | 44 |
|
61 |
| -```bash |
62 |
| -docker logs -f tracker |
63 |
| -``` |
| 45 | +- `worker`, reads CAT token transactions from the blockchain and stores them in a database. |
| 46 | +- `api`, reads data from the database and serves the RESTful APIs. |
64 | 47 |
|
65 |
| -### Use `yarn` |
| 48 | +To run the `worker` module: |
66 | 49 |
|
67 |
| -* development mode |
68 | 50 | ```bash
|
69 |
| -yarn run start |
| 51 | +# development |
| 52 | +yarn start:worker |
| 53 | + |
| 54 | +# production mode |
| 55 | +yarn start:worker:prod |
70 | 56 | ```
|
71 | 57 |
|
72 |
| -* production mode |
| 58 | +To run the `api` module: |
| 59 | + |
73 | 60 | ```bash
|
74 |
| -yarn run start:prod |
| 61 | +# development |
| 62 | +yarn start:api |
| 63 | + |
| 64 | +# production mode |
| 65 | +yarn start:api:prod |
75 | 66 | ```
|
76 | 67 |
|
77 |
| -> **Note:** Make sure the tracker syncs to the latest block before you run CLI over it. The sync-up progress can be found at http://127.0.0.1:3000/api after running. |
| 68 | +**Note:** Make sure the tracker syncs to the latest block before you run CLI over it. The sync-up progress can be found at http://127.0.0.1:3000/api after running. |
0 commit comments