import { AppABIEncodings , Node , OutcomeType , SolidityValueType } from "@counterfactual/types" ; import { BigNumber , BigNumberish } from "ethers/utils" ; import { Provider } from "./provider" ; import { EventType } from "./types" ; ignore function parseBigNumber ( val , paramName ) { try { return new BigNumber ( val ) ; } catch ( e ) { throw { type : EventType . ERROR , data : { errorName : "invalid_param" , message : `Invalid value for parameter '${ paramName }': ${ val }` , extra : { paramName , originalError : e } } } ; } } /**
 * Proposes installations of a given app
 */ export class AppFactory { param appDefinition param encodings param provider constructor ( readonly appDefinition , readonly encodings , readonly provider ) { } async param params return async proposeInstall ( params ) { const timeout = parseBigNumber ( params . timeout , "timeout" ) ; const initiatorDeposit = parseBigNumber ( params . initiatorDeposit , "initiatorDeposit" ) ; const responderDeposit = parseBigNumber ( params . responderDeposit , "responderDeposit" ) ; const response = await this . provider . callRawNodeMethod ( Node . RpcMethodName . PROPOSE_INSTALL , { timeout , responderDeposit , initiatorDeposit , proposedToIdentifier : params . proposedToIdentifier , initialState : params . initialState , appDefinition : this . appDefinition , abiEncodings : this . encodings , outcomeType : params . outcomeType } ) ; const { appInstanceId } = response . result as Node . ProposeInstallResult ; return appInstanceId ; } async param params return async proposeInstallVirtual ( params ) { const timeout = parseBigNumber ( params . timeout , "timeout" ) ; const initiatorDeposit = parseBigNumber ( params . initiatorDeposit , "initiatorDeposit" ) ; const responderDeposit = parseBigNumber ( params . responderDeposit , "responderDeposit" ) ; const response = await this . provider . callRawNodeMethod ( Node . RpcMethodName . PROPOSE_INSTALL , { timeout , responderDeposit , initiatorDeposit , proposedToIdentifier : params . proposedToIdentifier , initialState : params . initialState , intermediaryIdentifier : params . intermediaryIdentifier , appDefinition : this . appDefinition , abiEncodings : this . encodings , outcomeType : OutcomeType . TWO_PARTY_FIXED_OUTCOME } ) ; const { appInstanceId } = response . result as Node . ProposeInstallVirtualResult ; return appInstanceId ; } }