Example #1
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);
            }
Example #2
0
        private void InitializeLogSystem()
        {
            string curr = DirHandler.Instance.CurrentDirectory;

            string logConfigFile = Path.Combine(curr, Ids.CONFIG_DIR, Ids.LOG_CONFIG_FILE);

            if (string.IsNullOrEmpty(logConfigFile) || !File.Exists(logConfigFile))
            {
                // Unable to find log configuration file. So let's fall back upon default targets - Console and Log.
                Trace.WriteLine("Unable to locate the log configuration file - using default settings.");

                LogInitializationData log = new LogInitializationData     {
                    Active = true, TraceLevel = LogLevel.VERYHIGH, Filename = Path.Combine(curr, Ids.LOG_FILE)
                };
                ConsoleInitializationData console = new ConsoleInitializationData {
                    Active = true, TraceLevel = LogLevel.VERYHIGH, Filter = { DebugEnabled = false }
                };

                Out.Create(log);
                Out.Create(console);
            }
            else
            {
                // Log configuration file found, so log system will be based upon the settings defined in config file.
                try
                {
                    Out.LoadApplicationConfigFile(new FileInfo(logConfigFile));
                }
                catch (BaseException e)
                {
                    Trace.WriteLine("Failed to load log configuration file, {0}", logConfigFile);
                    Trace.WriteLine("Error description: \n{0}", e.ExceptionSummary());
                    return;
                }

                try
                {
                    // Start monitoring the log configuration file - changes are identified on file save occurrence.
                    Out.StartApplicationConfigMonitor(logConfigFile, Out.LASTWRITE);
                }
                catch (BaseException e)
                {
                    Trace.WriteLine("Failed to start the file monitor for monitoring the log configuration file, {0}. Continuing without monitoring the log configuration file.", logConfigFile);
                    Trace.WriteLine("Error description: \n{0}", e.ExceptionSummary());
                }
            }
        }
Example #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)
                });
            }