Add context to Logs that fail decoding due to ABI issues to help debugging.
This commit is contained in:
parent
d32f81b3c3
commit
f3c46f2299
@ -11,7 +11,7 @@ import {
|
|||||||
import {
|
import {
|
||||||
ContractEventPayload, ContractUnknownEventPayload,
|
ContractEventPayload, ContractUnknownEventPayload,
|
||||||
ContractTransactionResponse,
|
ContractTransactionResponse,
|
||||||
EventLog
|
EventLog, UndecodedEventLog
|
||||||
} from "./wrappers.js";
|
} from "./wrappers.js";
|
||||||
|
|
||||||
import type { EventFragment, FunctionFragment, InterfaceAbi, ParamType, Result } from "../abi/index.js";
|
import type { EventFragment, FunctionFragment, InterfaceAbi, ParamType, Result } from "../abi/index.js";
|
||||||
@ -892,10 +892,25 @@ export class BaseContract implements Addressable, EventEmitterable<ContractEvent
|
|||||||
* @_ignore:
|
* @_ignore:
|
||||||
*/
|
*/
|
||||||
async queryTransaction(hash: string): Promise<Array<EventLog>> {
|
async queryTransaction(hash: string): Promise<Array<EventLog>> {
|
||||||
// Is this useful?
|
|
||||||
throw new Error("@TODO");
|
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
|
* Provide historic access to event data for %%event%% in the range
|
||||||
* %%fromBlock%% (default: ``0``) to %%toBlock%% (default: ``"latest"``)
|
* %%fromBlock%% (default: ``0``) to %%toBlock%% (default: ``"latest"``)
|
||||||
@ -924,7 +939,9 @@ export class BaseContract implements Addressable, EventEmitterable<ContractEvent
|
|||||||
if (foundFragment) {
|
if (foundFragment) {
|
||||||
try {
|
try {
|
||||||
return new EventLog(log, this.interface, foundFragment);
|
return new EventLog(log, this.interface, foundFragment);
|
||||||
} catch (error) { }
|
} catch (error: any) {
|
||||||
|
return new UndecodedEventLog(log, error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Log(log, provider);
|
return new Log(log, provider);
|
||||||
|
@ -17,7 +17,7 @@ export {
|
|||||||
export {
|
export {
|
||||||
ContractEventPayload, ContractUnknownEventPayload,
|
ContractEventPayload, ContractUnknownEventPayload,
|
||||||
ContractTransactionReceipt, ContractTransactionResponse,
|
ContractTransactionReceipt, ContractTransactionResponse,
|
||||||
EventLog,
|
EventLog, UndecodedEventLog
|
||||||
} from "./wrappers.js";
|
} from "./wrappers.js";
|
||||||
|
|
||||||
export type {
|
export type {
|
||||||
|
@ -53,6 +53,25 @@ export class EventLog extends Log {
|
|||||||
get eventSignature(): string { return this.fragment.format(); }
|
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
|
* A **ContractTransactionReceipt** includes the parsed logs from a
|
||||||
* [[TransactionReceipt]].
|
* [[TransactionReceipt]].
|
||||||
@ -78,7 +97,9 @@ export class ContractTransactionReceipt extends TransactionReceipt {
|
|||||||
if (fragment) {
|
if (fragment) {
|
||||||
try {
|
try {
|
||||||
return new EventLog(log, this.#iface, fragment)
|
return new EventLog(log, this.#iface, fragment)
|
||||||
} catch (error) { }
|
} catch (error: any) {
|
||||||
|
return new UndecodedEventLog(log, error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return log;
|
return log;
|
||||||
|
@ -31,7 +31,7 @@ export {
|
|||||||
export {
|
export {
|
||||||
BaseContract, Contract,
|
BaseContract, Contract,
|
||||||
ContractFactory,
|
ContractFactory,
|
||||||
ContractEventPayload, ContractTransactionReceipt, ContractTransactionResponse, ContractUnknownEventPayload, EventLog,
|
ContractEventPayload, ContractTransactionReceipt, ContractTransactionResponse, ContractUnknownEventPayload, EventLog, UndecodedEventLog
|
||||||
} from "./contract/index.js";
|
} from "./contract/index.js";
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
Loading…
Reference in New Issue
Block a user