Add context to Logs that fail decoding due to ABI issues to help debugging.

This commit is contained in:
Richard Moore 2023-08-02 18:29:50 -04:00
parent d32f81b3c3
commit f3c46f2299
4 changed files with 44 additions and 6 deletions

@ -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<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"``)
@ -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);

@ -17,7 +17,7 @@ export {
export {
ContractEventPayload, ContractUnknownEventPayload,
ContractTransactionReceipt, ContractTransactionResponse,
EventLog,
EventLog, UndecodedEventLog
} from "./wrappers.js";
export type {

@ -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]].
@ -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;

@ -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 {