Skip to content

Commit f3a9030

Browse files
committed
Optimize the reading of Transaction ID upon serialization
- The Transaction ID on events won't be calculated multiple times in cases where the same instance is serialized twice. - Related to #269
1 parent 119776c commit f3a9030

3 files changed

Lines changed: 27 additions & 3 deletions

File tree

src/Blockcore/Connection/Broadcasting/BroadcastTransactionStateChanedEntry.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,18 @@ public class BroadcastTransactionStateChanedEntry
1010
[JsonIgnore] // The "Transaction" cannot serialize for Web Socket.
1111
public Transaction Transaction { get; }
1212

13+
private string transactionId;
14+
1315
/// <summary>
1416
/// Makes the transaction ID available for Web Socket consumers.
1517
/// </summary>
16-
public string TransactionId { get { return this.Transaction.ToString(); } }
18+
public string TransactionId
19+
{
20+
get
21+
{
22+
return this.transactionId ??= this.Transaction.ToString();
23+
}
24+
}
1725

1826
[JsonConverter(typeof(StringEnumConverter))]
1927
public TransactionBroadcastState TransactionBroadcastState { get; set; }

src/Blockcore/EventBus/CoreEvents/TransactionReceived.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,18 @@ public class TransactionReceived : EventBase
1414
[JsonIgnore] // The "Transaction" cannot serialize for Web Socket.
1515
public Transaction ReceivedTransaction { get; }
1616

17+
private string transactionId;
18+
1719
/// <summary>
1820
/// Makes the transaction ID available for Web Socket consumers.
1921
/// </summary>
20-
public string TransactionId { get { return this.ReceivedTransaction.ToString(); } }
22+
public string TransactionId
23+
{
24+
get
25+
{
26+
return this.transactionId ??= this.ReceivedTransaction.ToString();
27+
}
28+
}
2129

2230
public TransactionReceived(Transaction receivedTransaction)
2331
{

src/Features/Blockcore.Features.Wallet/Events/TransactionFound.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,18 @@ public class TransactionFound : EventBase
1717
[JsonIgnore] // The "Transaction" cannot serialize for Web Socket.
1818
public Transaction FoundTransaction { get; }
1919

20+
private string transactionId;
21+
2022
/// <summary>
2123
/// Makes the transaction ID available for Web Socket consumers.
2224
/// </summary>
23-
public string TransactionId { get { return this.FoundTransaction.ToString(); } }
25+
public string TransactionId
26+
{
27+
get
28+
{
29+
return this.transactionId ??= this.FoundTransaction.ToString();
30+
}
31+
}
2432

2533
public TransactionFound(Transaction foundTransaction)
2634
{

0 commit comments

Comments
 (0)