Skip to content

Commit

Permalink
Handle getStorage calls for old blocks (#145)
Browse files Browse the repository at this point in the history
* Handle getStorage calls for old blocks

* Refactor getStorage code in mobymask watcher

* Fix returning proof as null
  • Loading branch information
nikugogoi authored Jul 20, 2022
1 parent e266869 commit 58bbf4d
Show file tree
Hide file tree
Showing 15 changed files with 269 additions and 175 deletions.
11 changes: 11 additions & 0 deletions packages/codegen/src/data/entities/SyncStatus.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ columns:
pgType: integer
tsType: number
columnType: Column
- name: initialIndexedBlockHash
pgType: varchar
tsType: string
columnType: Column
columnOptions:
- option: length
value: 66
- name: initialIndexedBlockNumber
pgType: integer
tsType: number
columnType: Column
imports:
- toImport:
- Entity
Expand Down
6 changes: 6 additions & 0 deletions packages/eden-watcher/src/entity/SyncStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,10 @@ export class SyncStatus implements SyncStatusInterface {

@Column('integer')
latestCanonicalBlockNumber!: number;

@Column('varchar', { length: 66 })
initialIndexedBlockHash!: string;

@Column('integer')
initialIndexedBlockNumber!: number;
}
6 changes: 6 additions & 0 deletions packages/erc20-watcher/src/entity/SyncStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,10 @@ export class SyncStatus implements SyncStatusInterface {

@Column('integer')
latestCanonicalBlockNumber!: number;

@Column('varchar', { length: 66 })
initialIndexedBlockHash!: string;

@Column('integer')
initialIndexedBlockNumber!: number;
}
6 changes: 6 additions & 0 deletions packages/erc721-watcher/src/entity/SyncStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,10 @@ export class SyncStatus implements SyncStatusInterface {

@Column('integer')
latestCanonicalBlockNumber!: number;

@Column('varchar', { length: 66 })
initialIndexedBlockHash!: string;

@Column('integer')
initialIndexedBlockNumber!: number;
}
4 changes: 4 additions & 0 deletions packages/graph-node/test/utils/indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ class SyncStatus implements SyncStatusInterface {
latestIndexedBlockNumber: number;
latestCanonicalBlockHash: string;
latestCanonicalBlockNumber: number;
initialIndexedBlockHash: string;
initialIndexedBlockNumber: number;

constructor () {
this.id = 0;
Expand All @@ -143,6 +145,8 @@ class SyncStatus implements SyncStatusInterface {
this.latestIndexedBlockNumber = 0;
this.latestCanonicalBlockHash = '0';
this.latestCanonicalBlockNumber = 0;
this.initialIndexedBlockHash = '0';
this.initialIndexedBlockNumber = 0;
}
}

Expand Down
6 changes: 6 additions & 0 deletions packages/graph-test-watcher/src/entity/SyncStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,10 @@ export class SyncStatus implements SyncStatusInterface {

@Column('integer')
latestCanonicalBlockNumber!: number;

@Column('varchar', { length: 66 })
initialIndexedBlockHash!: string;

@Column('integer')
initialIndexedBlockNumber!: number;
}
12 changes: 11 additions & 1 deletion packages/mobymask-watcher/src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//

import assert from 'assert';
import { Connection, ConnectionOptions, DeepPartial, FindConditions, QueryRunner, FindManyOptions } from 'typeorm';
import { Connection, ConnectionOptions, DeepPartial, FindConditions, QueryRunner, FindManyOptions, LessThanOrEqual } from 'typeorm';
import path from 'path';

import { IPLDDatabase as BaseDatabase, IPLDDatabaseInterface, QueryOptions, StateKind, Where } from '@vulcanize/util';
Expand Down Expand Up @@ -101,6 +101,16 @@ export class Database implements IPLDDatabaseInterface {
});
}

async getPrevEntity<Entity> (entity: new () => Entity, fields: { blockNumber: number } & DeepPartial<Entity>): Promise<Entity | undefined> {
return this._conn.getRepository(entity)
.findOne({
where: {
...fields,
blockNumber: LessThanOrEqual(fields.blockNumber)
}
});
}

async saveDomainHash ({ blockHash, blockNumber, contractAddress, value, proof }: DeepPartial<DomainHash>): Promise<DomainHash> {
const repo = this._conn.getRepository(DomainHash);
const entity = repo.create({ blockHash, blockNumber, contractAddress, value, proof });
Expand Down
6 changes: 6 additions & 0 deletions packages/mobymask-watcher/src/entity/SyncStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,10 @@ export class SyncStatus implements SyncStatusInterface {

@Column('integer')
latestCanonicalBlockNumber!: number;

@Column('varchar', { length: 66 })
initialIndexedBlockHash!: string;

@Column('integer')
initialIndexedBlockNumber!: number;
}
Loading

0 comments on commit 58bbf4d

Please sign in to comment.