private bool CanAdd(TransactionDetail td)
        {
            bool ret = true;

            if (string.IsNullOrEmpty(td.Action) && string.IsNullOrEmpty(td.From) && string.IsNullOrEmpty(td.To) && string.IsNullOrEmpty(td.Action) && string.IsNullOrEmpty(td.EventType))
            {
                ret = false;
            }
            return(ret);
        }
 private void ResolveStreamKey(TransactionDetail td)
 {
     if (!string.IsNullOrEmpty(td.Action))
     {
         string from     = td.From;
         string to       = td.To;
         string hashfrom = td.HashFrom;
         string hashto   = td.HashTo;
     }
 }
        private string ResolveAddress(string address, TransactionDetail td)
        {
            string origAddress = address;

            if (!string.IsNullOrEmpty(address))
            {
                if (!address.Contains("<br"))
                {
                    address = $"<a href ='/BlockChain/Explorer/Address/{address}'>{address}</a>";
                }
            }
            return(address);
        }
        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);
        }