コード例 #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
ファイル: NEP5.cs プロジェクト: gubanotorious/neo-lux
        // 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");
        }