mirror of
https://github.com/cerc-io/watcher-ts
synced 2025-01-09 21:08:06 +00:00
2adc5e9c34
* Push address event to downstream subscribers. * Get addresses from trace - tests and fixes.
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;
|
|
};
|