Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Qiao Jin committed Nov 18, 2020
1 parent 9b0391d commit f2d4cdc
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions neo/Network/P2P/Payloads/Transaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,26 +82,24 @@ public virtual Fixed8 NetworkFee
}

private IReadOnlyDictionary<CoinReference, TransactionOutput> _references;
private bool hasCalculatedReferences = false;
public IReadOnlyDictionary<CoinReference, TransactionOutput> References
{
get
{
if (!hasCalculatedReferences && _references == null)
if (_references == null)
{
hasCalculatedReferences = true;
Dictionary<CoinReference, TransactionOutput> dictionary = new Dictionary<CoinReference, TransactionOutput>();
foreach (var group in Inputs.GroupBy(p => p.PrevHash))
{
Transaction tx = Blockchain.Singleton.Store.GetTransaction(group.Key);
if (tx == null) return null;
foreach (var reference in group)
foreach (var reference in group.Select(p => new
{
if (reference.PrevIndex >= Outputs.Length)
{
return null;
}
dictionary.Add(reference, tx.Outputs[reference.PrevIndex]);
Input = p,
Output = tx.Outputs[p.PrevIndex]
}))
{
dictionary.Add(reference.Input, reference.Output);
}
}
_references = dictionary;
Expand Down

0 comments on commit f2d4cdc

Please sign in to comment.