using System.Collections.Generic;
using System.Linq;
using NBitcoin;

namespace Stratis.Bitcoin.Features.Consensus.CoinViews
{
    public class DeStreamCoinviewHelper : CoinviewHelper
    {
        /// <inheritdoc />
        public override uint256[] GetIdsToFetch(Block block, bool enforceBIP30)
        {
            var ids = new HashSet<uint256>();
            foreach (Transaction tx in block.Transactions)
            {
                if (enforceBIP30)
                {
                    uint256 txId = tx.GetHash();
                    ids.Add(txId);
                }

                if (tx.IsCoinBase) continue;
                foreach (TxIn input in tx.Inputs.RemoveChangePointer())
                {
                    ids.Add(input.PrevOut.Hash);
                }
            }

            uint256[] res = ids.ToArray();
            return res;
        }
    }
}