Пример #1
0
        public async Task <string> GetAllAssets()
        {
            List <AssetBalance> list = new List <AssetBalance>();

            var assets = await client.Asset.ListAssetsAsync();

            foreach (var item in assets.Result)
            {
                AssetBalance balance = new AssetBalance();
                balance.AssetRef = item.AssetRef;
                balance.Name     = item.Name;
                balance.TxID     = item.GenesisTxId;
                balance.Details  = item.Details;

                client.Asset.Subscribe(item.Name, false);
                var transactions = await client.Asset.ListAssetTransactions(item.AssetRef, true);

                foreach (var transaction in transactions.Result)
                {
                    AssetTransaction at = new AssetTransaction();
                    at.Time      = transaction.Time;
                    at.Date      = BlockChainHelper.UnixTimeStampToDateTime(transaction.Time).ToString();
                    at.TxID      = transaction.TxId;
                    at.BlockHash = transaction.BlockHash;
                    if (transaction.Addresses.Count == 1)
                    {
                        KeyValuePair <string, decimal> address = transaction.Addresses.First();

                        at.AddressFrom = "";
                        at.AddressTo   = address.Key;
                        at.Qty         = address.Value;
                    }
                    else
                    {
                        IOrderedEnumerable <KeyValuePair <string, decimal> > oList = transaction.Addresses.OrderBy(e => e.Value);

                        KeyValuePair <string, decimal> addressFrom = oList.First();
                        KeyValuePair <string, decimal> addressTo   = oList.ElementAtOrDefault(1);

                        at.AddressFrom = addressFrom.Key;
                        at.AddressTo   = addressTo.Key;
                        at.Qty         = addressTo.Value;
                    }
                    balance.Transactions.Add(at);
                }

                list.Add(balance);
            }

            return(JsonConvert.SerializeObject(list, Formatting.Indented));
        }
        public List <TransactionDetail> Get(RawTransactionResponse model)
        {
            List <TransactionDetail> list      = new List <TransactionDetail>();
            TransactionDetail        td        = new TransactionDetail();
            List <string>            addresses = new List <string>();
            bool isExchange = false;

            foreach (var item in model.Vout)
            {
                td.BlockTime     = BlockChainHelper.UnixTimeStampToDateTime(model.Time);
                td.TxId          = model.TxId;
                td.Confirmations = model.Confirmations + " Confirmations";
                if (item.Assets != null)
                {
                    if (item.Assets.Count == 1)
                    {
                        isExchange = true;
                        AssetBalanceResponse asset = item.Assets.First();
                        // if asset transfer
                        if (asset.Type == "transfer")
                        {
                            td.EventType = "success fa fa-2x fa-arrow-right";
                        }
                        else // if issue of asset
                        {
                            td.EventType      = "fa fa-arrow-right";
                            td.EventTypeLabel = "Asset Issued";
                            td.Action         = item.Assets.First().Name;
                        }
                        if (item.ScriptPubKey.Addresses.Count > 0)
                        {
                            td.To = item.ScriptPubKey.Addresses.First();
                        }
                    }
                    else
                    {
                        if (item.ScriptPubKey.Addresses.Count > 0)
                        {
                            if (isExchange)
                            {
                                if (string.IsNullOrEmpty(td.From))
                                {
                                    td.From = item.ScriptPubKey.Addresses.First();
                                }
                            }
                            else
                            {
                                addresses.Add(item.ScriptPubKey.Addresses.First());
                            }
                        }

                        // if stream
                        if (item.Items.Count > 0)
                        {
                            td.From = item.Items.First().Publishers.First();

                            td.Action = item.Items.First().Key;
                            td.To     = item.Items.First().StreamRef;

                            if (!string.IsNullOrEmpty(item.Items.First().DataAsAscii))
                            {
                                if (BlockChainHelper.IsJsonObject(item.Items.First().DataAsAscii))
                                {
                                    StreamData data = JsonConvert.DeserializeObject <StreamData>(item.Items.First().DataAsAscii);
                                    if (data != null)
                                    {
                                        td.To        = data.Address;
                                        td.HashTo    = data.Hash;
                                        td.EventType = "fa fa-arrow-right";
                                    }
                                }
                            }

                            ResolveStreamKey(td);
                        }

                        // if permission change
                        if (item.Permissions.Count > 0)
                        {
                            td.From   = ExplorerSettings.Connection.RootNodeAddress;
                            td.To     = item.ScriptPubKey.Addresses.First();
                            td.Action = "Permissions Changed";
                        }
                    }
                }
                if (addresses.Count == 1)
                {
                    td.To = addresses.First();
                }
                else if (addresses.Count > 1)
                {
                    td.To   = addresses.First();
                    td.From = addresses.Last();
                }

                // is miner
                if (string.IsNullOrEmpty(td.From) && string.IsNullOrEmpty(td.To))
                {
                    td.Confirmations = model.Confirmations + " Confirmations";
                    Blocks blocks = new Blocks();
                    td.From           = blocks.GetMiner(model.BlockHash) + "<br/>";
                    td.EventTypeLabel = "Coinbase Miner Transaction";
                }

                if (string.IsNullOrEmpty(td.To))
                {
                    td.To   = td.From;
                    td.From = ExplorerSettings.Connection.RootNodeAddress;
                }
            }

            if (string.IsNullOrEmpty(td.Action))
            {
                // to be implemented
            }

            td.To   = ResolveAddress(td.To, td);
            td.From = ResolveAddress(td.From, td);

            if (CanAdd(td))
            {
                list.Add(td);
            }
            return(list);
        }