Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1030 from moreal/feature/mpt-debugger
feat(mpt): provide API to calculate state root hash in the action execution
- Loading branch information
Showing
20 changed files
with
219 additions
and
91 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
This file was deleted.
Oops, something went wrong.
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
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
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
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
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,49 @@ | ||
#nullable enable | ||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using System.Linq; | ||
using Bencodex.Types; | ||
using Libplanet.Assets; | ||
using static Libplanet.Blockchain.KeyConverters; | ||
|
||
namespace Libplanet.Action | ||
{ | ||
internal static class IAccountStateDeltaExtensions | ||
{ | ||
internal static IImmutableDictionary<Address, IValue> GetUpdatedStates( | ||
this IAccountStateDelta delta | ||
) | ||
{ | ||
return delta.StateUpdatedAddresses.Select(address => | ||
new KeyValuePair<Address, IValue>( | ||
address, | ||
delta.GetState(address)! | ||
) | ||
).ToImmutableDictionary(); | ||
} | ||
|
||
internal static IImmutableDictionary<(Address, Currency), FungibleAssetValue> | ||
GetUpdatedBalances(this IAccountStateDelta delta) => | ||
delta.UpdatedFungibleAssets.SelectMany(kv => | ||
kv.Value.Select(currency => | ||
new KeyValuePair<(Address, Currency), FungibleAssetValue>( | ||
(kv.Key, currency), | ||
delta.GetBalance(kv.Key, currency) | ||
) | ||
) | ||
).ToImmutableDictionary(); | ||
|
||
internal static IImmutableDictionary<string, IValue> GetUpdatedRawStates( | ||
this IAccountStateDelta delta) => | ||
delta.GetUpdatedStates() | ||
.Select(pair => | ||
new KeyValuePair<string, IValue>( | ||
ToStateKey(pair.Key), | ||
pair.Value)) | ||
.Union( | ||
delta.GetUpdatedBalances().Select(pair => | ||
new KeyValuePair<string, IValue>( | ||
ToFungibleAssetKey(pair.Key), | ||
(Integer)pair.Value.RawValue))).ToImmutableDictionary(); | ||
} | ||
} |
Oops, something went wrong.