-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merkle foundations with pre-commit hook
- Loading branch information
Showing
3 changed files
with
87 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using Paprika.Data; | ||
using Paprika.Utils; | ||
|
||
namespace Paprika.Chain; | ||
|
||
/// <summary> | ||
/// A pre-commit behavior run by <see cref="Blockchain"/> component just before commiting a <see cref="IWorldState"/> | ||
/// with <see cref="IWorldState.Commit"/>. Useful to provide concerns, like the Merkle construct and others. | ||
/// </summary> | ||
public interface IPreCommitBehavior | ||
{ | ||
/// <summary> | ||
/// Executed just before commit. | ||
/// </summary> | ||
/// <param name="commit">The object representing the commit.</param> | ||
public void BeforeCommit(ICommit commit); | ||
} | ||
|
||
/// <summary> | ||
/// The set of changes applied by <see cref="IWorldState"/>. | ||
/// Allows for additional modifications of the data just before the commit. | ||
/// </summary> | ||
/// <remarks> | ||
/// To access all the keys use the enumerator: | ||
/// | ||
/// public static void Foreach(this ICommit commit) | ||
/// { | ||
/// foreach (var key in commit) | ||
/// { | ||
/// key. | ||
/// } | ||
/// } | ||
/// </remarks> | ||
public interface ICommit | ||
{ | ||
/// <summary> | ||
/// Tries to retrieve the result stored under the given key. | ||
/// </summary> | ||
/// <returns> | ||
/// Whether the retrieval was successful. | ||
/// </returns> | ||
/// <remarks> | ||
/// If successful, returns a result as an owner. Must be disposed properly. | ||
/// </remarks> | ||
public bool TryGet(in Key key, out ReadOnlySpanOwner<byte> result); | ||
|
||
/// <summary> | ||
/// Sets the value under the given key. | ||
/// </summary> | ||
void Set(in Key key, in ReadOnlySpan<byte> payload); | ||
|
||
/// <summary> | ||
/// Gets the enumerator for the keys in the given commit. | ||
/// </summary> | ||
/// <returns></returns> | ||
IKeyEnumerator GetEnumerator(); | ||
} | ||
|
||
/// <summary> | ||
/// The <see cref="Key"/> enumerator. | ||
/// </summary> | ||
public interface IKeyEnumerator : IDisposable | ||
{ | ||
/// <summary> | ||
/// The current key. | ||
/// </summary> | ||
ref readonly Key Current { get; } | ||
|
||
/// <summary> | ||
/// Moves to the next. | ||
/// </summary> | ||
public bool MoveNext(); | ||
} | ||
|