Skip to content

Commit

Permalink
Add context to Logs that fail decoding due to ABI issues to help debu…
Browse files Browse the repository at this point in the history
…gging.
  • Loading branch information
ricmoo committed Aug 2, 2023
1 parent d32f81b commit f3c46f2
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 6 deletions.
23 changes: 20 additions & 3 deletions src.ts/contract/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -892,10 +892,25 @@ export class BaseContract implements Addressable, EventEmitterable<ContractEvent
* @_ignore:
*/
async queryTransaction(hash: string): Promise<Array<EventLog>> {
// 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<null | ContractTransactionReceipt> {
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"``)
Expand Down Expand Up @@ -924,7 +939,9 @@ export class BaseContract implements Addressable, EventEmitterable<ContractEvent
if (foundFragment) {
try {
return new EventLog(log, this.interface, foundFragment);
} catch (error) { }
} catch (error: any) {
return new UndecodedEventLog(log, error);
}
}

return new Log(log, provider);
Expand Down
2 changes: 1 addition & 1 deletion src.ts/contract/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export {
export {
ContractEventPayload, ContractUnknownEventPayload,
ContractTransactionReceipt, ContractTransactionResponse,
EventLog,
EventLog, UndecodedEventLog
} from "./wrappers.js";

export type {
Expand Down
23 changes: 22 additions & 1 deletion src.ts/contract/wrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,25 @@ export class EventLog extends Log {
get eventSignature(): string { return this.fragment.format(); }
}

/**
* An **EventLog** contains additional properties parsed from the [[Log]].
*/
export class UndecodedEventLog extends Log {

/**
* The error encounted when trying to decode the log.
*/
readonly error!: Error;

/**
* @_ignore:
*/
constructor(log: Log, error: Error) {
super(log, log.provider);
defineProperties<UndecodedEventLog>(this, { error });
}
}

/**
* A **ContractTransactionReceipt** includes the parsed logs from a
* [[TransactionReceipt]].
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src.ts/ethers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit f3c46f2

Please sign in to comment.