diff --git a/CHANGES.md b/CHANGES.md index f8f2897af60..87dd2bf84c6 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -33,6 +33,10 @@ be compatible with this version, specifically, those that ran with null or both should not be null at the same time. [[#3529]] - (Libplanet.Action) Removed `IAccountDelta` interface. [[#3535]] - (Libplanet.Action) Removed `IAccount.Delta` interface property. [[#3535]] + - (Libplanet.Action) Changed constructor `IAccount(IAccountState, + IImmutableDictionary<(Address, Currency), BigInteger>)` to + `IAccount(IAccountState, IImmutableHashSet<(Address, Currency)>)`. + [[#3537]] ### Backward-incompatible network protocol changes @@ -52,6 +56,7 @@ be compatible with this version, specifically, those that ran with [#3523]: https://github.com/planetarium/libplanet/pull/3523 [#3529]: https://github.com/planetarium/libplanet/pull/3529 [#3535]: https://github.com/planetarium/libplanet/pull/3535 +[#3537]: https://github.com/planetarium/libplanet/pull/3537 [Libplanet 2.0.0]: https://www.nuget.org/packages/Libplanet/2.0.0 diff --git a/Libplanet.Action/ActionEvaluator.cs b/Libplanet.Action/ActionEvaluator.cs index 46fb5c436af..12beb4a68c8 100644 --- a/Libplanet.Action/ActionEvaluator.cs +++ b/Libplanet.Action/ActionEvaluator.cs @@ -313,12 +313,9 @@ IActionContext CreateActionContext(IAccount newPrevState) state = feeCollector.Refund(state); state = feeCollector.Reward(state); - state = state is Account a - ? new Account( - new AccountState(stateStore.Commit(a.Trie)), - a.TotalUpdatedFungibles) - : throw new InvalidOperationException( - $"Internal {nameof(IAccount)} is not of valid type: {state.GetType()}"); + state = new Account( + new AccountState(stateStore.Commit(state.Trie)), + state.TotalUpdatedFungibleAssets); if (!state.Trie.Recorded) { diff --git a/Libplanet.Action/State/Account.cs b/Libplanet.Action/State/Account.cs index c9c5e3067d9..5d455c0dcec 100644 --- a/Libplanet.Action/State/Account.cs +++ b/Libplanet.Action/State/Account.cs @@ -21,27 +21,23 @@ public class Account : IAccount private readonly IAccountState _baseState; public Account(IAccountState baseState) - : this(baseState, ImmutableDictionary<(Address, Currency), BigInteger>.Empty) + : this(baseState, ImmutableHashSet<(Address, Currency)>.Empty) { } public Account( IAccountState baseState, - IImmutableDictionary<(Address, Currency), BigInteger> totalUpdatedFungibles) + IImmutableSet<(Address, Currency)> totalUpdatedFungibleAssets) { _baseState = baseState; - TotalUpdatedFungibles = totalUpdatedFungibles; + TotalUpdatedFungibleAssets = totalUpdatedFungibleAssets; } /// public ITrie Trie => _baseState.Trie; /// - public IImmutableSet<(Address, Currency)> TotalUpdatedFungibleAssets => - TotalUpdatedFungibles.Keys.ToImmutableHashSet(); - - public IImmutableDictionary<(Address, Currency), BigInteger> TotalUpdatedFungibles - { get; } + public IImmutableSet<(Address, Currency)> TotalUpdatedFungibleAssets { get; } /// [Pure] @@ -190,7 +186,7 @@ private Account UpdateState( new Account( new AccountState( Trie.Set(ToStateKey(address), value)), - TotalUpdatedFungibles); + TotalUpdatedFungibleAssets); [Pure] private Account UpdateFungibleAssets( @@ -203,18 +199,18 @@ private Account UpdateFungibleAssets( Trie .Set(ToFungibleAssetKey(address, currency), new Integer(amount)) .Set(ToTotalSupplyKey(currency), new Integer(sa))), - TotalUpdatedFungibles.SetItem((address, currency), amount)) + TotalUpdatedFungibleAssets.Add((address, currency))) : new Account( new AccountState( Trie.Set(ToFungibleAssetKey(address, currency), new Integer(amount))), - TotalUpdatedFungibles.SetItem((address, currency), amount)); + TotalUpdatedFungibleAssets.Add((address, currency))); [Pure] private Account UpdateValidatorSet(ValidatorSet validatorSet) => new Account( new AccountState( Trie.Set(ValidatorSetKey, validatorSet.Bencoded)), - TotalUpdatedFungibles); + TotalUpdatedFungibleAssets); [Pure] private IAccount TransferAssetV0(