Skip to content

Commit

Permalink
chore: add ActivityTrace for CurrencyAcount
Browse files Browse the repository at this point in the history
  • Loading branch information
limebell committed Aug 8, 2024
1 parent 6db26e1 commit 40eaf98
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/Libplanet.Action/State/CurrencyAccount.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.Numerics;
using Bencodex.Types;
using Libplanet.Crypto;
Expand All @@ -20,12 +21,14 @@ public sealed class CurrencyAccount
/// </summary>
public static readonly Address TotalSupplyAddress =
new Address("1000000000000000000000000000000000000000");
private readonly ActivitySource _activitySource;

Check warning on line 24 in src/Libplanet.Action/State/CurrencyAccount.cs

View workflow job for this annotation

GitHub Actions / docs

Elements should be separated by blank line

Check warning on line 24 in src/Libplanet.Action/State/CurrencyAccount.cs

View workflow job for this annotation

GitHub Actions / docs

Elements should be separated by blank line

Check warning on line 24 in src/Libplanet.Action/State/CurrencyAccount.cs

View workflow job for this annotation

GitHub Actions / check-build

Elements should be separated by blank line

Check warning on line 24 in src/Libplanet.Action/State/CurrencyAccount.cs

View workflow job for this annotation

GitHub Actions / check-build

Elements should be separated by blank line

Check warning on line 24 in src/Libplanet.Action/State/CurrencyAccount.cs

View workflow job for this annotation

GitHub Actions / check-build

Elements should be separated by blank line

public CurrencyAccount(ITrie trie, int worldVersion, Currency currency)
{
Trie = trie;
WorldVersion = worldVersion;
Currency = currency;
_activitySource = new ActivitySource("Libplanet.Action.State");
}

public ITrie Trie { get; }
Expand All @@ -36,6 +39,9 @@ public CurrencyAccount(ITrie trie, int worldVersion, Currency currency)

public FungibleAssetValue GetBalance(Address address, Currency currency)
{
using Activity? a = _activitySource
.StartActivity(ActivityKind.Internal)?
.AddTag("Address", address.ToString());
CheckCurrency(currency);
#pragma warning disable SA1118 // The parameter spans multiple lines
return FungibleAssetValue.FromRawValue(
Expand All @@ -48,6 +54,9 @@ public FungibleAssetValue GetBalance(Address address, Currency currency)

public FungibleAssetValue GetTotalSupply(Currency currency)
{
using Activity? a = _activitySource
.StartActivity(ActivityKind.Internal)?
.AddTag("Currency", currency.ToString());
CheckCurrency(currency);
#pragma warning disable SA1118 // The parameter spans multiple lines
return FungibleAssetValue.FromRawValue(
Expand Down Expand Up @@ -97,6 +106,11 @@ public CurrencyAccount TransferAsset(
Address recipient,
FungibleAssetValue value)
{
using Activity? a = _activitySource
.StartActivity(ActivityKind.Internal)?
.AddTag("Sender", sender.ToString())
.AddTag("Recipient", recipient.ToString())
.AddTag("Value", value.ToString());
CheckCurrency(value.Currency);
if (value.Sign <= 0)
{
Expand All @@ -118,6 +132,11 @@ public CurrencyAccount TransferAssetV0(
Address recipient,
FungibleAssetValue value)
{
using Activity? a = _activitySource
.StartActivity(ActivityKind.Internal)?
.AddTag("Sender", sender.ToString())
.AddTag("Recipient", recipient.ToString())
.AddTag("Value", value.ToString());
CheckCurrency(value.Currency);
if (value.Sign <= 0)
{
Expand Down

0 comments on commit 40eaf98

Please sign in to comment.