protected override BqlCommand GetCommand(TInstance leaveInstance, ICollection <TInstance> deletingInstances, bool forDeleting)
        {
            if (DeleteReferences ^ forDeleting)
            {
                return(null);
            }

            BqlCommand command = new Select <TRefItem>();

            command = command.WhereNew(In <TRefField> .Create(deletingInstances.Count));
            return(command);
        }
示例#2
0
            public static ColoredAsset Create(IInOutsByAsset inOutsByAsset, AssetDictionary assetDictionary)
            {
                var divisibility   = assetDictionary.GetAssetProp(inOutsByAsset.AssetId, p => p.Divisibility, 0);
                var assetShortName = assetDictionary.GetAssetProp(inOutsByAsset.AssetId, p => p.NameShort, null);

                var ins  = inOutsByAsset.TransactionIn.Select(p => In.Create(p, divisibility, inOutsByAsset.TransactionsOut, assetShortName)).ToList();
                var outs = inOutsByAsset.TransactionsOut.Select(p => Out.Create(p, divisibility, assetShortName)).ToList();

                var insWithoutChange  = ins.Select(p => p.Clone <In>()).ToList();
                var outsWithoutChange = outs.Select(p => p.Clone <Out>()).ToList();
                var showChange        = false;

                AssetHelper.CalculateWithReturnedChange(ins, outs, ref showChange);

                if (ins.All(p => p.Value == 0) && outs.All(p => p.Value == 0))
                {
                    ins  = ins.Take(1).ToList();
                    outs = outs.Take(1).ToList();
                }
                else
                {
                    ins  = ins.Where(p => p.Value != 0).ToList();
                    outs = outs.Where(p => p.Value != 0).ToList();
                }

                var issuedQuantity    = (-1) * outs.Sum(p => p.Value);
                var destroyedQuantity = (-1) * ins.Sum(p => p.Value);

                var result = new ColoredAsset
                {
                    AssetId      = inOutsByAsset.AssetId,
                    Divisibility = divisibility,
                    Name         = assetDictionary.GetAssetProp(inOutsByAsset.AssetId, p => p.Name, inOutsByAsset.AssetId),
                    IconImageUrl = assetDictionary.GetAssetProp(inOutsByAsset.AssetId, p => p.IconUrl, null),

                    AggregatedIns  = AssetHelper.GroupByAddress(ins),
                    AggregatedOuts = AssetHelper.GroupByAddress(outs),

                    AggregatedInsWithoutChange  = AssetHelper.GroupByAddress(insWithoutChange),
                    AggregatedOutsWithoutChange = AssetHelper.GroupByAddress(outsWithoutChange),

                    ShowWithoutChange = showChange,

                    IssedQuantity     = issuedQuantity,
                    DestroyedQuantity = destroyedQuantity,

                    ShortName = assetDictionary.GetAssetProp(inOutsByAsset.AssetId, p => p.NameShort, null),
                    IsKnown   = assetDictionary.Dic.ContainsKey(inOutsByAsset.AssetId)
                };

                return(result);
            }
示例#3
0
            public static BitcoinAsset Create(double fees,
                                              bool isCoinBase,
                                              IEnumerable <IInOut> ninjaIn,
                                              IEnumerable <IInOut> ninjaOuts,
                                              AssetDictionary assetDictionary)
            {
                var feesBtc = BitcoinUtils.SatoshiToBtc(fees);

                IEnumerable <AssetInOutBase> ins  = In.Create(ninjaIn, assetDictionary).ToList();
                IEnumerable <AssetInOutBase> outs = Out.Create(ninjaOuts, assetDictionary).ToList();

                IEnumerable <AssetInOutBase> insWithoutChange  = ins.Select(p => p.Clone <In>()).ToList();
                IEnumerable <AssetInOutBase> outsWithoutChange = outs.Select(p => p.Clone <Out>()).ToList();

                decimal coloredEquityIns = 0;

                ins = AssetHelper.RemoveColored(ins, out coloredEquityIns).ToList();

                decimal coloredEquityOuts = 0;

                outs = AssetHelper.RemoveColored(outs, out coloredEquityOuts).ToList();


                bool showChange = false;

                AssetHelper.CalculateWithReturnedChange(ins, outs, ref showChange);

                if (ins.All(p => p.Value == 0) && outs.All(p => p.Value == 0))
                {
                    ins  = ins.Take(1).ToList();
                    outs = outs.Take(1).ToList();
                }
                else
                {
                    ins  = ins.Where(p => p.Value != 0).ToList();
                    outs = outs.Where(p => p.Value != 0).ToList();
                }

                var coloredEquivalentValue = coloredEquityOuts + coloredEquityIns;
                var total = outs.Sum(p => Convert.ToDecimal(p.Value)) + Convert.ToDecimal(feesBtc);

                if (coloredEquivalentValue > 0)
                {
                    total += Convert.ToDecimal(coloredEquivalentValue);
                }

                var totalWithoutChange = outsWithoutChange.Sum(p => Convert.ToDecimal(p.Value)) + Convert.ToDecimal(feesBtc);

                return(new BitcoinAsset
                {
                    Fees = feesBtc,
                    IsCoinBase = isCoinBase,
                    AggregatedIns = AssetHelper.GroupByAddress(ins),
                    AggregatedOuts = AssetHelper.GroupByAddress(outs),
                    AggregatedInsWithoutChange = AssetHelper.GroupByAddress(insWithoutChange),
                    AggregatedOutsWithoutChange = AssetHelper.GroupByAddress(outsWithoutChange),
                    Total = Convert.ToDouble(total),
                    TotalWithoutChange = Convert.ToDouble(totalWithoutChange),
                    ShowWithoutChange = showChange || coloredEquityOuts != 0 || coloredEquityIns != 0,
                    ColoredEquivalentValue = Convert.ToDouble(coloredEquivalentValue)
                });
            }