internal ListTransactionsModel GetTransactionsModel(TransactionVerboseModel transactionInfo)
 {
     var transactionResult = new ListTransactionsModel
     {
         Confirmations = transactionInfo.Confirmations ?? 0,
         BlockHash = transactionInfo.BlockHash ?? string.Empty,
         BlockTime = transactionInfo.BlockTime ?? 0,
         TransactionId = transactionInfo.TxId,
         TransactionTime = (long)(transactionInfo.Time ?? 0),
         Amount = transactionInfo.VOut.Sum(a => a.Value)
     };
     return transactionResult;
 }
        /**
         * Collects all related outputs for a given transaction.
         * 1. For "send" transactions, find a later transaction that spent an output.
         * 2. For "receive" transactions, just render the output.
         */
        private IEnumerable <ListTransactionsModel> GetListTransactionModels(
            TransactionOutputData transactionOutputData, bool isWatchOnly)
        {
            var transaction   = this.blockStore.GetTransactionById(transactionOutputData.Id);
            var chainedHeader = GetTransactionBlockHeader(transactionOutputData.Id);

            if (transaction == null)
            {
                return(new List <ListTransactionsModel>());
            }

            var  listTransactionModels = new List <ListTransactionsModel>();
            uint blockTime             = Utils.DateTimeToUnixTime(chainedHeader.Header.BlockTime);

            // Add all "receives" to the wallet.
            var listTransactionModel = new ListTransactionsModel()
            {
                InvolvesWatchOnly = isWatchOnly,
                Amount            = transactionOutputData.Amount.ToDecimal(MoneyUnit.BTC),
                Address           = transactionOutputData.Address,
                Category          = ListSinceBlockTransactionCategoryModel.Receive,
                TransactionId     = transaction.GetHash().ToString(),
                BlockHeight       = chainedHeader.Height,
                BlockHash         = chainedHeader.HashBlock.ToString(),
                BlockTime         = blockTime,
                TransactionTime   = blockTime,
                Confirmations     = this.chainIndexer.Tip.Height - chainedHeader.Height + 1
            };

            if (transaction.IsCoinBase)
            {
                // COIN_MATURITY = 100 as part of bitcoin consensus.
                listTransactionModel.Category = listTransactionModel.Confirmations < 100 ?
                                                ListSinceBlockTransactionCategoryModel.Immature :
                                                ListSinceBlockTransactionCategoryModel.Generate;
            }

            listTransactionModels.Add(listTransactionModel);

            var spendingDetails = transactionOutputData.SpendingDetails;

            if (spendingDetails?.BlockHeight == null)
            {
                return(listTransactionModels);
            }
            var spendChainHeader = GetTransactionBlockHeader(spendingDetails.TransactionId);

            var spentTransactionOutput = new ListTransactionsModel()
            {
                InvolvesWatchOnly = isWatchOnly,
                Amount            = -transactionOutputData.Amount.ToDecimal(MoneyUnit.BTC),
                Address           = transactionOutputData.Address,
                Category          = ListSinceBlockTransactionCategoryModel.Send,
                TransactionId     = spendingDetails.TransactionId.ToString(),
                BlockHeight       = spendingDetails.BlockHeight ?? -1,
                BlockHash         = spendingDetails.IsSpentConfirmed() ? spendChainHeader.HashBlock.ToString() : "",
                BlockTime         = spendChainHeader.Header.Time,
                Confirmations     = this.chainIndexer.Tip.Height - spendChainHeader.Height + 1,
                TimeReceived      = Utils.DateTimeToUnixTime(spendingDetails.CreationTime)
            };

            listTransactionModels.Add(spentTransactionOutput);

            return(listTransactionModels);
        }