Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Add custom inspect alias to codec inspectors, to support browser-util-inspect #4953

Merged
merged 1 commit into from
Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions packages/codec/lib/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,17 @@ function ethersCompatibleNativizeEventArgs(
*/
export class CalldataDecodingInspector {
decoding: CalldataDecoding;

constructor(decoding: CalldataDecoding) {
this.decoding = decoding;
}
/**
* @dev non-standard alternative interface name used by browser-util-inspect
* package
*/
inspect(depth: number | null, options: InspectOptions): string {
return this[util.inspect.custom].bind(this)(depth, options);
}
[util.inspect.custom](depth: number | null, options: InspectOptions): string {
switch (this.decoding.kind) {
case "function":
Expand Down Expand Up @@ -346,6 +354,13 @@ export class LogDecodingInspector {
constructor(decoding: LogDecoding) {
this.decoding = decoding;
}
/**
* @dev non-standard alternative interface name used by browser-util-inspect
* package
*/
inspect(depth: number | null, options: InspectOptions): string {
return this[util.inspect.custom].bind(this)(depth, options);
}
[util.inspect.custom](depth: number | null, options: InspectOptions): string {
const className = this.decoding.definedIn
? this.decoding.definedIn.typeName
Expand Down Expand Up @@ -374,6 +389,13 @@ export class ReturndataDecodingInspector {
constructor(decoding: ReturndataDecoding) {
this.decoding = decoding;
}
/**
* @dev non-standard alternative interface name used by browser-util-inspect
* package
*/
inspect(depth: number | null, options: InspectOptions): string {
return this[util.inspect.custom].bind(this)(depth, options);
}
[util.inspect.custom](depth: number | null, options: InspectOptions): string {
switch (this.decoding.kind) {
case "return":
Expand Down
23 changes: 18 additions & 5 deletions packages/codec/lib/format/utils/inspect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ export class ResultInspector {
constructor(result: Format.Values.Result) {
this.result = result;
}
/**
* @dev non-standard alternative interface name used by browser-util-inspect
* package
*/
inspect(depth: number | null, options: InspectOptions): string {
return this[util.inspect.custom].bind(this)(depth, options);
}
[util.inspect.custom](depth: number | null, options: InspectOptions): string {
switch (this.result.kind) {
case "value":
Expand Down Expand Up @@ -665,11 +672,17 @@ export function nativizeAccessList(
return wrappedAccessList.value.map(wrappedAccessListForAddress => {
//HACK: we're just going to coerce all over the place here
const addressStorageKeysPair = <Format.Values.OptionallyNamedValue[]>(
<Format.Values.TupleValue>wrappedAccessListForAddress
).value;
const wrappedAddress = <Format.Values.AddressValue>addressStorageKeysPair[0].value;
const wrappedStorageKeys = <Format.Values.ArrayValue>addressStorageKeysPair[1].value;
const wrappedStorageKeysArray = <Format.Values.UintValue[]>wrappedStorageKeys.value;
(<Format.Values.TupleValue>wrappedAccessListForAddress).value
);
const wrappedAddress = <Format.Values.AddressValue>(
addressStorageKeysPair[0].value
);
const wrappedStorageKeys = <Format.Values.ArrayValue>(
addressStorageKeysPair[1].value
);
const wrappedStorageKeysArray = <Format.Values.UintValue[]>(
wrappedStorageKeys.value
);
return {
address: wrappedAddress.value.asAddress,
storageKeys: wrappedStorageKeysArray.map(wrappedStorageKey =>
Expand Down