public async Task <ActionResult> Index(string id)
        {
            var result = await _assetService.GetAssetAsync(id);

            if (result != null)
            {
                return(View(AssetViewModel.Create(result)));
            }

            return(View("NotFound"));
        }
            public static ColoredBalance CreateEmpty(string assetId, IReadOnlyDictionary <string, IAssetDefinition> assetDictionary)
            {
                var asset = assetDictionary.GetValueOrDefault(assetId, null);

                var assetViewModel = asset != null
                    ? AssetViewModel.Create(asset)
                    : AssetViewModel.CreateNotFoundAsset(assetId);

                return(new ColoredBalance
                {
                    AssetId = assetId,
                    Quantity = 0,
                    UnconfirmedQuantityDelta = 0,
                    Asset = assetViewModel,
                });
            }
        protected OffchainGroupViewModel(IGroup group, IReadOnlyDictionary <string, IAssetDefinition> assetDictionary)
        {
            AssetViewModel asset;

            if (group.IsColored)
            {
                asset = assetDictionary.ContainsKey(group.AssetId) ?
                        AssetViewModel.Create(assetDictionary[group.AssetId]) :
                        AssetViewModel.CreateNotFoundAsset(group.AssetId);
            }
            else
            {
                asset = AssetViewModel.BtcAsset.Value;
            }

            var offchainTransactions = group.Transactions.Where(p => p.OffchainTransactionData != null).Select(p => OffchainTransactionViewModel.Create(p.OffchainTransactionData));

            this.OffChainTransactions = offchainTransactions;
            this.Asset = asset;
        }
        private async Task <AssetCoinholdersViewModel> GetOwnersAsync(string id, int?at)
        {
            var asset = await _assetService.GetAssetAsync(id);

            if (asset != null)
            {
                var summaryTask        = _balanceChangesRepository.GetSummaryAsync(at, asset.AssetIds.ToArray());
                var addressChangesTask = _balanceChangesRepository.GetBlocksWithChanges(asset.AssetIds);
                var lastBlockTask      = _blockService.GetLastBlockHeaderAsync();
                Task <IDictionary <string, double> > addressChangesAtBlockTask;
                Task <IBlockHeader> atBlockInfoTask;
                if (at != null)
                {
                    atBlockInfoTask           = _blockService.GetBlockHeaderAsync(at.ToString());
                    addressChangesAtBlockTask = _balanceChangesRepository.GetAddressQuantityChangesAtBlock(at.Value, asset.AssetIds.ToArray());
                }
                else
                {
                    atBlockInfoTask           = Task.FromResult((IBlockHeader)null);
                    addressChangesAtBlockTask = Task.FromResult((IDictionary <string, double>) new Dictionary <string, double>());
                }

                await Task.WhenAll(addressChangesAtBlockTask, summaryTask, addressChangesTask, lastBlockTask, atBlockInfoTask);

                var result = AssetCoinholdersViewModel.Create(
                    AssetViewModel.Create(asset),
                    summaryTask.Result,
                    at,
                    addressChangesAtBlockTask.Result,
                    addressChangesTask.Result,
                    lastBlockTask.Result,
                    atBlockInfoTask.Result
                    );

                return(result);
            }

            return(null);
        }
        public static OffChainTransactionViewModel Create(IOffchainTransaction tx,
                                                          IReadOnlyDictionary <string, IAssetDefinition> assetDictionary)
        {
            if (tx == null)
            {
                return(null);
            }


            AssetViewModel asset;

            if (tx.IsColored)
            {
                asset = assetDictionary.ContainsKey(tx.AssetId) ?
                        AssetViewModel.Create(assetDictionary[tx.AssetId]) :
                        AssetViewModel.CreateNotFoundAsset(tx.AssetId);
            }
            else
            {
                asset = AssetViewModel.BtcAsset.Value;
            }



            return(OffChainTransactionViewModel.Create(
                       transactionId: tx.TransactionId,
                       address1: tx.Address1,
                       asset: asset,
                       dateTime: tx.DateTime,
                       hubAddress: tx.HubAddress,
                       address2: tx.Address2,
                       address1Quantity: tx.Address1Quantity,
                       address1QuantityDiff: tx.Address1QuantityDiff,
                       address2Quantity: tx.Address2Quantity,
                       address2QuantityDiff: tx.Address2QuantityDiff,
                       type: tx.Type));
        }