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
/// <summary>
/// Sum of inputs spent in transaction
/// </summary>
Money TotalIn { get; set; }
IDictionary<uint256, Money> TotalIn { get; set; }
}
/// <inheritdoc cref="PosRuleContext" />
......@@ -34,7 +34,7 @@ namespace Stratis.Bitcoin.Features.Consensus
/// <inheritdoc />
public Money TotalIn { get; set; }
public IDictionary<uint256, Money> TotalIn { get; set; } = new Dictionary<uint256, Money>();
}
/// <inheritdoc cref="PowRuleContext" />
......@@ -53,6 +53,6 @@ namespace Stratis.Bitcoin.Features.Consensus
public List<Script> InputScriptPubKeys { get; set; }
/// <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
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,
totalIn, p.Outputs
totalIn[p.GetHash()], p.Outputs
.Select(q => q.ScriptPubKey).Intersect(inputScriptPubKeys)
.Concat(p.Inputs.GetChangePointers()
.Select(q => p.Outputs[q].ScriptPubKey))
......
......@@ -234,12 +234,12 @@ namespace Stratis.Bitcoin.Features.Consensus.Rules.CommonRules
case DeStreamPowRuleContext deStreamPowRuleContext:
deStreamPowRuleContext.InputScriptPubKeys.AddRange(transaction.Inputs.RemoveChangePointer()
.Select(p => view.GetOutputFor(p).ScriptPubKey));
deStreamPowRuleContext.TotalIn = view.GetValueIn(transaction);
deStreamPowRuleContext.TotalIn.Add(transaction.GetHash(), view.GetValueIn(transaction));
break;
case DeStreamRuleContext deStreamPosRuleContext:
deStreamPosRuleContext.InputScriptPubKeys.AddRange(transaction.Inputs.RemoveChangePointer()
.Select(p => view.GetOutputFor(p).ScriptPubKey));
deStreamPosRuleContext.TotalIn = view.GetValueIn(transaction);
deStreamPosRuleContext.TotalIn.Add(transaction.GetHash(), view.GetValueIn(transaction));
break;
default:
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