Esempio n. 1
0
        public static TransactionViewModel Create(ITransaction ninjaTransaction, IReadOnlyDictionary <string, IAssetDefinition> assetDictionary, MixedTransactionType?offchainType = null)
        {
            if (ninjaTransaction == null)
            {
                return(null);
            }

            var bc       = ninjaTransaction.TransactionsByAssets.First(p => !p.IsColored);
            var colored  = ninjaTransaction.TransactionsByAssets.Where(p => p.IsColored).OrderBy(p => p.AssetId);
            var assetDic = AssetDictionary.Create(assetDictionary);

            var result = new TransactionViewModel
            {
                TransactionId = ninjaTransaction.TransactionId,
                IsCoinBase    = ninjaTransaction.IsCoinBase,
                IsColor       = ninjaTransaction.IsColor,
                Block         = BlockViewModel.Create(ninjaTransaction.Block),
                AssetsCount   = ninjaTransaction.TransactionsByAssets.Count(p => p.IsColored),
                IsConfirmed   = ninjaTransaction.Block != null,
                Bitcoin       = BitcoinAsset.Create(ninjaTransaction.Fees, ninjaTransaction.IsCoinBase, bc.TransactionIn.Union(colored.SelectMany(p => p.TransactionIn)), bc.TransactionsOut.Union(colored.SelectMany(p => p.TransactionsOut)), assetDic),
                ColoredAssets = colored.Select(p => ColoredAsset.Create(p, assetDic)),
                InputsCount   = ninjaTransaction.InputsCount,
                OutputsCount  = ninjaTransaction.OutputsCount,
                OffchainType  = offchainType
            };

            return(result);
        }
Esempio n. 2
0
        public static AssetDictionary RemoveInvalidOfficeDocs(this AssetDictionary unfiltered)
        {
            var filtered = unfiltered.IfNullEmpty()
                           .Where(asset => OfficeExtensions.Contains(new FileInfo(asset.Key).Extension,
                                                                     StringComparer.InvariantCultureIgnoreCase));

            return(new AssetDictionary().FluentAddRange(filtered));
        }
Esempio n. 3
0
        /// <summary>
        /// Ensures the merged documents appear in the order each was added.
        /// Gotenberg merges files in alphabetical order via the key/file name.
        /// https://thecodingmachine.github.io/gotenberg/#merge
        /// </summary>
        /// <param name="unordered"></param>
        /// <remarks>
        ///     Note: For merges only. Embedded assets for html docs have
        ///     key values with whatever extension the html references: .md, .css, .jpg, etc
        /// </remarks>
        public static AssetDictionary ToAlphabeticalOrderByIndex(this AssetDictionary unordered)
        {
            var ordered = unordered.IfNullEmpty().Select((item, index) =>
                                                         KeyValuePair.Create(index.ToAlphabeticallySortableFileName(new FileInfo(item.Key).Extension),
                                                                             item.Value));

            return(new AssetDictionary().FluentAddRange(ordered));
        }
Esempio n. 4
0
    public static IPromise InstanceAsync <T>() where T : AddressableSingletonAsset
    {
        if (AssetDictionary.TryGetValue(typeof(T), out var asset))
        {
            return(Promise.Resolved((T)asset));
        }

        return(AddressableExtensions.LoadAsync <T>(typeof(T).Name));
    }
Esempio n. 5
0
 public static IEnumerable <In> Create(IEnumerable <IInOut> ins, AssetDictionary assetDictionary)
 {
     return(ins.Where(p => p.Value != 0)
            .Select(p => new In(
                        value: BitcoinUtils.SatoshiToBtc(p.Value * (-1)),
                        coloredEquivalentAsset: assetDictionary.Get(p.AssetId),
                        coloredEquivalentQuantityQuantity: p.Quantity,
                        address: p.Address,
                        previousTransactionId: p.TransactionId)));
 }
Esempio n. 6
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);
            }
Esempio n. 7
0
        /// <summary>
        ///     LoadContent will be called once per game and is the place to load
        ///     all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            textures = new AssetDictionary <Texture2D>("Textures", Content);
            textures.TryAddAsset("Cell32");

            fonts = new AssetDictionary <SpriteFont>("Fonts", Content);
            fonts.TryAddAsset("CourierNew");

            // TODO: use this.Content to load your game content here

            InitialiseContentDependents();
            BuildStates();
        }
        public static AddressBalanceViewModel Create(IAddressBalance balance,
                                                     IReadOnlyDictionary <string, IAssetDefinition> assetDictionary,
                                                     IBlockHeader lastBlock,
                                                     IBlockHeader atBlock,
                                                     IEnumerable <IGroup> offchainGroups,
                                                     bool isHub)
        {
            var onchainColoredBalances =
                (balance.ColoredBalances ?? Enumerable.Empty <IColoredBalance>()).Select(p =>
                                                                                         ColoredBalance.Create(p, assetDictionary)).ToList();

            var existedOnchainAssetsBalances = onchainColoredBalances.Select(p => p.AssetId).ToDictionary(p => p);

            //show balances for offchain assets with 0 onchain balance
            var missedOffchainColoredBalances = offchainGroups.Where(p => p.IsColored && !existedOnchainAssetsBalances.ContainsKey(p.AssetId))
                                                .Select(p => p.AssetId)
                                                .Distinct()
                                                .Select(assetId => ColoredBalance.CreateEmpty(assetId, assetDictionary));

            return(new AddressBalanceViewModel
            {
                AddressId = balance.AddressId,
                TotalConfirmedTransactions = balance.TotalTransactions,
                Balance = balance.BtcBalance,
                Assets = onchainColoredBalances.Union(missedOffchainColoredBalances).ToList(),
                UnconfirmedBalanceDelta = balance.UnconfirmedBalanceDelta,
                AssetDic = AssetDictionary.Create(assetDictionary),
                LastBlockHeight = lastBlock.Height,
                LastBlockDateTime = lastBlock.Time,
                AtBlockHeight = (atBlock ?? lastBlock).Height,
                AtBlockDateTime = (atBlock ?? lastBlock).Time,
                OffchainGroupsByAsset = OffchainGroupsByAsset.Create(offchainGroups, assetDictionary),
                TotalTransactionsCountCalculated = balance.TotalTransactionsCountCalculated,
                TotalSpendedTransactions = balance.TotalSpendedTransactions,
                TotalSpendedTransactionsCountCalculated = balance.TotalSpendedTransactionsCountCalculated,
                TotalReceivedTransactions = balance.TotalReceivedTransactions,
                TotalReceivedTransactionsCountCalculated = balance.TotalReceivedTransactionsCountCalculated,
                IsOffchainHub = isHub
            });
        }
Esempio n. 9
0
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            textures = new AssetDictionary <Texture2D>("Textures", Content);
            textures.TryAddAsset("Obelisk");
            textures.TryAddAsset("House");
            textures.TryAddAsset("GrassTile");
            textures.TryAddAsset("GrassTopDown");
            textures.TryAddAsset("GridTile");

            fonts = new AssetDictionary <SpriteFont>("Fonts", Content);
            fonts.TryAddAsset("CourierNew");

            uiTextures = new AssetDictionary <Texture2D>("UI", Content);
            uiTextures.TryAddAsset("Button");

            InitialiseContentDependents();

            BuildStates();

            // StateManager.Initialise(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);
        }
Esempio n. 10
0
        public static Asset <TValue> Add <TValue>(Asset <TValue> value, bool replace = true)
        {
            Type type = value.GetType();

            try {
                if (LookupDictionary.ContainsKey(type))
                {
                    LookupDictionary[type].Add(value.ID, value, replace);
                }
                else
                {
                    AssetDictionary <TValue> assetDict = new AssetDictionary <TValue>();
                    assetDict.Add(value.ID, value, replace);
                    LookupDictionary.Add(type, assetDict);
                }
            } catch (ArgumentNullException e) {
                if (Screen.IsFullHeadless)
                {
                    throw new HeadlessNotSupportedException("Cannot add asset of type '" + type + "' while in fully headless display mode.", e);
                }
            }
            return(value);
        }
Esempio n. 11
0
        private async Task GetAllSymbols()
        {
            using (var client = new BinanceClient())
            {
                var result = await client.GetAllPricesAsync();

                if (result.Success)
                {
                    AllPrices = new ObservableCollection <BinanceSymbolViewModel>(result.Data.Select(r => new BinanceSymbolViewModel(r.Symbol, r.Price)).OrderBy(s => s.SymbolCurrency).ThenBy(s => s.SymbolAsset).ToList());

                    foreach (var price in AllPrices)
                    {
                        if (CurrencyDictionary.ContainsKey(price.SymbolCurrency))
                        {
                            if (!CurrencyDictionary[price.SymbolCurrency].Contains(price.SymbolAsset))
                            {
                                CurrencyDictionary[price.SymbolCurrency].Add(price.SymbolAsset);
                            }
                        }
                        else
                        {
                            CurrencyDictionary.Add(price.SymbolCurrency, new ObservableCollection <string> {
                                price.SymbolAsset
                            });
                        }

                        if (AssetDictionary.ContainsKey(price.SymbolAsset))
                        {
                            if (!AssetDictionary[price.SymbolAsset].Contains(price.SymbolCurrency))
                            {
                                AssetDictionary[price.SymbolAsset].Add(price.SymbolCurrency);
                            }
                        }
                        else
                        {
                            AssetDictionary.Add(price.SymbolAsset, new ObservableCollection <string> {
                                price.SymbolCurrency
                            });
                        }
                    }

                    var cdKeys = CurrencyDictionary.Keys.ToList();
                    var adKeys = AssetDictionary.Keys.ToList();
                    for (int k = 0; k < cdKeys.Count; k++)
                    {
                        CurrencyDictionary[cdKeys[k]] = new ObservableCollection <string>(CurrencyDictionary[cdKeys[k]].OrderBy(v => v));
                    }
                    for (int k = 0; k < adKeys.Count; k++)
                    {
                        AssetDictionary[adKeys[k]] = new ObservableCollection <string>(AssetDictionary[adKeys[k]].OrderBy(v => v));
                    }
                }
                else
                {
                    messageBoxService.ShowMessage($"Error getting all symbols data.\n{result.Error.Message}", $"Error Code: {result.Error.Code}", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }

            List <Task> tasks = new List <Task>();

            foreach (var symbol in AllPrices)
            {
                var task = new Task(() => binanceSocketClient.SubscribeToKlineStream(symbol.Symbol.ToLower(), KlineInterval.OneMinute, (data) =>
                {
                    symbol.Price = data.Data.Close;
                }));
                tasks.Add(task);
                task.Start();
            }
            Task.WaitAll(tasks.ToArray());
        }
Esempio n. 12
0
 public static IEnumerable <Out> Create(IEnumerable <IInOut> outs, AssetDictionary assetDictionary)
 {
     return(outs.Where(p => p.Value != 0).Select(p => Create(p, assetDictionary.Get(p.AssetId))));
 }
Esempio n. 13
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)
                });
            }