-
Notifications
You must be signed in to change notification settings - Fork 837
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove recursion when colorizing Transaction
- Loading branch information
1 parent
d0cab1a
commit a8d0490
Showing
4 changed files
with
140 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace NBitcoin | ||
{ | ||
public class CachedTransactionRepository : ITransactionRepository | ||
{ | ||
ITransactionRepository _Inner; | ||
Dictionary<uint256, Transaction> _Transactions = new Dictionary<uint256, Transaction>(); | ||
public CachedTransactionRepository(ITransactionRepository inner) | ||
{ | ||
if(inner == null) | ||
throw new ArgumentNullException("inner"); | ||
_Inner = inner; | ||
} | ||
#region ITransactionRepository Members | ||
|
||
public Transaction Get(uint256 txId) | ||
{ | ||
Transaction result = null; | ||
if(!_Transactions.TryGetValue(txId, out result)) | ||
{ | ||
result = _Inner.Get(txId); | ||
_Transactions.Add(txId, result); | ||
} | ||
return result; | ||
} | ||
|
||
public void Put(uint256 txId, Transaction tx) | ||
{ | ||
if(!_Transactions.ContainsKey(txId)) | ||
_Transactions.Add(txId, tx); | ||
else | ||
_Transactions[txId] = tx; | ||
_Inner.Put(txId, tx); | ||
} | ||
|
||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace NBitcoin.OpenAsset | ||
{ | ||
public class CachedColoredTransactionRepository : IColoredTransactionRepository | ||
{ | ||
IColoredTransactionRepository _Inner; | ||
ITransactionRepository _InnerTransactionRepository; | ||
Dictionary<uint256, ColoredTransaction> _ColoredTransactions = new Dictionary<uint256, ColoredTransaction>(); | ||
public CachedColoredTransactionRepository(IColoredTransactionRepository inner) | ||
{ | ||
if(inner == null) | ||
throw new ArgumentNullException("inner"); | ||
_Inner = inner; | ||
_InnerTransactionRepository = new CachedTransactionRepository(inner.Transactions); | ||
} | ||
#region IColoredTransactionRepository Members | ||
|
||
public ITransactionRepository Transactions | ||
{ | ||
get | ||
{ | ||
return _InnerTransactionRepository; | ||
} | ||
} | ||
|
||
public ColoredTransaction Get(uint256 txId) | ||
{ | ||
ColoredTransaction result = null; | ||
if(!_ColoredTransactions.TryGetValue(txId, out result)) | ||
{ | ||
result = _Inner.Get(txId); | ||
_ColoredTransactions.Add(txId, result); | ||
} | ||
return result; | ||
} | ||
|
||
public void Put(uint256 txId, ColoredTransaction tx) | ||
{ | ||
if(!_ColoredTransactions.ContainsKey(txId)) | ||
_ColoredTransactions.Add(txId, tx); | ||
else | ||
_ColoredTransactions[txId] = tx; | ||
_Inner.Put(txId, tx); | ||
} | ||
|
||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters