Skip to content

Commit

Permalink
refactor: use statement instead of self-disposing on Delegatee
Browse files Browse the repository at this point in the history
  • Loading branch information
OnedgeLee committed Dec 3, 2024
1 parent a6856fa commit d72fe38
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions Lib9c/Delegation/Delegatee.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,13 @@ public virtual BigInteger Bond(T delegator, FungibleAssetValue fav, long height)
{
using var activity = ActivitySource.StartActivity("Bond");

var distributeRewardActivity = ActivitySource.StartActivity(
using (Activity? _ = ActivitySource.StartActivity(
"DistributeReward",
ActivityKind.Internal,
activity?.Id ?? string.Empty);
DistributeReward(delegator, height);
distributeRewardActivity?.Dispose();
activity?.Id ?? string.Empty))
{
DistributeReward(delegator, height);
}

if (!fav.Currency.Equals(DelegationCurrency))
{
Expand Down Expand Up @@ -240,12 +241,13 @@ public virtual BigInteger Bond(T delegator, FungibleAssetValue fav, long height)
Repository.SetBond(bond);
setBondActivity?.Dispose();

var startNewRewardPeriodActivity = ActivitySource.StartActivity(
using (Activity? _ = ActivitySource.StartActivity(
"StartNewRewardPeriod",
ActivityKind.Internal,
activity?.Id ?? string.Empty);
StartNewRewardPeriod(height);
startNewRewardPeriodActivity?.Dispose();
activity?.Id ?? string.Empty))
{
StartNewRewardPeriod(height);
}

var setDelegateeMetadataActivity = ActivitySource.StartActivity(
"SetDelegateeMetadata",
Expand All @@ -266,12 +268,13 @@ public FungibleAssetValue Unbond(T delegator, BigInteger share, long height)
{
using var activity = ActivitySource.StartActivity("Unbond");

var distributeRewardActivity = ActivitySource.StartActivity(
using (Activity? _ = ActivitySource.StartActivity(
"DistributeReward",
ActivityKind.Internal,
activity?.Id ?? string.Empty);
DistributeReward(delegator, height);
distributeRewardActivity?.Dispose();
activity?.Id ?? string.Empty))
{
DistributeReward(delegator, height);
}

if (TotalShares.IsZero || TotalDelegated.RawValue.IsZero)
{
Expand Down Expand Up @@ -324,12 +327,13 @@ public FungibleAssetValue Unbond(T delegator, BigInteger share, long height)
Repository.SetBond(bond);
setBondActivity?.Dispose();

var startNewRewardPeriodActivity = ActivitySource.StartActivity(
using (Activity? _ = ActivitySource.StartActivity(
"StartNewRewardPeriod",
ActivityKind.Internal,
activity?.Id ?? string.Empty);
StartNewRewardPeriod(height);
startNewRewardPeriodActivity?.Dispose();
activity?.Id ?? string.Empty))
{
StartNewRewardPeriod(height);
}

var setDelegateeMetadataActivity = ActivitySource.StartActivity(
"SetDelegateeMetadata",
Expand Down

0 comments on commit d72fe38

Please sign in to comment.