mirror of
https://github.com/cerc-io/watcher-ts
synced 2025-01-24 20:10:34 +00:00
Use blockHash for eth_calls in watchers (#283)
This commit is contained in:
parent
7953ba2949
commit
6f3b8029b2
@ -134,17 +134,14 @@ export class Indexer {
|
|||||||
{{#if (compare query.mode @root.constants.MODE_ETH_CALL)}}
|
{{#if (compare query.mode @root.constants.MODE_ETH_CALL)}}
|
||||||
const contract = new ethers.Contract(contractAddress, this._abi, this._ethProvider);
|
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')}}
|
{{#if (compare query.returnType 'bigint')}}
|
||||||
let value = await contract.{{query.name}}(
|
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 = value.toString();
|
||||||
value = BigInt(value);
|
value = BigInt(value);
|
||||||
{{else}}
|
{{else}}
|
||||||
const value = await contract.{{query.name}}(
|
const value = await contract.{{query.name}}(
|
||||||
{{~#each query.params}}{{this.name}}, {{/each}}{ blockTag: blockNumber });
|
{{~#each query.params}}{{this.name}}, {{/each}}{ blockTag: blockHash });
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
const result: ValueResult = { value };
|
const result: ValueResult = { value };
|
||||||
|
@ -124,7 +124,7 @@ export class Indexer {
|
|||||||
const contract = new ethers.Contract(token, this._abi, this._ethProvider);
|
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
|
// 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 = {
|
result = {
|
||||||
value: BigInt(value.toString())
|
value: BigInt(value.toString())
|
||||||
@ -160,7 +160,7 @@ export class Indexer {
|
|||||||
|
|
||||||
if (this._serverMode === ETH_CALL_MODE) {
|
if (this._serverMode === ETH_CALL_MODE) {
|
||||||
const contract = new ethers.Contract(token, this._abi, this._ethProvider);
|
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 = {
|
result = {
|
||||||
value: BigInt(value.toString())
|
value: BigInt(value.toString())
|
||||||
|
@ -295,11 +295,8 @@ export class Indexer implements IndexerInterface {
|
|||||||
async callGetPool (blockHash: string, contractAddress: string, key0: string, key1: string, key2: number): Promise<ValueResult> {
|
async callGetPool (blockHash: string, contractAddress: string, key0: string, key1: string, key2: number): Promise<ValueResult> {
|
||||||
const contract = new ethers.Contract(contractAddress, factoryABI, this._ethProvider);
|
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 {
|
try {
|
||||||
const value = await contract.getPool(key0, key1, key2, { blockTag: blockNumber });
|
const value = await contract.getPool(key0, key1, key2, { blockTag: blockHash });
|
||||||
|
|
||||||
return { value };
|
return { value };
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
@ -317,11 +314,8 @@ export class Indexer implements IndexerInterface {
|
|||||||
async positions (blockHash: string, contractAddress: string, tokenId: string): Promise<ValueResult> {
|
async positions (blockHash: string, contractAddress: string, tokenId: string): Promise<ValueResult> {
|
||||||
const contract = new ethers.Contract(contractAddress, nfpmABI, this._ethProvider);
|
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 {
|
try {
|
||||||
const value = await contract.positions(tokenId, { blockTag: blockNumber });
|
const value = await contract.positions(tokenId, { blockTag: blockHash });
|
||||||
|
|
||||||
return { value };
|
return { value };
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
|
Loading…
Reference in New Issue
Block a user