cartesi / rollups-node

Reference implementation of the Cartesi Rollups Node
Apache License 2.0
24 stars 65 forks source link

Create a prototype in Go to retrieve blockchain data using subsquid #329

Closed marcelstanley closed 8 months ago

marcelstanley commented 9 months ago

We shall create a simple prototype in Go that uses subsquid to retrieve data from the blockchain

https://docs.subsquid.io/sdk/how-to-start/ seems to be a good starting point for a PoC.

marcelstanley commented 9 months ago

Start by following [/squid-from-scratch](https://docs.subsquid.io/sdk/how-to-start/ squid-from-scratch/) to create a bare bones squid to track USDT transfers on mainnet.

Putting aside some issues found along the way, which may be easily fixed, you'll end up with a structure like this:

 .
 ├── README.md
 ├── db
 │   └── migrations
 │       └── 1708974949640-Data.js
 ├── docker-compose.yaml
 ├── lib
 │   ├── abi
 │   │   ├── abi.support.js
 │   │   ├── usdt.abi.js
 │   │   └── usdt.js
 │   ├── main.js
 │   └── model
 │       ├── generated
 │       │   ├── index.js
 │       │   ├── marshal.js
 │       │   └── transfer.model.js
 │       └── index.js
 ├── package.json
 ├── schema.graphql
 ├── src
 │   ├── abi
 │   │   ├── abi.support.ts
 │   │   ├── usdt.abi.ts
 │   │   └── usdt.ts
 │   ├── main.ts
 │   └── model
 │       ├── generated
 │       │   ├── index.ts
 │       │   ├── marshal.ts
 │       │   └── transfer.model.ts
 │       └── index.ts
 ├── tsconfig.json
 └── yarn.lock

Go program

In order to read the transfer data from the blockchain, copy main.go.txt (remember to rename it to main.go) to the project root directory. Also initialize a Go project, if needed be.

Running the project

With the project created, make sure to stop the processor process and the Postgres database.

Then, start over by bringing the environment (DB only) up as follows:

 docker compose up -d

Then, run the Go program with:

 go run .

The program will print all USDT transfer data until cancelled (CTRL+C).

When done, take the environment down as follows:

 docker compose down -v