Skip to content
This repository was archived by the owner on Dec 4, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
0c88e72
Blazor working commit
JayArrowz Oct 16, 2019
3a2e428
Add blazor module
JayArrowz Oct 17, 2019
be42516
Cleanup
JayArrowz Oct 17, 2019
88e65ef
Update MempoolViewer.razor
JayArrowz Oct 17, 2019
3f1405e
Update SendTransactionForm.razor.cs
JayArrowz Oct 17, 2019
fc75e15
Update MempoolViewer.razor
JayArrowz Oct 17, 2019
cfa7e6c
Build fix (#21)
nshCore Oct 22, 2019
68d8851
now apply PR comments 🤞
monsieurleberre Oct 22, 2019
ef2f876
WIP - @monsieurleberre
nshCore Oct 22, 2019
8c63dda
now apply PR comments 🤞 (#22)
nshCore Oct 22, 2019
039064b
Register IHashingModule
nshCore Oct 22, 2019
c617cc8
some stuff has gone async
monsieurleberre Oct 23, 2019
9529603
some stuff has gone async
monsieurleberre Oct 23, 2019
dc5d400
another temp submodule update
monsieurleberre Oct 23, 2019
f6047ac
Merge pull request #23 from catalyst-network/submodule-update
nshCore Oct 23, 2019
f2336bc
Merge remote-tracking branch 'origin/develop' into try-fix-api-module
monsieurleberre Oct 24, 2019
ba179ba
submodule back on develop
monsieurleberre Oct 24, 2019
6c7a213
Merge pull request #24 from catalyst-network/try-fix-api-module
nshCore Oct 24, 2019
123512e
try remove config files
monsieurleberre Oct 24, 2019
3913f1e
Merge branch 'develop' into 1071-fix-config-files
monsieurleberre Oct 24, 2019
69a0f35
.AssignableTo<IRpcRequestObserver>().As<IRpcRequestObserver>() not Re…
monsieurleberre Oct 24, 2019
f827a54
Merge branch '1071-fix-config-files' of https://github.com/catalyst-n…
monsieurleberre Oct 24, 2019
fbc33bc
try remove config files (#25)
nshCore Oct 24, 2019
63bf5b8
Merge branch 'build_fix' into blazor-v2
nshCore Oct 24, 2019
19d164a
update submodule and add registrations
monsieurleberre Oct 30, 2019
55d33b0
tests update
monsieurleberre Oct 30, 2019
c16f371
Merge pull request #26 from catalyst-network/update-submodule-dao
nshCore Nov 4, 2019
1d37ff5
Merge branch 'develop' into blazor-v2
JayArrowz Nov 8, 2019
4b11c5f
Commit fixes
JayArrowz Nov 8, 2019
e3a2eb0
Revert "Commit fixes"
JayArrowz Nov 8, 2019
a284e07
Revert "Merge branch 'develop' into blazor-v2"
JayArrowz Nov 8, 2019
9acd2cc
Update Catalyst.Node
JayArrowz Nov 8, 2019
27eb3a1
Blazor fix
JayArrowz Nov 8, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/Catalyst.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using Autofac;
using Catalyst.Abstractions.Cli;
using Catalyst.Core.Lib.Kernel;
Expand Down Expand Up @@ -59,26 +60,26 @@ public static int Main(string[] args)
// Parse the arguments.
Parser.Default
.ParseArguments<Options>(args)
.WithParsed(Run);
.WithParsed(o => _ = RunAsync(o));

return Environment.ExitCode;
}

private static void Run(Options options)
private static async Task RunAsync(Options options)
{
Kernel.Logger.Information("Catalyst.Cli started with process id {0}",
Process.GetCurrentProcess().Id.ToString());

try
{
Kernel.WithDataDirectory()
await Kernel.WithDataDirectory()
.WithSerilogConfigFile()
.WithConfigCopier(new CliConfigCopier())
.WithConfigurationFile(CliConstants.ShellNodesConfigFile)
.WithConfigurationFile(CliConstants.ShellConfigFile)
.WithNetworksConfigFile(NetworkType.Devnet, options.OverrideNetworkFile)
.BuildKernel()
.StartCustom(StartCli);
.StartCustomAsync(StartCliAsync);

Environment.ExitCode = 0;
}
Expand All @@ -90,7 +91,7 @@ private static void Run(Options options)
}


private static void StartCli(Kernel kernel)
private static Task StartCliAsync(Kernel kernel)
{
const int bufferSize = 1024 * 67 + 128;

Expand All @@ -110,6 +111,7 @@ private static void StartCli(Kernel kernel)

kernel.Instance.Resolve<ICatalystCli>()
.RunConsole(kernel.CancellationTokenProvider.CancellationTokenSource.Token);
return Task.CompletedTask;
}
}
}
10 changes: 10 additions & 0 deletions src/Catalyst.Modules.Server.Blazor/App.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Router AppAssembly="@typeof(BlazorServerModule).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
</Found>
<NotFound>
<LayoutView Layout="@typeof(MainLayout)">
<p>Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
128 changes: 128 additions & 0 deletions src/Catalyst.Modules.Server.Blazor/AutofacServiceProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
using Autofac;
using Autofac.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using System;

namespace Catalyst.Modules.Server.Blazor
{

/// <summary>
/// A factory for creating a <see cref="ContainerBuilder"/> and an <see cref="IServiceProvider" />.
/// </summary>
public class AutofacServiceProviderFactory : IServiceProviderFactory<ContainerBuilder>
{
private readonly ContainerBuilder _containerBuilder;
private AutofacServiceProvider _autofacServiceProvider;

public AutofacServiceProviderFactory(ContainerBuilder containerBuilder)
{
_containerBuilder = containerBuilder;
}

/// <summary>
/// Creates a container builder from an <see cref="IServiceCollection" />.
/// </summary>
/// <param name="services">The collection of services.</param>
/// <returns>A container builder that can be used to create an <see cref="IServiceProvider" />.</returns>
public ContainerBuilder CreateBuilder(IServiceCollection services)
{
_containerBuilder.Populate(services);
return _containerBuilder;
}

public void SetContainer(IContainer container)
{
_autofacServiceProvider.LifetimeScope = container;
}


/// <summary>
/// Creates an <see cref="IServiceProvider" /> from the container builder.
/// </summary>
/// <param name="containerBuilder">The container builder.</param>
/// <returns>An <see cref="IServiceProvider" />.</returns>
public IServiceProvider CreateServiceProvider(ContainerBuilder containerBuilder)
{
if (containerBuilder == null) throw new ArgumentNullException(nameof(containerBuilder));

return (_autofacServiceProvider = new AutofacServiceProvider());
}
}

/// <summary>
/// Autofac implementation of the ASP.NET Core <see cref="IServiceProvider"/>.
/// </summary>
/// <seealso cref="System.IServiceProvider" />
/// <seealso cref="Microsoft.Extensions.DependencyInjection.ISupportRequiredService" />
internal class AutofacServiceProvider : IServiceProvider, ISupportRequiredService, IDisposable
{
public ILifetimeScope LifetimeScope { get; set; }

private bool _disposed = false;

/// <summary>
/// Gets service of type <paramref name="serviceType" /> from the
/// <see cref="AutofacServiceProvider" /> and requires it be present.
/// </summary>
/// <param name="serviceType">
/// An object that specifies the type of service object to get.
/// </param>
/// <returns>
/// A service object of type <paramref name="serviceType" />.
/// </returns>
/// <exception cref="Autofac.Core.Registration.ComponentNotRegisteredException">
/// Thrown if the <paramref name="serviceType" /> isn't registered with the container.
/// </exception>
/// <exception cref="Autofac.Core.DependencyResolutionException">
/// Thrown if the object can't be resolved from the container.
/// </exception>
public object GetRequiredService(Type serviceType)
{
return LifetimeScope.Resolve(serviceType);
}

/// <summary>
/// Gets the service object of the specified type.
/// </summary>
/// <param name="serviceType">
/// An object that specifies the type of service object to get.
/// </param>
/// <returns>
/// A service object of type <paramref name="serviceType" />; or <see langword="null" />
/// if there is no service object of type <paramref name="serviceType" />.
/// </returns>
public object GetService(Type serviceType)
{
return LifetimeScope.ResolveOptional(serviceType);
}

/// <summary>
/// Releases unmanaged and - optionally - managed resources.
/// </summary>
/// <param name="disposing">
/// <see langword="true" /> to release both managed and unmanaged resources;
/// <see langword="false" /> to release only unmanaged resources.
/// </param>
protected virtual void Dispose(bool disposing)
{
if (!this._disposed)
{
if (disposing)
{
LifetimeScope.Dispose();
}

this._disposed = true;
}
}

/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}
}
}
82 changes: 82 additions & 0 deletions src/Catalyst.Modules.Server.Blazor/BlazorServerModule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using System;
using System.Diagnostics;
using Autofac;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Module = Autofac.Module;

namespace Catalyst.Modules.Server.Blazor
{
public class BlazorServerModule : Module
{
public static void Main(string[] args) { }
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed for some reason without it build errors.


private IHostBuilder _hostBuilder;
private AutofacServiceProviderFactory _autofacServiceProviderFactory;

protected override void Load(ContainerBuilder builder)
{
_autofacServiceProviderFactory = new AutofacServiceProviderFactory(builder);
_hostBuilder = CreateHostBuilder();
try
{
_hostBuilder.Build();
}
catch (Exception)
{
//Ignored exception as the server cannot start without container being built
}

builder.RegisterBuildCallback(Start);

}

private void Start(IContainer container)
{
_autofacServiceProviderFactory.SetContainer(container);
_ = container.Resolve<IHost>().RunAsync().ConfigureAwait(false);
}

public IHostBuilder CreateHostBuilder() =>
Host.CreateDefaultBuilder(null)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.Configure(Configure);
})
.UseServiceProviderFactory(_autofacServiceProviderFactory)
.ConfigureServices(ConfigureServices);

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app)
{
app.UseExceptionHandler("/Error");

// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();

app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();

app.UseEndpoints(endpoints =>
{
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage("/_Host");
});
}

// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
var listener = new DiagnosticListener("Microsoft.AspNetCore");
services.AddSingleton(listener);
services.AddSingleton<DiagnosticSource>(listener);
services.AddRazorPages();
services.AddServerSideBlazor();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<None Include="wwwroot\css\bootstrap\bootstrap.min.css" />
<None Include="wwwroot\css\bootstrap\bootstrap.min.css.map" />
<None Include="wwwroot\css\open-iconic\FONT-LICENSE" />
<None Include="wwwroot\css\open-iconic\font\css\open-iconic-bootstrap.min.css" />
<None Include="wwwroot\css\open-iconic\font\fonts\open-iconic.eot" />
<None Include="wwwroot\css\open-iconic\font\fonts\open-iconic.otf" />
<None Include="wwwroot\css\open-iconic\font\fonts\open-iconic.svg" />
<None Include="wwwroot\css\open-iconic\font\fonts\open-iconic.ttf" />
<None Include="wwwroot\css\open-iconic\font\fonts\open-iconic.woff" />
<None Include="wwwroot\css\open-iconic\ICON-LICENSE" />
<None Include="wwwroot\css\open-iconic\README.md" />
<None Include="wwwroot\css\site.css" />
<None Include="wwwroot\favicon.ico" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Autofac" Version="4.8.1" />
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="4.3.1" />
</ItemGroup>

<ItemGroup>
<None Include="$(ProjectDir)wwwroot\**" CopyToOutputDirectory="PreserveNewest" />

</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\submodules\Catalyst.Node\src\Catalyst.Abstractions\Catalyst.Abstractions.csproj" />
<ProjectReference Include="..\..\submodules\Catalyst.Node\src\Catalyst.Core.Lib\Catalyst.Core.Lib.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@inherits SendTransactionFormBase

<EditForm Model="@Model" OnValidSubmit="@HandleValidSubmit">
<DataAnnotationsValidator />
<ValidationSummary />
<p>
<label for="amount">Amount: </label>
<InputNumber @bind-Value="Model.Amount" />
</p>

<button type="submit">Submit</button>
</EditForm>
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using Catalyst.Abstractions.IO.Events;
using Catalyst.Abstractions.KeySigner;
using Catalyst.Abstractions.P2P;
using Catalyst.Core.Lib.Extensions;
using Catalyst.Core.Lib.IO.Messaging.Correlation;
using Catalyst.Modules.Server.Blazor.Models;
using Catalyst.Protocol.Cryptography;
using Catalyst.Protocol.Wire;
using Google.Protobuf;
using Google.Protobuf.WellKnownTypes;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using System;
using Catalyst.Core.Lib.Util;
using Catalyst.Protocol.Transaction;

namespace Catalyst.Modules.Server.Blazor.Components
{
public class SendTransactionFormBase : ComponentBase
{
public SendTransactionModel Model { get; set; } = new SendTransactionModel();

[Inject]
public IJSRuntime JsRuntime { get; set; }

[Inject]
public IKeySigner KeySigner { get; set; }

[Inject]
public IPeerSettings PeerSettings { get; set; }

[Inject]
public ITransactionReceivedEvent TransactionReceivedEvent { get; set; }

public void HandleValidSubmit()
{
//TODO: Currently there is no method to actually set the transaction amount
var transaction = new TransactionBroadcast {Timestamp = Timestamp.FromDateTime(DateTime.UtcNow)};
transaction.PublicEntries.Add(new PublicEntry
{
Base = new BaseEntry
{
SenderPublicKey = PeerSettings.PublicKey.KeyToByteString()
}
});
var signingContext = new SigningContext
{
NetworkType = PeerSettings.NetworkType,
SignatureType = SignatureType.ProtocolPeer
};

var signature = KeySigner.Sign(transaction.ToByteArray(), signingContext);
transaction.Signature = new Signature {
RawBytes = signature.SignatureBytes.ToByteString(),
SigningContext = signingContext
};
var status = TransactionReceivedEvent
.OnTransactionReceived(transaction.ToProtocolMessage(PeerSettings.PeerId, CorrelationId.GenerateCorrelationId()));
JsRuntime.InvokeAsync<object>("window.alert", $"Transaction Status: {status.ToString()}").ConfigureAwait(false);
Model = new SendTransactionModel();
this.StateHasChanged();
}

}
}
Loading