import { Node } from "@counterfactual/types" ; import { jsonRpcMethod } from "rpc-server" ; import { CONVENTION_FOR_ETH_TOKEN_ADDRESS } from "../../../constants" ; import { RequestHandler } from "../../../request-handler" ; import { NodeController } from "../../controller" ; export default class GetFreeBalanceController extends NodeController { @ jsonRpcMethod ( Node . RpcMethodName . GET_FREE_BALANCE_STATE ) public executeMethod = super . executeMethod ; protected async executeMethodImplementation ( requestHandler , params ) { const { store } = requestHandler ; const { multisigAddress , tokenAddress : tokenAddressParam } = params ; const tokenAddress = tokenAddressParam || CONVENTION_FOR_ETH_TOKEN_ADDRESS ; if ( ! multisigAddress ) { throw Error ( "getFreeBalanceState method was given undefined multisigAddress" ) ; } const stateChannel = await store . getStateChannel ( multisigAddress ) ; return stateChannel . getFreeBalanceClass ( ) . withTokenAddress ( tokenAddress ) ; } }