Commit 1887f997 authored by Sergei Zubov's avatar Sergei Zubov

Merge funds preservation rule

parent 12dd1aa9
...@@ -116,6 +116,7 @@ namespace Stratis.Bitcoin.Features.Consensus ...@@ -116,6 +116,7 @@ namespace Stratis.Bitcoin.Features.Consensus
// rules that require the store to be loaded (coinview) // rules that require the store to be loaded (coinview)
new DeStreamLoadCoinviewRule(), new DeStreamLoadCoinviewRule(),
new DeStreamFundsPreservationRule(),
new TransactionDuplicationActivationRule(), // implements BIP30 new TransactionDuplicationActivationRule(), // implements BIP30
new DeStreamPowCoinviewRule(), // implements BIP68, MaxSigOps and BlockReward calculation new DeStreamPowCoinviewRule(), // implements BIP68, MaxSigOps and BlockReward calculation
new SaveCoinviewRule(), new SaveCoinviewRule(),
...@@ -174,6 +175,7 @@ namespace Stratis.Bitcoin.Features.Consensus ...@@ -174,6 +175,7 @@ namespace Stratis.Bitcoin.Features.Consensus
// rules that require the store to be loaded (coinview) // rules that require the store to be loaded (coinview)
new DeStreamLoadCoinviewRule(), new DeStreamLoadCoinviewRule(),
new DeStreamFundsPreservationRule(),
new TransactionDuplicationActivationRule(), // implements BIP30 new TransactionDuplicationActivationRule(), // implements BIP30
new DeStreamPosCoinviewRule(), // implements BIP68, MaxSigOps and BlockReward calculation new DeStreamPosCoinviewRule(), // implements BIP68, MaxSigOps and BlockReward calculation
// Place the PosColdStakingRule after the PosCoinviewRule to ensure that all input scripts have been evaluated // Place the PosColdStakingRule after the PosCoinviewRule to ensure that all input scripts have been evaluated
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using NBitcoin; using NBitcoin;
using Stratis.Bitcoin.Consensus;
using Stratis.Bitcoin.Consensus.Rules; using Stratis.Bitcoin.Consensus.Rules;
namespace Stratis.Bitcoin.Features.Consensus.Rules.CommonRules namespace Stratis.Bitcoin.Features.Consensus.Rules.CommonRules
...@@ -9,7 +10,6 @@ namespace Stratis.Bitcoin.Features.Consensus.Rules.CommonRules ...@@ -9,7 +10,6 @@ namespace Stratis.Bitcoin.Features.Consensus.Rules.CommonRules
/// <summary> /// <summary>
/// A rule verifies that total amount of coins in blockchain is not changed /// A rule verifies that total amount of coins in blockchain is not changed
/// </summary> /// </summary>
[ExecutionRule]
public class DeStreamFundsPreservationRule : UtxoStoreConsensusRule public class DeStreamFundsPreservationRule : UtxoStoreConsensusRule
{ {
public override Task RunAsync(RuleContext context) public override Task RunAsync(RuleContext context)
...@@ -17,12 +17,12 @@ namespace Stratis.Bitcoin.Features.Consensus.Rules.CommonRules ...@@ -17,12 +17,12 @@ namespace Stratis.Bitcoin.Features.Consensus.Rules.CommonRules
UnspentOutputSet inputs = UnspentOutputSet inputs =
(context as UtxoRuleContext ?? (context as UtxoRuleContext ??
throw new NotSupportedException($"Rule context must be {nameof(UtxoRuleContext)}")).UnspentOutputSet; throw new NotSupportedException($"Rule context must be {nameof(UtxoRuleContext)}")).UnspentOutputSet;
long totalIn = context.ValidationContext.Block.Transactions.SelectMany(p => long totalIn = context.ValidationContext.BlockToValidate.Transactions.SelectMany(p =>
p.Inputs.RemoveChangePointer().Where(q => q.PrevOut != null) p.Inputs.RemoveChangePointer().Where(q => q.PrevOut != null)
.Select(q => inputs.AccessCoins(q.PrevOut.Hash)?.TryGetOutput(q.PrevOut.N)?.Value ?? 0)) .Select(q => inputs.AccessCoins(q.PrevOut.Hash)?.TryGetOutput(q.PrevOut.N)?.Value ?? 0))
.Sum(p => p ?? 0); .Sum(p => p ?? 0);
long totalOut = context.ValidationContext.Block.Transactions.SelectMany(p => p.Outputs.Select(q => q.Value)) long totalOut = context.ValidationContext.BlockToValidate.Transactions.SelectMany(p => p.Outputs.Select(q => q.Value))
.Sum(p => p); .Sum(p => p);
if (totalIn != totalOut) if (totalIn != totalOut)
......
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