Open therealjmj opened 1 year ago
Besides the bug with fix above, I suppose the main question is this - What's the best way to parse from decoded Result (nested Proxy arrays) to a JavaScript object or array?
It's not type-safe, but definitely functional:
const recursivelyDecodeResult = (result: Result): any => {
if (typeof result !== 'object') {
// Raw primitive value
return result;
}
try {
const obj = result.toObject();
if (obj._) {
throw new Error('Decode as array, not object');
}
Object.keys(obj).forEach((key) => {
obj[key] = recursivelyDecodeResult(obj[key]);
});
return obj;
} catch (err) {
// Result is array.
return result
.toArray()
.map((item) => recursivelyDecodeResult(item as Result));
}
};
Besides the bug with fix above, I suppose the main question is this - What's the best way to parse from decoded Result (nested Proxy arrays) to a JavaScript object or array?
Seconded. It'd be super useful for Result
objects to have a method that recursively converts the Result
to a JavaScript object or array. Basically the same as Result.toObject()
, except it resolves things recursively for nested data structures. I'm currently using something similar to the recursivelyDecodeResult
function that @therealjmj posted above.
Ethers Version
6.4.0
Search Terms
No response
Describe the Problem
The 'args' aren't parsing correctly for polling JsonRpcProviders.
See logic here:
https://github.com/ethers-io/ethers.js/blob/c785c1e5153d5a85a78f90f177577f2c8df15529/src.ts/contract/contract.ts#L538-L544
It seems like the logic here, should change to:
This DOES fix the issue - event args pass to the listeners. However, this results in "Proxy" Result objects, that are not decoded and typed correctly.
Code Snippet
Actual: