mirror of
https://github.com/cerc-io/watcher-ts
synced 2025-02-09 11:32:49 +00:00
31 lines
620 B
TypeScript
31 lines
620 B
TypeScript
|
|
||
|
import _ from 'lodash';
|
||
|
import { ethers } from 'ethers';
|
||
|
|
||
|
export const addressesInTrace = (obj: any): any => {
|
||
|
return _.uniq(_.compact(_.flattenDeep(addressesIn(obj))))
|
||
|
.sort()
|
||
|
.map(address => ethers.utils.getAddress(<string>address));
|
||
|
};
|
||
|
|
||
|
const addressesIn = (obj: any): any => {
|
||
|
const addresses: any = [];
|
||
|
|
||
|
if (obj) {
|
||
|
addresses.push(obj.from);
|
||
|
addresses.push(obj.to);
|
||
|
|
||
|
if (obj.addresses) {
|
||
|
addresses.push(_.keys(obj.addresses));
|
||
|
}
|
||
|
|
||
|
if (obj.calls) {
|
||
|
obj.calls.forEach((call: any) => {
|
||
|
addresses.push(addressesIn(call));
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return addresses;
|
||
|
};
|