Commit 0370b7af authored by Sergei Zubov's avatar Sergei Zubov

Add DeStreamCoinviewHelper

parent a8d20c51
......@@ -12,7 +12,7 @@ namespace Stratis.Bitcoin.Features.Consensus.CoinViews
/// <param name="block">The block with the transactions.</param>
/// <param name="enforceBIP30">Whether to enforce look up of the transaction id itself and not only the reference to previous transaction id.</param>
/// <returns>A list of transaction ids to fetch from store</returns>
public uint256[] GetIdsToFetch(Block block, bool enforceBIP30)
public virtual uint256[] GetIdsToFetch(Block block, bool enforceBIP30)
{
var ids = new HashSet<uint256>();
foreach (Transaction tx in block.Transactions)
......
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;
}
}
}
\ No newline at end of file
......@@ -10,7 +10,7 @@ namespace Stratis.Bitcoin.Features.Consensus.Rules.CommonRules
/// <summary>
/// A rule verifies that total amount of coins in blockchain is not changed
/// </summary>
public class DeStreamFundsPreservationRule : UtxoStoreConsensusRule
public class DeStreamFundsPreservationRule : DeStreamUtxoStoreConsensusRule
{
public override Task RunAsync(RuleContext context)
{
......
......@@ -11,7 +11,7 @@ using Stratis.Bitcoin.Utilities;
namespace Stratis.Bitcoin.Features.Consensus.Rules.CommonRules
{
public class DeStreamLoadCoinviewRule : LoadCoinviewRule
public class DeStreamLoadCoinviewRule : DeStreamUtxoStoreConsensusRule
{
public override async Task RunAsync(RuleContext context)
{
......
using Stratis.Bitcoin.Features.Consensus.CoinViews;
using Stratis.Bitcoin.Utilities;
namespace Stratis.Bitcoin.Features.Consensus.Rules
{
public abstract class DeStreamUtxoStoreConsensusRule : UtxoStoreConsensusRule
{
/// <inheritdoc />
public override void Initialize()
{
this.PowParent = this.Parent as PowConsensusRuleEngine;
Guard.NotNull(this.PowParent, nameof(this.PowParent));
this.coinviewHelper = new DeStreamCoinviewHelper();
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment