Commit 390de8e5 authored by Clint Mourlevat's avatar Clint Mourlevat

Vanity generation working

parent 153252bb
......@@ -20,7 +20,7 @@ namespace Stratis.Guru.Controllers
public class HomeController : Controller
{
private readonly IMemoryCache _memoryCache;
private IAsk _ask;
private readonly IAsk _ask;
public HomeController(IMemoryCache memoryCache, IAsk ask)
{
......@@ -65,9 +65,12 @@ namespace Stratis.Guru.Controllers
[HttpPost]
[Route("vanity")]
public IActionResult Vanity(Vanity vanity)
{
if (ModelState.IsValid)
{
_ask.NewVanity(vanity);
ViewBag.Succeed = true;
}
return View();
}
......
......@@ -5,16 +5,16 @@ namespace Stratis.Guru.Modules
{
public class Ask : IAsk
{
private Queue<Vanity> VanityAsking = new Queue<Vanity>();
private readonly Queue<Vanity> _vanities = new Queue<Vanity>();
public void NewVanity(Vanity vanity)
{
VanityAsking.Enqueue(vanity);
_vanities.Enqueue(vanity);
}
public Queue<Vanity> GetVanities()
{
return VanityAsking;
return _vanities;
}
}
}
\ No newline at end of file
......@@ -19,6 +19,7 @@ namespace Stratis.Guru
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseUrls("http://localhost:1989")
.UseStartup<Startup>();
}
}
\ No newline at end of file
......@@ -4,7 +4,6 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Hosting;
using Newtonsoft.Json;
using RestSharp;
using Stratis.Guru.Hubs;
......@@ -15,17 +14,18 @@ namespace Stratis.Guru.Services
private readonly IMemoryCache _memoryCache;
private readonly IHubContext<UpdateHub> _hubContext;
private readonly UpdateHub _hub;
private readonly System.Timers.Timer updateTimer;
public TickerService(IMemoryCache memoryCache, UpdateHub hub, IHubContext<UpdateHub> hubContext)
{
_memoryCache = memoryCache;
_hub = hub;
_hubContext = hubContext;
updateTimer = new System.Timers.Timer();
}
public Task StartAsync(CancellationToken cancellationToken)
{
var updateTimer = new System.Timers.Timer();
updateTimer.Interval = 10;
updateTimer.Enabled = true;
updateTimer.Elapsed += async (sender, args) =>
......@@ -48,6 +48,8 @@ namespace Stratis.Guru.Services
public void Dispose()
{
updateTimer?.Stop();
updateTimer?.Dispose();;
}
}
}
\ No newline at end of file
......@@ -10,28 +10,38 @@ namespace Stratis.Guru.Services
{
public class VanityService : IHostedService, IDisposable
{
private IMemoryCache _memoryCache;
private IAsk _ask;
private readonly IAsk _ask;
public VanityService(IMemoryCache memoryCache, IAsk ask)
public VanityService(IAsk ask)
{
_memoryCache = memoryCache;
_ask = ask;
}
public Task StartAsync(CancellationToken cancellationToken)
{
/*while (true)
Task.Run(() =>
{
while (true)
{
if (_ask.GetVanities().Count > 0)
{
var getVanity = _ask.GetVanities().Dequeue();
while (true)
{
var stratisKey = new Key();
var stratisAddress = stratisKey.GetWif(Network.StratisMain).PubKey.GetAddress(Network.StratisMain).ToString();
if (stratisAddress.ToLower().StartsWith("stra"))
if (stratisAddress.ToLower().StartsWith(string.Concat("s", getVanity.Prefix)))
{
Console.WriteLine(stratisAddress);
Console.WriteLine(stratisAddress + " - " + getVanity.Email);
break;
}
}
}
//Thread.Sleep((int) TimeSpan.FromSeconds(10).TotalMilliseconds);
}*/
Thread.Sleep((int) TimeSpan.FromSeconds(10).TotalMilliseconds);
}
}, cancellationToken);
return Task.CompletedTask;
}
......@@ -42,7 +52,6 @@ namespace Stratis.Guru.Services
public void Dispose()
{
}
}
}
\ No newline at end of file
......@@ -43,11 +43,10 @@ namespace Stratis.Guru
services.AddMemoryCache();
services.AddTransient<UpdateHub>();
services.AddTransient<IAsk, Ask>();
services.AddHostedService<TickerService>();
services.AddHostedService<VanityService>();
services.AddTransient<UpdateHub>();
services.AddSingleton<IAsk, Ask>();
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
......
......@@ -5,6 +5,8 @@
</PropertyGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.DotNet.Watcher.Tools" Version="2.0.0" />
<PackageReference Include="BuildBundlerMinifier" Version="2.8.391" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" />
......
......@@ -47,7 +47,8 @@
{
<i class="fa fa-check text-success fa-5x"></i>
<h1>Process Started</h1>
<p>The process has been taken in hand by our vanity service !</p>
<p class="m-2">The process has been taken in hand by our vanity service !</p>
<p class="small text-muted extra">You can leave, you will informed by email, please don't refresh the page.</p>
}
</div>
</div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment