コード例 #1
0
    public static BigInteger getTransactionValue(byte tokenType, byte[] receiver)
    {
        PbEntity.TokenType token = PbEntity.getStandardTokenType();
        Transaction        tx    = ExecutionEngine.ScriptContainer as Transaction;

        TransactionOutput[] outputs = tx.GetOutputs();
        BigInteger          result  = 0;

        foreach (TransactionOutput output in outputs)
        {
            byte[] scriptHash = output.ScriptHash;
            if (!scriptHash.Equals(receiver))
            {
                continue;
            }
            byte[] assetid = output.AssetId;
            //Temperately only support NEO and GAS
            byte type = token.INVALID;
            if (assetid.Equals(NeoID))
            {
                type = token.NEO;
            }
            else if (assetid.Equals(GasID))
            {
                type = token.GAS;
            }
            if (tokenType != type)
            {
                continue;
            }
            result += output.Value;
        }
        return(result);
    }
コード例 #2
0
        public static object depositNEO(byte[] walletId)
        {
            BasicMethods.assert(BasicMethods._isByte32(walletId), "walletId is not byte32");
            PbEntity.TokenType token = PbEntity.getStandardTokenType();
            BigInteger         value = LedgerStruct.getTransactionValue(token.NEO, ExecutionEngine.ExecutingScriptHash);

            BasicMethods.assert(value >= 0, "amount is less than zero");
            _whenNotPaused();
            BasicMethods.assert(_updateBalance(walletId, LedgerStruct.NeoAddress, value, getStandardMathOperation().add), "updateBalance failed");

            DepositToWallet(walletId, LedgerStruct.NeoAddress, value);
            return(true);
        }