From f3c46f22994d194ff78b3b176407b2ecb7af1c77 Mon Sep 17 00:00:00 2001 From: Richard Moore Date: Wed, 2 Aug 2023 18:29:50 -0400 Subject: [PATCH] Add context to Logs that fail decoding due to ABI issues to help debugging. --- src.ts/contract/contract.ts | 23 ++++++++++++++++++++--- src.ts/contract/index.ts | 2 +- src.ts/contract/wrappers.ts | 23 ++++++++++++++++++++++- src.ts/ethers.ts | 2 +- 4 files changed, 44 insertions(+), 6 deletions(-) diff --git a/src.ts/contract/contract.ts b/src.ts/contract/contract.ts index f1ccd05cc..0c6e9d644 100644 --- a/src.ts/contract/contract.ts +++ b/src.ts/contract/contract.ts @@ -11,7 +11,7 @@ import { import { ContractEventPayload, ContractUnknownEventPayload, ContractTransactionResponse, - EventLog + EventLog, UndecodedEventLog } from "./wrappers.js"; import type { EventFragment, FunctionFragment, InterfaceAbi, ParamType, Result } from "../abi/index.js"; @@ -892,10 +892,25 @@ export class BaseContract implements Addressable, EventEmitterable> { - // Is this useful? throw new Error("@TODO"); } + /* + // @TODO: this is a non-backwards compatible change, but will be added + // in v7 and in a potential SmartContract class in an upcoming + // v6 release + async getTransactionReceipt(hash: string): Promise { + const provider = getProvider(this.runner); + assert(provider, "contract runner does not have a provider", + "UNSUPPORTED_OPERATION", { operation: "queryTransaction" }); + + const receipt = await provider.getTransactionReceipt(hash); + if (receipt == null) { return null; } + + return new ContractTransactionReceipt(this.interface, provider, receipt); + } + */ + /** * Provide historic access to event data for %%event%% in the range * %%fromBlock%% (default: ``0``) to %%toBlock%% (default: ``"latest"``) @@ -924,7 +939,9 @@ export class BaseContract implements Addressable, EventEmitterable(this, { error }); + } +} + /** * A **ContractTransactionReceipt** includes the parsed logs from a * [[TransactionReceipt]]. @@ -78,7 +97,9 @@ export class ContractTransactionReceipt extends TransactionReceipt { if (fragment) { try { return new EventLog(log, this.#iface, fragment) - } catch (error) { } + } catch (error: any) { + return new UndecodedEventLog(log, error); + } } return log; diff --git a/src.ts/ethers.ts b/src.ts/ethers.ts index cd148ce62..7f3786e80 100644 --- a/src.ts/ethers.ts +++ b/src.ts/ethers.ts @@ -31,7 +31,7 @@ export { export { BaseContract, Contract, ContractFactory, - ContractEventPayload, ContractTransactionReceipt, ContractTransactionResponse, ContractUnknownEventPayload, EventLog, + ContractEventPayload, ContractTransactionReceipt, ContractTransactionResponse, ContractUnknownEventPayload, EventLog, UndecodedEventLog } from "./contract/index.js"; export {