-
Notifications
You must be signed in to change notification settings - Fork 144
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 #3842 from greymistcube/refactor/memory-next-state…
…-root-hash ♻️ In memory "next state root hash"
- Loading branch information
Showing
24 changed files
with
203 additions
and
285 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 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
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,53 @@ | ||
using System.Security.Cryptography; | ||
using Libplanet.Action.State; | ||
using Libplanet.Blockchain; | ||
using Libplanet.Common; | ||
using Libplanet.Types.Blocks; | ||
|
||
namespace Libplanet.Tests | ||
{ | ||
public static class BlockChainExtensions | ||
{ | ||
/// <summary> | ||
/// Returns an <see cref="IWorldState"/> resulting from the execution of | ||
/// the tip of <paramref name="blockChain"/>. | ||
/// </summary> | ||
/// <param name="blockChain">The <see cref="BlockChain"/> to search.</param> | ||
/// <returns>An <see cref="IWorldState"/> resulting from the execution of | ||
/// the tip of <paramref name="blockChain"/>.</returns> | ||
public static IWorldState GetNextWorldState(this BlockChain blockChain) => | ||
blockChain.GetNextStateRootHash() is HashDigest<SHA256> stateRootHash | ||
? blockChain.GetWorldState(stateRootHash) | ||
: null; | ||
|
||
/// <summary> | ||
/// Returns an <see cref="IWorldState"/> resulting from the execution of | ||
/// a <see cref="Block"/> associated with given <paramref name="index"/> | ||
/// from <paramref name="blockChain"/>. | ||
/// </summary> | ||
/// <param name="blockChain">The <see cref="BlockChain"/> to search.</param> | ||
/// <param name="index">The index of a <see cref="Block"/> to search.</param> | ||
/// <returns>An <see cref="IWorldState"/> resulting from the execution of | ||
/// a <see cref="Block"/> associated with given <paramref name="index"/>.</returns> | ||
public static IWorldState GetNextWorldState(this BlockChain blockChain, long index) => | ||
blockChain.GetNextStateRootHash(index) is HashDigest<SHA256> stateRootHash | ||
? blockChain.GetWorldState(stateRootHash) | ||
: null; | ||
|
||
/// <summary> | ||
/// Returns an <see cref="IWorldState"/> resulting from the execution of | ||
/// a <see cref="Block"/> associated with given <paramref name="blockHash"/> | ||
/// from <paramref name="blockChain"/>. | ||
/// </summary> | ||
/// <param name="blockChain">The <see cref="BlockChain"/> to search.</param> | ||
/// <param name="blockHash">The <see cref="BlockHash"/> to search.</param> | ||
/// <returns>An <see cref="IWorldState"/> resulting from the execution of | ||
/// a <see cref="Block"/> associated with given <paramref name="blockHash"/>.</returns> | ||
public static IWorldState GetNextWorldState( | ||
this BlockChain blockChain, | ||
BlockHash blockHash) => | ||
blockChain.GetNextStateRootHash(blockHash) is HashDigest<SHA256> stateRootHash | ||
? blockChain.GetWorldState(stateRootHash) | ||
: null; | ||
} | ||
} |
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
Oops, something went wrong.