Fixed Event args keyword access.
This commit is contained in:
parent
bd32ee0af5
commit
2692e783b4
@ -8,8 +8,8 @@ import { Logger } from "@ethersproject/logger";
|
||||
import { version } from "../_version";
|
||||
const logger = new Logger(version);
|
||||
|
||||
export interface Result extends Array<any> {
|
||||
[key: string]: any;
|
||||
export interface Result extends ReadonlyArray<any> {
|
||||
readonly [key: string]: any;
|
||||
}
|
||||
|
||||
export type CoerceFunc = (type: string, value: any) => any;
|
||||
|
@ -102,7 +102,7 @@ export function unpack(reader: Reader, coders: Array<Coder>): Array<any> {
|
||||
values[name] = values[index];
|
||||
});
|
||||
|
||||
return values;
|
||||
return Object.freeze(values);
|
||||
}
|
||||
|
||||
|
||||
|
@ -400,7 +400,7 @@ export class Interface {
|
||||
let resultIndexed = (topics != null) ? this._abiCoder.decode(indexed, concat(topics)): null;
|
||||
let resultNonIndexed = this._abiCoder.decode(nonIndexed, data);
|
||||
|
||||
let result: Result = [ ];
|
||||
let result: (Array<any> & { [ key: string ]: any }) = [ ];
|
||||
let nonIndexedIndex = 0, indexedIndex = 0;
|
||||
eventFragment.inputs.forEach((param, index) => {
|
||||
if (param.indexed) {
|
||||
@ -416,10 +416,11 @@ export class Interface {
|
||||
} else {
|
||||
result[index] = resultNonIndexed[nonIndexedIndex++];
|
||||
}
|
||||
|
||||
if (param.name && result[param.name] == null) { result[param.name] = result[index]; }
|
||||
});
|
||||
|
||||
return result;
|
||||
return Object.freeze(result);
|
||||
}
|
||||
|
||||
// Given a transaction, find the matching function fragment (if any) and
|
||||
|
@ -244,7 +244,8 @@ function runMethod(contract: Contract, functionName: string, options: RunOptions
|
||||
let parsed: LogDescription = null;
|
||||
try {
|
||||
parsed = contract.interface.parseLog(log);
|
||||
} catch (e){}
|
||||
} catch (e){ }
|
||||
|
||||
if (parsed) {
|
||||
event.args = parsed.args;
|
||||
event.decode = (data: BytesLike, topics?: Array<any>) => {
|
||||
|
@ -72,14 +72,32 @@ export function shallowCopy<T>(object: T): Similar<T> {
|
||||
return result;
|
||||
}
|
||||
|
||||
const opaque: { [key: string]: boolean } = { bigint: true, boolean: true, number: true, string: true };
|
||||
const opaque: { [key: string]: boolean } = { bigint: true, boolean: true, "function": true, number: true, string: true };
|
||||
|
||||
function _isFrozen(object: any): boolean {
|
||||
|
||||
// Opaque objects are not mutable, so safe to copy by assignment
|
||||
if (object === undefined || object === null || opaque[typeof(object)]) { return true; }
|
||||
|
||||
if (Array.isArray(object) || typeof(object) === "object") {
|
||||
if (!Object.isFrozen(object)) { return false; }
|
||||
|
||||
const keys = Object.keys(object);
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
if (!_isFrozen(object[keys[i]])) { return false; }
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return logger.throwArgumentError(`Cannot deepCopy ${ typeof(object) }`, "object", object);
|
||||
}
|
||||
|
||||
// Returns a new copy of object, such that no properties may be replaced.
|
||||
// New properties may be added only to objects.
|
||||
function _deepCopy(object: any): any {
|
||||
|
||||
// Opaque objects are not mutable, so safe to copy by assignment
|
||||
if (object === undefined || object === null || opaque[typeof(object)]) { return object; }
|
||||
if (_isFrozen(object)) { return object; }
|
||||
|
||||
// Arrays are mutable, so we need to create a copy
|
||||
if (Array.isArray(object)) {
|
||||
@ -87,10 +105,6 @@ function _deepCopy(object: any): any {
|
||||
}
|
||||
|
||||
if (typeof(object) === "object") {
|
||||
|
||||
// Immutable objects are safe to just use
|
||||
if (Object.isFrozen(object)) { return object; }
|
||||
|
||||
const result: { [ key: string ]: any } = {};
|
||||
for (const key in object) {
|
||||
const value = object[key];
|
||||
@ -101,12 +115,7 @@ function _deepCopy(object: any): any {
|
||||
return result;
|
||||
}
|
||||
|
||||
// The function type is also immutable, so safe to copy by assignment
|
||||
if (typeof(object) === "function") {
|
||||
return object;
|
||||
}
|
||||
|
||||
logger.throwArgumentError(`Cannot deepCopy ${ typeof(object) }`, "object", object);
|
||||
return logger.throwArgumentError(`Cannot deepCopy ${ typeof(object) }`, "object", object);
|
||||
}
|
||||
|
||||
export function deepCopy<T>(object: T): Similar<T> {
|
||||
|
Loading…
Reference in New Issue
Block a user