public static bool depositInBatch(byte[][] _senders, byte[][] _channelIds, byte[][] _receivers, BigInteger[] _transferFromAmounts)
        {
            BasicMethods.assert(
                _channelIds.Length == _receivers.Length && _receivers.Length == _transferFromAmounts.Length && _transferFromAmounts.Length == _senders.Length,
                "Lengths do not match"
                );
            bool balanceLimited = LedgerBalanceLimit.getBalanceLimitsEnabledInner();

            for (int i = 0; i < _channelIds.Length; i++)
            {
                LedgerOperation.depositInner(_senders[i], getLedger(), _channelIds[i], _receivers[i], _transferFromAmounts[i], balanceLimited);
            }
            return(true);
        }
    public static byte[] migrateChannelToInner(byte[] sender, LedgerStruct.Ledger _self, byte[][] pubKeys, byte[] _migrationRequest)
    {
        BasicMethods.assert(BasicMethods._isLegalAddress(sender), "sender illegal");
        PbChain.ChannelMigrationRequest migrationRequest =
            (PbChain.ChannelMigrationRequest)Neo.SmartContract.Framework.Helper.Deserialize(_migrationRequest);
        PbEntity.ChannelMigrationInfo migrationInfo =
            (PbEntity.ChannelMigrationInfo)Neo.SmartContract.Framework.Helper.Deserialize(migrationRequest.channelMigrationInfo);
        byte[] channelId = migrationInfo.channelId;
        BasicMethods.assert(BasicMethods._isByte32(channelId), "channelId illegal");
        LedgerStruct.Channel c = LedgerStruct.getChannelMap(channelId);
        byte[] toLedgerAddr    = migrationInfo.toLedgerAddress;

        LedgerStruct.ChannelStatus channelStatus = LedgerStruct.getStandardChannelStatus();
        BasicMethods.assert(
            c.status == channelStatus.Operable ||
            c.status == channelStatus.Settling, "status illegal"
            );
        byte[] h = Hash256(migrationRequest.channelMigrationInfo);
        // use Channel Library instead

        BasicMethods.assert(LedgerChannel._checkCoSignatures(c, h, pubKeys, migrationRequest.sigs), "Check co-sigs failed");
        BasicMethods.assert(migrationInfo.fromLedgerAddress.Equals(ExecutionEngine.ExecutingScriptHash), "From ledger address is not this");
        BasicMethods.assert(toLedgerAddr.Equals(sender), "To ledger address is not msg.sender");
        BasicMethods.assert(Blockchain.GetHeight() <= migrationInfo.migrationDeadline, "Passed migration deadline");

        c            = LedgerOperation._updateChannelStatus(c, channelStatus.Migrated);
        c.migratedTo = toLedgerAddr;
        LedgerStruct.setChannelMap(channelId, c);
        MigrateChannelToEvent(channelId, toLedgerAddr);

        byte[] celerWallet = _self.celerWallet;

        NEP5Contract dyncall = (NEP5Contract)celerWallet.ToDelegate();

        Object[] args = new object[] { channelId, toLedgerAddr };
        dyncall("transferOperatorship", args);

        return(channelId);
    }
        public static bool openChannelMockSet(byte[] _channelId, BigInteger _disputeTimeout, byte[] _tokenAddress, byte _tokenType, byte[][] _peerAddrs, BigInteger[] _deposits)
        {
            BasicMethods.assert(BasicMethods._isByte32(_channelId), "_channelId illegal");
            BasicMethods.assert(BasicMethods._isLegalAddress(_tokenAddress), "_channelId illegal");
            BasicMethods.assert(_tokenType >= 0 && _tokenType <= 3, "_tokenType illegal");
            BasicMethods.assert(_peerAddrs.Length == 2, "_peerAddrs length illegal");
            BasicMethods.assert(BasicMethods._isLegalAddress(_peerAddrs[0]), "_peerAddrs 0 illegal");
            BasicMethods.assert(BasicMethods._isLegalAddress(_peerAddrs[1]), "_peerAddrs 1 illegal");
            BasicMethods.assert(_deposits.Length == 2, "_deposits length illegal");
            BasicMethods.assert(_deposits[0] >= 0, "_deposits 0 illegal");
            BasicMethods.assert(_deposits[1] >= 0, "_deposits 1 illegal");

            setTmpChannelId(_channelId);

            LedgerStruct.Channel c = LedgerStruct.getChannelMap(_channelId);
            c.disputeTimeout = _disputeTimeout;
            LedgerStruct.ChannelStatus channelStatus = LedgerStruct.getStandardChannelStatus();
            c = LedgerOperation._updateChannelStatus(c, channelStatus.Operable);
            PbEntity.TokenInfo token = new PbEntity.TokenInfo()
            {
                address   = _tokenAddress,
                tokenType = _tokenType
            };
            c.token = token;

            LedgerStruct.PeerProfile[] peerProfiles = c.peerProfiles;
            LedgerStruct.PeerProfile   peerProfile0 = peerProfiles[0];
            LedgerStruct.PeerProfile   peerProfile1 = peerProfiles[1];
            peerProfile0.peerAddr = _peerAddrs[0];
            peerProfile0.deposit  = _deposits[0];
            peerProfile1.peerAddr = _peerAddrs[1];
            peerProfile1.deposit  = _deposits[1];
            peerProfiles[0]       = peerProfile0;
            peerProfiles[1]       = peerProfile1;
            c.peerProfiles        = peerProfiles;
            LedgerStruct.setChannelMap(_channelId, c);
            return(true);
        }
    public static bool migrateChannelFromInner(LedgerStruct.Ledger _self, byte[] _fromLedgerAddr, byte[] _migrationRequest, byte[][] pubKeys)
    {
        BasicMethods.assert(BasicMethods._isLegalAddress(_fromLedgerAddr), "_fromLedgerAddr illegal");

        // TODO: latest version of openzeppelin Address.sol provide this api toPayable()
        byte[] fromLedgerAddrPayable = _fromLedgerAddr;

        NEP5Contract dyncall = (NEP5Contract)fromLedgerAddrPayable.ToDelegate();

        Object[] args      = new object[] { _migrationRequest, pubKeys };
        byte[]   channelId = (byte[])dyncall("migrateChannelTo", args);

        LedgerStruct.Channel       c             = LedgerStruct.getChannelMap(channelId);
        LedgerStruct.ChannelStatus channelStatus = LedgerStruct.getStandardChannelStatus();
        BasicMethods.assert(c.status == channelStatus.Uninitialized, "Immigrated channel already exists");

        byte[] celerWallet = _self.celerWallet;
        args    = new object[] { channelId };
        dyncall = (NEP5Contract)celerWallet.ToDelegate();
        byte[] oper = (byte[])dyncall("getOperator", args);
        BasicMethods.assert(
            oper.Equals(ExecutionEngine.ExecutingScriptHash),
            "Operatorship not transferred"
            );

        c = LedgerOperation._updateChannelStatus(c, channelStatus.Operable);
        // Do not migrate WithdrawIntent, in other words, migration will implicitly veto
        // pending WithdrawIntent if any.
        c = LedgerChannel._importChannelMigrationArgs(c, fromLedgerAddrPayable, channelId);
        c = LedgerChannel._importPeersMigrationInfo(c, fromLedgerAddrPayable, channelId);
        LedgerStruct.setChannelMap(channelId, c);

        MigrateChannelFromEvent(channelId, _fromLedgerAddr);

        return(true);
    }
 public static byte[] getCelerWallet()
 {
     return(LedgerOperation.getCelerWalletInner(getLedger()));
 }
 public static byte[] getPayRegistry()
 {
     return(LedgerOperation.getPayRegistryInner(getLedger()));
 }
 public static BigInteger getChannelStatusNum(BigInteger _channelStatus)
 {
     return(LedgerOperation.getChannelStatusNumInner(_channelStatus));
 }
 public static bool cooperativeSettle(byte[] _settleRequest, byte[][] pubKeys)
 {
     LedgerOperation.cooperativeSettleInner(getLedger(), pubKeys, _settleRequest);
     return(true);
 }
 public static bool confirmSettle(byte[] _channelId)
 {
     LedgerOperation.confirmSettleInner(getLedger(), _channelId);
     return(true);
 }
 public static bool deposit(byte[] _sender, byte[] _channelId, byte[] _receiver, BigInteger _transferFromAmount)
 {
     LedgerStruct.Ledger ledger = getLedger();
     LedgerOperation.depositInner(_sender, ledger, _channelId, _receiver, _transferFromAmount, LedgerBalanceLimit.getBalanceLimitsEnabledInner());
     return(true);
 }
 public static bool intendSettle(byte[] _signedSimplexStateArray, byte[] _sender, byte[][] pubKeys)
 {
     LedgerOperation.intendSettleInner(_sender, getLedger(), pubKeys, _signedSimplexStateArray);
     return(true);
 }
 public static bool cooperativeWithdraw(byte[] _cooperativeWithdrawRequest, byte[][] pubKeys)
 {
     LedgerOperation.cooperativeWithdrawInner(getLedger(), pubKeys, _cooperativeWithdrawRequest, LedgerBalanceLimit.getBalanceLimitsEnabledInner());
     return(true);
 }
 public static bool vetoWithdraw(byte[] _channelId, byte[] _sender)
 {
     LedgerOperation.vetoWithdrawInner(_sender, getLedger(), _channelId);
     return(true);
 }
 public static bool confirmWithdraw(byte[] _channelId)
 {
     LedgerOperation.confirmWithdrawInner(getLedger(), _channelId, LedgerBalanceLimit.getBalanceLimitsEnabledInner());
     return(true);
 }
 public static bool intendWithdraw(byte[] _channelId, BigInteger _amount, byte[] _recipientChannelId, byte[] _sender)
 {
     LedgerOperation.intendWithdrawInner(_sender, getLedger(), _channelId, _amount, _recipientChannelId);
     return(true);
 }
 public static bool snapshotStates(byte[] _signedSimplexStateArray, byte[][] pubKeys)
 {
     LedgerOperation.snapshotStatesInner(getLedger(), pubKeys, _signedSimplexStateArray);
     return(true);
 }
 public static bool clearPays(byte[] _channelId, byte[] _peerFrom, byte[] _payIdList)
 {
     LedgerOperation.clearPaysInner(getLedger(), _channelId, _peerFrom, _payIdList);
     return(true);
 }
 public static bool openChannel(byte[] _openRequest, byte[][] pubKeys)
 {
     LedgerStruct.Ledger ledger = getLedger();
     LedgerOperation.openChannelInner(ledger, pubKeys, _openRequest, LedgerBalanceLimit.getBalanceLimitsEnabledInner());
     return(true);
 }