Use blockHash for eth_calls in watchers (#283)

This commit is contained in:
nikugogoi 2021-10-21 15:23:46 +05:30 committed by GitHub
parent 7953ba2949
commit 6f3b8029b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 15 deletions

View File

@ -134,17 +134,14 @@ export class Indexer {
{{#if (compare query.mode @root.constants.MODE_ETH_CALL)}}
const contract = new ethers.Contract(contractAddress, this._abi, this._ethProvider);
const { block: { number } } = await this._ethClient.getBlockByHash(blockHash);
const blockNumber = ethers.BigNumber.from(number).toNumber();
{{#if (compare query.returnType 'bigint')}}
let value = await contract.{{query.name}}(
{{~#each query.params}}{{this.name}}, {{/each}}{ blockTag: blockNumber });
{{~#each query.params}}{{this.name}}, {{/each}}{ blockTag: blockHash });
value = value.toString();
value = BigInt(value);
{{else}}
const value = await contract.{{query.name}}(
{{~#each query.params}}{{this.name}}, {{/each}}{ blockTag: blockNumber });
{{~#each query.params}}{{this.name}}, {{/each}}{ blockTag: blockHash });
{{/if}}
const result: ValueResult = { value };

View File

@ -124,7 +124,7 @@ export class Indexer {
const contract = new ethers.Contract(token, this._abi, this._ethProvider);
// eth_call doesnt support calling method by blockHash https://eth.wiki/json-rpc/API#the-default-block-parameter
const value = await contract.balanceOf(owner, { blockTag: blockNumber });
const value = await contract.balanceOf(owner, { blockTag: blockHash });
result = {
value: BigInt(value.toString())
@ -160,7 +160,7 @@ export class Indexer {
if (this._serverMode === ETH_CALL_MODE) {
const contract = new ethers.Contract(token, this._abi, this._ethProvider);
const value = await contract.allowance(owner, spender, { blockTag: blockNumber });
const value = await contract.allowance(owner, spender, { blockTag: blockHash });
result = {
value: BigInt(value.toString())

View File

@ -295,11 +295,8 @@ export class Indexer implements IndexerInterface {
async callGetPool (blockHash: string, contractAddress: string, key0: string, key1: string, key2: number): Promise<ValueResult> {
const contract = new ethers.Contract(contractAddress, factoryABI, this._ethProvider);
const { block: { number } } = await this._ethClient.getBlockByHash(blockHash);
const blockNumber = ethers.BigNumber.from(number).toNumber();
try {
const value = await contract.getPool(key0, key1, key2, { blockTag: blockNumber });
const value = await contract.getPool(key0, key1, key2, { blockTag: blockHash });
return { value };
} catch (error: any) {
@ -317,11 +314,8 @@ export class Indexer implements IndexerInterface {
async positions (blockHash: string, contractAddress: string, tokenId: string): Promise<ValueResult> {
const contract = new ethers.Contract(contractAddress, nfpmABI, this._ethProvider);
const { block: { number } } = await this._ethClient.getBlockByHash(blockHash);
const blockNumber = ethers.BigNumber.from(number).toNumber();
try {
const value = await contract.positions(tokenId, { blockTag: blockNumber });
const value = await contract.positions(tokenId, { blockTag: blockHash });
return { value };
} catch (error: any) {