mirror of
https://github.com/cerc-io/watcher-ts
synced 2025-01-21 10:39:06 +00:00
Add isPruned flag to erc721-watcher custom transferCount entity (#266)
* Remove block number param from job-queue reset CLI in readme * Add isPruned flag to erc721-watcher custom transferCount entity
This commit is contained in:
parent
bd8f003322
commit
05bfd57278
@ -163,7 +163,7 @@ Steps:
|
||||
* Reset job-queue:
|
||||
|
||||
```bash
|
||||
yarn reset job-queue --block-number <previous-block-number>
|
||||
yarn reset job-queue
|
||||
```
|
||||
|
||||
* To export the watcher state:
|
||||
|
@ -37,6 +37,7 @@
|
||||
"yargs": "^17.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@openzeppelin/contracts": "^4.3.2",
|
||||
"@types/js-yaml": "^4.0.3",
|
||||
"@types/node": "^16.9.0",
|
||||
"@typescript-eslint/eslint-plugin": "^4.25.0",
|
||||
|
@ -163,7 +163,7 @@ To enable GQL requests caching:
|
||||
* Reset job-queue:
|
||||
|
||||
```bash
|
||||
yarn reset job-queue --block-number <previous-block-number>
|
||||
yarn reset job-queue
|
||||
```
|
||||
|
||||
* Reset state:
|
||||
|
@ -26,7 +26,7 @@
|
||||
git checkout v1.10.26-statediff-4.2.2-alpha
|
||||
```
|
||||
|
||||
* Update to use latest images for ipld-eth-db and ipld-eth-server
|
||||
* Update docker compose file to use latest images for ipld-eth-db and ipld-eth-server
|
||||
|
||||
* In [docker/latest/docker-compose-db-sharding.yml](https://github.com/vulcanize/stack-orchestrator/blob/main/docker/latest/docker-compose-db-sharding.yml) update image version
|
||||
|
||||
|
@ -149,7 +149,7 @@
|
||||
* Reset job-queue:
|
||||
|
||||
```bash
|
||||
yarn reset job-queue --block-number <previous-block-number>
|
||||
yarn reset job-queue
|
||||
```
|
||||
|
||||
* Reset state:
|
||||
|
@ -58,6 +58,7 @@
|
||||
"@ethersproject/abi": "^5.3.0",
|
||||
"@nomiclabs/hardhat-ethers": "^2.0.2",
|
||||
"@nomiclabs/hardhat-waffle": "^2.0.1",
|
||||
"@openzeppelin/contracts": "^4.3.2",
|
||||
"@types/json-bigint": "^1.0.0",
|
||||
"@typescript-eslint/eslint-plugin": "^4.25.0",
|
||||
"@typescript-eslint/parser": "^4.25.0",
|
||||
|
@ -151,7 +151,7 @@ Follow the steps below or follow the [Demo](./demo.md)
|
||||
* Reset job-queue:
|
||||
|
||||
```bash
|
||||
yarn reset job-queue --block-number <previous-block-number>
|
||||
yarn reset job-queue
|
||||
```
|
||||
|
||||
* Reset state:
|
||||
|
@ -15,13 +15,31 @@
|
||||
./setup-repositories.sh -p ssh
|
||||
```
|
||||
|
||||
* Checkout [v4 release](https://github.com/vulcanize/go-ethereum/releases/tag/v1.10.19-statediff-4.0.2-alpha) in go-ethereum repo. The path for go-ethereum is specified by `vulcanize_go_ethereum` variable in `config.sh` file created in stack-orchestrator repo.
|
||||
* Checkout [v4 release](https://github.com/vulcanize/go-ethereum/releases/tag/v1.10.26-statediff-4.2.2-alpha) in go-ethereum repo. The path for go-ethereum is specified by `vulcanize_go_ethereum` variable in `config.sh` file created in stack-orchestrator repo.
|
||||
|
||||
```bash
|
||||
# In go-ethereum repo.
|
||||
git checkout v1.10.19-statediff-4.0.2-alpha
|
||||
git checkout v1.10.26-statediff-4.2.2-alpha
|
||||
```
|
||||
|
||||
* Update docker compose file to use latest images for ipld-eth-db and ipld-eth-server
|
||||
|
||||
* In [docker/latest/docker-compose-db-sharding.yml](https://github.com/vulcanize/stack-orchestrator/blob/main/docker/latest/docker-compose-db-sharding.yml) update image version
|
||||
|
||||
```yml
|
||||
services:
|
||||
migrations:
|
||||
image: git.vdb.to/cerc-io/ipld-eth-db/ipld-eth-db:v4.2.3-alpha
|
||||
```
|
||||
|
||||
* In [docker/latest/docker-compose-ipld-eth-server.yml](https://github.com/vulcanize/stack-orchestrator/blob/main/docker/latest/docker-compose-ipld-eth-server.yml) update image version
|
||||
|
||||
```yml
|
||||
services:
|
||||
ipld-eth-server:
|
||||
image: git.vdb.to/cerc-io/ipld-eth-server/ipld-eth-server:v4.2.3-alpha
|
||||
```
|
||||
|
||||
* To run the stack-orchestrator, the docker-compose version used is:
|
||||
|
||||
```bash
|
||||
|
@ -65,6 +65,7 @@
|
||||
"@ethersproject/abi": "^5.3.0",
|
||||
"@nomiclabs/hardhat-ethers": "^2.0.2",
|
||||
"@nomiclabs/hardhat-waffle": "^2.0.1",
|
||||
"@openzeppelin/contracts": "^4.3.2",
|
||||
"@types/yargs": "^17.0.0",
|
||||
"@typescript-eslint/eslint-plugin": "^4.25.0",
|
||||
"@typescript-eslint/parser": "^4.25.0",
|
||||
|
@ -3,7 +3,7 @@
|
||||
//
|
||||
|
||||
import assert from 'assert';
|
||||
import { Connection, ConnectionOptions, DeepPartial, FindConditions, QueryRunner, FindManyOptions, FindOneOptions, LessThanOrEqual, EntityTarget } from 'typeorm';
|
||||
import { Connection, ConnectionOptions, DeepPartial, FindConditions, QueryRunner, FindManyOptions, FindOneOptions, LessThanOrEqual, EntityTarget, UpdateResult } from 'typeorm';
|
||||
import path from 'path';
|
||||
|
||||
import { Database as BaseDatabase, DatabaseInterface, QueryOptions, StateKind, Where } from '@cerc-io/util';
|
||||
@ -504,6 +504,15 @@ export class Database implements DatabaseInterface {
|
||||
return this._baseDatabase.getAncestorAtDepth(blockHash, depth);
|
||||
}
|
||||
|
||||
async updateEntity<Entity> (queryRunner: QueryRunner, entityType: new () => Entity, criteria: any, update: any): Promise<UpdateResult> {
|
||||
const repo = queryRunner.manager.getRepository(entityType);
|
||||
return repo.createQueryBuilder()
|
||||
.update()
|
||||
.set(update)
|
||||
.where(criteria)
|
||||
.execute();
|
||||
}
|
||||
|
||||
_getPropertyColumnMapForEntity (entityName: string): Map<string, string> {
|
||||
return this._conn.getMetadata(entityName).ownColumns.reduce((acc, curr) => {
|
||||
return acc.set(curr.propertyName, curr.databaseName);
|
||||
|
@ -17,4 +17,7 @@ export class TransferCount {
|
||||
|
||||
@Column('integer')
|
||||
count!: number;
|
||||
|
||||
@Column('boolean', { default: false })
|
||||
isPruned!: boolean
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
import assert from 'assert';
|
||||
import debug from 'debug';
|
||||
import { DeepPartial, FindConditions, FindManyOptions } from 'typeorm';
|
||||
import { DeepPartial, FindConditions, FindManyOptions, In } from 'typeorm';
|
||||
import JSONbig from 'json-bigint';
|
||||
import { ethers } from 'ethers';
|
||||
|
||||
@ -870,7 +870,36 @@ export class Indexer implements IndexerInterface {
|
||||
}
|
||||
|
||||
async markBlocksAsPruned (blocks: BlockProgress[]): Promise<void> {
|
||||
return this._baseIndexer.markBlocksAsPruned(blocks);
|
||||
await this._baseIndexer.markBlocksAsPruned(blocks);
|
||||
|
||||
await this._pruneEntities(blocks);
|
||||
}
|
||||
|
||||
// Prune custom entities.
|
||||
async _pruneEntities (blocks: BlockProgress[]): Promise<void> {
|
||||
const entityTypes = [TransferCount];
|
||||
const blockHashes = blocks.map(block => block.blockHash);
|
||||
|
||||
const dbTx = await this._db.createTransactionRunner();
|
||||
|
||||
try {
|
||||
const updatePromises = entityTypes.map(async entityType => {
|
||||
await this._db.updateEntity(
|
||||
dbTx,
|
||||
entityType,
|
||||
{ blockHash: In(blockHashes) },
|
||||
{ isPruned: true }
|
||||
);
|
||||
});
|
||||
|
||||
await Promise.all(updatePromises);
|
||||
await dbTx.commitTransaction();
|
||||
} catch (error) {
|
||||
await dbTx.rollbackTransaction();
|
||||
throw error;
|
||||
} finally {
|
||||
await dbTx.release();
|
||||
}
|
||||
}
|
||||
|
||||
async updateBlockProgress (block: BlockProgress, lastProcessedEventIndex: number): Promise<BlockProgress> {
|
||||
|
@ -149,7 +149,7 @@
|
||||
* Reset job-queue:
|
||||
|
||||
```bash
|
||||
yarn reset job-queue --block-number <previous-block-number>
|
||||
yarn reset job-queue
|
||||
```
|
||||
|
||||
* Reset state:
|
||||
|
@ -141,7 +141,7 @@ Follow the steps below or follow the [Demo](./demo.md)
|
||||
* Reset job-queue:
|
||||
|
||||
```bash
|
||||
yarn reset job-queue --block-number <previous-block-number>
|
||||
yarn reset job-queue
|
||||
```
|
||||
|
||||
* Reset state:
|
||||
|
@ -2322,6 +2322,11 @@
|
||||
dependencies:
|
||||
"@octokit/openapi-types" "^7.2.3"
|
||||
|
||||
"@openzeppelin/contracts@^4.3.2":
|
||||
version "4.3.2"
|
||||
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-4.3.2.tgz#ff80affd6d352dbe1bbc5b4e1833c41afd6283b6"
|
||||
integrity sha512-AybF1cesONZStg5kWf6ao9OlqTZuPqddvprc0ky7lrUVOjXeKpmQ2Y9FK+6ygxasb+4aic4O5pneFBfwVsRRRg==
|
||||
|
||||
"@poanet/solidity-flattener@https://github.com/vulcanize/solidity-flattener.git":
|
||||
version "3.0.6"
|
||||
resolved "https://github.com/vulcanize/solidity-flattener.git#144ef6cda8823f4a5e48cb4f615be87a32e2dcbc"
|
||||
|
Loading…
Reference in New Issue
Block a user