示例#1
0
文件: NEP5.cs 项目: uvmetal/neo-lux
 public decimal BalanceOf(byte[] addressHash)
 {
     try
     {
         var response = api.TestInvokeScript(contractHash, "balanceOf", new object[] { addressHash });
         var balance  = new BigInteger((byte[])response.result);
         return(ConvertToDecimal(balance));
     }
     catch
     {
         throw new NeoException("Api did not return a value.");
     }
 }
示例#2
0
        // FIXME - I'm almost sure that this code won't return non-integer balances correctly...
        public decimal BalanceOf(byte[] addressHash)
        {
            var response = api.TestInvokeScript(contractHash, "balanceOf", new object[] { addressHash });
            var balance  = new BigInteger((byte[])response.result);
            var decs     = this.Decimals;

            while (decs > 0)
            {
                balance /= 10;
                decs--;
            }
            return((decimal)balance);
        }
示例#3
0
        // FIXME - I'm almost sure that this code won't return non-integer balances correctly...
        public static decimal GetTokenBalance(string address, string symbol)
        {
            var info = GetTokenInfo();

            if (info.ContainsKey(symbol))
            {
                var token    = info[symbol];
                var response = NeoAPI.TestInvokeScript(NeoAPI.Net.Main, token.scriptHash, "balanceOf", new object[] { address.GetScriptHashFromAddress() });
                var balance  = new BigInteger((byte[])response.result);
                var decimals = token.decimals;
                while (decimals > 0)
                {
                    balance /= 10;
                    decimals--;
                }
                return((decimal)balance);
            }

            throw new NeoException("Invalid token symbol");
        }