2
0
mirror of synced 2025-01-13 18:14:14 +00:00
2024-08-21 15:03:20 +02:00

75 lines
2.4 KiB
C#

using ArgsUniform;
using Microsoft.Extensions.Options;
using Nethereum.Model;
using System.Reflection;
namespace MarketInsights
{
public class Program
{
public static void Main(string[] args)
{
var uniformArgs = new ArgsUniform<Configuration>(PrintHelp, args);
var config = uniformArgs.Parse(true);
var cts = new CancellationTokenSource();
var appState = new AppState(config);
Console.CancelKeyPress += (s, e) =>
{
appState.Log.Log("Stopping...");
cts.Cancel();
e.Cancel = true;
};
var connector = GethConnector.GethConnector.Initialize(appState.Log);
if (connector == null) throw new Exception("Invalid Geth information");
var updater = new Updater(appState, connector.CodexContracts, cts.Token);
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddSingleton(appState);
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(s =>
{
var xmlFilename = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
s.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFilename));
});
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
updater.Run();
app.Run();
}
private static void PrintHelp()
{
Console.WriteLine("WebAPI for generating market overview for Codex network. Comes with OpenAPI swagger endpoint.");
var nl = Environment.NewLine;
Console.WriteLine($"Required environment variables: {nl}" +
$"'GETH_HOST'{nl}",
$"'GETH_HTTP_PORT'{nl}",
$"'CODEXCONTRACTS_MARKETPLACEADDRESS'{nl}",
$"'CODEXCONTRACTS_TOKENADDRESS'{nl}",
$"'CODEXCONTRACTS_ABI'{nl}");
}
}
}