Added interation methods for Interface fragments.

This commit is contained in:
Richard Moore 2023-01-22 16:39:11 -05:00
parent 27c9563ca5
commit c45ee95146

@ -147,8 +147,6 @@ function checkNames(fragment: Fragment, type: "input" | "output", params: Array<
}, <{ [ name: string ]: boolean }>{ });
}
*/
//export type AbiCoder = any;
//const defaultAbiCoder: AbiCoder = { };
/**
* @TODO
@ -402,6 +400,18 @@ export class Interface {
return this.#getFunction(key, values || null, true)
}
/**
* Iterate over all functions, calling %%callback%%, sorted by their name.
*/
forEachFunction(callback: (func: FunctionFragment, index: number) => void): void {
const names = Array.from(this.#functions.keys());
names.sort((a, b) => a.localeCompare(b));
for (let i = 0; i < names.length; i++) {
const name = names[i];
callback(<FunctionFragment>(this.#functions.get(name)), i);
}
}
// Find an event definition by any means necessary (unless it is ambiguous)
#getEvent(key: string, values: null | Array<null | any | Typed>, forceUnique: boolean): EventFragment {
@ -484,6 +494,18 @@ export class Interface {
return this.#getEvent(key, values || null, true)
}
/**
* Iterate over all events, calling %%callback%%, sorted by their name.
*/
forEachEvent(callback: (func: EventFragment, index: number) => void): void {
const names = Array.from(this.#events.keys());
names.sort((a, b) => a.localeCompare(b));
for (let i = 0; i < names.length; i++) {
const name = names[i];
callback(<EventFragment>(this.#events.get(name)), i);
}
}
/**
* Get the [[ErrorFragment]] for %%key%%, which may be an error
* selector, error name or error signature that belongs to the ABI.
@ -538,6 +560,18 @@ export class Interface {
assertArgument(false, "no matching error", "signature", key);
}
/**
* Iterate over all errors, calling %%callback%%, sorted by their name.
*/
forEachError(callback: (func: ErrorFragment, index: number) => void): void {
const names = Array.from(this.#errors.keys());
names.sort((a, b) => a.localeCompare(b));
for (let i = 0; i < names.length; i++) {
const name = names[i];
callback(<ErrorFragment>(this.#errors.get(name)), i);
}
}
// Get the 4-byte selector used by Solidity to identify a function
/*
getSelector(fragment: ErrorFragment | FunctionFragment): string {