import { Address } from '@aragon/connect-types' ; import { utils as ethersUtils , providers as ethersProvider } from 'ethers' ; import { addressesEqual } from './address' ; import { decodeKernelSetAppParameters , isKernelAppCodeNamespace , isKernelSetAppIntent , } from './kernel' ; import { getForwardingPath , getACLForwardingPath } from './path/index' ; import { StepDecoded } from '../types' ; import App from '../entities/App' ; import ForwardingPath from '../entities/ForwardingPath' ; export async function appIntent ( sender , destinationApp , methodSignature , params , installedApps , provider ) { const acl = installedApps . find ( ( app ) => app . name === 'acl' ) ; if ( acl && addressesEqual ( destinationApp . address , acl . address ) ) { try { return getACLForwardingPath ( sender , acl , methodSignature , params , installedApps , provider ) ; } catch ( _ ) { return new ForwardingPath ( { destination : destinationApp , path : [ ] , transactions : [ ] , } , installedApps , provider ) ; } } return getForwardingPath ( sender , destinationApp , methodSignature , params , installedApps , provider ) ; } export function filterAndDecodeAppUpgradeIntents ( intents , installedApps ) { const kernel = installedApps . find ( ( app ) => app . name === 'kernel' ) ; if ( ! kernel ) { throw new Error ( `Organization not found.` ) ; } return ( intents . filter ( ( intent ) => isKernelSetAppIntent ( kernel , intent ) ) . map ( ( intent ) => { try { return decodeKernelSetAppParameters ( intent . data ) ; } catch ( _ ) { } return [ ] ; } ) . filter ( ( result ) => isKernelAppCodeNamespace ( result [ 'namesapce' ] ) ) ) ; }