Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix provider logger #2770

Merged
merged 9 commits into from
Nov 8, 2023
46 changes: 34 additions & 12 deletions src/modules/blockchain/implementation/web3-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class Web3Service {
await this.initializeWeb3();
this.startBlock = await this.getBlockNumber();
await this.initializeContracts();
// this.initializeProviderDebugging();
this.initializeProviderDebugging();
}

initializeTransactionQueue(concurrency) {
Expand Down Expand Up @@ -189,32 +189,38 @@ class Web3Service {
const { method } = info.request;

if (['call', 'estimateGas'].includes(method)) {
const contractInstance = this.contractAddresses[info.request.params.to];
const inputData = info.request.params.data;
const contractInstance = this.contractAddresses[info.request.params.transaction.to];
const inputData = info.request.params.transaction.data;
const decodedInputData = this._decodeInputData(
inputData,
contractInstance.interface,
);

const functionFragment = contractInstance.interface.getFunction(
inputData.slice(0, 10),
);
const functionName = functionFragment.name;
const inputs = functionFragment.inputs.map(
(input, i) => `${input.name}=${decodedInputData[i]}`,
);
if (info.backend.error) {
const decodedErrorData = this._decodeErrorData(
info.backend.error,
contractInstance.interface,
);
this.logger.debug(
`${decodedInputData} ${method} has failed; Error: ${decodedErrorData}; ` +
`${functionName}(${inputs}) ${method} has failed; Error: ${decodedErrorData}; ` +
`RPC: ${info.backend.provider.connection.url}.`,
);
} else if (info.backend.result !== undefined) {
let message = `${decodedInputData} ${method} has been successfully executed; `;
let message = `${functionName}(${inputs}) ${method} has been successfully executed; `;

if (info.backend.result !== null) {
if (info.backend.result !== null && method !== 'estimateGas') {
const decodedResultData = this._decodeResultData(
inputData.slice(0, 10),
info.backend.result,
contractInstance.interface,
);
message += `Result: ${decodedResultData} `;
message += `Result: ${decodedResultData}; `;
}

message += `RPC: ${info.backend.provider.connection.url}.`;
Expand Down Expand Up @@ -395,10 +401,17 @@ class Web3Service {
result = await contractInstance[functionName](...args);
} catch (error) {
const decodedErrorData = this._decodeErrorData(error, contractInstance.interface);

const functionFragment = contractInstance.interface.getFunction(
error.transaction.data.slice(0, 10),
);
const inputs = functionFragment.inputs.map(
(input, i) => `${input.name}=${args[i]}`,
);

// eslint-disable-next-line no-await-in-loop
await this.handleError(
Error(`Call failed, reason: ${decodedErrorData}`),
functionName,
Error(`Call ${functionName}(${inputs}) failed, reason: ${decodedErrorData}`),
);
}
}
Expand All @@ -419,9 +432,18 @@ class Web3Service {
gasLimit = await contractInstance.estimateGas[functionName](...args);
} catch (error) {
const decodedErrorData = this._decodeErrorData(error, contractInstance.interface);

const functionFragment = contractInstance.interface.getFunction(
error.transaction.data.slice(0, 10),
);
const inputs = functionFragment.inputs.map(
(input, i) => `${input.name}=${args[i]}`,
);

await this.handleError(
Error(`Gas estimation failed, reason: ${decodedErrorData}`),
functionName,
Error(
`Gas estimation ${functionName}(${inputs}) failed, reason: ${decodedErrorData}`,
),
);
}

Expand Down
Loading