public static LedgerStruct.BalanceMap getBalanceMapInner(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.BalanceMap  balanceMap = new LedgerStruct.BalanceMap();
     balanceMap.peerAddrs      = new byte[2][];
     balanceMap.deposits       = new BigInteger[2];
     balanceMap.withdrawals    = new BigInteger[2];
     balanceMap.peerAddrs[0]   = peer0.peerAddr;
     balanceMap.peerAddrs[1]   = peer1.peerAddr;
     balanceMap.deposits[0]    = peer0.deposit;
     balanceMap.deposits[1]    = peer1.deposit;
     balanceMap.withdrawals[0] = peer0.withdrawal;
     balanceMap.withdrawals[1] = peer1.withdrawal;
     return(balanceMap);
 }
        public static bool confirmWithdraw(byte[] _channelId)
        {
            BasicMethods.assert(BasicMethods._isByte32(_channelId), "_channelId illegal");

            LedgerStruct.Channel        c = LedgerStruct.getChannelMap(_channelId);
            LedgerStruct.WithdrawIntent withdrawIntent = c.withdrawIntent;
            byte[]     receiver = BasicMethods.clone(withdrawIntent.receiver);
            BigInteger amount   = withdrawIntent.amount;

            byte[] recipientChannelId = BasicMethods.clone(withdrawIntent.recipientChannelId);
            withdrawIntent.receiver           = null;
            withdrawIntent.amount             = 0;
            withdrawIntent.requestTime        = 0;
            withdrawIntent.recipientChannelId = null;
            c.withdrawIntent = withdrawIntent;
            c = LedgerChannel._addWithdrawal(c, receiver, amount);
            LedgerStruct.setChannelMap(_channelId, c);
            LedgerStruct.BalanceMap balanceMap = LedgerChannel.getBalanceMapInner(c);
            ConfirmWithdrawEvent(_channelId, amount, receiver, recipientChannelId, balanceMap.deposits, balanceMap.withdrawals);

            return(true);
        }
        public static bool deposit(byte[] _channelId, byte[] _receiver, BigInteger _transferFromAmount)
        {
            BasicMethods.assert(BasicMethods._isByte32(_channelId), "_channelId illegal");
            BasicMethods.assert(BasicMethods._isLegalAddress(_receiver), "_receiver illegal");
            BasicMethods.assert(_transferFromAmount >= 0, "_transferFromAmount illegal");

            LedgerStruct.Channel c = LedgerStruct.getChannelMap(_channelId);
            byte rid = LedgerChannel._getPeerId(c, _receiver);

            BasicMethods.assert(rid == 0 || rid == 1, "rid illegal");
            PbEntity.TokenInfo token  = c.token;
            BigInteger         value  = LedgerStruct.getTransactionValue(token.tokenType, getCelerWallet());
            BigInteger         amount = _transferFromAmount + value;

            LedgerStruct.PeerProfile[] peerProfiles = c.peerProfiles;
            LedgerStruct.PeerProfile   peerProfile  = peerProfiles[rid];
            peerProfile.deposit = peerProfile.deposit + amount;
            peerProfiles[rid]   = peerProfile;
            c.peerProfiles      = peerProfiles;
            LedgerStruct.BalanceMap balanceMap = LedgerChannel.getBalanceMapInner(c);
            LedgerStruct.setChannelMap(_channelId, c);
            DepositEvent(_channelId, balanceMap.peerAddrs, balanceMap.deposits, balanceMap.withdrawals);
            return(true);
        }