2021-06-17 12:26:38 +00:00
# watcher-ts
2021-05-11 11:08:30 +00:00
## Setup
2021-10-27 09:13:48 +00:00
There are packages used from github so we need to follow the following steps to install them:
2022-04-27 10:07:13 +00:00
1. Create a github PAT (personal access token) if it does not already exist.
2021-10-27 09:13:48 +00:00
2022-04-27 10:07:13 +00:00
https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token#creating-a-token
2021-10-27 09:13:48 +00:00
2022-04-27 10:07:13 +00:00
2. Configure the PAT with scopes mentioned in https://docs.github.com/en/packages/learn-github-packages/about-permissions-for-github-packages#about-scopes-and-permissions-for-package-registries. This is required to install or publish github packages.
2021-10-27 09:13:48 +00:00
2022-04-27 10:07:13 +00:00
3. Follow the steps in https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-npm-registry#authenticating-with-a-personal-access-token to authenticate to github packages. We can also run the follwing to authenticate by logging in to npm.
```bash
2022-09-09 11:43:01 +00:00
$ npm login --scope=@cerc-io --registry=https://npm.pkg.github.com
2022-04-27 10:07:13 +00:00
> Username: USERNAME
> Password: TOKEN
> Email: PUBLIC-EMAIL-ADDRESS
```
Replace with the following:
- `USERNAME` : GitHub username
- `TOKEN` : Personal access token (configured above)
- `PUBLIC-EMAIL-ADDRESS` : Email address
2022-07-07 07:08:32 +00:00
4. When authenticating to github packages for the first time, yarn install may throw Unauthorized error. To overcome this we need to run yarn install in `packages/graph-node` directory. After this yarn install for watcher-ts works properly even from root of the repo.
2021-10-27 09:13:48 +00:00
2021-05-13 10:19:15 +00:00
This project uses [yarn workspaces ](https://classic.yarnpkg.com/en/docs/workspaces/ ).
2021-12-09 05:09:35 +00:00
Install packages (Node.JS v16.13.1):
2021-05-11 11:08:30 +00:00
```bash
yarn
```
2022-04-28 11:43:32 +00:00
Build packages:
```bash
yarn build
```
2022-04-27 10:07:13 +00:00
## Tests
* [graph-node ](./packages/graph-node/README.md )
2022-05-05 14:13:45 +00:00
## Demos
* [IPLD statediff and checkpointing ](./ipld-demo.md )
2022-04-27 10:07:13 +00:00
## Services
2021-06-17 12:26:38 +00:00
2021-07-16 11:05:49 +00:00
The default config files used by the watchers assume the following services are setup and running on localhost:
2021-06-04 09:49:30 +00:00
2021-07-16 11:05:49 +00:00
* `vulcanize/go-ethereum` on port 8545
* `vulcanize/ipld-eth-server` with native GQL API enabled, on port 8082
2021-06-04 09:49:30 +00:00
2022-04-27 10:07:13 +00:00
### Note
2021-08-11 10:57:42 +00:00
* In `vulcanize/ipld-eth-server` , add the following statement to `[ethereum]` section in `environments/config.toml` :
2021-09-21 11:13:55 +00:00
2021-08-11 10:57:42 +00:00
`chainConfig = "./chain.json" # ETH_CHAIN_CONFIG`
2022-04-28 11:43:32 +00:00
## Watchers
* [eden-watcher ](./packages/eden-watcher/README.md )
2022-04-27 10:07:13 +00:00
## Databases
2021-06-04 09:49:30 +00:00
2021-07-16 11:05:49 +00:00
Note: Requires `postgres12` .
2021-06-28 11:42:53 +00:00
2021-07-16 11:05:49 +00:00
Login as the postgres user:
2021-05-11 11:08:30 +00:00
```bash
2021-07-16 11:05:49 +00:00
sudo su - postgres
```
Create the databases for the watchers:
```
createdb erc20-watcher
createdb address-watcher
2021-05-11 11:08:30 +00:00
```
2021-07-16 11:05:49 +00:00
Create the databases for the job queues and enable the `pgcrypto` extension on them (https://github.com/timgit/pg-boss/blob/master/docs/usage.md#intro):
2021-05-11 11:08:30 +00:00
2021-07-16 11:05:49 +00:00
```
2021-09-21 11:13:55 +00:00
createdb erc20-watcher-job-queue
2021-07-16 11:05:49 +00:00
createdb address-watcher-job-queue
```
2021-05-28 11:26:40 +00:00
2021-09-21 11:13:55 +00:00
```
postgres@tesla:~$ psql -U postgres -h localhost erc20-watcher-job-queue
Password for user postgres:
psql (12.7 (Ubuntu 12.7-1.pgdg18.04+1))
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)
Type "help" for help.
erc20-watcher-job-queue=# CREATE EXTENSION pgcrypto;
CREATE EXTENSION
erc20-watcher-job-queue=# exit
```
2021-05-28 11:26:40 +00:00
```
2021-07-16 11:05:49 +00:00
postgres@tesla:~$ psql -U postgres -h localhost address-watcher-job-queue
Password for user postgres:
psql (12.7 (Ubuntu 12.7-1.pgdg18.04+1))
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)
Type "help" for help.
address-watcher-job-queue=# CREATE EXTENSION pgcrypto;
CREATE EXTENSION
address-watcher-job-queue=# exit
2021-05-28 11:26:40 +00:00
```
2021-05-13 13:48:08 +00:00
2021-08-12 09:24:31 +00:00
#### Reset
Reset the databases used by the watchers:
```bash
yarn db:reset
```
2021-07-16 11:05:49 +00:00
## Run
2021-09-02 04:57:56 +00:00
Build the files in packages:
```bash
yarn build
# To watch for changes and build (used in development).
yarn build:watch
```
2021-07-16 11:05:49 +00:00
To run any watcher, `cd` into their package folder and run:
2021-05-13 13:48:08 +00:00
```bash
2021-07-16 11:05:49 +00:00
yarn server
2021-05-13 13:48:08 +00:00
```
2021-05-11 11:08:30 +00:00
2021-07-16 11:05:49 +00:00
If the watcher uses a job queue, start the job runner in another terminal:
2021-06-03 12:01:21 +00:00
2021-07-16 11:05:49 +00:00
```bash
yarn job-runner
2021-05-11 11:08:30 +00:00
```