Generate watcher with caching for multiple return type (#16)

This commit is contained in:
Nabarun Gogoi 2023-04-27 16:47:54 +05:30 committed by GitHub
parent 0bce143a00
commit f02afc0ed3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 3 deletions

View File

@ -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);
}

View File

@ -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;

View File

@ -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;
}