-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add GenesisBlockPath option to GenesisOptions
- Loading branch information
Showing
7 changed files
with
145 additions
and
40 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
43 changes: 43 additions & 0 deletions
43
sdk/node/Libplanet.Node/Options/GenesisOptionsValidator.cs
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,43 @@ | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace Libplanet.Node.Options; | ||
|
||
internal sealed class GenesisOptionsValidator : OptionsValidatorBase<GenesisOptions> | ||
{ | ||
protected override void OnValidate(string? name, GenesisOptions options) | ||
{ | ||
if (options.GenesisBlockPath != string.Empty) | ||
{ | ||
if (options.GenesisKey != string.Empty) | ||
{ | ||
var message = $"{nameof(options.GenesisKey)} cannot be used with " + | ||
$"{nameof(options.GenesisBlockPath)}."; | ||
throw new OptionsValidationException( | ||
optionsName: name ?? string.Empty, | ||
optionsType: typeof(GenesisOptions), | ||
failureMessages: [message]); | ||
} | ||
|
||
if (options.Validators.Length > 0) | ||
{ | ||
var message = $"{nameof(options.Validators)} cannot be used with " + | ||
$"{nameof(options.GenesisBlockPath)}."; | ||
throw new OptionsValidationException( | ||
optionsName: name ?? string.Empty, | ||
optionsType: typeof(GenesisOptions), | ||
failureMessages: [message]); | ||
} | ||
|
||
if (!Uri.TryCreate(options.GenesisBlockPath, UriKind.Absolute, out _) | ||
&& !File.Exists(options.GenesisBlockPath)) | ||
{ | ||
var message = $"{nameof(options.GenesisBlockPath)} must be a Uri or a existing " + | ||
$"file path."; | ||
throw new OptionsValidationException( | ||
optionsName: name ?? string.Empty, | ||
optionsType: typeof(GenesisOptions), | ||
failureMessages: [message]); | ||
} | ||
} | ||
} | ||
} |
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