Commit b2b99c47 authored by Sergei Zubov's avatar Sergei Zubov

Fix total input in fee calculation

parent 2ae2f379
...@@ -14,7 +14,7 @@ namespace Stratis.Bitcoin.Features.Consensus ...@@ -14,7 +14,7 @@ namespace Stratis.Bitcoin.Features.Consensus
/// <summary> /// <summary>
/// Sum of inputs spent in transaction /// Sum of inputs spent in transaction
/// </summary> /// </summary>
Money TotalIn { get; set; } IDictionary<uint256, Money> TotalIn { get; set; }
} }
/// <inheritdoc cref="PosRuleContext" /> /// <inheritdoc cref="PosRuleContext" />
...@@ -34,7 +34,7 @@ namespace Stratis.Bitcoin.Features.Consensus ...@@ -34,7 +34,7 @@ namespace Stratis.Bitcoin.Features.Consensus
/// <inheritdoc /> /// <inheritdoc />
public Money TotalIn { get; set; } public IDictionary<uint256, Money> TotalIn { get; set; } = new Dictionary<uint256, Money>();
} }
/// <inheritdoc cref="PowRuleContext" /> /// <inheritdoc cref="PowRuleContext" />
...@@ -53,6 +53,6 @@ namespace Stratis.Bitcoin.Features.Consensus ...@@ -53,6 +53,6 @@ namespace Stratis.Bitcoin.Features.Consensus
public List<Script> InputScriptPubKeys { get; set; } public List<Script> InputScriptPubKeys { get; set; }
/// <inheritdoc /> /// <inheritdoc />
public Money TotalIn { get; set; } public IDictionary<uint256, Money> TotalIn { get; set; } = new Dictionary<uint256, Money>();
} }
} }
\ No newline at end of file
...@@ -53,10 +53,10 @@ namespace Stratis.Bitcoin.Features.Consensus.Rules.CommonRules ...@@ -53,10 +53,10 @@ namespace Stratis.Bitcoin.Features.Consensus.Rules.CommonRules
return outputsToFeeWallet.Single().Value; return outputsToFeeWallet.Single().Value;
} }
private long GetExpectedFee(Block block, Money totalIn, ICollection<Script> inputScriptPubKeys) private long GetExpectedFee(Block block, IDictionary<uint256, Money> totalIn, ICollection<Script> inputScriptPubKeys)
{ {
return block.Transactions.Where(p => !p.IsCoinBase && !p.IsCoinStake).Sum(p => this.GetFeeInTransaction(p, return block.Transactions.Where(p => !p.IsCoinBase && !p.IsCoinStake).Sum(p => this.GetFeeInTransaction(p,
totalIn, p.Outputs totalIn[p.GetHash()], p.Outputs
.Select(q => q.ScriptPubKey).Intersect(inputScriptPubKeys) .Select(q => q.ScriptPubKey).Intersect(inputScriptPubKeys)
.Concat(p.Inputs.GetChangePointers() .Concat(p.Inputs.GetChangePointers()
.Select(q => p.Outputs[q].ScriptPubKey)) .Select(q => p.Outputs[q].ScriptPubKey))
......
...@@ -234,12 +234,12 @@ namespace Stratis.Bitcoin.Features.Consensus.Rules.CommonRules ...@@ -234,12 +234,12 @@ namespace Stratis.Bitcoin.Features.Consensus.Rules.CommonRules
case DeStreamPowRuleContext deStreamPowRuleContext: case DeStreamPowRuleContext deStreamPowRuleContext:
deStreamPowRuleContext.InputScriptPubKeys.AddRange(transaction.Inputs.RemoveChangePointer() deStreamPowRuleContext.InputScriptPubKeys.AddRange(transaction.Inputs.RemoveChangePointer()
.Select(p => view.GetOutputFor(p).ScriptPubKey)); .Select(p => view.GetOutputFor(p).ScriptPubKey));
deStreamPowRuleContext.TotalIn = view.GetValueIn(transaction); deStreamPowRuleContext.TotalIn.Add(transaction.GetHash(), view.GetValueIn(transaction));
break; break;
case DeStreamRuleContext deStreamPosRuleContext: case DeStreamRuleContext deStreamPosRuleContext:
deStreamPosRuleContext.InputScriptPubKeys.AddRange(transaction.Inputs.RemoveChangePointer() deStreamPosRuleContext.InputScriptPubKeys.AddRange(transaction.Inputs.RemoveChangePointer()
.Select(p => view.GetOutputFor(p).ScriptPubKey)); .Select(p => view.GetOutputFor(p).ScriptPubKey));
deStreamPosRuleContext.TotalIn = view.GetValueIn(transaction); deStreamPosRuleContext.TotalIn.Add(transaction.GetHash(), view.GetValueIn(transaction));
break; break;
default: default:
throw new NotSupportedException( throw new NotSupportedException(
......
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