import { Address } from '@aragon/connect-types' ; import { providers as ethersProviders } from 'ethers' ; import { getForwardingPath } from './getForwardingPath' ; import { findMethodAbiFragment } from '../abi' ; import { findAppMethodFromSignature } from '../app' ; import App from '../../entities/App' ; import ForwardingPath from '../../entities/ForwardingPath' ; param { string } appAddress param { string } roleHash return { Promise < string > } async function getPermissionManager ( appAddress , roleHash , installedApps ) { const app = installedApps . find ( ( app ) => app . address === appAddress ) ; const roles = await app ?. roles ( ) ; return roles ?. find ( ( role ) => role . hash === roleHash ) ?. manager ; } param { string } methodSignature param { Array < * > } params return { Promise < Array < Object > > } export async function getACLForwardingPath ( sender , acl , methodSignature , params , installedApps , provider ) { const method = findAppMethodFromSignature ( acl , methodSignature , { allowDeprecated : false , } ) ; if ( ! method ) { throw new Error ( `No method named ${ methodSignature } on ACL` ) ; } if ( method . roles && method . roles . length !== 0 ) { return getForwardingPath ( sender , acl , methodSignature , params , installedApps , provider ) ; } else { const methodAbiFragment = findMethodAbiFragment ( acl . abi , methodSignature ) ; if ( ! methodAbiFragment ) { throw new Error ( `Method ${ method } not found on ACL ABI` ) ; } const inputNames = methodAbiFragment . inputs . map ( ( input ) => input . name ) ; const appIndex = inputNames . indexOf ( '_app' ) ; const roleIndex = inputNames . indexOf ( '_role' ) ; if ( appIndex === - 1 || roleIndex === - 1 ) { throw new Error ( `Method ${ methodSignature } doesn't take _app and _role as input. Permission manager cannot be found.` ) ; } const manager = await getPermissionManager ( params [ appIndex ] , params [ roleIndex ] , installedApps ) ; return getForwardingPath ( sender , acl , methodSignature , params , installedApps , provider , manager ) ; } }