From 61238ab6243c38abea51222a9bd852ae75eba5cd Mon Sep 17 00:00:00 2001 From: ssallam Date: Wed, 9 Dec 2020 15:03:40 +0100 Subject: [PATCH] update README file. --- README.md | 38 ++++++++++++++++++++++++++++++++++---- src/mappings/factory.ts | 9 +++------ tsconfig.json | 23 ++++++++++++++++++++--- 3 files changed, 57 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 096ac5f..12bb42b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,13 @@ # Ocean Protocol Subgraph ## Running locally -* Install the Graph: `https://thegraph.com/docs/quick-start` + +* Install Graph CLI globally with npm +```bash +npm install -g @graphprotocol/graph-cli +``` + +* Install/run the Graph: `https://thegraph.com/docs/quick-start` * You can skip running ganache-cli and connect directly to `mainnet` using Infura ```bash @@ -14,9 +20,24 @@ docker-compose up ``` -* Install Graph CLI globally with npm -```bash -npm install -g @graphprotocol/graph-cli +Note: making contract calls using Infura fails with `missing trie node` errors. +The fix requires editing `ethereum_adapter.rs` line 434 to use the latest block +instead of a specific block number. +Replace: +`web3.eth().call(req, Some(block_id)).then(|result| {` +with `web3.eth().call(req, Some(BlockNumber::Latest.into())).then(|result| {` + +To run the graph-node with this fix it must be run from source. + +First, delete the `graph-node` container from the `docker-compose.yml` file +then run `docker-compose up` to get the postgresql and ipfs services running. + +Now you can build and run the graph-node from source +``` +cargo run -p graph-node --release > graphnode.log -- + --postgres-url postgres://graph-node:let-me-in@localhost:5432/graph-node + --ethereum-rpc mainnet:https://mainnet.infura.io/v3/INFURA_PROJECT_ID + --ipfs 127.0.0.1:5001 ``` * Once the graph node is ready, do the following to deploy the ocean-subgraph to the local graph-node @@ -29,3 +50,12 @@ npm run create:local npm run deploy:local ``` + +* You can edit the event handler code and then run `npm run deploy:local` + * Running deploy will fail if the code has no changes + * Sometimes deploy will fail no matter what, in this case: + * Stop the docker-compose run (`docker-compose down`) + * Delete the `ipfs` and `postgres` folders in `graph-node/docker/data` + * Restart docker-compose + * Run `npm run create:local` to create the ocean-subgraph + * Run `npm run deploy:local` to deploy the ocean-subgraph diff --git a/src/mappings/factory.ts b/src/mappings/factory.ts index f8f33f9..443a25f 100644 --- a/src/mappings/factory.ts +++ b/src/mappings/factory.ts @@ -1,16 +1,13 @@ -import { Address, BigInt, BigDecimal } from '@graphprotocol/graph-ts' +import { BigInt, BigDecimal } from '@graphprotocol/graph-ts' import { BPoolRegistered } from '../types/Factory/Factory' import { PoolFactory, Pool } from '../types/schema' import { Pool as PoolContract } from '../types/templates' -import { - ZERO_BD, -} from './helpers' +import { ZERO_BD } from './helpers' import { log } from '@graphprotocol/graph-ts' export function handleNewPool(event: BPoolRegistered): void { let factory = PoolFactory.load('1') - // if no factory yet, set up blank initial if (factory == null) { factory = new PoolFactory('1') factory.totalLiquidity = ZERO_BD @@ -22,7 +19,7 @@ export function handleNewPool(event: BPoolRegistered): void { } let pool = new Pool(event.params.bpoolAddress.toHexString()) - log.error('************************ handleNewPool: poolId {}', [pool.id.toString()]) + log.info('************************ handleNewPool: poolId {}', [pool.id.toString()]) pool.factoryID = event.address.toHexString() pool.controller = event.params.registeredBy diff --git a/tsconfig.json b/tsconfig.json index 2d3ce67..f2aaf20 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,23 @@ { "extends": "./node_modules/@graphprotocol/graph-ts/tsconfig.json", "compilerOptions": { - "types": ["@graphprotocol/graph-ts"] - } -} \ No newline at end of file + "types": ["@graphprotocol/graph-ts"], + "resolveJsonModule": true, + "moduleResolution": "node", + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "lib": ["es5", "dom"], + "declaration": true, + "module": "commonjs", + "target": "es5", + "removeComments": true, + "experimentalDecorators": true, + "preserveConstEnums": true, + "outDir": "./dist/node/", + "rootDir": "./src/", + "sourceMap": true, + "typeRoots": ["node_modules/@types"] + }, + "include": ["src/**/*"], + "exclude": ["node_modules", "**/*.test.ts"] +}