2024-08-21 11:59:54 +00:00
|
|
|
using ArgsUniform;
|
2024-08-21 09:34:54 +00:00
|
|
|
using System.Reflection;
|
|
|
|
|
2024-08-21 09:00:47 +00:00
|
|
|
namespace MarketInsights
|
|
|
|
{
|
|
|
|
public class Program
|
|
|
|
{
|
|
|
|
public static void Main(string[] args)
|
|
|
|
{
|
2024-08-21 11:59:54 +00:00
|
|
|
var uniformArgs = new ArgsUniform<Configuration>(PrintHelp, args);
|
|
|
|
var config = uniformArgs.Parse(true);
|
2024-08-21 13:03:20 +00:00
|
|
|
var cts = new CancellationTokenSource();
|
2024-08-21 11:59:54 +00:00
|
|
|
var appState = new AppState(config);
|
2024-08-21 13:03:20 +00:00
|
|
|
|
|
|
|
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);
|
2024-08-21 11:59:54 +00:00
|
|
|
|
2024-08-21 09:00:47 +00:00
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
|
2024-09-11 12:06:48 +00:00
|
|
|
var listenPort = Environment.GetEnvironmentVariable("APIPORT");
|
|
|
|
if (string.IsNullOrEmpty(listenPort)) listenPort = "31090";
|
|
|
|
|
|
|
|
builder.WebHost.ConfigureKestrel((context, options) =>
|
|
|
|
{
|
|
|
|
options.ListenAnyIP(Convert.ToInt32(listenPort));
|
|
|
|
});
|
|
|
|
|
2024-08-21 11:59:54 +00:00
|
|
|
builder.Services.AddSingleton(appState);
|
2024-08-21 09:00:47 +00:00
|
|
|
|
|
|
|
builder.Services.AddControllers();
|
|
|
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
|
|
|
builder.Services.AddEndpointsApiExplorer();
|
2024-08-21 09:34:54 +00:00
|
|
|
builder.Services.AddSwaggerGen(s =>
|
|
|
|
{
|
|
|
|
var xmlFilename = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
|
|
|
|
s.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFilename));
|
|
|
|
});
|
2024-08-21 09:00:47 +00:00
|
|
|
|
|
|
|
var app = builder.Build();
|
|
|
|
|
|
|
|
// Configure the HTTP request pipeline.
|
|
|
|
if (app.Environment.IsDevelopment())
|
|
|
|
{
|
|
|
|
app.UseSwagger();
|
|
|
|
app.UseSwaggerUI();
|
|
|
|
}
|
|
|
|
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
|
|
|
|
app.UseAuthorization();
|
|
|
|
|
|
|
|
app.MapControllers();
|
|
|
|
|
2024-09-11 12:06:48 +00:00
|
|
|
Console.WriteLine("MarketInsights listening on port " + listenPort);
|
|
|
|
|
2024-08-21 11:59:54 +00:00
|
|
|
updater.Run();
|
2024-08-21 09:00:47 +00:00
|
|
|
app.Run();
|
|
|
|
}
|
2024-08-21 11:59:54 +00:00
|
|
|
|
|
|
|
private static void PrintHelp()
|
|
|
|
{
|
|
|
|
Console.WriteLine("WebAPI for generating market overview for Codex network. Comes with OpenAPI swagger endpoint.");
|
2024-08-21 13:03:20 +00:00
|
|
|
|
|
|
|
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}");
|
2024-08-21 11:59:54 +00:00
|
|
|
}
|
2024-08-21 09:00:47 +00:00
|
|
|
}
|
|
|
|
}
|