public static bool confirmSettle(byte[] _channelId)
 {
     BasicMethods.assert(BasicMethods._isByte32(_channelId), "_channelId illegal");
     LedgerStruct.Channel       c       = LedgerStruct.getChannelMap(_channelId);
     LedgerStruct.SettleBalance balance = LedgerChannel._validateSettleBalance(c);
     if (balance.isSettled != 1)
     {
         c = _resetDuplexState(c);
         ConfirmSettleFailEvent(_channelId);
         return(false);
     }
     LedgerStruct.ChannelStatus channelStatus = LedgerStruct.getStandardChannelStatus();
     c = _updateChannelStatus(c, channelStatus.Closed);
     LedgerStruct.setChannelMap(_channelId, c);
     ConfirmSettleEvent(_channelId, balance.balance);
     return(true);
 }
    public static LedgerStruct.SettleBalance _validateSettleBalance(LedgerStruct.Channel _c)
    {
        LedgerStruct.PeerProfile[] peerProfiles = _c.peerProfiles;
        BasicMethods.assert(peerProfiles.Length == 2, "Illegal peerProfiles length");
        LedgerStruct.PeerProfile   peer0         = peerProfiles[0];
        LedgerStruct.PeerProfile   peer1         = peerProfiles[1];
        LedgerStruct.PeerState     peerState0    = peer0.state;
        LedgerStruct.PeerState     peerState1    = peer1.state;
        LedgerStruct.SettleBalance settleBalance = new LedgerStruct.SettleBalance();
        settleBalance.balance = new BigInteger[2];
        BigInteger[] balance = settleBalance.balance;
        balance[0] = peer0.deposit + peerState1.transferOut;
        balance[1] = peer1.deposit + peerState0.transferOut;

        BigInteger subAmt = peerState0.transferOut + peer0.withdrawal;

        if (balance[0] < subAmt)
        {
            settleBalance.isSettled = 0;
            balance[0] = 0;
            balance[1] = 0;
            return(settleBalance);
        }
        balance[0] = balance[0] - subAmt;

        subAmt = peerState1.transferOut + peer1.withdrawal;
        if (balance[1] < subAmt)
        {
            settleBalance.isSettled = 0;
            balance[0] = 0;
            balance[1] = 0;
            return(settleBalance);
        }
        balance[1] = balance[1] - subAmt;

        settleBalance.isSettled = 1;
        return(settleBalance);
    }