This repository has been archived by the owner on Nov 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
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
3 changed files
with
60 additions
and
57 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using chia.dotnet; | ||
|
||
namespace Web2Gateway; | ||
|
||
/// <summary> | ||
/// Provides methods for interacting with the Chia blockchain. | ||
/// </summary> | ||
public sealed class ChiaConfig | ||
{ | ||
private readonly IConfiguration _configuration; | ||
private readonly ILogger<ChiaService> _logger; | ||
|
||
public ChiaConfig(ILogger<ChiaService> logger, IConfiguration configuration) => | ||
(_logger, _configuration) = (logger, configuration); | ||
|
||
private Config GetConfig() | ||
{ | ||
// first see if we have a config file path in the appsettings.json | ||
var configPath = _configuration.GetValue("App:chia_config_path", ""); | ||
if (!string.IsNullOrEmpty(configPath)) | ||
{ | ||
return Config.Open(configPath); | ||
} | ||
|
||
// if not use the chia default '~/.chia/mainnet/config/config.yaml' | ||
return Config.Open(); | ||
} | ||
|
||
public EndpointInfo GetDataLayerEndpoint() | ||
{ | ||
// first check user secrets for the data_layer connection | ||
// https://learn.microsoft.com/en-us/aspnet/core/security/app-secrets?view=aspnetcore-7.0&tabs=windows | ||
var dataLayerUri = _configuration.GetValue("data_layer_uri", "")!; | ||
if (!string.IsNullOrEmpty(dataLayerUri)) | ||
{ | ||
_logger.LogInformation($"Connecting to {dataLayerUri}"); | ||
return new EndpointInfo() | ||
{ | ||
Uri = new Uri(dataLayerUri), | ||
// when stored in an environment variable the newlines might be escaped | ||
Cert = _configuration.GetValue("data_layer_cert", "")!.Replace("\\n", "\n"), | ||
Key = _configuration.GetValue("data_layer_key", "")!.Replace("\\n", "\n") | ||
}; | ||
} | ||
else | ||
{ | ||
// if not present see if we can get it from the config file | ||
return GetConfig().GetEndpoint("data_layer"); | ||
} | ||
} | ||
} | ||
|
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