Generate watcher with caching for multiple return type (#16)
This commit is contained in:
parent
0bce143a00
commit
f02afc0ed3
@ -433,9 +433,9 @@ export class Database implements DatabaseInterface {
|
||||
return repo.save(entity);
|
||||
}
|
||||
|
||||
async saveGetKeys ({ blockHash, blockNumber, contractAddress, _point, value, proof }: DeepPartial<GetKeys>): Promise<GetKeys> {
|
||||
async saveGetKeys ({ blockHash, blockNumber, contractAddress, _point, value0, value1, value2, value3, proof }: DeepPartial<GetKeys>): Promise<GetKeys> {
|
||||
const repo = this._conn.getRepository(GetKeys);
|
||||
const entity = repo.create({ blockHash, blockNumber, contractAddress, _point, value, proof });
|
||||
const entity = repo.create({ blockHash, blockNumber, contractAddress, _point, value0, value1, value2, value3, proof });
|
||||
return repo.save(entity);
|
||||
}
|
||||
|
||||
|
||||
@ -24,7 +24,16 @@ export class GetKeys {
|
||||
_point!: bigint;
|
||||
|
||||
@Column('varchar')
|
||||
value!: string;
|
||||
value0!: string;
|
||||
|
||||
@Column('varchar')
|
||||
value1!: string;
|
||||
|
||||
@Column('numeric', { transformer: bigintTransformer })
|
||||
value2!: bigint;
|
||||
|
||||
@Column('numeric', { transformer: bigintTransformer })
|
||||
value3!: bigint;
|
||||
|
||||
@Column('text', { nullable: true })
|
||||
proof!: string;
|
||||
|
||||
@ -124,6 +124,24 @@ export class Indexer implements IndexerInterface {
|
||||
}
|
||||
|
||||
async getKeys (blockHash: string, contractAddress: string, _point: bigint): Promise<ValueResult> {
|
||||
const entity = await this._db.getGetKeys({ blockHash, contractAddress, _point });
|
||||
if (entity) {
|
||||
log('getKeys: db hit.');
|
||||
|
||||
return {
|
||||
value: {
|
||||
value0: entity.value0,
|
||||
value1: entity.value1,
|
||||
value2: entity.value2,
|
||||
value3: entity.value3
|
||||
},
|
||||
proof: JSON.parse(entity.proof)
|
||||
};
|
||||
}
|
||||
|
||||
const { block: { number } } = await this._ethClient.getBlockByHash(blockHash);
|
||||
const blockNumber = ethers.BigNumber.from(number).toNumber();
|
||||
|
||||
log('getKeys: db miss, fetching from upstream server');
|
||||
|
||||
const abi = this._abiMap.get(KIND_AZIMUTH);
|
||||
@ -141,6 +159,8 @@ export class Indexer implements IndexerInterface {
|
||||
|
||||
const result: ValueResult = { value };
|
||||
|
||||
await this._db.saveGetKeys({ blockHash, blockNumber, contractAddress, _point, value0: value.value0, value1: value.value1, value2: value.value2, value3: value.value3, proof: JSONbigNative.stringify(result.proof) });
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user