public ActionResult <ResponseApiModel> GetBalance(RequestKeyApiModel model)
        {
            BalanceResponseApiModel res;

            try
            {
                res         = ServiceProvider.GetService <MonitorService>().GetBalance(model);
                res.Success = true;
            }
            catch (Exception ex)
            {
                res         = new BalanceResponseApiModel();
                res.Success = false;
                res.Message = ex.Message;
            }

            return(Ok(res));
        }
Ejemplo n.º 2
0
        public BalanceResponseApiModel GetBalance(RequestKeyApiModel model)
        {
            var response = new BalanceResponseApiModel();

            using (var client = GetClientByModel(model))
            {
                var publicKeyByte = SimpleBase.Base58.Bitcoin.Decode(model.PublicKey);

                var     balanceCS = client.WalletBalanceGet(publicKeyByte.ToArray());
                var     amount    = BCTransactionTools.GetDecimalByAmount(balanceCS.Balance);
                decimal delOut    = 0;
                decimal delIn     = 0;
                if (balanceCS.Delegated != null)
                {
                    if (balanceCS.Delegated.Outgoing != null)
                    {
                        delOut = BCTransactionTools.GetDecimalByAmount(balanceCS.Delegated.Outgoing);
                    }
                    if (balanceCS.Delegated.Outgoing != null)
                    {
                        delIn = BCTransactionTools.GetDecimalByAmount(balanceCS.Delegated.Incoming);
                    }
                }

                response.Balance      = amount;
                response.DelegatedOut = delOut;
                response.DelegatedIn  = delIn;

                if (balanceCS.Status.Code > 0)
                {
                    throw new Exception(balanceCS.Status.Message);
                }

                var balanceToken = client.TokenBalancesGet(publicKeyByte.ToArray());
                if (balanceToken.Status.Code > 0)
                {
                    throw new Exception(balanceToken.Status.Message);
                }

                foreach (var item in balanceToken.Balances)
                {
                    if (String.IsNullOrEmpty(item.Balance))
                    {
                        continue;
                    }

                    var item1 = new Token();
                    item1.Alias     = item.Code;
                    item1.Amount    = Decimal.Parse(item.Balance, CultureInfo.InvariantCulture);
                    item1.PublicKey = SimpleBase.Base58.Bitcoin.Encode(item.Token);
                    item1.Name      = item.Name;

                    response.Tokens.Add(
                        item1
                        );
                }
            }

            response.Success = true;
            return(response);
        }