-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
76 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using Neo.IO; | ||
using Neo.Persistence; | ||
using System.IO; | ||
|
||
namespace Neo.Consensus | ||
{ | ||
internal static class Helper | ||
{ | ||
/// <summary> | ||
/// Prefix for saving consensus state. | ||
/// </summary> | ||
public const byte CN_Context = 0xf4; | ||
|
||
public static void Save(this IConsensusContext context, Store store) | ||
{ | ||
store.PutSync(CN_Context, new byte[0], context.ToArray()); | ||
} | ||
|
||
public static bool Load(this IConsensusContext context, Store store) | ||
{ | ||
byte[] data = store.Get(CN_Context, new byte[0]); | ||
if (data is null) return false; | ||
using (MemoryStream ms = new MemoryStream(data, false)) | ||
using (BinaryReader reader = new BinaryReader(ms)) | ||
{ | ||
try | ||
{ | ||
context.Deserialize(reader); | ||
} | ||
catch | ||
{ | ||
return false; | ||
} | ||
return true; | ||
} | ||
} | ||
} | ||
} |
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