Exemplo n.º 1
0
        public static BalanceSummaryDetails operator -(BalanceSummaryDetails c1)
        {
            if (c1 == null)
            {
                return(null);
            }
            BalanceSummaryDetails result = new BalanceSummaryDetails
            {
                Amount           = -c1.Amount,
                Received         = -c1.Received,
                TransactionCount = -c1.TransactionCount,
                Assets           = Minus(c1.Assets)
            };

            return(result);
        }
Exemplo n.º 2
0
        internal static BalanceSummaryDetails CreateFrom(List <OrderedBalanceChange> changes, Network network, bool colored)
        {
            var details = new BalanceSummaryDetails
            {
                Amount           = CalculateAmount(changes, c => c is Coin),
                TransactionCount = changes.Count,
                Received         = changes.Select(_ => _.Amount < Money.Zero ? Money.Zero : _.Amount).Sum(),
            };

            if (colored)
            {
                Dictionary <AssetId, AssetBalanceSummaryDetails> coloredDetails = new Dictionary <AssetId, AssetBalanceSummaryDetails>();
                foreach (var change in changes)
                {
                    foreach (var coin in change.ReceivedCoins.OfType <ColoredCoin>())
                    {
                        AssetBalanceSummaryDetails coloredDetail = null;
                        if (!coloredDetails.TryGetValue(coin.AssetId, out coloredDetail))
                        {
                            coloredDetail       = new AssetBalanceSummaryDetails();
                            coloredDetail.Asset = coin.AssetId.GetWif(network);
                            coloredDetails.Add(coin.AssetId, coloredDetail);
                        }
                        coloredDetail.Quantity += (long)coin.Asset.Quantity;
                        coloredDetail.Received += (long)coin.Asset.Quantity;
                    }
                    foreach (var coin in change.SpentCoins.OfType <ColoredCoin>())
                    {
                        AssetBalanceSummaryDetails coloredDetail = null;
                        if (!coloredDetails.TryGetValue(coin.AssetId, out coloredDetail))
                        {
                            coloredDetail       = new AssetBalanceSummaryDetails();
                            coloredDetail.Asset = coin.AssetId.GetWif(network);
                            coloredDetails.Add(coin.AssetId, coloredDetail);
                        }
                        coloredDetail.Quantity -= (long)coin.Asset.Quantity;
                    }
                }
                details.Assets = coloredDetails.Values.ToArray();
            }
            return(details);
        }
Exemplo n.º 3
0
 public BalanceSummary()
 {
     Confirmed = new BalanceSummaryDetails();
 }