private static bool _withdrawToken(byte[] _tokenAddress, byte[] _receiver, BigInteger _amount)
        {
            NEP5Contract dyncall = (NEP5Contract)_tokenAddress.ToDelegate();

            Object[] args = new object[] { ExecutionEngine.ExecutingScriptHash, _receiver, _amount };
            bool     res  = (bool)dyncall("transfer", args);

            return(res);
        }
예제 #2
0
        private static bool _withdrawToken(byte[] _tokenAddress, byte[] _receiver, BigInteger _amount)
        {
            if (_tokenAddress.Equals(LedgerStruct.NeoAddress) || _tokenAddress.Equals(LedgerStruct.GasAddress))
            {
                return(true);
            }
            byte[]       thisContract = ExecutionEngine.ExecutingScriptHash;
            NEP5Contract dyncall      = (NEP5Contract)_tokenAddress.ToDelegate();
            bool         res          = (bool)dyncall("transfer", new object[] { thisContract, _receiver, _amount });

            return(res);
        }
예제 #3
0
        public static TransferInfo GetTxInfo(byte[] assetid, byte[] txid)
        {
            var tInfo = new TransferInfo();

            object[] _p = new object[1] {
                txid
            };
            NEP5Contract call = (NEP5Contract)assetid.ToDelegate();
            var          info = call("getTxInfo", _p);

            if (((object[])info).Length == 3)
            {
                return(info as TransferInfo);
            }

            return(tInfo);
        }
예제 #4
0
        public static object depositNEP5(byte[] invoker, byte[] walletId, byte[] tokenAddress, BigInteger amount)
        {
            BasicMethods.assert(Runtime.CheckWitness(invoker), "CheckWitness failed");
            BasicMethods.assert(BasicMethods._isByte32(walletId), "walletId is not byte32");
            BasicMethods.assert(BasicMethods._isLegalAddress(tokenAddress), "tokenAddress is not byte20");
            BasicMethods.assert(amount >= 0, "amount is less than zero");

            _whenNotPaused();

            BasicMethods.assert(_updateBalance(walletId, tokenAddress, amount, getStandardMathOperation().add), "updateBalance failed");
            byte[]       thisContract = ExecutionEngine.ExecutingScriptHash;
            NEP5Contract dyncall      = (NEP5Contract)tokenAddress.ToDelegate();
            bool         res          = (bool)dyncall("transfer", new object[] { invoker, thisContract, amount });

            BasicMethods.assert(res, "transfer NEP5 tokens failed");

            DepositToWallet(walletId, tokenAddress, amount);
            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 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);
    }