示例#1
0
        public BigInteger GetBalance(string bcname, string address)
        {
            if (client == null)
            {
                throw new NullReferenceException();
            }
            var reqData = new Pb.AddressStatus
            {
                Address = address,
            };
            var tokenDetail = new Pb.TokenDetail
            {
                Bcname = bcname,
            };

            reqData.Bcs.Add(tokenDetail);
            var res = client.GetBalance(reqData);

            if (res.Header.Error != Pb.XChainErrorEnum.Success)
            {
                throw new Exception(res.Header.Error.ToString())
                      {
                          HResult = (int)res.Header.Error,
                      };
            }
            var balanceStr = res.Bcs[0].Balance;
            var balance    = BigInteger.Parse(balanceStr);

            return(balance);
        }
示例#2
0
        // Get the balance of given address
        /// <summary>Get the balance of given address</summary>
        /// <param name="bcname">the name of the blockchain</param>
        /// <param name="address">the address to query</param>
        /// <returns>the balance of given address</returns>
        public BigInteger GetBalance(string bcname, string address)
        {
            if (client == null)
            {
                return(new BigInteger(0));
            }
            var reqData = new Pb.AddressStatus
            {
                Address = address,
            };
            var tokenDetail = new Pb.TokenDetail
            {
                Bcname = bcname,
            };

            reqData.Bcs.Add(tokenDetail);
            var res = client.GetBalance(reqData);

            if (res.Header.Error != Pb.XChainErrorEnum.Success)
            {
                return(new BigInteger(0));
            }
            var balanceStr = res.Bcs[0].Balance;
            var balance    = BigInteger.Parse(balanceStr);

            return(balance);
        }