This repository was archived by the owner on Dec 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Add blazor module #20
Open
JayArrowz
wants to merge
33
commits into
build_fix
Choose a base branch
from
blazor-v2
base: build_fix
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
0c88e72
Blazor working commit
JayArrowz 3a2e428
Add blazor module
JayArrowz be42516
Cleanup
JayArrowz 88e65ef
Update MempoolViewer.razor
JayArrowz 3f1405e
Update SendTransactionForm.razor.cs
JayArrowz fc75e15
Update MempoolViewer.razor
JayArrowz cfa7e6c
Build fix (#21)
nshCore 68d8851
now apply PR comments 🤞
monsieurleberre ef2f876
WIP - @monsieurleberre
nshCore 8c63dda
now apply PR comments 🤞 (#22)
nshCore 039064b
Register IHashingModule
nshCore c617cc8
some stuff has gone async
monsieurleberre 9529603
some stuff has gone async
monsieurleberre dc5d400
another temp submodule update
monsieurleberre f6047ac
Merge pull request #23 from catalyst-network/submodule-update
nshCore f2336bc
Merge remote-tracking branch 'origin/develop' into try-fix-api-module
monsieurleberre ba179ba
submodule back on develop
monsieurleberre 6c7a213
Merge pull request #24 from catalyst-network/try-fix-api-module
nshCore 123512e
try remove config files
monsieurleberre 3913f1e
Merge branch 'develop' into 1071-fix-config-files
monsieurleberre 69a0f35
.AssignableTo<IRpcRequestObserver>().As<IRpcRequestObserver>() not Re…
monsieurleberre f827a54
Merge branch '1071-fix-config-files' of https://github.com/catalyst-n…
monsieurleberre fbc33bc
try remove config files (#25)
nshCore 63bf5b8
Merge branch 'build_fix' into blazor-v2
nshCore 19d164a
update submodule and add registrations
monsieurleberre 55d33b0
tests update
monsieurleberre c16f371
Merge pull request #26 from catalyst-network/update-submodule-dao
nshCore 1d37ff5
Merge branch 'develop' into blazor-v2
JayArrowz 4b11c5f
Commit fixes
JayArrowz e3a2eb0
Revert "Commit fixes"
JayArrowz a284e07
Revert "Merge branch 'develop' into blazor-v2"
JayArrowz 9acd2cc
Update Catalyst.Node
JayArrowz 27eb3a1
Blazor fix
JayArrowz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,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
128
src/Catalyst.Modules.Server.Blazor/AutofacServiceProvider.cs
This file contains hidden or 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,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); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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,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) { } | ||
|
|
||
| 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(); | ||
| } | ||
| } | ||
| } | ||
38 changes: 38 additions & 0 deletions
38
src/Catalyst.Modules.Server.Blazor/Catalyst.Modules.Server.Blazor.csproj
This file contains hidden or 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,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> |
12 changes: 12 additions & 0 deletions
12
src/Catalyst.Modules.Server.Blazor/Components/SendTransactionForm.razor
This file contains hidden or 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,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> |
65 changes: 65 additions & 0 deletions
65
src/Catalyst.Modules.Server.Blazor/Components/SendTransactionForm.razor.cs
This file contains hidden or 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,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(); | ||
| } | ||
|
|
||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.